butler.sql.metadata
Class StringDatatype

java.lang.Object
  extended by butler.sql.metadata.DefaultDatatype
      extended by butler.sql.metadata.StringDatatype
All Implemented Interfaces:
Datatype
Direct Known Subclasses:
NumericDatatype, PasswordDatatype, StringDatatype.StringLikeDatatype, TextDatatype, YearDatatype

public class StringDatatype
extends DefaultDatatype

Simple implementation of Datatype for strings.

Author:
Fredrik Bertilsson

Nested Class Summary
static class StringDatatype.StringLikeDatatype
           
 
Field Summary
protected  int _maxLength
           
protected  int _minLength
           
protected  java.lang.String _partialRegex
           
protected  java.lang.String _regex
           
 
Constructor Summary
StringDatatype()
           
StringDatatype(int length)
           
StringDatatype(int minLength, int maxLength, java.lang.String regex)
           
StringDatatype(int minLength, int maxLength, java.lang.String regex, java.lang.String partialRegex)
           
 
Method Summary
 java.lang.Object db2obj(java.lang.Object obj)
          Converts from database format to java object format.
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
           
 Datatype getDatatype(Operator op)
          Datatype to be used for (sql) values other than equals.
 java.lang.Class getJavaClass()
          Returns the java class that is used for this datatype.
 StringDatatype getLikeDatatype()
          Deprecated. Use getDatatype(Operator.LIKE)
 int getMaxLength()
           
 int getMinLength()
           
 java.lang.String getPartialRegex()
           
 java.lang.String getRegex()
           
 int getSize()
           
 int getType()
           
 boolean isTrim()
           
 boolean isTruncate()
           
 java.lang.Object obj2db(java.lang.Object obj)
          Converts from java object format to database format.
static StringDatatype parseStringDatatype(org.dom4j.Element element)
           
 void setTrim(boolean trim)
           
 void setTruncate(boolean truncate)
           
 void toXML(org.xml.sax.ContentHandler handler)
          Builds an xml representation of this object.
 void validate(java.lang.Object value)
          Validated column value.
 java.lang.Object xml2obj(java.lang.String xml)
          Converts from xml string format to java object format.
 
Methods inherited from class butler.sql.metadata.DefaultDatatype
getDecimalDigits, getFormat, getInstance, getMaskFormatter, getOperators, obj2xml, parse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_minLength

protected int _minLength

_maxLength

protected int _maxLength

_regex

protected java.lang.String _regex

_partialRegex

protected java.lang.String _partialRegex
Constructor Detail

StringDatatype

public StringDatatype()

StringDatatype

public StringDatatype(int minLength,
                      int maxLength,
                      java.lang.String regex)

StringDatatype

public StringDatatype(int minLength,
                      int maxLength,
                      java.lang.String regex,
                      java.lang.String partialRegex)

StringDatatype

public StringDatatype(int length)
Method Detail

db2obj

public java.lang.Object db2obj(java.lang.Object obj)
                        throws java.lang.Exception
Description copied from interface: Datatype
Converts from database format to java object format.

Specified by:
db2obj in interface Datatype
Overrides:
db2obj in class DefaultDatatype
Throws:
java.lang.Exception

obj2db

public java.lang.Object obj2db(java.lang.Object obj)
                        throws java.lang.Exception
Description copied from interface: Datatype
Converts from java object format to database format.

Specified by:
obj2db in interface Datatype
Overrides:
obj2db in class DefaultDatatype
Throws:
java.lang.Exception

xml2obj

public java.lang.Object xml2obj(java.lang.String xml)
                         throws java.lang.Exception
Description copied from interface: Datatype
Converts from xml string format to java object format.

Specified by:
xml2obj in interface Datatype
Overrides:
xml2obj in class DefaultDatatype
Throws:
java.lang.Exception

validate

public void validate(java.lang.Object value)
              throws java.lang.Exception
Description copied from interface: Datatype
Validated column value. If the value is invalid, an IllegalArgumentException should be thrown.

Specified by:
validate in interface Datatype
Overrides:
validate in class DefaultDatatype
Throws:
java.lang.Exception

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)

getRegex

public java.lang.String getRegex()

getPartialRegex

public java.lang.String getPartialRegex()

getMaxLength

public int getMaxLength()
                 throws java.lang.Exception
Throws:
java.lang.Exception

getMinLength

public int getMinLength()

getLikeDatatype

public StringDatatype getLikeDatatype()
Deprecated. Use getDatatype(Operator.LIKE)


getDatatype

public Datatype getDatatype(Operator op)
Datatype to be used for (sql) values other than equals.

Specified by:
getDatatype in interface Datatype
Overrides:
getDatatype in class DefaultDatatype

getJavaClass

public java.lang.Class getJavaClass()
                             throws java.lang.Exception
Description copied from interface: Datatype
Returns the java class that is used for this datatype.

Specified by:
getJavaClass in interface Datatype
Overrides:
getJavaClass in class DefaultDatatype
Throws:
java.lang.Exception

parseStringDatatype

public static StringDatatype parseStringDatatype(org.dom4j.Element element)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

toXML

public void toXML(org.xml.sax.ContentHandler handler)
           throws java.lang.Exception
Description copied from interface: Datatype
Builds an xml representation of this object.

Specified by:
toXML in interface Datatype
Overrides:
toXML in class DefaultDatatype
Throws:
java.lang.Exception

getType

public int getType()
            throws java.lang.Exception
Specified by:
getType in interface Datatype
Overrides:
getType in class DefaultDatatype
Throws:
java.lang.Exception

getSize

public int getSize()
            throws java.lang.Exception
Specified by:
getSize in interface Datatype
Overrides:
getSize in class DefaultDatatype
Throws:
java.lang.Exception

isTruncate

public boolean isTruncate()

setTruncate

public void setTruncate(boolean truncate)

isTrim

public boolean isTrim()

setTrim

public void setTrim(boolean trim)