mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Merge pull request #2800 from ebean-orm/feature/refactor-databasePlatform
Refactor database platform - remove unused tableExists() method, rename getters to accessors
This commit is contained in:
56 files changed
+160
-174
No files matched your search
@@ -119,7 +119,7 @@ public abstract class AbstractSqlQueryRequest implements CancelableQuery {
|
||||
int firstRow = query.getFirstRow();
|
||||
int maxRows = query.getMaxRows();
|
||||
if (firstRow > 0 || maxRows > 0) {
|
||||
return server.databasePlatform().getBasicSqlLimiter().limit(sql, firstRow, maxRows);
|
||||
return server.databasePlatform().basicSqlLimiter().limit(sql, firstRow, maxRows);
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public final class DefaultContainer implements SpiContainer {
|
||||
startServer(online, server);
|
||||
}
|
||||
DbOffline.reset();
|
||||
log.log(INFO, "Started database[{0}] platform[{1}] in {2}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start);
|
||||
log.log(INFO, "Started database[{0}] platform[{1}] in {2}ms", config.getName(), config.getDatabasePlatform().platform(), System.currentTimeMillis() - start);
|
||||
return server;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
|
||||
@@ -251,7 +251,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
|
||||
@Override
|
||||
public Platform platform() {
|
||||
return databasePlatform.getPlatform();
|
||||
return databasePlatform.platform();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -318,7 +318,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
migrationRunner.setDefaultDbSchema(dbSchema);
|
||||
}
|
||||
migrationRunner.setName(config.getName());
|
||||
Platform platform = config.getDatabasePlatform().getPlatform();
|
||||
Platform platform = config.getDatabasePlatform().platform();
|
||||
migrationRunner.setBasePlatform(platform.base().name().toLowerCase());
|
||||
migrationRunner.setPlatform(platform.name().toLowerCase());
|
||||
migrationRunner.loadProperties(config.getProperties());
|
||||
@@ -560,7 +560,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
try (Connection connection = dataSource().getConnection()) {
|
||||
for (String table : tables) {
|
||||
executeSql(connection, databasePlatform.truncateStatement(table));
|
||||
if (databasePlatform.getPlatform().base() == Platform.DB2) {
|
||||
if (databasePlatform.platform().base() == Platform.DB2) {
|
||||
// DB2 requires commit after each truncate statement
|
||||
connection.commit();
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ final class InitDataSource {
|
||||
}
|
||||
|
||||
boolean isPostgresAllQuotedIdentifiers() {
|
||||
return config.isAllQuotedIdentifiers() && Platform.POSTGRES == config.getDatabasePlatform().getPlatform().base();
|
||||
return config.isAllQuotedIdentifiers() && Platform.POSTGRES == config.getDatabasePlatform().platform().base();
|
||||
}
|
||||
|
||||
private DataSource create(DataSourceConfig dsConfig, boolean readOnly) {
|
||||
|
||||
@@ -116,7 +116,7 @@ public final class InternalConfiguration {
|
||||
this.databasePlatform = config.getDatabasePlatform();
|
||||
this.expressionFactory = initExpressionFactory(config);
|
||||
this.typeManager = new DefaultTypeManager(config, bootupClasses);
|
||||
this.multiValueBind = createMultiValueBind(databasePlatform.getPlatform());
|
||||
this.multiValueBind = createMultiValueBind(databasePlatform.platform());
|
||||
this.deployInherit = new DeployInherit(bootupClasses);
|
||||
this.deployCreateProperties = new DeployCreateProperties(typeManager);
|
||||
this.deployUtil = new DeployUtil(typeManager, config);
|
||||
@@ -171,7 +171,7 @@ public final class InternalConfiguration {
|
||||
* Create and return the ExpressionFactory based on configuration and database platform.
|
||||
*/
|
||||
private ExpressionFactory initExpressionFactory(DatabaseConfig config) {
|
||||
boolean nativeIlike = config.isExpressionNativeIlike() && databasePlatform.isSupportsNativeIlike();
|
||||
boolean nativeIlike = config.isExpressionNativeIlike() && databasePlatform.supportsNativeIlike();
|
||||
return new DefaultExpressionFactory(config.isExpressionEqualsWithNullAsNoop(), nativeIlike);
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public final class InternalConfiguration {
|
||||
|
||||
DbExpressionHandler jsonHandler = getDbExpressionHandler(databasePlatform);
|
||||
|
||||
DbHistorySupport historySupport = databasePlatform.getHistorySupport();
|
||||
DbHistorySupport historySupport = databasePlatform.historySupport();
|
||||
if (historySupport == null) {
|
||||
return new Binder(typeManager, logManager, 0, false, jsonHandler, dataTimeZone, multiValueBind);
|
||||
}
|
||||
@@ -321,7 +321,7 @@ public final class InternalConfiguration {
|
||||
}
|
||||
|
||||
private Platform getPlatform() {
|
||||
return getDatabasePlatform().getPlatform();
|
||||
return getDatabasePlatform().platform();
|
||||
}
|
||||
|
||||
public DatabasePlatform getDatabasePlatform() {
|
||||
@@ -577,7 +577,7 @@ public final class InternalConfiguration {
|
||||
return QueryPlanManager.NOOP;
|
||||
}
|
||||
long threshold = config.getQueryPlanThresholdMicros();
|
||||
return new CQueryPlanManager(transactionManager, threshold, queryPlanLogger(databasePlatform.getPlatform()), extraMetrics);
|
||||
return new CQueryPlanManager(transactionManager, threshold, queryPlanLogger(databasePlatform.platform()), extraMetrics);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -100,7 +100,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
||||
*/
|
||||
@Override
|
||||
public String dbLikeClause(boolean rawLikeExpression) {
|
||||
return server.databasePlatform().getLikeClause(rawLikeExpression);
|
||||
return server.databasePlatform().likeClause(rawLikeExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -761,7 +761,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
||||
* Return true if no MaxRows or use LIMIT in SQL update.
|
||||
*/
|
||||
public boolean isInlineSqlUpdateLimit() {
|
||||
return query.getMaxRows() < 1 || server.databasePlatform().isInlineSqlUpdateLimit();
|
||||
return query.getMaxRows() < 1 || server.databasePlatform().inlineSqlUpdateLimit();
|
||||
}
|
||||
|
||||
public int forwardOnlyFetchSize() {
|
||||
|
||||
@@ -134,7 +134,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
||||
this.encryptKeyManager = this.config.getEncryptKeyManager();
|
||||
this.databasePlatform = this.config.getDatabasePlatform();
|
||||
this.multiValueBind = config.getMultiValueBind();
|
||||
this.idBinderFactory = new IdBinderFactory(databasePlatform.isIdInExpandedForm(), multiValueBind);
|
||||
this.idBinderFactory = new IdBinderFactory(databasePlatform.idInExpandedForm(), multiValueBind);
|
||||
this.queryPlanTTLSeconds = this.config.getQueryPlanTTLSeconds();
|
||||
this.asOfViewSuffix = asOfViewSuffix(databasePlatform, this.config);
|
||||
String versionsBetweenSuffix = versionsBetweenSuffix(databasePlatform, this.config);
|
||||
@@ -142,7 +142,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
||||
this.bootupClasses = config.getBootupClasses();
|
||||
this.createProperties = config.getDeployCreateProperties();
|
||||
this.namingConvention = this.config.getNamingConvention();
|
||||
this.dbIdentity = config.getDatabasePlatform().getDbIdentity();
|
||||
this.dbIdentity = config.getDatabasePlatform().dbIdentity();
|
||||
this.deplyInherit = config.getDeployInherit();
|
||||
this.deployUtil = config.getDeployUtil();
|
||||
this.typeManager = deployUtil.getTypeManager();
|
||||
@@ -196,7 +196,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
||||
* Return the AsOfViewSuffix based on the DbHistorySupport.
|
||||
*/
|
||||
private String asOfViewSuffix(DatabasePlatform databasePlatform, DatabaseConfig serverConfig) {
|
||||
DbHistorySupport historySupport = databasePlatform.getHistorySupport();
|
||||
DbHistorySupport historySupport = databasePlatform.historySupport();
|
||||
// with historySupport returns a simple view suffix or the sql2011 as of timestamp suffix
|
||||
return (historySupport == null) ? serverConfig.getAsOfViewSuffix() : historySupport.getAsOfViewSuffix(serverConfig.getAsOfViewSuffix());
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
||||
* Return the versions between timestamp suffix based on the DbHistorySupport.
|
||||
*/
|
||||
private String versionsBetweenSuffix(DatabasePlatform databasePlatform, DatabaseConfig serverConfig) {
|
||||
DbHistorySupport historySupport = databasePlatform.getHistorySupport();
|
||||
DbHistorySupport historySupport = databasePlatform.historySupport();
|
||||
// with historySupport returns a simple view suffix or the sql2011 versions between timestamp suffix
|
||||
return (historySupport == null) ? serverConfig.getAsOfViewSuffix() : historySupport.getVersionsBetweenSuffix(serverConfig.getAsOfViewSuffix());
|
||||
}
|
||||
@@ -1251,7 +1251,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
|
||||
String primaryKeyColumn = desc.getSinglePrimaryKeyColumn();
|
||||
seqName = namingConvention.getSequenceName(desc.getBaseTable(), primaryKeyColumn);
|
||||
}
|
||||
int stepSize = desc.setIdentitySequenceBatchMode(databasePlatform.isSequenceBatchMode());
|
||||
int stepSize = desc.setIdentitySequenceBatchMode(databasePlatform.sequenceBatchMode());
|
||||
desc.setIdGenerator(createSequenceIdGenerator(seqName, stepSize));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ abstract class AnnotationBase {
|
||||
AnnotationBase(DeployUtil util) {
|
||||
this.util = util;
|
||||
this.databasePlatform = util.getDbPlatform();
|
||||
this.platform = databasePlatform.getPlatform();
|
||||
this.platform = databasePlatform.platform();
|
||||
this.namingConvention = util.getNamingConvention();
|
||||
}
|
||||
|
||||
|
||||
@@ -398,7 +398,7 @@ final class AnnotationFields extends AnnotationParser {
|
||||
return;
|
||||
}
|
||||
if (dbEncString) {
|
||||
DbEncrypt dbEncrypt = util.getDbPlatform().getDbEncrypt();
|
||||
DbEncrypt dbEncrypt = util.getDbPlatform().dbEncrypt();
|
||||
if (dbEncrypt != null) {
|
||||
// check if we have a DB encryption function for this type
|
||||
int jdbcType = prop.getScalarType().getJdbcType();
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ public final class DbExpressionHandlerFactory {
|
||||
* Create and return the appropriate platform specific handing of expressions.
|
||||
*/
|
||||
public static DbExpressionHandler from(DatabasePlatform databasePlatform) {
|
||||
Platform platform = databasePlatform.getPlatform().base();
|
||||
Platform platform = databasePlatform.platform().base();
|
||||
switch (platform) {
|
||||
case H2:
|
||||
return new H2DbExpression();
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class DefaultPersister implements Persister {
|
||||
this.server = server;
|
||||
this.beanDescriptorManager = descMgr;
|
||||
this.persistExecute = new DefaultPersistExecute(binder, server.config().getPersistBatchSize());
|
||||
this.maxInBinding = server.databasePlatform().getMaxInBinding();
|
||||
this.maxInBinding = server.databasePlatform().maxInBinding();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ final class InsertMeta {
|
||||
private final Platform platform;
|
||||
|
||||
InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
|
||||
this.platform = dbPlatform.getPlatform();
|
||||
this.platform = dbPlatform.platform();
|
||||
this.discriminator = getDiscriminator(desc);
|
||||
this.id = id;
|
||||
this.all = all;
|
||||
@@ -69,7 +69,7 @@ final class InsertMeta {
|
||||
this.supportsSelectLastInsertedId = false;
|
||||
} else {
|
||||
this.identityDbColumns = new String[]{id.getIdentityColumn()};
|
||||
this.supportsGetGeneratedKeys = dbPlatform.getDbIdentity().isSupportsGetGeneratedKeys();
|
||||
this.supportsGetGeneratedKeys = dbPlatform.dbIdentity().isSupportsGetGeneratedKeys();
|
||||
this.supportsSelectLastInsertedId = desc.supportsSelectLastInsertedId();
|
||||
}
|
||||
this.sqlNullId = genSql(true, tableName, false);
|
||||
|
||||
@@ -40,7 +40,7 @@ final class MetaFactory {
|
||||
MetaFactory(DatabasePlatform dbPlatform) {
|
||||
this.dbPlatform = dbPlatform;
|
||||
// to bind encryption data before or after the encryption key
|
||||
DbEncrypt dbEncrypt = dbPlatform.getDbEncrypt();
|
||||
DbEncrypt dbEncrypt = dbPlatform.dbEncrypt();
|
||||
boolean bindEncryptDataFirst = dbEncrypt == null || dbEncrypt.isBindEncryptDataFirst();
|
||||
this.baseFact = new FactoryBaseProperties(bindEncryptDataFirst);
|
||||
this.embeddedFact = new FactoryEmbedded(bindEncryptDataFirst);
|
||||
|
||||
@@ -60,11 +60,11 @@ final class CQueryBuilder {
|
||||
this.binder = binder;
|
||||
this.draftSupport = draftSupport;
|
||||
this.historySupport = historySupport;
|
||||
this.columnAliasPrefix = dbPlatform.getColumnAliasPrefix();
|
||||
this.sqlLimiter = dbPlatform.getSqlLimiter();
|
||||
this.columnAliasPrefix = dbPlatform.columnAliasPrefix();
|
||||
this.sqlLimiter = dbPlatform.sqlLimiter();
|
||||
this.rawSqlHandler = new CQueryBuilderRawSql(sqlLimiter, dbPlatform);
|
||||
this.selectCountWithAlias = dbPlatform.isSelectCountWithAlias();
|
||||
this.selectCountWithColumnAlias = dbPlatform.isSelectCountWithColumnAlias();
|
||||
this.selectCountWithAlias = dbPlatform.selectCountWithAlias();
|
||||
this.selectCountWithColumnAlias = dbPlatform.selectCountWithColumnAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,10 +118,10 @@ final class CQueryBuilder {
|
||||
private <T> String buildDeleteSql(OrmQueryRequest<T> request, String rootTableAlias, CQueryPredicates predicates, SqlTree sqlTree) {
|
||||
String alias = alias(rootTableAlias);
|
||||
if (sqlTree.noJoins() && !request.query().hasMaxRowsOrFirstRow()) {
|
||||
if (dbPlatform.isSupportsDeleteTableAlias()) {
|
||||
if (dbPlatform.supportsDeleteTableAlias()) {
|
||||
// delete from table <alias> ...
|
||||
return aliasReplace(buildSqlDelete("delete", request, predicates, sqlTree).getSql(), alias);
|
||||
} else if (isMySql(dbPlatform.getPlatform())) {
|
||||
} else if (isMySql(dbPlatform.platform())) {
|
||||
return aliasReplace(buildSqlDelete("delete " + alias, request, predicates, sqlTree).getSql(), alias);
|
||||
} else {
|
||||
// simple - delete from table ...
|
||||
@@ -380,7 +380,7 @@ final class CQueryBuilder {
|
||||
}
|
||||
|
||||
private String nativeQueryPaging(SpiQuery<?> query, String sql) {
|
||||
return dbPlatform.getBasicSqlLimiter().limit(sql, query.getFirstRow(), query.getMaxRows());
|
||||
return dbPlatform.basicSqlLimiter().limit(sql, query.getFirstRow(), query.getMaxRows());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +399,7 @@ final class CQueryBuilder {
|
||||
try {
|
||||
// For SqlServer we need either "selectMethod=cursor" in the connection string or fetch explicitly a cursorable
|
||||
// statement here by specifying ResultSet.CONCUR_UPDATABLE
|
||||
PreparedStatement statement = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, dbPlatform.isSupportsResultSetConcurrencyModeUpdatable() ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
|
||||
PreparedStatement statement = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, dbPlatform.supportsResultSetConcurrencyModeUpdatable() ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
|
||||
predicates.bind(statement, connection);
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
|
||||
@@ -43,13 +43,13 @@ public final class CQueryEngine {
|
||||
this.dbPlatform = dbPlatform;
|
||||
this.defaultFetchSizeFindEach = config.getJdbcFetchSizeFindEach();
|
||||
this.defaultFetchSizeFindList = config.getJdbcFetchSizeFindList();
|
||||
this.forwardOnlyHintOnFindIterate = dbPlatform.isForwardOnlyHintOnFindIterate();
|
||||
this.historySupport = new CQueryHistorySupport(dbPlatform.getHistorySupport(), asOfTableMapping, config.getAsOfSysPeriod());
|
||||
this.forwardOnlyHintOnFindIterate = dbPlatform.forwardOnlyHintOnFindIterate();
|
||||
this.historySupport = new CQueryHistorySupport(dbPlatform.historySupport(), asOfTableMapping, config.getAsOfSysPeriod());
|
||||
this.queryBuilder = new CQueryBuilder(dbPlatform, binder, historySupport, new CQueryDraftSupport(draftTableMap));
|
||||
}
|
||||
|
||||
public int forwardOnlyFetchSize() {
|
||||
Platform base = dbPlatform.getPlatform().base();
|
||||
Platform base = dbPlatform.platform().base();
|
||||
return Platform.MYSQL == base ? Integer.MIN_VALUE : 1;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
this.txnLogger = logManager.txn();
|
||||
this.txnDebug = txnLogger.isDebug();
|
||||
this.databasePlatform = options.config.getDatabasePlatform();
|
||||
this.supportsSavepointId = databasePlatform.isSupportsSavepointId();
|
||||
this.supportsSavepointId = databasePlatform.supportsSavepointId();
|
||||
this.skipCacheAfterWrite = options.config.isSkipCacheAfterWrite();
|
||||
this.notifyL2CacheInForeground = options.notifyL2CacheInForeground;
|
||||
this.autoPersistUpdates = options.config.isAutoPersistUpdates();
|
||||
|
||||
@@ -50,7 +50,7 @@ final class DefaultTypeFactory {
|
||||
return createBoolean(trueValue, falseValue);
|
||||
}
|
||||
// determine based on database platform configuration
|
||||
int booleanDbType = config.getDatabasePlatform().getBooleanDbType();
|
||||
int booleanDbType = config.getDatabasePlatform().booleanDbType();
|
||||
if (booleanDbType == Types.BIT) {
|
||||
return new ScalarTypeBoolean.BitBoolean();
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
|
||||
private PlatformArrayTypeFactory arrayTypeListFactory(DatabasePlatform databasePlatform) {
|
||||
if (databasePlatform.isNativeArrayType()) {
|
||||
if (databasePlatform.nativeArrayType()) {
|
||||
return ScalarTypeArrayList.factory();
|
||||
} else if (databasePlatform.isPlatform(Platform.H2)) {
|
||||
return ScalarTypeArrayListH2.factory();
|
||||
@@ -176,7 +176,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
|
||||
private PlatformArrayTypeFactory arrayTypeSetFactory(DatabasePlatform databasePlatform) {
|
||||
if (databasePlatform.isNativeArrayType()) {
|
||||
if (databasePlatform.nativeArrayType()) {
|
||||
return ScalarTypeArraySet.factory();
|
||||
} else if (databasePlatform.isPlatform(Platform.H2)) {
|
||||
return ScalarTypeArraySetH2.factory();
|
||||
@@ -834,8 +834,8 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
*/
|
||||
private void initialiseStandard(DatabaseConfig config) {
|
||||
DatabasePlatform databasePlatform = config.getDatabasePlatform();
|
||||
int platformClobType = databasePlatform.getClobDbType();
|
||||
int platformBlobType = databasePlatform.getBlobDbType();
|
||||
int platformClobType = databasePlatform.clobDbType();
|
||||
int platformBlobType = databasePlatform.blobDbType();
|
||||
|
||||
nativeMap.put(DbPlatformType.HSTORE, hstoreType);
|
||||
|
||||
@@ -857,7 +857,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
}
|
||||
|
||||
PlatformConfig.DbUuid dbUuid = config.getPlatformConfig().getDbUuid();
|
||||
if (offlineMigrationGeneration || (databasePlatform.isNativeUuidType() && dbUuid.useNativeType())) {
|
||||
if (offlineMigrationGeneration || (databasePlatform.nativeUuidType() && dbUuid.useNativeType())) {
|
||||
addType(UUID.class, new ScalarTypeUUIDNative());
|
||||
} else {
|
||||
// Store UUID as binary(16) or varchar(40)
|
||||
|
||||
Reference in new issue
Block a user