mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4b7c631da | ||
|
|
4f98ca5d91 | ||
|
|
014a9aef6f | ||
|
|
f21c33df7b | ||
|
|
f1eb494e0d | ||
|
|
d26203db1f | ||
|
|
abfe58fb06 | ||
|
|
d0ad5f6c48 | ||
|
|
bc4a246f33 |
@@ -9,7 +9,7 @@
|
||||
|
||||
<groupId>org.avaje.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>8.3.1</version>
|
||||
<version>8.4.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ebean</name>
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:https://github.com/ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-8.3.1</tag>
|
||||
<tag>ebean-8.4.1</tag>
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -746,14 +746,6 @@ public interface EbeanServer {
|
||||
*/
|
||||
<T> int findCount(Query<T> query, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Deprecated in favor of findCount()
|
||||
*
|
||||
* Return the number of 'top level' or 'root' entities this query should return.
|
||||
* @deprecated
|
||||
*/
|
||||
<T> int findRowCount(Query<T> query, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Return the Id values of the query as a List.
|
||||
*
|
||||
@@ -892,18 +884,10 @@ public interface EbeanServer {
|
||||
* @param query the query to execute the row count on
|
||||
* @param transaction the transaction (can be null).
|
||||
* @return a Future object for the row count query
|
||||
* @see com.avaje.ebean.Query#findFutureRowCount()
|
||||
* @see com.avaje.ebean.Query#findFutureCount()
|
||||
*/
|
||||
<T> FutureRowCount<T> findFutureCount(Query<T> query, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Deprecated in favor of findFutureCount().
|
||||
*
|
||||
* Execute find row count query in a background thread.
|
||||
* @deprecated
|
||||
*/
|
||||
<T> FutureRowCount<T> findFutureRowCount(Query<T> query, Transaction transaction);
|
||||
|
||||
/**
|
||||
* Execute find Id's query in a background thread.
|
||||
* <p>
|
||||
|
||||
@@ -185,13 +185,6 @@ public interface ExpressionList<T> {
|
||||
*/
|
||||
int findCount();
|
||||
|
||||
/**
|
||||
* Deprecated in favor of findCount().
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
int findRowCount();
|
||||
|
||||
/**
|
||||
* Execute the query returning a set.
|
||||
*
|
||||
@@ -265,13 +258,6 @@ public interface ExpressionList<T> {
|
||||
*/
|
||||
FutureRowCount<T> findFutureCount();
|
||||
|
||||
/**
|
||||
* Deprecated in favor of findFutureCount().
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
FutureRowCount<T> findFutureRowCount();
|
||||
|
||||
/**
|
||||
* Execute find Id's query in a background thread.
|
||||
* <p>
|
||||
|
||||
@@ -845,15 +845,6 @@ public interface Query<T> {
|
||||
*/
|
||||
int findCount();
|
||||
|
||||
/**
|
||||
* Deprecated in favor of findCount().
|
||||
* <p>
|
||||
* Return the count of entities this query should return.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
int findRowCount();
|
||||
|
||||
/**
|
||||
* Execute find row count query in a background thread.
|
||||
* <p>
|
||||
@@ -866,21 +857,6 @@ public interface Query<T> {
|
||||
*/
|
||||
FutureRowCount<T> findFutureCount();
|
||||
|
||||
/**
|
||||
* Deprecated in favor of findFutureCount().
|
||||
* <p>
|
||||
* Execute find row count query in a background thread.
|
||||
* <p>
|
||||
* This returns a Future object which can be used to cancel, check the
|
||||
* execution status (isDone etc) and get the value (with or without a
|
||||
* timeout).
|
||||
* </p>
|
||||
*
|
||||
* @return a Future object for the row count query
|
||||
* @deprecated
|
||||
*/
|
||||
FutureRowCount<T> findFutureRowCount();
|
||||
|
||||
/**
|
||||
* Execute find Id's query in a background thread.
|
||||
* <p>
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.avaje.ebean.config;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
|
||||
/**
|
||||
* Custom mappings for DB types that override the default.
|
||||
*
|
||||
* @see ServerConfig#addCustomMapping(DbType, String)
|
||||
*/
|
||||
public class CustomDbTypeMapping {
|
||||
|
||||
protected final DbType type;
|
||||
|
||||
protected final String columnDefinition;
|
||||
|
||||
protected final Platform platform;
|
||||
|
||||
/**
|
||||
* Create a mapping.
|
||||
*/
|
||||
public CustomDbTypeMapping(DbType type, String columnDefinition, Platform platform) {
|
||||
this.type = type;
|
||||
this.columnDefinition = columnDefinition;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mapping that should apply to all the database platforms.
|
||||
*/
|
||||
public CustomDbTypeMapping(DbType type, String columnDefinition) {
|
||||
this(type, columnDefinition, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB type the mapping applies to.
|
||||
*/
|
||||
public DbType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB column definition to use.
|
||||
*/
|
||||
public String getColumnDefinition() {
|
||||
return columnDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the platform this mapping should apply to. Null means it applied to all platforms.
|
||||
*/
|
||||
public Platform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.avaje.ebean.config;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformName;
|
||||
import com.avaje.ebean.dbmigration.DbMigration;
|
||||
import org.avaje.dbmigration.MigrationConfig;
|
||||
import org.avaje.dbmigration.MigrationRunner;
|
||||
@@ -20,7 +19,7 @@ public class DbMigrationConfig {
|
||||
/**
|
||||
* The database platform to generate migration DDL for.
|
||||
*/
|
||||
protected DbPlatformName platform;
|
||||
protected Platform platform;
|
||||
|
||||
/**
|
||||
* Set to true if the DB migration should be generated on server start.
|
||||
@@ -112,14 +111,14 @@ public class DbMigrationConfig {
|
||||
* We typically need to explicitly specify this as migration can often be generated
|
||||
* when running against H2.
|
||||
*/
|
||||
public DbPlatformName getPlatform() {
|
||||
public Platform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the DB platform to generate migration DDL for.
|
||||
*/
|
||||
public void setPlatform(DbPlatformName platform) {
|
||||
public void setPlatform(Platform platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@@ -366,7 +365,7 @@ public class DbMigrationConfig {
|
||||
includeGeneratedFileComment = properties.getBoolean("migration.includeGeneratedFileComment", includeGeneratedFileComment);
|
||||
generatePendingDrop = properties.get("migration.generatePendingDrop", generatePendingDrop);
|
||||
|
||||
platform = properties.getEnum(DbPlatformName.class, "migration.platform", platform);
|
||||
platform = properties.getEnum(Platform.class, "migration.platform", platform);
|
||||
|
||||
generate = properties.getBoolean("migration.generate", generate);
|
||||
version = properties.get("migration.version", version);
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
package com.avaje.ebean.config;
|
||||
|
||||
/**
|
||||
* Built in supported platforms.
|
||||
*/
|
||||
public enum DbPlatformName {
|
||||
public enum Platform {
|
||||
|
||||
/**
|
||||
* Generic base platform configured via properties or code.
|
||||
@@ -7,6 +7,7 @@ import com.avaje.ebean.cache.ServerCacheManager;
|
||||
import com.avaje.ebean.cache.ServerCachePlugin;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncrypt;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.event.BeanFindController;
|
||||
import com.avaje.ebean.event.BeanPersistController;
|
||||
import com.avaje.ebean.event.BeanPersistListener;
|
||||
@@ -83,6 +84,8 @@ public class ServerConfig {
|
||||
|
||||
private ContainerConfig containerConfig;
|
||||
|
||||
private List<CustomDbTypeMapping> customDbTypeMappings = new ArrayList<CustomDbTypeMapping>();
|
||||
|
||||
/**
|
||||
* The underlying properties that were used during configuration.
|
||||
*/
|
||||
@@ -1437,7 +1440,7 @@ public class ServerConfig {
|
||||
* <p>
|
||||
* You can also set this in ebean.proprerties:
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <pre>{@code
|
||||
* # set via ebean.properties
|
||||
* ebean.encryptKeyManager=com.avaje.tests.basic.encrypt.BasicEncyptKeyManager
|
||||
@@ -1770,7 +1773,7 @@ public class ServerConfig {
|
||||
* queries that normally hit L2 bean cache automatically will not do so after a write/persist
|
||||
* on the transaction.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* <pre>{@code
|
||||
*
|
||||
* // assume Customer has L2 bean caching enabled ...
|
||||
@@ -1932,6 +1935,54 @@ public class ServerConfig {
|
||||
this.resourceDirectory = resourceDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom type mapping.
|
||||
* <p>
|
||||
* <pre>{@code
|
||||
*
|
||||
* // set the default mapping for BigDecimal.class/decimal
|
||||
* serverConfig.addCustomMapping(DbType.DECIMAL, "decimal(18,6)");
|
||||
*
|
||||
* // set the default mapping for String.class/varchar but only for Postgres
|
||||
* serverConfig.addCustomMapping(DbType.VARCHAR, "text", Platform.POSTGRES);
|
||||
*
|
||||
* }</pre>
|
||||
*
|
||||
* @param type The DB type this mapping should apply to
|
||||
* @param columnDefinition The column definition that should be used
|
||||
* @param platform Optionally specify the platform this mapping should apply to.
|
||||
*/
|
||||
public void addCustomMapping(DbType type, String columnDefinition, Platform platform) {
|
||||
customDbTypeMappings.add(new CustomDbTypeMapping(type, columnDefinition, platform));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom type mapping that applies to all platforms.
|
||||
* <p>
|
||||
* <pre>{@code
|
||||
*
|
||||
* // set the default mapping for BigDecimal/decimal
|
||||
* serverConfig.addCustomMapping(DbType.DECIMAL, "decimal(18,6)");
|
||||
*
|
||||
* // set the default mapping for String/varchar
|
||||
* serverConfig.addCustomMapping(DbType.VARCHAR, "text");
|
||||
*
|
||||
* }</pre>
|
||||
*
|
||||
* @param type The DB type this mapping should apply to
|
||||
* @param columnDefinition The column definition that should be used
|
||||
*/
|
||||
public void addCustomMapping(DbType type, String columnDefinition) {
|
||||
customDbTypeMappings.add(new CustomDbTypeMapping(type, columnDefinition));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of custom type mappings.
|
||||
*/
|
||||
public List<CustomDbTypeMapping> getCustomTypeMappings() {
|
||||
return customDbTypeMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a BeanQueryAdapter instance.
|
||||
* <p>
|
||||
|
||||
@@ -24,9 +24,9 @@ public class DB2Platform extends DatabasePlatform {
|
||||
this.dbIdentity.setSupportsSequence(true);
|
||||
|
||||
booleanDbType = Types.BOOLEAN;
|
||||
dbTypeMap.put(Types.REAL, new DbType("real"));
|
||||
dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
|
||||
dbTypeMap.put(Types.DECIMAL, new DbType("decimal", 15));
|
||||
dbTypeMap.put(DbType.REAL, new DbPlatformType("real"));
|
||||
dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint"));
|
||||
dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("decimal", 15));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import com.avaje.ebean.BackgroundExecutor;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.config.CustomDbTypeMapping;
|
||||
import com.avaje.ebean.config.PersistBatch;
|
||||
import com.avaje.ebean.config.Platform;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.DdlHandler;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.platform.PlatformDdl;
|
||||
@@ -73,7 +75,7 @@ public class DatabasePlatform {
|
||||
/**
|
||||
* Mapping of JDBC to Database types.
|
||||
*/
|
||||
protected DbTypeMap dbTypeMap = new DbTypeMap();
|
||||
protected DbPlatformTypeMapping dbTypeMap = new DbPlatformTypeMapping();
|
||||
|
||||
/**
|
||||
* Default values for DB columns.
|
||||
@@ -180,6 +182,19 @@ public class DatabasePlatform {
|
||||
*/
|
||||
public void configure(ServerConfig serverConfig) {
|
||||
dbTypeMap.config(nativeUuidType, serverConfig.getDbUuid());
|
||||
for (CustomDbTypeMapping mapping : serverConfig.getCustomTypeMappings()) {
|
||||
if (platformMatch(mapping.getPlatform())) {
|
||||
dbTypeMap.put(mapping.getType(), parse(mapping.getColumnDefinition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DbPlatformType parse(String columnDefinition) {
|
||||
return DbPlatformType.parse(columnDefinition);
|
||||
}
|
||||
|
||||
private boolean platformMatch(Platform platform) {
|
||||
return platform == null || platform.name().equalsIgnoreCase(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -309,7 +324,7 @@ public class DatabasePlatform {
|
||||
*
|
||||
* @return the db type map
|
||||
*/
|
||||
public DbTypeMap getDbTypeMap() {
|
||||
public DbPlatformTypeMapping getDbTypeMap() {
|
||||
return dbTypeMap;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
/**
|
||||
* Represents a DB type with name, length, precision, and scale.
|
||||
* <p>
|
||||
* The length is for VARCHAR types and precision/scale for DECIMAL types.
|
||||
* </p>
|
||||
*/
|
||||
public class DbPlatformType implements ExtraDbTypes {
|
||||
|
||||
/**
|
||||
* The data type name (VARCHAR, INTEGER ...)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The default length or precision.
|
||||
*/
|
||||
private final int defaultLength;
|
||||
|
||||
/**
|
||||
* The default scale (decimal).
|
||||
*/
|
||||
private final int defaultScale;
|
||||
|
||||
/**
|
||||
* Set to true if the type should never have a length or scale.
|
||||
*/
|
||||
private final boolean canHaveLength;
|
||||
|
||||
/**
|
||||
* Parse a type definition into a DbPlatformType.
|
||||
* <p>
|
||||
* e.g. "decimal(18,6)"
|
||||
* e.g. "text"
|
||||
* </p>
|
||||
*/
|
||||
public static DbPlatformType parse(String columnDefinition) {
|
||||
return DbPlatformTypeParser.parse(columnDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with no length or scale.
|
||||
*/
|
||||
public DbPlatformType(String name) {
|
||||
this(name, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with a given length.
|
||||
*/
|
||||
public DbPlatformType(String name, int defaultLength) {
|
||||
this(name, defaultLength, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct for Decimal with precision and scale.
|
||||
*/
|
||||
public DbPlatformType(String name, int defaultPrecision, int defaultScale) {
|
||||
this.name = name;
|
||||
this.defaultLength = defaultPrecision;
|
||||
this.defaultScale = defaultScale;
|
||||
this.canHaveLength = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use with canHaveLength=false for types that should never have a length.
|
||||
*
|
||||
* @param name
|
||||
* the type name
|
||||
* @param canHaveLength
|
||||
* set this to false for type that should never have a length
|
||||
*/
|
||||
public DbPlatformType(String name, boolean canHaveLength) {
|
||||
this.name = name;
|
||||
this.defaultLength = 0;
|
||||
this.defaultScale = 0;
|
||||
this.canHaveLength = canHaveLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default length/precision.
|
||||
*/
|
||||
public int getDefaultLength() {
|
||||
return defaultLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default scale.
|
||||
*/
|
||||
public int getDefaultScale() {
|
||||
return defaultScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for a specific property that incorporates the name, length,
|
||||
* precision and scale.
|
||||
* <p>
|
||||
* The deployLength and deployScale are for the property we are rendering the
|
||||
* DB type for.
|
||||
* </p>
|
||||
*
|
||||
* @param deployLength
|
||||
* the length or precision defined by deployment on a specific
|
||||
* property.
|
||||
* @param deployScale
|
||||
* the scale defined by deployment on a specific property.
|
||||
*/
|
||||
public String renderType(int deployLength, int deployScale) {
|
||||
return renderType(deployLength, deployScale, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the type defining strict mode.
|
||||
* <p>
|
||||
* If strict mode if OFF then this will render with a scale value even if
|
||||
* that is not strictly supported. The reason for supporting this is to enable
|
||||
* use to use types like jsonb(200) as a "logical" type that maps to JSONB for
|
||||
* Postgres and VARCHAR(200) for other databases.
|
||||
* </p>
|
||||
*/
|
||||
public String renderType(int deployLength, int deployScale, boolean strict) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name);
|
||||
|
||||
if (canHaveLength || !strict) {
|
||||
// see if there is a precision/scale to add (or not)
|
||||
int len = deployLength != 0 ? deployLength : defaultLength;
|
||||
if (len > 0) {
|
||||
sb.append("(");
|
||||
sb.append(len);
|
||||
int scale = deployScale != 0 ? deployScale : defaultScale;
|
||||
if (scale > 0) {
|
||||
sb.append(",");
|
||||
sb.append(scale);
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy of the type with a new default length.
|
||||
*/
|
||||
public DbPlatformType withLength(int defaultLength) {
|
||||
return new DbPlatformType(name, defaultLength);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Helper to reverse lookup a DbType given the name or JDBC int value.
|
||||
*/
|
||||
class DbPlatformTypeLookup {
|
||||
|
||||
/**
|
||||
* A map to lookup the type by name.
|
||||
*/
|
||||
private Map<String, DbType> nameLookup = new HashMap<String, DbType>();
|
||||
|
||||
/**
|
||||
* A map to lookup the type by JDBC int value.
|
||||
*/
|
||||
private Map<Integer, DbType> idLookup = new HashMap<Integer, DbType>();
|
||||
|
||||
DbPlatformTypeLookup() {
|
||||
addAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DbType for the given name.
|
||||
*/
|
||||
DbType byName(String name) {
|
||||
return nameLookup.get(name.trim().toUpperCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DbType for the given name.
|
||||
*/
|
||||
DbType byId(int jdbcId) {
|
||||
return idLookup.get(jdbcId);
|
||||
}
|
||||
|
||||
private void addAll() {
|
||||
// Extra mapping for Float and Varchar2
|
||||
add("FLOAT", DbType.REAL);
|
||||
add("VARCHAR2", DbType.VARCHAR);
|
||||
for (DbType type : DbType.values()) {
|
||||
add(type.name(), type);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(String name, DbType dbType) {
|
||||
nameLookup.put(name, dbType);
|
||||
idLookup.put(dbType.id(), dbType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to map bean property types to DB specific types for DDL generation.
|
||||
*/
|
||||
public class DbPlatformTypeMapping {
|
||||
|
||||
private static DbPlatformTypeLookup lookup = new DbPlatformTypeLookup();
|
||||
|
||||
private static final DbPlatformType UUID_NATIVE = new DbPlatformType("uuid", false);
|
||||
private static final DbPlatformType UUID_PLACEHOLDER = new DbPlatformType("uuidPlaceholder");
|
||||
private static final DbPlatformType JSON_CLOB_PLACEHOLDER = new DbPlatformType("jsonClobPlaceholder");
|
||||
private static final DbPlatformType JSON_BLOB_PLACEHOLDER = new DbPlatformType("jsonBlobPlaceholder");
|
||||
private static final DbPlatformType JSON_VARCHAR_PLACEHOLDER = new DbPlatformType("jsonVarcharPlaceholder");
|
||||
|
||||
private final Map<DbType, DbPlatformType> typeMap = new HashMap<DbType, DbPlatformType>();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
public DbPlatformTypeMapping() {
|
||||
loadDefaults(false);
|
||||
}
|
||||
|
||||
private DbPlatformTypeMapping(boolean logicalTypes) {
|
||||
loadDefaults(logicalTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the standard types. These can be overridden by DB specific platform.
|
||||
*/
|
||||
private void loadDefaults(boolean logicalTypes) {
|
||||
|
||||
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);
|
||||
// most commonly real maps to db float
|
||||
put(DbType.REAL, new DbPlatformType("float"));
|
||||
|
||||
if (logicalTypes) {
|
||||
// keep it logical for 2 layer DDL generation
|
||||
put(DbType.VARCHAR, new DbPlatformType("varchar"));
|
||||
put(DbType.DECIMAL, new DbPlatformType("decimal"));
|
||||
put(DbType.VARBINARY, new DbPlatformType("varbinary"));
|
||||
put(DbType.BINARY, new DbPlatformType("binary"));
|
||||
put(DbType.CHAR, new DbPlatformType("char"));
|
||||
|
||||
put(DbType.HSTORE, new DbPlatformType("hstore", false));
|
||||
put(DbType.JSON, new DbPlatformType("json", false));
|
||||
put(DbType.JSONB, new DbPlatformType("jsonb", false));
|
||||
put(DbType.JSONCLOB, new DbPlatformType("jsonclob"));
|
||||
put(DbType.JSONBLOB, new DbPlatformType("jsonblob"));
|
||||
put(DbType.JSONVARCHAR, new DbPlatformType("jsonvarchar", 1000));
|
||||
put(DbType.UUID, UUID_NATIVE);
|
||||
|
||||
} else {
|
||||
put(DbType.VARCHAR, new DbPlatformType("varchar", 255));
|
||||
put(DbType.DECIMAL, new DbPlatformType("decimal", 38));
|
||||
put(DbType.VARBINARY, new DbPlatformType("varbinary", 255));
|
||||
put(DbType.BINARY, new DbPlatformType("binary", 255));
|
||||
put(DbType.CHAR, new DbPlatformType("char", 1));
|
||||
|
||||
put(DbType.JSON, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSON
|
||||
put(DbType.JSONB, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSONB
|
||||
put(DbType.JSONCLOB, JSON_CLOB_PLACEHOLDER);
|
||||
put(DbType.JSONBLOB, JSON_BLOB_PLACEHOLDER);
|
||||
put(DbType.JSONVARCHAR, JSON_VARCHAR_PLACEHOLDER);
|
||||
put(DbType.UUID, UUID_PLACEHOLDER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the type for a given JDBC type.
|
||||
*/
|
||||
private void put(DbType type) {
|
||||
typeMap.put(type, type.createPlatformType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the type for a given JDBC type.
|
||||
*/
|
||||
public void put(DbType type, DbPlatformType platformType) {
|
||||
typeMap.put(type, platformType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for a given jdbc type.
|
||||
*/
|
||||
public DbPlatformType get(int jdbcType) {
|
||||
return get(lookup.byId(jdbcType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for a given jdbc type.
|
||||
*/
|
||||
public DbPlatformType get(DbType dbType) {
|
||||
return typeMap.get(dbType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
/**
|
||||
* Parse raw column definitions into DbPlatformType like "decimal(18,6)" and "varchar(20) and "json".
|
||||
*/
|
||||
class DbPlatformTypeParser {
|
||||
|
||||
/**
|
||||
* Parse the column definition and return the DbPlatformType.
|
||||
*/
|
||||
static DbPlatformType parse(String columnDefinition) {
|
||||
|
||||
columnDefinition = columnDefinition.trim();
|
||||
|
||||
int openPos = columnDefinition.indexOf('(');
|
||||
if (openPos == -1) {
|
||||
return new DbPlatformType(columnDefinition, false);
|
||||
}
|
||||
int closePos = columnDefinition.indexOf(')', openPos);
|
||||
if (closePos == -1) {
|
||||
return new DbPlatformType(columnDefinition, false);
|
||||
}
|
||||
try {
|
||||
int commaPos = columnDefinition.indexOf(',', openPos);
|
||||
if (commaPos > -1) {
|
||||
String type = columnDefinition.substring(0, openPos);
|
||||
int scale = Integer.parseInt(columnDefinition.substring(openPos + 1, commaPos));
|
||||
int precision = Integer.parseInt(columnDefinition.substring(commaPos + 1, closePos));
|
||||
return new DbPlatformType(type, scale, precision);
|
||||
|
||||
} else {
|
||||
String type = columnDefinition.substring(0, openPos);
|
||||
int scale = Integer.parseInt(columnDefinition.substring(openPos + 1, closePos));
|
||||
return new DbPlatformType(type, scale);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
return new DbPlatformType(columnDefinition, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,161 +1,65 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* Represents a DB type with name, length, precision, and scale.
|
||||
* The known DB types that are mapped.
|
||||
* <p>
|
||||
* The length is for VARCHAR types and precision/scale for DECIMAL types.
|
||||
* This includes extra types such as UUID, JSON, JSONB and HSTORE.
|
||||
* </p>
|
||||
*/
|
||||
public class DbType {
|
||||
public enum DbType {
|
||||
|
||||
/**
|
||||
* DB native UUID type (H2 and Postgres).
|
||||
*/
|
||||
public static final int UUID = 5010;
|
||||
BOOLEAN(Types.BOOLEAN),
|
||||
BIT(Types.BIT),
|
||||
INTEGER(Types.INTEGER),
|
||||
BIGINT(Types.BIGINT),
|
||||
SMALLINT(Types.SMALLINT),
|
||||
TINYINT(Types.TINYINT),
|
||||
REAL(Types.REAL),
|
||||
//FLOAT(Types.FLOAT),
|
||||
DOUBLE(Types.DOUBLE),
|
||||
DECIMAL(Types.DECIMAL),
|
||||
VARCHAR(Types.VARCHAR),
|
||||
CHAR(Types.CHAR),
|
||||
BLOB(Types.BLOB),
|
||||
CLOB(Types.CLOB),
|
||||
LONGVARBINARY(Types.LONGVARBINARY),
|
||||
LONGVARCHAR(Types.LONGVARCHAR),
|
||||
VARBINARY(Types.VARBINARY),
|
||||
BINARY(Types.BINARY),
|
||||
DATE(Types.DATE),
|
||||
TIME(Types.TIME),
|
||||
TIMESTAMP(Types.TIMESTAMP),
|
||||
|
||||
/**
|
||||
* Type to map Map content to Postgres HSTORE.
|
||||
*/
|
||||
public static final int HSTORE = 5000;
|
||||
ARRAY(Types.ARRAY),
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Clob or Postgres JSON type.
|
||||
*/
|
||||
public static final int JSON = 5001;
|
||||
UUID(ExtraDbTypes.UUID),
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Clob or Postgres JSONB type.
|
||||
*/
|
||||
public static final int JSONB = 5002;
|
||||
HSTORE(ExtraDbTypes.HSTORE),
|
||||
JSON(ExtraDbTypes.JSON),
|
||||
JSONB(ExtraDbTypes.JSONB),
|
||||
JSONCLOB(ExtraDbTypes.JSONClob),
|
||||
JSONBLOB(ExtraDbTypes.JSONBlob),
|
||||
JSONVARCHAR(ExtraDbTypes.JSONVarchar);
|
||||
|
||||
/**
|
||||
* Type to map JSON content to VARCHAR.
|
||||
*/
|
||||
public static final int JSONVarchar = 5003;
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Clob.
|
||||
*/
|
||||
public static final int JSONClob = 5004;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Blob.
|
||||
*/
|
||||
public static final int JSONBlob = 5005;
|
||||
|
||||
/**
|
||||
* The data type name (VARCHAR, INTEGER ...)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The default length or precision.
|
||||
*/
|
||||
private final int defaultLength;
|
||||
|
||||
/**
|
||||
* The default scale (decimal).
|
||||
*/
|
||||
private final int defaultScale;
|
||||
|
||||
/**
|
||||
* Set to true if the type should never have a length or scale.
|
||||
*/
|
||||
private final boolean canHaveLength;
|
||||
|
||||
/**
|
||||
* Construct with no length or scale.
|
||||
*/
|
||||
public DbType(String name) {
|
||||
this(name, 0, 0);
|
||||
DbType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with a given length.
|
||||
* Return the JDBC java.sql.Types value.
|
||||
*/
|
||||
public DbType(String name, int defaultLength) {
|
||||
this(name, defaultLength, 0);
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct for Decimal with precision and scale.
|
||||
* Create a platform type without scale or precision.
|
||||
*/
|
||||
public DbType(String name, int defaultPrecision, int defaultScale) {
|
||||
this.name = name;
|
||||
this.defaultLength = defaultPrecision;
|
||||
this.defaultScale = defaultScale;
|
||||
this.canHaveLength = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use with canHaveLength=false for types that should never have a length.
|
||||
*
|
||||
* @param name
|
||||
* the type name
|
||||
* @param canHaveLength
|
||||
* set this to false for type that should never have a length
|
||||
*/
|
||||
public DbType(String name, boolean canHaveLength) {
|
||||
this.name = name;
|
||||
this.defaultLength = 0;
|
||||
this.defaultScale = 0;
|
||||
this.canHaveLength = canHaveLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for a specific property that incorporates the name, length,
|
||||
* precision and scale.
|
||||
* <p>
|
||||
* The deployLength and deployScale are for the property we are rendering the
|
||||
* DB type for.
|
||||
* </p>
|
||||
*
|
||||
* @param deployLength
|
||||
* the length or precision defined by deployment on a specific
|
||||
* property.
|
||||
* @param deployScale
|
||||
* the scale defined by deployment on a specific property.
|
||||
*/
|
||||
public String renderType(int deployLength, int deployScale) {
|
||||
return renderType(deployLength, deployScale, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the type defining strict mode.
|
||||
* <p>
|
||||
* If strict mode if OFF then this will render with a scale value even if
|
||||
* that is not strictly supported. The reason for supporting this is to enable
|
||||
* use to use types like jsonb(200) as a "logical" type that maps to JSONB for
|
||||
* Postgres and VARCHAR(200) for other databases.
|
||||
* </p>
|
||||
*/
|
||||
public String renderType(int deployLength, int deployScale, boolean strict) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(name);
|
||||
|
||||
if (canHaveLength || !strict) {
|
||||
// see if there is a precision/scale to add (or not)
|
||||
int len = deployLength != 0 ? deployLength : defaultLength;
|
||||
if (len > 0) {
|
||||
sb.append("(");
|
||||
sb.append(len);
|
||||
int scale = deployScale != 0 ? deployScale : defaultScale;
|
||||
if (scale > 0) {
|
||||
sb.append(",");
|
||||
sb.append(scale);
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy of the type with a new default length.
|
||||
*/
|
||||
public DbType withLength(int defaultLength) {
|
||||
return new DbType(name, defaultLength);
|
||||
public DbPlatformType createPlatformType() {
|
||||
return new DbPlatformType(name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,210 +0,0 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to map bean property types to DB specific types for DDL generation.
|
||||
*/
|
||||
public class DbTypeMap {
|
||||
|
||||
private static final DbType UUID_NATIVE = new DbType("uuid", false);
|
||||
private static final DbType UUID_PLACEHOLDER = new DbType("uuidPlaceholder");
|
||||
private static final DbType JSON_CLOB_PLACEHOLDER = new DbType("jsonClobPlaceholder");
|
||||
private static final DbType JSON_BLOB_PLACEHOLDER = new DbType("jsonBlobPlaceholder");
|
||||
private static final DbType JSON_VARCHAR_PLACEHOLDER = new DbType("jsonVarcharPlaceholder");
|
||||
|
||||
/**
|
||||
* A map to reverse lookup the type by name.
|
||||
* <p>
|
||||
* Used when converting from logical types to platform types which we
|
||||
* want to do with 2 phase DDL generation.
|
||||
*/
|
||||
static Map<String, Integer> lookup = new HashMap<String, Integer>();
|
||||
|
||||
static {
|
||||
lookup.put("BOOLEAN", Types.BOOLEAN);
|
||||
lookup.put("BIT", Types.BIT);
|
||||
lookup.put("INTEGER", Types.INTEGER);
|
||||
lookup.put("BIGINT", Types.BIGINT);
|
||||
lookup.put("REAL", Types.REAL);
|
||||
// Float is most common REAL mapping to have that as well
|
||||
lookup.put("FLOAT", Types.REAL);
|
||||
|
||||
lookup.put("DOUBLE", Types.DOUBLE);
|
||||
lookup.put("SMALLINT", Types.SMALLINT);
|
||||
lookup.put("TINYINT", Types.TINYINT);
|
||||
lookup.put("DECIMAL", Types.DECIMAL);
|
||||
lookup.put("VARCHAR", Types.VARCHAR);
|
||||
// VARCHAR2 - extra for Oracle specific column definition
|
||||
lookup.put("VARCHAR2", Types.VARCHAR);
|
||||
lookup.put("CHAR", Types.CHAR);
|
||||
lookup.put("BLOB", Types.BLOB);
|
||||
lookup.put("CLOB", Types.CLOB);
|
||||
|
||||
lookup.put("LONGVARBINARY", Types.LONGVARBINARY);
|
||||
lookup.put("LONGVARCHAR", Types.LONGVARCHAR);
|
||||
lookup.put("VARBINARY", Types.VARBINARY);
|
||||
lookup.put("BINARY", Types.BINARY);
|
||||
lookup.put("DATE", Types.DATE);
|
||||
lookup.put("TIME", Types.TIME);
|
||||
lookup.put("TIMESTAMP", Types.TIMESTAMP);
|
||||
|
||||
lookup.put("ARRAY", Types.ARRAY);
|
||||
lookup.put("UUID", DbType.UUID);
|
||||
|
||||
// Not standard java.sql.Types
|
||||
// logical JSON storage types
|
||||
lookup.put("JSON", DbType.JSON);
|
||||
lookup.put("JSONB", DbType.JSONB);
|
||||
lookup.put("JSONCLOB", DbType.JSONClob);
|
||||
lookup.put("JSONBLOB", DbType.JSONBlob);
|
||||
lookup.put("JSONVARCHAR", DbType.JSONVarchar);
|
||||
}
|
||||
|
||||
|
||||
private final Map<Integer, DbType> typeMap = new HashMap<Integer, DbType>();
|
||||
|
||||
/**
|
||||
* 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 DbTypeMap logicalTypes() {
|
||||
return new DbTypeMap(true);
|
||||
}
|
||||
|
||||
public DbTypeMap() {
|
||||
loadDefaults(false);
|
||||
}
|
||||
|
||||
private DbTypeMap(boolean logicalTypes) {
|
||||
loadDefaults(logicalTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the standard types. These can be overridden by DB specific platform.
|
||||
*/
|
||||
private void loadDefaults(boolean logicalTypes) {
|
||||
|
||||
put(Types.BOOLEAN, new DbType("boolean"));
|
||||
put(Types.BIT, new DbType("bit"));
|
||||
|
||||
put(Types.INTEGER, new DbType("integer"));
|
||||
put(Types.BIGINT, new DbType("bigint"));
|
||||
put(Types.REAL, new DbType("float"));
|
||||
put(Types.DOUBLE, new DbType("double"));
|
||||
put(Types.SMALLINT, new DbType("smallint"));
|
||||
put(Types.TINYINT, new DbType("tinyint"));
|
||||
put(Types.DECIMAL, new DbType("decimal", 38));
|
||||
|
||||
put(Types.VARCHAR, new DbType("varchar", 255));
|
||||
put(Types.CHAR, new DbType("char", 1));
|
||||
|
||||
put(Types.BLOB, new DbType("blob"));
|
||||
put(Types.CLOB, new DbType("clob"));
|
||||
|
||||
put(Types.ARRAY, new DbType("array"));
|
||||
|
||||
if (logicalTypes) {
|
||||
// keep it logical for 2 layer DDL generation
|
||||
put(DbType.HSTORE, new DbType("hstore", false));
|
||||
put(DbType.JSON, new DbType("json", false));
|
||||
put(DbType.JSONB, new DbType("jsonb", false));
|
||||
put(DbType.JSONClob, new DbType("jsonclob"));
|
||||
put(DbType.JSONBlob, new DbType("jsonblob"));
|
||||
put(DbType.JSONVarchar, new DbType("jsonvarchar", 1000));
|
||||
put(DbType.UUID, UUID_NATIVE);
|
||||
|
||||
} else {
|
||||
put(DbType.JSON, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSON
|
||||
put(DbType.JSONB, JSON_CLOB_PLACEHOLDER); // Postgres maps this to JSONB
|
||||
put(DbType.JSONClob, JSON_CLOB_PLACEHOLDER);
|
||||
put(DbType.JSONBlob, JSON_BLOB_PLACEHOLDER);
|
||||
put(DbType.JSONVarchar, JSON_VARCHAR_PLACEHOLDER);
|
||||
put(DbType.UUID, UUID_PLACEHOLDER);
|
||||
}
|
||||
|
||||
put(Types.LONGVARBINARY, new DbType("longvarbinary"));
|
||||
put(Types.LONGVARCHAR, new DbType("lonvarchar"));
|
||||
put(Types.VARBINARY, new DbType("varbinary", 255));
|
||||
put(Types.BINARY, new DbType("binary", 255));
|
||||
|
||||
put(Types.DATE, new DbType("date"));
|
||||
put(Types.TIME, new DbType("time"));
|
||||
put(Types.TIMESTAMP, new DbType("timestamp"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup the platform specific DbType given the standard sql type name.
|
||||
*/
|
||||
public DbType lookup(String name, boolean withScale) {
|
||||
name = name.trim().toUpperCase();
|
||||
Integer typeKey = lookup.get(name);
|
||||
if (typeKey == null) {
|
||||
throw new IllegalArgumentException("Unknown type [" + name + "] - not standard sql type");
|
||||
}
|
||||
// handle JSON types mapped to clob, blob and varchar
|
||||
switch (typeKey) {
|
||||
case DbType.JSONBlob:
|
||||
return get(Types.BLOB);
|
||||
case DbType.JSONClob:
|
||||
return get(Types.CLOB);
|
||||
case DbType.JSONVarchar:
|
||||
return get(Types.VARCHAR);
|
||||
case DbType.JSON:
|
||||
return getJsonType(DbType.JSON, withScale);
|
||||
case DbType.JSONB:
|
||||
return getJsonType(DbType.JSONB, withScale);
|
||||
default:
|
||||
return get(typeKey);
|
||||
}
|
||||
}
|
||||
|
||||
private DbType getJsonType(int type, boolean withScale) {
|
||||
DbType dbType = get(type);
|
||||
if (dbType == JSON_CLOB_PLACEHOLDER) {
|
||||
// if we have scale that implies this maps to varchar
|
||||
return withScale ? get(Types.VARCHAR) : get(Types.CLOB);
|
||||
}
|
||||
if (dbType == JSON_BLOB_PLACEHOLDER) {
|
||||
return get(Types.BLOB);
|
||||
}
|
||||
if (dbType == JSON_VARCHAR_PLACEHOLDER) {
|
||||
return get(Types.VARCHAR);
|
||||
}
|
||||
// Postgres has specific type
|
||||
return get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the type for a given JDBC type.
|
||||
*/
|
||||
public void put(int jdbcType, DbType dbType) {
|
||||
typeMap.put(jdbcType, dbType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type for a given jdbc type.
|
||||
*/
|
||||
public DbType get(int jdbcType) {
|
||||
return typeMap.get(jdbcType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(Types.BINARY).withLength(16));
|
||||
} else {
|
||||
put(DbType.UUID, get(Types.VARCHAR).withLength(40));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
/**
|
||||
* Integer codes for the extra types beyond java.sql.Types.
|
||||
*/
|
||||
public interface ExtraDbTypes {
|
||||
|
||||
/**
|
||||
* DB native UUID type (H2 and Postgres).
|
||||
*/
|
||||
int UUID = 5010;
|
||||
|
||||
/**
|
||||
* Type to map Map content to Postgres HSTORE.
|
||||
*/
|
||||
int HSTORE = 5000;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Clob or Postgres JSON type.
|
||||
*/
|
||||
int JSON = 5001;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Clob or Postgres JSONB type.
|
||||
*/
|
||||
int JSONB = 5002;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to VARCHAR.
|
||||
*/
|
||||
int JSONVarchar = 5003;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Clob.
|
||||
*/
|
||||
int JSONClob = 5004;
|
||||
|
||||
/**
|
||||
* Type to map JSON content to Blob.
|
||||
*/
|
||||
int JSONBlob = 5005;
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.avaje.ebean.BackgroundExecutor;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.platform.HsqldbDdl;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* H2 specific platform.
|
||||
@@ -22,7 +21,7 @@ public class HsqldbPlatform extends DatabasePlatform {
|
||||
this.dbIdentity.setSupportsSequence(true);
|
||||
this.dbIdentity.setSupportsIdentity(true);
|
||||
|
||||
dbTypeMap.put(Types.INTEGER, new DbType("integer", false));
|
||||
dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import com.avaje.ebean.config.PersistBatch;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* Microsoft SQL Server 2000 specific platform.
|
||||
* <p>
|
||||
@@ -29,22 +27,22 @@ public class MsSqlServer2000Platform extends DatabasePlatform {
|
||||
this.openQuote = "[";
|
||||
this.closeQuote = "]";
|
||||
|
||||
dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
|
||||
dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0"));
|
||||
|
||||
dbTypeMap.put(Types.BIGINT, new DbType("numeric", 19));
|
||||
dbTypeMap.put(Types.REAL, new DbType("float(16)"));
|
||||
dbTypeMap.put(Types.DOUBLE, new DbType("float(32)"));
|
||||
dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
|
||||
dbTypeMap.put(Types.DECIMAL, new DbType("numeric", 28));
|
||||
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(Types.BLOB, new DbType("image"));
|
||||
dbTypeMap.put(Types.CLOB, new DbType("text"));
|
||||
dbTypeMap.put(Types.LONGVARBINARY, new DbType("image"));
|
||||
dbTypeMap.put(Types.LONGVARCHAR, new DbType("text"));
|
||||
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(Types.DATE, new DbType("datetime"));
|
||||
dbTypeMap.put(Types.TIME, new DbType("datetime"));
|
||||
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime"));
|
||||
dbTypeMap.put(DbType.DATE, new DbPlatformType("datetime"));
|
||||
dbTypeMap.put(DbType.TIME, new DbPlatformType("datetime"));
|
||||
dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.avaje.ebean.config.dbplatform;
|
||||
import com.avaje.ebean.config.PersistBatch;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.platform.MsSqlServerDdl;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* Microsoft SQL Server 2005 specific platform.
|
||||
* <p>
|
||||
@@ -34,23 +32,23 @@ public class MsSqlServer2005Platform extends DatabasePlatform {
|
||||
this.openQuote = "[";
|
||||
this.closeQuote = "]";
|
||||
|
||||
dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
|
||||
dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("bit default 0"));
|
||||
|
||||
dbTypeMap.put(Types.INTEGER, new DbType("integer", false));
|
||||
dbTypeMap.put(Types.BIGINT, new DbType("numeric", 19));
|
||||
dbTypeMap.put(Types.REAL, new DbType("float(16)"));
|
||||
dbTypeMap.put(Types.DOUBLE, new DbType("float(32)"));
|
||||
dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
|
||||
dbTypeMap.put(Types.DECIMAL, new DbType("numeric", 28));
|
||||
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(Types.BLOB, new DbType("image"));
|
||||
dbTypeMap.put(Types.CLOB, new DbType("text"));
|
||||
dbTypeMap.put(Types.LONGVARBINARY, new DbType("image"));
|
||||
dbTypeMap.put(Types.LONGVARCHAR, new DbType("text"));
|
||||
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(Types.DATE, new DbType("date"));
|
||||
dbTypeMap.put(Types.TIME, new DbType("time"));
|
||||
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime2"));
|
||||
dbTypeMap.put(DbType.DATE, new DbPlatformType("date"));
|
||||
dbTypeMap.put(DbType.TIME, new DbPlatformType("time"));
|
||||
dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime2"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ package com.avaje.ebean.config.dbplatform;
|
||||
* If no deployment length is defined longblob is used.
|
||||
* </p>
|
||||
*/
|
||||
public class MySqlBlob extends DbType {
|
||||
public class MySqlBlob extends DbPlatformType {
|
||||
|
||||
private static final int POWER_2_16 = 65536;
|
||||
private static final int POWER_2_24 = 16777216;
|
||||
|
||||
@@ -7,7 +7,7 @@ package com.avaje.ebean.config.dbplatform;
|
||||
* If no deployment length is defined longtext is used.
|
||||
* </p>
|
||||
*/
|
||||
public class MySqlClob extends DbType {
|
||||
public class MySqlClob extends DbPlatformType {
|
||||
|
||||
private static final int POWER_2_16 = 65536;
|
||||
private static final int POWER_2_24 = 16777216;
|
||||
|
||||
@@ -39,13 +39,13 @@ public class MySqlPlatform extends DatabasePlatform {
|
||||
this.forwardOnlyHintOnFindIterate = true;
|
||||
this.booleanDbType = Types.BIT;
|
||||
|
||||
dbTypeMap.put(Types.BIT, new DbType("tinyint(1) default 0"));
|
||||
dbTypeMap.put(Types.BOOLEAN, new DbType("tinyint(1) default 0"));
|
||||
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime(6)"));
|
||||
dbTypeMap.put(Types.CLOB, new MySqlClob());
|
||||
dbTypeMap.put(Types.BLOB, new MySqlBlob());
|
||||
dbTypeMap.put(Types.BINARY, new DbType("binary", 255));
|
||||
dbTypeMap.put(Types.VARBINARY, new DbType("varbinary", 255));
|
||||
dbTypeMap.put(DbType.BIT, new DbPlatformType("tinyint(1) default 0"));
|
||||
dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("tinyint(1) default 0"));
|
||||
dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime(6)"));
|
||||
dbTypeMap.put(DbType.CLOB, new MySqlClob());
|
||||
dbTypeMap.put(DbType.BLOB, new MySqlBlob());
|
||||
dbTypeMap.put(DbType.BINARY, new DbPlatformType("binary", 255));
|
||||
dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("varbinary", 255));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,24 +34,24 @@ public class OraclePlatform extends DatabasePlatform {
|
||||
this.closeQuote = "\"";
|
||||
|
||||
booleanDbType = Types.INTEGER;
|
||||
dbTypeMap.put(Types.BOOLEAN, new DbType("number(1) default 0"));
|
||||
dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("number(1) default 0"));
|
||||
|
||||
dbTypeMap.put(Types.INTEGER, new DbType("number", 10));
|
||||
dbTypeMap.put(Types.BIGINT, new DbType("number", 19));
|
||||
dbTypeMap.put(Types.REAL, new DbType("number", 19, 4));
|
||||
dbTypeMap.put(Types.DOUBLE, new DbType("number", 19, 4));
|
||||
dbTypeMap.put(Types.SMALLINT, new DbType("number", 5));
|
||||
dbTypeMap.put(Types.TINYINT, new DbType("number", 3));
|
||||
dbTypeMap.put(Types.DECIMAL, new DbType("number", 38));
|
||||
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(Types.VARCHAR, new DbType("varchar2", 255));
|
||||
dbTypeMap.put(DbType.VARCHAR, new DbPlatformType("varchar2", 255));
|
||||
|
||||
dbTypeMap.put(Types.LONGVARBINARY, new DbType("blob"));
|
||||
dbTypeMap.put(Types.LONGVARCHAR, new DbType("clob"));
|
||||
dbTypeMap.put(Types.VARBINARY, new DbType("raw", 255));
|
||||
dbTypeMap.put(Types.BINARY, new DbType("raw", 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(Types.TIME, new DbType("timestamp"));
|
||||
dbTypeMap.put(DbType.TIME, new DbPlatformType("timestamp"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,26 +41,26 @@ public class PostgresPlatform extends DatabasePlatform {
|
||||
this.openQuote = "\"";
|
||||
this.closeQuote = "\"";
|
||||
|
||||
DbType dbTypeText = new DbType("text");
|
||||
DbType dbBytea = new DbType("bytea", false);
|
||||
DbPlatformType dbTypeText = new DbPlatformType("text");
|
||||
DbPlatformType dbBytea = new DbPlatformType("bytea", false);
|
||||
|
||||
dbTypeMap.put(DbType.HSTORE, new DbType("hstore", false));
|
||||
dbTypeMap.put(DbType.JSON, new DbType("json", false));
|
||||
dbTypeMap.put(DbType.JSONB, new DbType("jsonb", 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(Types.INTEGER, new DbType("integer", false));
|
||||
dbTypeMap.put(Types.DOUBLE, new DbType("float"));
|
||||
dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
|
||||
dbTypeMap.put(Types.DECIMAL, new DbType("decimal", 38));
|
||||
dbTypeMap.put(Types.TIMESTAMP, new DbType("timestamptz"));
|
||||
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(Types.BINARY, dbBytea);
|
||||
dbTypeMap.put(Types.VARBINARY, dbBytea);
|
||||
dbTypeMap.put(DbType.BINARY, dbBytea);
|
||||
dbTypeMap.put(DbType.VARBINARY, dbBytea);
|
||||
|
||||
dbTypeMap.put(Types.BLOB, dbBytea);
|
||||
dbTypeMap.put(Types.CLOB, dbTypeText);
|
||||
dbTypeMap.put(Types.LONGVARBINARY, dbBytea);
|
||||
dbTypeMap.put(Types.LONGVARCHAR, dbTypeText);
|
||||
dbTypeMap.put(DbType.BLOB, dbBytea);
|
||||
dbTypeMap.put(DbType.CLOB, dbTypeText);
|
||||
dbTypeMap.put(DbType.LONGVARBINARY, dbBytea);
|
||||
dbTypeMap.put(DbType.LONGVARCHAR, dbTypeText);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +71,7 @@ public class PostgresPlatform extends DatabasePlatform {
|
||||
String tsType = properties.getProperty("ebean.postgres.timestamp");
|
||||
if (tsType != null) {
|
||||
// set timestamp type to "timestamp" without time zone
|
||||
dbTypeMap.put(Types.TIMESTAMP, new DbType(tsType));
|
||||
dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType(tsType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public class SQLitePlatform extends DatabasePlatform {
|
||||
|
||||
this.booleanDbType = Types.INTEGER;
|
||||
|
||||
dbTypeMap.put(Types.BIT, new DbType("int default 0"));
|
||||
dbTypeMap.put(Types.BOOLEAN, new DbType("int default 0"));
|
||||
dbTypeMap.put(Types.BIGINT, new DbType("integer"));
|
||||
dbTypeMap.put(Types.SMALLINT, new DbType("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"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* Sybase SQL Anywhere specific platform.
|
||||
* <p>
|
||||
@@ -23,17 +21,17 @@ public class SqlAnywherePlatform extends DatabasePlatform {
|
||||
this.dbIdentity.setSelectLastInsertedIdTemplate("select @@IDENTITY as X");
|
||||
this.dbIdentity.setSupportsIdentity(true);
|
||||
|
||||
dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
|
||||
dbTypeMap.put(Types.BIGINT, new DbType("numeric", 19));
|
||||
dbTypeMap.put(Types.REAL, new DbType("float(16)"));
|
||||
dbTypeMap.put(Types.DOUBLE, new DbType("float(32)"));
|
||||
dbTypeMap.put(Types.TINYINT, new DbType("smallint"));
|
||||
dbTypeMap.put(Types.DECIMAL, new DbType("numeric", 28));
|
||||
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(Types.BLOB, new DbType("binary(4500)"));
|
||||
dbTypeMap.put(Types.CLOB, new DbType("long varchar"));
|
||||
dbTypeMap.put(Types.LONGVARBINARY, new DbType("long binary"));
|
||||
dbTypeMap.put(Types.LONGVARCHAR, new DbType("long varchar"));
|
||||
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"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.avaje.ebean.config.DbMigrationConfig;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.dbplatform.DB2Platform;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformName;
|
||||
import com.avaje.ebean.config.Platform;
|
||||
import com.avaje.ebean.config.dbplatform.H2Platform;
|
||||
import com.avaje.ebean.config.dbplatform.MsSqlServer2005Platform;
|
||||
import com.avaje.ebean.config.dbplatform.MySqlPlatform;
|
||||
@@ -139,7 +139,7 @@ public class DbMigration {
|
||||
* If not set this defaults to the platform of the default server.
|
||||
* </p>
|
||||
*/
|
||||
public void setPlatform(DbPlatformName platform) {
|
||||
public void setPlatform(Platform platform) {
|
||||
setPlatform(getPlatform(platform));
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class DbMigration {
|
||||
* from the migration (e.g. generate migration sql for MySql, Postgres and Oracle).
|
||||
* </p>
|
||||
*/
|
||||
public void addPlatform(DbPlatformName platform, String prefix) {
|
||||
public void addPlatform(Platform platform, String prefix) {
|
||||
platforms.add(new Pair(getPlatform(platform), prefix));
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ public class DbMigration {
|
||||
/**
|
||||
* Return the DatabasePlatform given the platform key.
|
||||
*/
|
||||
protected DatabasePlatform getPlatform(DbPlatformName platform) {
|
||||
protected DatabasePlatform getPlatform(Platform platform) {
|
||||
switch (platform) {
|
||||
case H2:
|
||||
return new H2Platform();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebean.dbmigration;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformName;
|
||||
import com.avaje.ebean.config.Platform;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class DbOffline {
|
||||
/**
|
||||
* Set the platform to use when creating the next EbeanServer instance.
|
||||
*/
|
||||
public static void setPlatform(DbPlatformName dbPlatform) {
|
||||
public static void setPlatform(Platform dbPlatform) {
|
||||
System.setProperty(KEY, dbPlatform.name());
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DbOffline {
|
||||
* Bring up the next EbeanServer instance using the H2 platform.
|
||||
*/
|
||||
public static void asH2() {
|
||||
setPlatform(DbPlatformName.H2);
|
||||
setPlatform(Platform.H2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -110,7 +110,6 @@ public class PlatformDdl {
|
||||
* Set configuration options.
|
||||
*/
|
||||
public void configure(ServerConfig serverConfig) {
|
||||
platform.configure(serverConfig);
|
||||
historyDdl.configure(serverConfig, this);
|
||||
naming = serverConfig.getConstraintNaming();
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
package com.avaje.ebean.dbmigration.ddlgeneration.platform.util;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbTypeMap;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformTypeMapping;
|
||||
|
||||
/**
|
||||
* Converts a logical column definition into platform specific one.
|
||||
@@ -10,12 +10,12 @@ import com.avaje.ebean.config.dbplatform.DbTypeMap;
|
||||
*/
|
||||
public class PlatformTypeConverter {
|
||||
|
||||
protected final DbTypeMap platformTypes;
|
||||
protected final DbPlatformTypeMapping platformTypes;
|
||||
|
||||
/**
|
||||
* Construct with the platform specific types.
|
||||
*/
|
||||
public PlatformTypeConverter(DbTypeMap platformTypes) {
|
||||
public PlatformTypeConverter(DbPlatformTypeMapping platformTypes) {
|
||||
this.platformTypes = platformTypes;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class PlatformTypeConverter {
|
||||
String suffix = close + 1 < columnDefinition.length() ? columnDefinition.substring(close + 1) : "";
|
||||
String type = columnDefinition.substring(0, open);
|
||||
try {
|
||||
DbType dbType = platformTypes.lookup(type, true);
|
||||
DbPlatformType dbType = platformTypes.lookup(type, true);
|
||||
int comma = columnDefinition.indexOf(',', open);
|
||||
if (comma > -1) {
|
||||
// scale and precision - decimal(10,4)
|
||||
@@ -73,7 +73,7 @@ public class PlatformTypeConverter {
|
||||
protected String convertNoScale(String columnDefinition) {
|
||||
|
||||
try {
|
||||
DbType dbType = platformTypes.lookup(columnDefinition, false);
|
||||
DbPlatformType dbType = platformTypes.lookup(columnDefinition, false);
|
||||
return dbType.renderType(0, 0);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebean.dbmigration.model.build;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.config.dbplatform.IdType;
|
||||
import com.avaje.ebean.dbmigration.migration.IdentityType;
|
||||
import com.avaje.ebean.dbmigration.model.MColumn;
|
||||
@@ -52,7 +52,7 @@ public class ModelBuildBeanVisitor implements BeanVisitor {
|
||||
if (inheritInfo != null && inheritInfo.isRoot()) {
|
||||
// add the discriminator column
|
||||
String discColumn = inheritInfo.getDiscriminatorColumn();
|
||||
DbType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType());
|
||||
DbPlatformType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType());
|
||||
String discDbType = dbType.renderType(inheritInfo.getDiscriminatorLength(), 0);
|
||||
|
||||
table.addColumn(new MColumn(discColumn, discDbType, true));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.avaje.ebean.dbmigration.model.build;
|
||||
|
||||
import com.avaje.ebean.config.DbConstraintNaming;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbTypeMap;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformTypeMapping;
|
||||
import com.avaje.ebean.dbmigration.model.MColumn;
|
||||
import com.avaje.ebean.dbmigration.model.MTable;
|
||||
import com.avaje.ebean.dbmigration.model.ModelContainer;
|
||||
@@ -21,7 +21,7 @@ public class ModelBuildContext {
|
||||
* Use platform agnostic logical types. These types are converted to
|
||||
* platform specific types in the DDL generation.
|
||||
*/
|
||||
private final DbTypeMap dbTypeMap = DbTypeMap.logicalTypes();
|
||||
private final DbPlatformTypeMapping dbTypeMap = DbPlatformTypeMapping.logicalTypes();
|
||||
|
||||
private final ModelContainer model;
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ModelBuildContext {
|
||||
* Return the map used to determine the DB specific type
|
||||
* for a given bean property.
|
||||
*/
|
||||
public DbTypeMap getDbTypeMap() {
|
||||
public DbPlatformTypeMapping getDbTypeMap() {
|
||||
return dbTypeMap;
|
||||
}
|
||||
|
||||
@@ -115,14 +115,14 @@ public class ModelBuildContext {
|
||||
* Render the DB type for this property given the strict mode.
|
||||
*/
|
||||
public String getColumnDefn(BeanProperty p, boolean strict) {
|
||||
DbType dbType = getDbType(p);
|
||||
DbPlatformType dbType = getDbType(p);
|
||||
if (dbType == null) {
|
||||
throw new IllegalStateException("Unknown DbType mapping for " + p.getFullBeanName());
|
||||
}
|
||||
return p.renderDbType(dbType, strict);
|
||||
}
|
||||
|
||||
private DbType getDbType(BeanProperty p) {
|
||||
private DbPlatformType getDbType(BeanProperty p) {
|
||||
|
||||
if (p.isDbEncrypted()) {
|
||||
return dbTypeMap.get(p.getDbEncryptedType());
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.plugin.Property;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -972,7 +972,7 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
/**
|
||||
* Return the DB column type definition.
|
||||
*/
|
||||
public String renderDbType(DbType dbType, boolean strict) {
|
||||
public String renderDbType(DbPlatformType dbType, boolean strict) {
|
||||
if (dbColumnDefn != null) {
|
||||
return dbColumnDefn;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.avaje.ebean.config.NamingConvention;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.TableName;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound;
|
||||
import com.avaje.ebeaninternal.server.type.DataEncryptSupport;
|
||||
@@ -254,7 +254,7 @@ public class DeployUtil {
|
||||
}
|
||||
|
||||
public void setDbJsonBType(DeployBeanProperty prop, DbJsonB dbJsonB) {
|
||||
setDbJsonType(prop, DbType.JSONB, dbJsonB.length());
|
||||
setDbJsonType(prop, DbPlatformType.JSONB, dbJsonB.length());
|
||||
}
|
||||
|
||||
private void setDbJsonType(DeployBeanProperty prop, int dbType, int dbLength) {
|
||||
@@ -280,9 +280,9 @@ public class DeployUtil {
|
||||
|
||||
switch (dbJsonType) {
|
||||
case JSON:
|
||||
return DbType.JSON;
|
||||
return DbPlatformType.JSON;
|
||||
case JSONB:
|
||||
return DbType.JSONB;
|
||||
return DbPlatformType.JSONB;
|
||||
case VARCHAR:
|
||||
return Types.VARCHAR;
|
||||
case CLOB:
|
||||
@@ -290,7 +290,7 @@ public class DeployUtil {
|
||||
case BLOB:
|
||||
return Types.BLOB;
|
||||
default:
|
||||
return DbType.JSON;
|
||||
return DbPlatformType.JSON;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -323,11 +323,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
return query.findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureRowCount<T> findFutureRowCount() {
|
||||
return findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureList<T> findFutureList() {
|
||||
return query.findFutureList();
|
||||
@@ -343,11 +338,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
return query.findCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findRowCount() {
|
||||
return findCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A> List<A> findIds() {
|
||||
return query.findIds();
|
||||
|
||||
@@ -53,11 +53,6 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
|
||||
return rootQuery.findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureRowCount<T> findFutureRowCount() {
|
||||
return findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> findList() {
|
||||
return rootQuery.findList();
|
||||
@@ -73,11 +68,6 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
|
||||
return rootQuery.findCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findRowCount() {
|
||||
return findCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<T> findSet() {
|
||||
return rootQuery.findSet();
|
||||
|
||||
@@ -362,11 +362,6 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
return exprList.findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureRowCount<T> findFutureRowCount() {
|
||||
return findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A> List<A> findIds() {
|
||||
return exprList.findIds();
|
||||
@@ -409,12 +404,7 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
|
||||
@Override
|
||||
public int findCount() {
|
||||
return exprList.findRowCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findRowCount() {
|
||||
return findCount();
|
||||
return exprList.findCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.server.core.DbExpressionHandler;
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
@@ -321,7 +321,7 @@ public class Binder {
|
||||
b.setBytes((byte[]) data);
|
||||
break;
|
||||
|
||||
case DbType.UUID:
|
||||
case DbPlatformType.UUID:
|
||||
// native UUID support in H2 and Postgres
|
||||
b.setObject(data);
|
||||
break;
|
||||
|
||||
@@ -83,6 +83,11 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
*/
|
||||
private EntityBean currentBean;
|
||||
|
||||
/**
|
||||
* Caches hasNext for consecutive hasNext() calls.
|
||||
*/
|
||||
private boolean hasNextCache;
|
||||
|
||||
private final BeanPropertyAssocMany<?> lazyLoadManyProperty;
|
||||
|
||||
private Object lazyLoadParentId;
|
||||
@@ -504,6 +509,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
if (auditFindIterate) {
|
||||
auditIterateNextBean();
|
||||
}
|
||||
hasNextCache = false;
|
||||
return nextBean;
|
||||
}
|
||||
|
||||
@@ -513,7 +519,11 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
if (noMoreRows || cancelled || loadedBeanCount >= maxRowsLimit) {
|
||||
return false;
|
||||
}
|
||||
return readNextBean();
|
||||
if (hasNextCache) {
|
||||
return true;
|
||||
}
|
||||
hasNextCache = readNextBean();
|
||||
return hasNextCache;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1099,11 +1099,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return server.findCount(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findRowCount() {
|
||||
return findCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void findEachWhile(QueryEachWhileConsumer<T> consumer) {
|
||||
server.findEachWhile(this, consumer, null);
|
||||
@@ -1177,11 +1172,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return server.findFutureCount(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureRowCount<T> findFutureRowCount() {
|
||||
return findFutureCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagedList<T> findPagedList() {
|
||||
return server.findPagedList(this, null);
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.dbmigration.DbOffline;
|
||||
import com.avaje.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
import com.avaje.ebeaninternal.server.type.reflect.CheckImmutable;
|
||||
@@ -421,9 +421,9 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
return jsonNodeBlob;
|
||||
case Types.CLOB:
|
||||
return jsonNodeClob;
|
||||
case DbType.JSONB:
|
||||
case DbPlatformType.JSONB:
|
||||
return jsonNodeJsonb;
|
||||
case DbType.JSON:
|
||||
case DbPlatformType.JSON:
|
||||
return jsonNodeJson;
|
||||
default:
|
||||
return jsonNodeJson;
|
||||
@@ -939,7 +939,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
int platformClobType = databasePlatform.getClobDbType();
|
||||
int platformBlobType = databasePlatform.getBlobDbType();
|
||||
|
||||
nativeMap.put(DbType.HSTORE, hstoreType);
|
||||
nativeMap.put(DbPlatformType.HSTORE, hstoreType);
|
||||
|
||||
ScalarType<?> utilDateType = extraTypeFactory.createUtilDate(mode);
|
||||
typeMap.put(java.util.Date.class, utilDateType);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.text.json.EJson;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@@ -22,9 +22,9 @@ public class ScalarTypeJsonList {
|
||||
public static ScalarType<?> typeFor(boolean postgres, int dbType, DocPropertyType docType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbType.JSONB:
|
||||
case DbPlatformType.JSONB:
|
||||
return new ScalarTypeJsonList.JsonB(docType);
|
||||
case DbType.JSON:
|
||||
case DbPlatformType.JSON:
|
||||
return new ScalarTypeJsonList.Json(docType);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class ScalarTypeJsonList {
|
||||
*/
|
||||
private static class Json extends ScalarTypeJsonList.PgBase {
|
||||
public Json(DocPropertyType docType) {
|
||||
super(DbType.JSON, PostgresHelper.JSON_TYPE, docType);
|
||||
super(DbPlatformType.JSON, PostgresHelper.JSON_TYPE, docType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ScalarTypeJsonList {
|
||||
*/
|
||||
private static class JsonB extends ScalarTypeJsonList.PgBase {
|
||||
public JsonB(DocPropertyType docType) {
|
||||
super(DbType.JSONB, PostgresHelper.JSONB_TYPE, docType);
|
||||
super(DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE, docType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebean.text.json.EJson;
|
||||
import com.avaje.ebeaninternal.util.EncodeUtil;
|
||||
@@ -41,9 +41,9 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase<Map> {
|
||||
return BLOB;
|
||||
case Types.CLOB:
|
||||
return CLOB;
|
||||
case DbType.JSONB:
|
||||
case DbPlatformType.JSONB:
|
||||
return postgres ? JSONB : CLOB;
|
||||
case DbType.JSON:
|
||||
case DbPlatformType.JSON:
|
||||
return postgres ? JSON : CLOB;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown dbType " + dbType);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
@@ -30,7 +30,7 @@ public abstract class ScalarTypeJsonMapPostgres extends ScalarTypeJsonMap {
|
||||
public static class JSON extends ScalarTypeJsonMapPostgres {
|
||||
|
||||
public JSON() {
|
||||
super(DbType.JSON, PostgresHelper.JSON_TYPE);
|
||||
super(DbPlatformType.JSON, PostgresHelper.JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class ScalarTypeJsonMapPostgres extends ScalarTypeJsonMap {
|
||||
public static class JSONB extends ScalarTypeJsonMapPostgres {
|
||||
|
||||
public JSONB() {
|
||||
super(DbType.JSONB, PostgresHelper.JSONB_TYPE);
|
||||
super(DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode {
|
||||
public static class JSON extends ScalarTypeJsonNodePostgres {
|
||||
|
||||
public JSON(ObjectMapper objectMapper) {
|
||||
super(objectMapper, DbType.JSON, PostgresHelper.JSON_TYPE);
|
||||
super(objectMapper, DbPlatformType.JSON, PostgresHelper.JSON_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode {
|
||||
public static class JSONB extends ScalarTypeJsonNodePostgres {
|
||||
|
||||
public JSONB(ObjectMapper objectMapper) {
|
||||
super(objectMapper, DbType.JSONB, PostgresHelper.JSONB_TYPE);
|
||||
super(objectMapper, DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
@@ -45,9 +45,9 @@ public class ScalarTypeJsonObjectMapper {
|
||||
private static String getPostgresType(boolean postgres, int dbType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbType.JSON:
|
||||
case DbPlatformType.JSON:
|
||||
return PostgresHelper.JSON_TYPE;
|
||||
case DbType.JSONB:
|
||||
case DbPlatformType.JSONB:
|
||||
return PostgresHelper.JSONB_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.text.json.EJson;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@@ -25,9 +25,9 @@ public class ScalarTypeJsonSet {
|
||||
public static ScalarType<?> typeFor(boolean postgres, int dbType, DocPropertyType docPropertyType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbType.JSONB:
|
||||
case DbPlatformType.JSONB:
|
||||
return new ScalarTypeJsonSet.JsonB(docPropertyType);
|
||||
case DbType.JSON:
|
||||
case DbPlatformType.JSON:
|
||||
return new ScalarTypeJsonSet.Json(docPropertyType);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class ScalarTypeJsonSet {
|
||||
*/
|
||||
private static class Json extends ScalarTypeJsonSet.PgBase {
|
||||
public Json(DocPropertyType docPropertyType) {
|
||||
super(DbType.JSON, PostgresHelper.JSON_TYPE, docPropertyType);
|
||||
super(DbPlatformType.JSON, PostgresHelper.JSON_TYPE, docPropertyType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ScalarTypeJsonSet {
|
||||
*/
|
||||
private static class JsonB extends ScalarTypeJsonSet.PgBase {
|
||||
public JsonB(DocPropertyType docPropertyType) {
|
||||
super(DbType.JSONB, PostgresHelper.JSONB_TYPE, docPropertyType);
|
||||
super(DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE, docPropertyType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebean.text.json.EJson;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
@@ -20,7 +20,7 @@ import java.util.Map;
|
||||
public class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
|
||||
|
||||
public ScalarTypePostgresHstore() {
|
||||
super(Map.class, false, DbType.HSTORE);
|
||||
super(Map.class, false, DbPlatformType.HSTORE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@@ -22,7 +22,7 @@ public abstract class ScalarTypeUUIDBase extends ScalarTypeBase<UUID> implements
|
||||
|
||||
@Override
|
||||
public int getLogicalType() {
|
||||
return DbType.UUID;
|
||||
return DbPlatformType.UUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformType;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
@@ -11,7 +11,7 @@ import java.util.UUID;
|
||||
public class ScalarTypeUUIDNative extends ScalarTypeUUIDBase {
|
||||
|
||||
public ScalarTypeUUIDNative() {
|
||||
super(false, DbType.UUID);
|
||||
super(false, DbPlatformType.UUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.avaje.ebean.config;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformName;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
@@ -25,9 +24,9 @@ public class PropertiesWrapperTest {
|
||||
properties.put("platform","postgres");
|
||||
|
||||
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", properties);
|
||||
assertEquals(DbPlatformName.POSTGRES, pw.getEnum(DbPlatformName.class, "platform", DbPlatformName.H2));
|
||||
assertEquals(DbPlatformName.H2, pw.getEnum(DbPlatformName.class, "junk", DbPlatformName.H2));
|
||||
assertNull(pw.getEnum(DbPlatformName.class, "junk", null));
|
||||
assertEquals(Platform.POSTGRES, pw.getEnum(Platform.class, "platform", Platform.H2));
|
||||
assertEquals(Platform.H2, pw.getEnum(Platform.class, "junk", Platform.H2));
|
||||
assertNull(pw.getEnum(Platform.class, "junk", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import com.avaje.ebean.config.Platform;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DatabasePlatformTest {
|
||||
|
||||
@Test
|
||||
public void defaultTypesForDecimalAndVarchar() throws Exception {
|
||||
|
||||
DatabasePlatform dbPlatform = new DatabasePlatform();
|
||||
assertEquals(defaultDecimalDefn(dbPlatform), "decimal(38)");
|
||||
assertEquals(defaultDefn(DbType.VARCHAR, dbPlatform), "varchar(255)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configure_customType() throws Exception {
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.addCustomMapping(DbType.VARCHAR, "text", Platform.POSTGRES);
|
||||
serverConfig.addCustomMapping(DbType.DECIMAL, "decimal(24,4)");
|
||||
|
||||
// PG renders custom decimal and varchar
|
||||
PostgresPlatform pgPlatform = new PostgresPlatform();
|
||||
pgPlatform.configure(serverConfig);
|
||||
assertEquals(defaultDecimalDefn(pgPlatform), "decimal(24,4)");
|
||||
assertEquals(defaultDefn(DbType.VARCHAR, pgPlatform), "text");
|
||||
|
||||
// H2 only renders custom decimal
|
||||
H2Platform h2Platform = new H2Platform();
|
||||
h2Platform.configure(serverConfig);
|
||||
assertEquals(defaultDecimalDefn(h2Platform), "decimal(24,4)");
|
||||
assertEquals(defaultDefn(DbType.VARCHAR, h2Platform), "varchar(255)");
|
||||
}
|
||||
|
||||
private String defaultDecimalDefn(DatabasePlatform dbPlatform) {
|
||||
return defaultDefn(DbType.DECIMAL, dbPlatform);
|
||||
}
|
||||
|
||||
private String defaultDefn(DbType type, DatabasePlatform dbPlatform) {
|
||||
return dbPlatform.getDbTypeMap().get(type).renderType(0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DbPlatformTypeLookupTest {
|
||||
|
||||
DbPlatformTypeLookup lookup = new DbPlatformTypeLookup();
|
||||
|
||||
@Test
|
||||
public void byName() throws Exception {
|
||||
|
||||
assertEquals(lookup.byName("DECIMAL"), DbType.DECIMAL);
|
||||
assertEquals(lookup.byName("Decimal"), DbType.DECIMAL);
|
||||
assertEquals(lookup.byName("decimal"), DbType.DECIMAL);
|
||||
|
||||
assertEquals(lookup.byName("varchar"), DbType.VARCHAR);
|
||||
assertEquals(lookup.byName("varchar2"), DbType.VARCHAR);
|
||||
|
||||
assertEquals(lookup.byName("float"), DbType.REAL);
|
||||
assertEquals(lookup.byName("real"), DbType.REAL);
|
||||
|
||||
assertEquals(lookup.byName("uuid"), DbType.UUID);
|
||||
assertEquals(lookup.byName("hstore"), DbType.HSTORE);
|
||||
|
||||
assertEquals(lookup.byName("json"), DbType.JSON);
|
||||
assertEquals(lookup.byName("jsonb"), DbType.JSONB);
|
||||
assertEquals(lookup.byName("jsonclob"), DbType.JSONCLOB);
|
||||
assertEquals(lookup.byName("jsonblob"), DbType.JSONBLOB);
|
||||
assertEquals(lookup.byName("jsonVarchar"), DbType.JSONVARCHAR);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byId() throws Exception {
|
||||
|
||||
assertEquals(lookup.byId(Types.ARRAY), DbType.ARRAY);
|
||||
assertEquals(lookup.byId(Types.BIGINT), DbType.BIGINT);
|
||||
|
||||
assertEquals(lookup.byId(ExtraDbTypes.UUID), DbType.UUID);
|
||||
assertEquals(lookup.byId(ExtraDbTypes.HSTORE), DbType.HSTORE);
|
||||
|
||||
assertEquals(lookup.byId(ExtraDbTypes.JSON), DbType.JSON);
|
||||
assertEquals(lookup.byId(ExtraDbTypes.JSONB), DbType.JSONB);
|
||||
assertEquals(lookup.byId(ExtraDbTypes.JSONClob), DbType.JSONCLOB);
|
||||
assertEquals(lookup.byId(ExtraDbTypes.JSONBlob), DbType.JSONBLOB);
|
||||
assertEquals(lookup.byId(ExtraDbTypes.JSONVarchar), DbType.JSONVARCHAR);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.avaje.ebean.config.dbplatform;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DbPlatformTypeParserTest {
|
||||
|
||||
@Test
|
||||
public void parse_text() throws Exception {
|
||||
|
||||
DbPlatformType type = DbPlatformTypeParser.parse("text");
|
||||
|
||||
assertEquals(type.getName(), "text");
|
||||
assertEquals(type.getDefaultLength(), 0);
|
||||
assertEquals(type.getDefaultScale(), 0);
|
||||
|
||||
assertEquals(type.renderType(0, 0), "text");
|
||||
assertEquals(type.renderType(40, 0), "text");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_varchar20() throws Exception {
|
||||
|
||||
DbPlatformType type = DbPlatformTypeParser.parse("varchar(20)");
|
||||
|
||||
assertEquals(type.getName(), "varchar");
|
||||
assertEquals(type.getDefaultLength(), 20);
|
||||
assertEquals(type.getDefaultScale(), 0);
|
||||
|
||||
assertEquals(type.renderType(0, 0), "varchar(20)");
|
||||
assertEquals(type.renderType(40, 0), "varchar(40)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_decimal_18_6() throws Exception {
|
||||
|
||||
DbPlatformType type = DbPlatformTypeParser.parse("decimal(18,6)");
|
||||
|
||||
assertEquals(type.getName(), "decimal");
|
||||
assertEquals(type.getDefaultLength(), 18);
|
||||
assertEquals(type.getDefaultScale(), 6);
|
||||
assertEquals(type.renderType(0, 0), "decimal(18,6)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_something() throws Exception {
|
||||
|
||||
DbPlatformType type = DbPlatformTypeParser.parse("something(asd,6)");
|
||||
|
||||
assertEquals(type.getName(), "something(asd,6)");
|
||||
assertEquals(type.getDefaultLength(), 0);
|
||||
assertEquals(type.getDefaultScale(), 0);
|
||||
assertEquals(type.renderType(0, 0), "something(asd,6)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_invalid() throws Exception {
|
||||
|
||||
DbPlatformType type = DbPlatformTypeParser.parse("something(asd");
|
||||
|
||||
assertEquals(type.getName(), "something(asd");
|
||||
assertEquals(type.getDefaultLength(), 0);
|
||||
assertEquals(type.getDefaultScale(), 0);
|
||||
assertEquals(type.renderType(0, 0), "something(asd");
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class DbTypeMapTest {
|
||||
public void testLookupRender_given_postgresPlatformType() throws Exception {
|
||||
|
||||
PostgresPlatform pg = new PostgresPlatform();
|
||||
DbTypeMap dbTypeMap = pg.getDbTypeMap();
|
||||
DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap();
|
||||
|
||||
assertThat(dbTypeMap.lookup("clob", false).renderType(0,0)).isEqualTo("text");
|
||||
assertThat(dbTypeMap.lookup("CLOB", false).renderType(0, 0)).isEqualTo("text");
|
||||
@@ -29,9 +29,9 @@ public class DbTypeMapTest {
|
||||
@Test
|
||||
public void testPlatformTypes() {
|
||||
|
||||
DbTypeMap dbTypeMap = DbTypeMap.logicalTypes();
|
||||
DbType dbType = dbTypeMap.get(DbType.JSON);
|
||||
DbType json = dbTypeMap.lookup("json", false);
|
||||
DbPlatformTypeMapping dbTypeMap = DbPlatformTypeMapping.logicalTypes();
|
||||
DbPlatformType dbType = dbTypeMap.get(DbPlatformType.JSON);
|
||||
DbPlatformType json = dbTypeMap.lookup("json", false);
|
||||
|
||||
assertThat(dbType).isSameAs(json);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class MySqlPlatformTest {
|
||||
MySqlPlatform platform = new MySqlPlatform();
|
||||
platform.configure(new ServerConfig());
|
||||
|
||||
DbType dbType = platform.getDbTypeMap().get(DbType.UUID);
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
assertThat(dbType.renderType(0, 0)).isEqualTo("varchar(40)");
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MySqlPlatformTest {
|
||||
serverConfig.setDbUuid(ServerConfig.DbUuid.AUTO_BINARY);
|
||||
platform.configure(serverConfig);
|
||||
|
||||
DbType dbType = platform.getDbTypeMap().get(DbType.UUID);
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
assertThat(dbType.renderType(0, 0)).isEqualTo("binary(16)");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class OraclePlatformTest {
|
||||
|
||||
OraclePlatform platform = new OraclePlatform();
|
||||
platform.configure(new ServerConfig());
|
||||
DbType dbType = platform.getDbTypeMap().get(DbType.UUID);
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
|
||||
assertThat(dbType.renderType(0, 0)).isEqualTo("varchar2(40)");
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class OraclePlatformTest {
|
||||
|
||||
platform.configure(serverConfig);
|
||||
|
||||
DbType dbType = platform.getDbTypeMap().get(DbType.UUID);
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
assertThat(dbType.renderType(0, 0)).isEqualTo("raw(16)");
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class PostgresPlatformTest {
|
||||
PostgresPlatform platform = new PostgresPlatform();
|
||||
platform.configure(new ServerConfig());
|
||||
|
||||
DbType dbType = platform.getDbTypeMap().get(DbType.UUID);
|
||||
DbPlatformType dbType = platform.getDbTypeMap().get(DbPlatformType.UUID);
|
||||
String columnDefn = dbType.renderType(0, 0);
|
||||
|
||||
assertThat(columnDefn).isEqualTo("uuid");
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebean.dbmigration.ddlgeneration.platform;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DbTypeMap;
|
||||
import com.avaje.ebean.config.dbplatform.DbPlatformTypeMapping;
|
||||
import com.avaje.ebean.config.dbplatform.H2Platform;
|
||||
import com.avaje.ebean.config.dbplatform.PostgresPlatform;
|
||||
import com.avaje.ebean.dbmigration.ddlgeneration.platform.util.PlatformTypeConverter;
|
||||
@@ -14,7 +14,7 @@ public class PlatformTypeConverterTest {
|
||||
public void convert_withSuffix_expect_suffix() {
|
||||
|
||||
PostgresPlatform pg = new PostgresPlatform();
|
||||
DbTypeMap dbTypeMap = pg.getDbTypeMap();
|
||||
DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap();
|
||||
|
||||
PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PlatformTypeConverterTest {
|
||||
public void testConvert_given_postgres() throws Exception {
|
||||
|
||||
PostgresPlatform pg = new PostgresPlatform();
|
||||
DbTypeMap dbTypeMap = pg.getDbTypeMap();
|
||||
DbPlatformTypeMapping dbTypeMap = pg.getDbTypeMap();
|
||||
|
||||
PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PlatformTypeConverterTest {
|
||||
|
||||
|
||||
H2Platform platform = new H2Platform();
|
||||
DbTypeMap dbTypeMap = platform.getDbTypeMap();
|
||||
DbPlatformTypeMapping dbTypeMap = platform.getDbTypeMap();
|
||||
|
||||
PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class PlatformTypeConverterTest {
|
||||
public void testConvertJsonTypes_given_postgres() {
|
||||
|
||||
PostgresPlatform platform = new PostgresPlatform();
|
||||
DbTypeMap dbTypeMap = platform.getDbTypeMap();
|
||||
DbPlatformTypeMapping dbTypeMap = platform.getDbTypeMap();
|
||||
|
||||
PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap);
|
||||
|
||||
@@ -84,7 +84,7 @@ public class PlatformTypeConverterTest {
|
||||
public void testConvertJsonTypes_given_h2() {
|
||||
|
||||
H2Platform platform = new H2Platform();
|
||||
DbTypeMap dbTypeMap = platform.getDbTypeMap();
|
||||
DbPlatformTypeMapping dbTypeMap = platform.getDbTypeMap();
|
||||
|
||||
PlatformTypeConverter converter = new PlatformTypeConverter(dbTypeMap);
|
||||
|
||||
|
||||
@@ -460,11 +460,6 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int findRowCount(Query<T> query, Transaction transaction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A> List<A> findIds(Query<?> query, Transaction transaction) {
|
||||
return null;
|
||||
@@ -495,11 +490,6 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> FutureRowCount<T> findFutureRowCount(Query<T> query, Transaction transaction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> FutureIds<T> findFutureIds(Query<T> query, Transaction transaction) {
|
||||
return null;
|
||||
|
||||
@@ -46,6 +46,40 @@ public class TestQueryFindIterate extends BaseTestCase {
|
||||
assertEquals(2, count.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_hasNext_hasNext() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
QueryIterator<Customer> queryIterator = server.find(Customer.class)
|
||||
.where()
|
||||
.isNotNull("name")
|
||||
.setMaxRows(3)
|
||||
.order().asc("id")
|
||||
.findIterate();
|
||||
|
||||
try {
|
||||
// check that hasNext does not move to the next bean
|
||||
assertTrue(queryIterator.hasNext());
|
||||
assertTrue(queryIterator.hasNext());
|
||||
assertTrue(queryIterator.hasNext());
|
||||
assertTrue(queryIterator.hasNext());
|
||||
assertTrue(queryIterator.hasNext());
|
||||
|
||||
Customer first = queryIterator.next();
|
||||
logger.info("first: {}", queryIterator.next());
|
||||
assertEquals(first.getId(), Integer.valueOf(1));
|
||||
|
||||
while (queryIterator.hasNext()) {
|
||||
logger.info("next: {}", queryIterator.next());
|
||||
}
|
||||
|
||||
} finally {
|
||||
queryIterator.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findEach() {
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TestQueryPlanCacheRowCount extends BaseTestCase {
|
||||
Query<Order> query = Ebean.find(Order.class).where().eq("status", Order.Status.NEW).ge("id", 1)
|
||||
.order().desc("id");
|
||||
|
||||
int rc0 = query.findRowCount();
|
||||
int rc0 = query.findCount();
|
||||
|
||||
List<Integer> ids = query.findIds();
|
||||
Assert.assertEquals(rc0, ids.size());
|
||||
|
||||
Reference in New Issue
Block a user