Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.java.ao.types;
  
  
  import static net.java.ao.types.TypeQualifiers.qualifiers;

Describes a mapping between a LogicalType, with optional qualifiers, and the underlying database type.

The database provider constructs one instance of this class for each supported logical type, and may provide additional derived instances for specific entity properties. The caller will never construct an instance of this class directly.

 
 public final class TypeInfo<T>
 {
     private final LogicalType<T> logicalType;
     private final SchemaProperties schemaProperties;
     private final TypeQualifiers defaultQualifiers;
     private final TypeQualifiers qualifiers;
 
     public TypeInfo(LogicalType<T> logicalType,
                     SchemaProperties schemaProperties,
                     TypeQualifiers defaultQualifiers)
     {
         this(logicalTypeschemaPropertiesdefaultQualifiersqualifiers());
     }
 
     protected TypeInfo(LogicalType<T> logicalType,
                        SchemaProperties schemaProperties,
                        TypeQualifiers defaultQualifiers,
                        TypeQualifiers qualifiers)
     {
         this. = logicalType;
         this. = schemaProperties;
         this. = defaultQualifiers;
         this. = qualifiers;
     }

    
Returns the LogicalType describing what Java types are supported by this type and how they are mapped to JDBC operations.
 
     public LogicalType<T> getLogicalType()
     {
         return ;
     }
    
    
Returns the SchemaProperties describing the SQL representation of this type, as specified by the database provider.
 
     {
         return ;
     }
    
    
Returns the TypeQualifiers describing optional length/precision modifiers for this type, which may include defaults set by the database provider and/or values specified by annotations for particular entity properties.
 
     public TypeQualifiers getQualifiers()
     {
         return .withQualifiers();
     }

    
Returns a boolean specifying if this type can be used as a primary key value.

Returns:
if it's allowed or not
 
     public boolean isAllowedAsPrimaryKey()
     {
         return .isAllowedAsPrimaryKey() && (!.isUnlimitedLength());
     }

    
Returns the SQL type identifier for this type, including any length or precision modifiers.
 
     public String getSqlTypeIdentifier()
     {
         TypeQualifiers allQualifiers = getQualifiers();
         if (!allQualifiers.isDefined())
         {
             return .getSqlTypeName();
         }
         StringBuffer ret = new StringBuffer();
         ret.append(.getSqlTypeName());
         if (.isPrecisionAllowed() && allQualifiers.hasPrecision())
         {
             ret.append("(").append(allQualifiers.getPrecision());
             if (.isScaleAllowed() && allQualifiers.hasScale())
             {
                 ret.append(",").append(allQualifiers.getScale());
             }
             ret.append(")");
         }
         else if (.isStringLengthAllowed() && allQualifiers.hasStringLength() && !allQualifiers.isUnlimitedLength())
         {
            ret.append("(").append(allQualifiers.getStringLength()).append(")");
        }
        return ret.toString();
    }
    
    
Returns the JDBC type code to use when passing values to the database. This is based on the default value from the LogicalType but can be overridden by each database provider in the SchemaProperties.
    public int getJdbcWriteType()
    {
            .getDefaultJdbcWriteType();
    }
    
    
Returns a new instance of this class with the same properties, but with the default TypeQualifiers overridden by the specified values.

Throws:
net.java.ao.ActiveObjectsConfigurationException if the qualifiers are not allowed for this type
    public TypeInfo<T> withQualifiers(TypeQualifiers qualifiers)
    {
        if (qualifiers.hasStringLength() && !.isStringLengthAllowed())
        {
            throw new ActiveObjectsConfigurationException("String length cannot be specified for the type "
                + .getName());
        }
        return new TypeInfo<T>(this.this.,
                               this..withQualifiers(qualifiers));
    }
    
    
Returns true if this type is compatible with the given qualifiers.
    public boolean acceptsQualifiers(TypeQualifiers qualifiers)
    {
        return (!qualifiers.hasPrecision() || .isPrecisionAllowed())
            && (!qualifiers.hasScale() || .isScaleAllowed())
            && (!qualifiers.hasStringLength() || .isStringLengthAllowed());
    }
    
    @Override
    public boolean equals(Object other)
    {
        if (other instanceof TypeInfo<?>)
        {
            TypeInfo<?> type = (TypeInfo<?>) other;
            return type.logicalType.equals()
                && type.schemaProperties.equals()
                && type.defaultQualifiers.equals()
                && type.qualifiers.equals();
        }
        
        return false;
    }
    
    @Override
    public int hashCode()
    {
        return ((((.hashCode() * 31) + .hashCode()) * 31)
            + .hashCode() * 31) + .hashCode();
    }
    
    
Describes the type mapping in a format that includes the logical type name, any non-default qualifiers, and the SQL type name, e.g. "String(255):VARCHAR".
    @Override
    public String toString()
    {
        StringBuffer ret = new StringBuffer();
        ret.append(.getName());
        if (.isDefined())
        {
            ret.append("(");
            if (.hasPrecision())
            {
                ret.append(.getPrecision());
                if (.hasScale())
                {
                    ret.append(", ").append(.getScale());
                }
            }
            else if (.hasStringLength())
            {
                ret.append(.getStringLength());
            }
            ret.append(")");
        }
        ret.append(":");
        ret.append(.getSqlTypeName());
        return ret.toString();
    }
New to GrepCode? Check out our FAQ X