FileDocCategorySizeDatePackage
DefaultNameConstraints.javaAPI DocExample4485Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.SQL.impl

DefaultNameConstraints

public class DefaultNameConstraints extends Object implements SQLNameConstraints

Fields Summary
private int
myNameLength
private boolean
myCaseSensitive
private String[]
myReservedWords
private static final char[]
vowels
private static final String[]
defaultReservedWords
Constructors Summary
public DefaultNameConstraints(int nameLength, boolean caseSensitive, String[] reservedWords)

    myNameLength = nameLength;
    myCaseSensitive = caseSensitive;
    myReservedWords = reservedWords;
  
public DefaultNameConstraints()

    this(18,false,defaultReservedWords);
  
Methods Summary
public intgetMaxColumnNameLength()

    return myNameLength;
  
public intgetMaxConstraintNameLength()

    return myNameLength;
  
public intgetMaxTableNameLength()

    return myNameLength;
  
public booleanisCaseSensitiveNames()

    return myCaseSensitive;
  
private static booleanisDigit(char ch)

    return Character.isDigit(ch);
  
public booleanisReservedWord(java.lang.String word)

    for(int i=0; i<myReservedWords.length; ++i ){
      if(myReservedWords[i].equalsIgnoreCase(word)){
        return true;
      }
    }
    return false;
  
private static booleanisVowel(char ch)

    for( int i=0; i<vowels.length; ++i ){
      if(ch == vowels[i]){
        return true;
      }
    }
    return false;
  
public java.lang.Stringshorten(java.lang.String name, int length)

    int originalLength = name.length();
    if(originalLength <= length){
      return name;
    }
    int vowelCount = 0;
    for(int i=0; i<name.length(); ++i){
      if(isVowel(name.charAt(i))){
        ++vowelCount;
      }
    }
    int needRemoveNotVowels = originalLength-vowelCount-length;
    int removedNotVowels = 0;
    int removedVowels = 0;
    StringBuffer result = new StringBuffer();
    for(int i=name.length()-1; i>=0; --i ){
      if( isDigit(name.charAt(i)) ){
        result.append(name.charAt(i));
      }
      else if(needRemoveNotVowels > removedNotVowels){
        if(isVowel(name.charAt(i))){
          ++removedVowels;
        }
        else{
          ++removedNotVowels;
        }
      }
      else if(originalLength-removedNotVowels-removedVowels > length && isVowel(name.charAt(i))){
        ++removedVowels;
      }
      else{
        result.append(name.charAt(i));
      }
    }
    return result.reverse().toString();