/** * Return the DbTypeMap with standard (not platform specific) types. * <p> * This has some extended JSON types (JSON, JSONB, JSONVarchar, JSONClob, JSONBlob). * These types get translated to specific database platform types during DDL generation. */ public static DbPlatformTypeMapping logicalTypes() { return new DbPlatformTypeMapping(true); }
/** * Map the UUID appropriately based on native DB support and ServerConfig.DbUuid. */ public void config(boolean nativeUuidType, ServerConfig.DbUuid dbUuid) { if (nativeUuidType && dbUuid.useNativeType()) { put(DbType.UUID, UUID_NATIVE); } else if (dbUuid.useBinary()) { put(DbType.UUID, get(DbType.BINARY).withLength(16)); } else { put(DbType.UUID, get(DbType.VARCHAR).withLength(40)); } } }
/** * Lookup the platform specific DbType given the standard sql type name. */ public DbPlatformType lookup(String name, boolean withScale) { DbType type = lookup.byName(name); if (type == null) { throw new IllegalArgumentException("Unknown type [" + name + "] - not standard sql type"); } // handle JSON types mapped to clob, blob and varchar switch (type) { case JSONBLOB: return get(DbType.BLOB); case JSONCLOB: return get(DbType.CLOB); case JSONVARCHAR: return get(DbType.VARCHAR); case JSON: return getJsonType(DbType.JSON, withScale); case JSONB: return getJsonType(DbType.JSONB, withScale); default: return get(type); } }
protected void addGeoTypes(int srid) { dbTypeMap.put(DbType.POINT, geoType("point", srid)); dbTypeMap.put(DbType.POLYGON, geoType("polygon", srid)); dbTypeMap.put(DbType.LINESTRING, geoType("linestring", srid)); dbTypeMap.put(DbType.MULTIPOINT, geoType("multipoint", srid)); dbTypeMap.put(DbType.MULTILINESTRING, geoType("multilinestring", srid)); dbTypeMap.put(DbType.MULTIPOLYGON, geoType("multipolygon", srid)); }
/** * Configure UUID Storage etc based on ServerConfig settings. */ public void configure(DbTypeConfig config) { addGeoTypes(config.getGeometrySRID()); configureIdType(config.getIdType()); dbTypeMap.config(nativeUuidType, config.getDbUuid()); for (CustomDbTypeMapping mapping : config.getCustomTypeMappings()) { if (platformMatch(mapping.getPlatform())) { dbTypeMap.put(mapping.getType(), parse(mapping.getColumnDefinition())); } } }
private DbPlatformType getJsonType(DbType type, boolean withScale) { DbPlatformType dbType = get(type); if (dbType == JSON_CLOB_PLACEHOLDER) { // if we have scale that implies this maps to varchar return withScale ? get(DbType.VARCHAR) : get(DbType.CLOB); } if (dbType == JSON_BLOB_PLACEHOLDER) { return get(DbType.BLOB); } if (dbType == JSON_VARCHAR_PLACEHOLDER) { return get(DbType.VARCHAR); } // Postgres has specific type return get(type); }
/** * Convert a simple type with not scale or precision. */ protected String convertNoScale(String columnDefinition) { try { DbPlatformType dbType = platformTypes.lookup(columnDefinition, false); return dbType.renderType(0, 0); } catch (IllegalArgumentException e) { // assume already platform specific, leave as is return columnDefinition; } }
public DbPlatformTypeMapping() { loadDefaults(false); }
public SqlAnywherePlatform() { super(); this.platform = Platform.SQLANYWHERE; this.dbIdentity.setIdType(IdType.IDENTITY); this.sqlLimiter = new SqlAnywhereLimiter(); this.dbIdentity.setSupportsGetGeneratedKeys(false); this.dbIdentity.setSelectLastInsertedIdTemplate("select @@IDENTITY as X"); this.dbIdentity.setSupportsIdentity(true); dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0")); dbTypeMap.put(DbType.BIGINT, new DbPlatformType("numeric", 19)); dbTypeMap.put(DbType.REAL, new DbPlatformType("float(16)")); dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float(32)")); dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("numeric", 28)); dbTypeMap.put(DbType.BLOB, new DbPlatformType("binary(4500)")); dbTypeMap.put(DbType.CLOB, new DbPlatformType("long varchar")); dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("long binary")); dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("long varchar")); }
/** * Return the type for a given jdbc type. */ public DbPlatformType get(int jdbcType) { return get(lookup.byId(jdbcType)); }
/** * Convert a type that has scale and possibly precision. */ protected String convertWithScale(String columnDefinition, int open) { int close = columnDefinition.lastIndexOf(')'); if (close == -1) { // assume already platform specific, leave as is return columnDefinition; } String suffix = close + 1 < columnDefinition.length() ? columnDefinition.substring(close + 1) : ""; String type = columnDefinition.substring(0, open); try { DbPlatformType dbType = platformTypes.lookup(type, true); int comma = columnDefinition.indexOf(',', open); if (comma > -1) { // scale and precision - decimal(10,4) int scale = Integer.parseInt(columnDefinition.substring(open + 1, comma)); int precision = Integer.parseInt(columnDefinition.substring(comma + 1, close)); return dbType.renderType(scale, precision) + suffix; } else { // scale - varchar(10) int scale = Integer.parseInt(columnDefinition.substring(open + 1, close)); return dbType.renderType(scale, 0) + suffix; } } catch (IllegalArgumentException e) { // assume already platform specific, leave as is return columnDefinition; } }
private DbPlatformTypeMapping(boolean logicalTypes) { loadDefaults(logicalTypes); }
DbPlatformType dbBytea = new DbPlatformType("bytea", false); dbTypeMap.put(DbType.UUID, new DbPlatformType("uuid", false)); dbTypeMap.put(DbType.HSTORE, new DbPlatformType("hstore", false)); dbTypeMap.put(DbType.JSON, new DbPlatformType("json", false)); dbTypeMap.put(DbType.JSONB, new DbPlatformType("jsonb", false)); dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false)); dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float")); dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("decimal", 38)); dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("timestamptz")); dbTypeMap.put(DbType.BINARY, dbBytea); dbTypeMap.put(DbType.VARBINARY, dbBytea); dbTypeMap.put(DbType.BLOB, dbBytea); dbTypeMap.put(DbType.CLOB, dbTypeText); dbTypeMap.put(DbType.LONGVARBINARY, dbBytea); dbTypeMap.put(DbType.LONGVARCHAR, dbTypeText);
put(DbType.BOOLEAN); put(DbType.BIT); put(DbType.INTEGER); put(DbType.BIGINT); put(DbType.DOUBLE); put(DbType.SMALLINT); put(DbType.TINYINT); put(DbType.BLOB); put(DbType.CLOB); put(DbType.ARRAY); put(DbType.DATE); put(DbType.TIME); put(DbType.TIMESTAMP); put(DbType.LONGVARBINARY); put(DbType.LONGVARCHAR); put(DbType.REAL, new DbPlatformType("float")); put(DbType.POINT, POINT); put(DbType.POLYGON, POLYGON); put(DbType.LINESTRING, LINESTRING); put(DbType.MULTIPOINT, MULTIPOINT); put(DbType.MULTILINESTRING, MULTILINESTRING); put(DbType.MULTIPOLYGON, MULTIPOLYGON); put(DbType.VARCHAR, new DbPlatformType("varchar")); put(DbType.DECIMAL, new DbPlatformType("decimal")); put(DbType.VARBINARY, new DbPlatformType("varbinary")); put(DbType.BINARY, new DbPlatformType("binary"));
private DbPlatformType getDbType(BeanProperty p) { if (p.isDbEncrypted()) { return dbTypeMap.get(p.getDbEncryptedType()); } if (p.isLocalEncrypted()) { // scalar type potentially wrapping varbinary db type ScalarType<Object> scalarType = p.getScalarType(); int jdbcType = scalarType.getJdbcType(); return dbTypeMap.get(jdbcType); } // can be the logical JSON types (JSON, JSONB, JSONClob, JSONBlob, JSONVarchar) int dbType = p.getDbType(platformTypes); if (dbType == 0) { throw new RuntimeException("No scalarType defined for " + p.getFullBeanName()); } return dbTypeMap.get(dbType); }
public DB2Platform() { super(); this.platform = Platform.DB2; this.maxTableNameLength = 18; this.maxConstraintNameLength = 18; this.sqlLimiter = new Db2SqlLimiter(); this.platformDdl = new DB2Ddl(this); this.dbIdentity.setSupportsGetGeneratedKeys(true); this.dbIdentity.setSupportsSequence(true); booleanDbType = Types.BOOLEAN; dbTypeMap.put(DbType.REAL, new DbPlatformType("real")); dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("decimal", 15)); }
DbPlatformType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType()); String discDbType = dbType.renderType(inheritInfo.getDiscriminatorLength(), 0);
public SQLitePlatform() { super(); this.platform = Platform.SQLITE; this.platformDdl = new SQLiteDdl(this); this.dbIdentity.setIdType(IdType.IDENTITY); this.dbIdentity.setSupportsGetGeneratedKeys(false); this.dbIdentity.setSupportsSequence(false); this.dbIdentity.setSelectLastInsertedIdTemplate("select last_insert_rowid()"); this.booleanDbType = Types.INTEGER; dbTypeMap.put(DbType.BIT, new DbPlatformType("int default 0")); dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("int default 0")); dbTypeMap.put(DbType.BIGINT, new DbPlatformType("integer")); dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("integer")); }
this.closeQuote = "]"; dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0")); dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false)); dbTypeMap.put(DbType.BIGINT, new DbPlatformType("numeric", 19)); dbTypeMap.put(DbType.REAL, new DbPlatformType("float(16)")); dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("float(32)")); dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint")); dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("numeric", 28)); dbTypeMap.put(DbType.BLOB, new DbPlatformType("image")); dbTypeMap.put(DbType.CLOB, new DbPlatformType("text")); dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("image")); dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("text")); dbTypeMap.put(DbType.DATE, new DbPlatformType("date")); dbTypeMap.put(DbType.TIME, new DbPlatformType("time")); dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime2"));
dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("number(1) default 0")); dbTypeMap.put(DbType.INTEGER, new DbPlatformType("number", 10)); dbTypeMap.put(DbType.BIGINT, new DbPlatformType("number", 19)); dbTypeMap.put(DbType.REAL, new DbPlatformType("number", 19, 4)); dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("number", 19, 4)); dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("number", 5)); dbTypeMap.put(DbType.TINYINT, new DbPlatformType("number", 3)); dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("number", 38)); dbTypeMap.put(DbType.VARCHAR, new DbPlatformType("varchar2", 255)); dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("blob")); dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("clob")); dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("raw", 255)); dbTypeMap.put(DbType.BINARY, new DbPlatformType("raw", 255)); dbTypeMap.put(DbType.TIME, new DbPlatformType("timestamp"));