private String buildColumnTypeString()

in google-cloud-spanner-hibernate-dialect/src/main/java/com/google/cloud/spanner/hibernate/schema/SpannerTableStatements.java [173:226]


  private String buildColumnTypeString(Column col, Metadata metadata) {
    String typeString;
    if (col.getValue() != null && col.getSqlTypeCode(metadata) == Types.ARRAY) {
      Code typeCode = Code.UNRECOGNIZED;
      if (col.getValue().getType() instanceof SpannerArrayListType) {
        typeCode = ((SpannerArrayListType) (col.getValue().getType())).getSpannerSqlType();
      } else {
        if (col.getValue().getType() instanceof CustomType) {
          CustomType<?> customType = (CustomType<?>) col.getValue().getType();
          if (customType.getUserType() instanceof AbstractSpannerArrayType) {
            typeCode =
                ((AbstractSpannerArrayType<?, ?>) customType.getUserType()).getSpannerTypeCode();
          }
        }
      }
      if (typeCode == Code.UNRECOGNIZED) {
        throw new IllegalArgumentException(
            "Column "
                + col.getName()
                + " has type 'ARRAY', but the mapped Hibernate type is not a subclass of "
                + AbstractSpannerArrayType.class.getName());
      }

      String arrayType = typeCode.toString();
      if (typeCode == Code.STRING || typeCode == Code.BYTES) {
        // If String or Bytes, must specify size in parentheses.
        if (col.getLength() == null) {
          arrayType += "(MAX)";
        } else {
          arrayType += "(" + col.getLength() + ")";
        }
      }
      typeString = String.format("ARRAY<%s>", arrayType);
    } else {
      typeString = col.getSqlType(metadata);
    }

    String result =
        col.getQuotedName()
            + " "
            + typeString
            + (col.isNullable() ? this.spannerDialect.getNullColumnString() : " not null");
    if (col.isIdentity()) {
      result =
          result
              + " "
              + SpannerIdentityColumnSupport.INSTANCE.getIdentityColumnString(
                  col.getSqlTypeCode(metadata));
    } else if (col.getDefaultValue() != null) {
      result = result + " default (" + col.getDefaultValue() + ")";
    }

    return result;
  }