public TInstance typeForJDBCType(
     int jdbcType,
     int att,
     boolean nullable,
     String schemaName,
     String tableName,
     String columnName) {
   TClass tclass = typeClassForJDBCType(jdbcType, schemaName, tableName, columnName);
   if (tclass == null) return null;
   else return tclass.instance(att, nullable);
 }
 private AkCollator collator(
     ComparisonCondition cond, TPreparedExpression left, TPreparedExpression right) {
   TInstance leftInstance = left.resultType();
   TInstance rightInstance = right.resultType();
   TClass tClass = leftInstance.typeClass();
   assert tClass.compatibleForCompare(rightInstance.typeClass())
       : tClass + " != " + rightInstance.typeClass();
   if (tClass.underlyingType() != UnderlyingType.STRING) return null;
   CharacterTypeAttributes leftAttributes = StringAttribute.characterTypeAttributes(leftInstance);
   CharacterTypeAttributes rightAttributes =
       StringAttribute.characterTypeAttributes(rightInstance);
   return TString.mergeAkCollators(leftAttributes, rightAttributes);
 }
 public TInstance typeForString(
     int length,
     String charset,
     String collation,
     int defaultCharsetId,
     int defaultCollationId,
     boolean nullable) {
   TClass tclass = typeClassForString();
   assert tclass.hasAttributes(StringAttribute.class) : tclass;
   int charsetId = defaultCharsetId, collationId = defaultCollationId;
   if (charset != null) {
     charsetId = StringFactory.charsetNameToId(charset);
   }
   if (collation != null) {
     collationId = StringFactory.collationNameToId(collation);
   }
   return tclass.instance(length, charsetId, collationId, nullable);
 }
 /** Does this type represent a signed numeric type? */
 public boolean isTypeSigned(TInstance type) {
   TClass tclass = TInstance.tClass(type);
   if (tclass == null) return false;
   switch (tclass.jdbcType()) {
     case Types.BIGINT:
     case Types.DECIMAL:
     case Types.DOUBLE:
     case Types.FLOAT:
     case Types.INTEGER:
     case Types.NUMERIC:
     case Types.REAL:
     case Types.SMALLINT:
     case Types.TINYINT:
       return true;
     default:
       return false;
   }
 }
  public void init(List<String> explanation) {
    this.explanation = explanation;

    int maxlen = 32;
    for (String row : explanation) {
      if (maxlen < row.length()) maxlen = row.length();
    }
    colName = "OPERATORS";
    colType =
        new PostgresType(
            PostgresType.TypeOid.VARCHAR_TYPE_OID,
            (short) -1,
            maxlen,
            colTClass.instance(maxlen, false));
  }
 protected TInstance typeForStringType(
     TClass tclass,
     DataTypeDescriptor type,
     int defaultCharsetId,
     int defaultCollationId,
     String schemaName,
     String tableName,
     String columnName) {
   int charsetId, collationId;
   CharacterTypeAttributes typeAttributes = type.getCharacterAttributes();
   if ((typeAttributes == null) || (typeAttributes.getCharacterSet() == null)) {
     charsetId = defaultCharsetId;
   } else {
     charsetId = StringFactory.charsetNameToId(typeAttributes.getCharacterSet());
   }
   if ((typeAttributes == null) || (typeAttributes.getCollation() == null)) {
     collationId = defaultCollationId;
   } else {
     collationId = StringFactory.collationNameToId(typeAttributes.getCollation());
   }
   return tclass.instance(type.getMaximumWidth(), charsetId, collationId, type.isNullable());
 }
  public Class<?> jdbcClass(TInstance type) {
    TClass tclass = TInstance.tClass(type);
    if (tclass == null) return Object.class;
    int jdbcType = tclass.jdbcType();
    switch (jdbcType) {
      case Types.DECIMAL:
      case Types.NUMERIC:
        return BigDecimal.class;
      case Types.BOOLEAN:
        return Boolean.class;
      case Types.TINYINT:
        return Byte.class;
      case Types.BINARY:
      case Types.BIT:
      case Types.LONGVARBINARY:
      case Types.VARBINARY:
      case Types.BLOB:
        return byte[].class;
      case Types.DATE:
        return java.sql.Date.class;
      case Types.DOUBLE:
        return Double.class;
      case Types.FLOAT:
      case Types.REAL:
        return Float.class;
      case Types.INTEGER:
        return Integer.class;
      case Types.BIGINT:
        return Long.class;
      case Types.SMALLINT:
        return Short.class;
      case Types.CHAR:
      case Types.LONGNVARCHAR:
      case Types.LONGVARCHAR:
      case Types.NCHAR:
      case Types.NVARCHAR:
      case Types.VARCHAR:
      case Types.CLOB:
        return String.class;
      case Types.TIME:
        return java.sql.Time.class;
      case Types.TIMESTAMP:
        return java.sql.Timestamp.class;

        /*
        case Types.ARRAY:
            return java.sql.Array.class;
        case Types.BLOB:
            return java.sql.Blob.class;
        case Types.CLOB:
            return java.sql.Clob.class;
        case Types.NCLOB:
            return java.sql.NClob.class;
        case Types.REF:
            return java.sql.Ref.class;
        case Types.ROWID:
            return java.sql.RowId.class;
        case Types.SQLXML:
            return java.sql.SQLXML.class;
        */

      case Types.NULL:
      case Types.DATALINK:
      case Types.DISTINCT:
      case Types.JAVA_OBJECT:
      case Types.OTHER:
      case Types.STRUCT:
      default:
        break;
    }
    if (tclass == AkResultSet.INSTANCE) return java.sql.ResultSet.class;
    return Object.class;
  }
 public int jdbcType(TInstance type) {
   TClass tclass = TInstance.tClass(type);
   if (tclass == null) return Types.OTHER;
   else return tclass.jdbcType();
 }
 protected TInstance typeForSQLType(
     TypeId typeId,
     DataTypeDescriptor sqlType,
     int defaultCharsetId,
     int defaultCollationId,
     String schemaName,
     String tableName,
     String columnName) {
   switch (typeId.getTypeFormatId()) {
       /* No attribute types. */
     case TypeId.FormatIds.TINYINT_TYPE_ID:
       return typeForJDBCType(
           Types.TINYINT, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.SMALLINT_TYPE_ID:
       return typeForJDBCType(
           Types.SMALLINT, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.MEDIUMINT_ID:
     case TypeId.FormatIds.INT_TYPE_ID:
       return typeForJDBCType(
           Types.INTEGER, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.LONGINT_TYPE_ID:
       return typeForJDBCType(
           Types.BIGINT, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.DATE_TYPE_ID:
       return typeForJDBCType(Types.DATE, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.TIME_TYPE_ID:
       return typeForJDBCType(Types.TIME, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.TIMESTAMP_TYPE_ID:
       return typeForJDBCType(
           Types.TIMESTAMP, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.REAL_TYPE_ID:
       return typeForJDBCType(Types.REAL, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.DOUBLE_TYPE_ID:
       return typeForJDBCType(
           Types.DOUBLE, sqlType.isNullable(), schemaName, tableName, columnName);
     case TypeId.FormatIds.BLOB_TYPE_ID:
       return typeForJDBCType(
           Types.LONGVARBINARY,
           sqlType.isNullable(), // TODO: Types.BLOB
           schemaName,
           tableName,
           columnName);
       /* Width attribute types. */
     case TypeId.FormatIds.BIT_TYPE_ID:
       return typeForJDBCType(
           Types.BIT,
           sqlType.getMaximumWidth(),
           sqlType.isNullable(),
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.VARBIT_TYPE_ID:
       return typeForJDBCType(
           Types.VARBINARY,
           sqlType.getMaximumWidth(),
           sqlType.isNullable(),
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.LONGVARBIT_TYPE_ID:
       return typeForJDBCType(
           Types.LONGVARBINARY, sqlType.isNullable(), schemaName, tableName, columnName);
       /* Precision, scale attribute types. */
     case TypeId.FormatIds.DECIMAL_TYPE_ID:
       return typeForJDBCType(
           Types.DECIMAL,
           sqlType.getPrecision(),
           sqlType.getScale(),
           sqlType.isNullable(),
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.NUMERIC_TYPE_ID:
       return typeForJDBCType(
           Types.NUMERIC,
           sqlType.getPrecision(),
           sqlType.getScale(),
           sqlType.isNullable(),
           schemaName,
           tableName,
           columnName);
       /* String (charset, collation) attribute types. */
     case TypeId.FormatIds.CHAR_TYPE_ID:
       return typeForStringType(
           Types.CHAR,
           sqlType,
           defaultCharsetId,
           defaultCollationId,
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.VARCHAR_TYPE_ID:
       return typeForStringType(
           Types.VARCHAR,
           sqlType,
           defaultCharsetId,
           defaultCollationId,
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.LONGVARCHAR_TYPE_ID:
       return typeForStringType(
           Types.LONGVARCHAR,
           sqlType,
           defaultCharsetId,
           defaultCollationId,
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.CLOB_TYPE_ID:
       return typeForStringType(
           Types.LONGVARCHAR,
           sqlType, // TODO: Types.CLOB
           defaultCharsetId,
           defaultCollationId,
           schemaName,
           tableName,
           columnName);
     case TypeId.FormatIds.XML_TYPE_ID:
       return typeForStringType(
           Types.SQLXML,
           sqlType,
           defaultCharsetId,
           defaultCollationId,
           schemaName,
           tableName,
           columnName);
       /* Special case AkSQL types. */
     case TypeId.FormatIds.BOOLEAN_TYPE_ID:
       return AkBool.INSTANCE.instance(sqlType.isNullable());
     case TypeId.FormatIds.INTERVAL_DAY_SECOND_ID:
       return AkInterval.SECONDS.typeFrom(sqlType);
     case TypeId.FormatIds.INTERVAL_YEAR_MONTH_ID:
       return AkInterval.MONTHS.typeFrom(sqlType);
     case TypeId.FormatIds.ROW_MULTISET_TYPE_ID_IMPL:
       {
         TypeId.RowMultiSetTypeId rmsTypeId = (TypeId.RowMultiSetTypeId) typeId;
         String[] columnNames = rmsTypeId.getColumnNames();
         DataTypeDescriptor[] columnTypes = rmsTypeId.getColumnTypes();
         List<AkResultSet.Column> columns = new ArrayList<>(columnNames.length);
         for (int i = 0; i < columnNames.length; i++) {
           columns.add(new AkResultSet.Column(columnNames[i], typeForSQLType(columnTypes[i])));
         }
         return AkResultSet.INSTANCE.instance(columns);
       }
     case TypeId.FormatIds.GUID_TYPE_ID:
       return AkGUID.INSTANCE.instance(sqlType.isNullable());
     case TypeId.FormatIds.USERDEFINED_TYPE_ID:
       {
         String name = typeId.getSQLTypeName();
         TClass tclass = typeClassForUserDefined(name);
         return tclass.instance(sqlType.isNullable());
       }
     default:
       if (columnName != null) {
         throw new UnsupportedColumnDataTypeException(
             schemaName, tableName, columnName, sqlType.toString());
       } else {
         throw new UnsupportedDataTypeException(sqlType.toString());
       }
   }
 }
 public boolean isTypeUnsigned(TInstance type) {
   TClass tclass = TInstance.tClass(type);
   if (tclass == null) return false;
   else return tclass.isUnsigned();
 }