Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.java.ao.types;
  
  
Describes optional modifiers to a type: string length for string types, precision and scale for numeric types. Each TypeInfo may have default qualifiers set by the database provider; qualifiers may also be modified by annotations.
 
 public class TypeQualifiers
 {
    
Maximum string length (for strings of limited length) cannot be set to greater than this value. This is the lowest common denominator for maximum string length in all supported databases.
 
     public static final int MAX_STRING_LENGTH = .;
    
    
If stringLength is set to this constant, the field is an unlimited-length string (TEXT, CLOB, or LONG VARCHAR).
 
     public static final int UNLIMITED_LENGTH = .;
     
     private final Integer precision;
     private final Integer scale;
     private final Integer stringLength;
     
     private TypeQualifiers(Integer precisionInteger scaleInteger stringLength)
     {
         this. = precision;
         this. = scale;
         this. = stringLength;
     }
 
     public static TypeQualifiers qualifiers()
     {
         return new TypeQualifiers(nullnullnull);
     }
 
     public TypeQualifiers precision(int precision)
     {
         if (precision <= 0)
         {
             throw new ActiveObjectsConfigurationException("Numeric precision must be greater than zero");
         }
         return new TypeQualifiers(precisionthis.this.);
     }
     
     public TypeQualifiers scale(int scale)
     {
         if (scale < 0)
         {
             throw new ActiveObjectsConfigurationException("Numeric scale must be greater than or equal to zero");
         }
         return new TypeQualifiers(this.scalethis.);
     }
     
     public TypeQualifiers stringLength(int stringLength)
     {
         if (stringLength != )
         {
             if (stringLength <= 0)
             {
                 throw new ActiveObjectsConfigurationException("String length must be greater than zero or unlimited");
             }
             else if (stringLength > )
             {
                 // There is a separate check in SchemaGenerator.getSQLTypeFromMethod to raise an
                 // error if someone explicitly tries to specify a length greater than this limit with
                 // the @StringLength annotation.  But we can't put that check here, because we also
                 // use TypeQualifiers for metadata that is read directly from a database schema, and
                 // some databases like to report very large numbers for the length of what is really
                 // an unlimited-length (CLOB) column.
                 stringLength = ;
             }
         }
         return new TypeQualifiers(this.this.stringLength);
     }
 
     public TypeQualifiers withQualifiers(TypeQualifiers overrides)
     {
         if (overrides.isDefined())
         {
             return new TypeQualifiers(overrides.hasPrecision() ? overrides.precision : this.,
                                       overrides.hasScale() ? overrides.scale : this.,
                                       overrides.hasStringLength() ? overrides.stringLength : this.);
         }
         return this;
     }
     
     public Integer getPrecision()
     {
         return ;
     }
     
    public Integer getScale()
    {
        return ;
    }
    
    public Integer getStringLength()
    {
        return ;
    }
    
    public boolean isDefined()
    {
        return hasPrecision() || hasScale() || hasStringLength();
    }
    
    public boolean hasPrecision()
    {
        return ( != null);
    }
    
    public boolean hasScale()
    {
        return ( != null);
    }
    
    public boolean hasStringLength()
    {
        return ( != null);
    }
    
    public boolean isUnlimitedLength()
    {
        return (( != null) && ( == ));
    }
    {
        if (hasStringLength() || other.hasStringLength())
        {
            return (isUnlimitedLength() == other.isUnlimitedLength());
        }
        return true;
    }
    /*
     * Even when the schema hasn't changed, we can get into a mismatch when comparing qualifiers that come from a requested logical type
     * versus qualifiers that come from an existing column in the database. Therefore this method determines if the mismatch is due to the
     * ambiguity when going from logical type -> physical type.
     * versus qualifiers that come from an existing column in the database. This method determines if the mismatch is due to the
     * ambiguity when going from logical type -> physical type, and should be used to compare qualifiers derived from entity annotations
     * versus those derived from table metadata.
     */
    public static boolean areCompatible(TypeQualifiers derivedFromEntityAnnotationsTypeQualifiers derivedFromTableMetadata)
    {
        if (derivedFromEntityAnnotations.hasPrecision() && !Objects.equal(derivedFromEntityAnnotations.getPrecision(), derivedFromTableMetadata.getPrecision()))
        {
            return false;
        }
        else if (derivedFromEntityAnnotations.hasScale() && !Objects.equal(derivedFromEntityAnnotations.getScale(), derivedFromTableMetadata.getScale()))
        {
            return false;
        }
        return derivedFromEntityAnnotations.isUnlimitedStringLengthSupportCompatible(derivedFromTableMetadata);
    }
    
    @Override
    public boolean equals(Object other)
    {
        if (other instanceof TypeQualifiers)
        {
            TypeQualifiers q = (TypeQualifiersother;
            return Objects.equal(q.precision)
                && Objects.equal(q.scale)
                && Objects.equal(q.stringLength);
        }
        return false;
    }
    
    @Override
    public int hashCode()
    {
        return Objects.hashCode();
    }
    
    @Override
    public String toString()
    {
        StringBuilder ret = new StringBuilder("(");
        if ( != null)
        {
            ret.append("precision=").append();
        }
        if ( != null)
        {
            if (ret.length() > 1)
            {
                ret.append(",");
            }
            ret.append("scale=").append();
        }
        if ( != null)
        {
            ret.append("length=").append();
        }
        return ret.append(")").toString();
    }
New to GrepCode? Check out our FAQ X