mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-22 22:54:54 +00:00
Merge pull request #3018 from ebean-orm/refactor/add-final-remove-public-platformHelpers
Refactor platforms adding final and removing public from sequence, history, encryption helpers
This commit is contained in:
-56
@@ -1,56 +0,0 @@
|
||||
package io.ebean.xtest.config.dbplatform.sqlserver;
|
||||
|
||||
import io.ebean.BackgroundExecutor;
|
||||
import io.ebean.xtest.BaseTestCase;
|
||||
import io.ebean.xtest.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.platform.sqlserver.SqlServerStepSequence;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SqlServerStepSequenceTest extends BaseTestCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SqlServerStepSequenceTest.class);
|
||||
|
||||
@Disabled
|
||||
@ForPlatform(Platform.SQLSERVER)
|
||||
@Test
|
||||
public void seq() {
|
||||
|
||||
|
||||
server().sqlUpdate("drop sequence if exists sqls_testseq_9876").execute();
|
||||
server().sqlUpdate("create sequence sqls_testseq_9876 start with 1 increment by 50").execute();
|
||||
|
||||
BackgroundExecutor be = server().backgroundExecutor();
|
||||
DataSource ds = server().dataSource();
|
||||
|
||||
SqlServerStepSequence s = new SqlServerStepSequence(be, ds, "sqls_testseq_9876", 50);
|
||||
|
||||
Object id = s.nextId(null);
|
||||
assertThat(id).isEqualTo(1L);
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Object val = s.nextId(null);
|
||||
log.warn("val: "+val);
|
||||
}
|
||||
|
||||
log.warn("here");
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Object val = s.nextId(null);
|
||||
log.warn("val: "+val);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Object val = s.nextId(null);
|
||||
log.warn("val: "+val);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,5 +17,12 @@
|
||||
<version>13.16.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>1.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -2,13 +2,12 @@ package io.ebean.platform.hana;
|
||||
|
||||
import io.ebean.config.dbplatform.BasicSqlLimiter;
|
||||
|
||||
public class HanaBasicSqlLimiter implements BasicSqlLimiter {
|
||||
final class HanaBasicSqlLimiter implements BasicSqlLimiter {
|
||||
|
||||
@Override
|
||||
public String limit(String dbSql, int firstRow, int maxRows) {
|
||||
StringBuilder sb = new StringBuilder(50 + dbSql.length());
|
||||
|
||||
sb.append(dbSql);
|
||||
|
||||
if (maxRows > 0) {
|
||||
sb.append(" ").append("limit");
|
||||
sb.append(" ").append(maxRows);
|
||||
@@ -18,7 +17,6 @@ public class HanaBasicSqlLimiter implements BasicSqlLimiter {
|
||||
sb.append(firstRow);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.ebean.platform.hana;
|
||||
|
||||
import io.ebean.config.dbplatform.DbStandardHistorySupport;
|
||||
|
||||
public class HanaHistorySupport extends DbStandardHistorySupport {
|
||||
final class HanaHistorySupport extends DbStandardHistorySupport {
|
||||
|
||||
@Override
|
||||
public String getAsOfViewSuffix(String asOfViewSuffix) {
|
||||
|
||||
+8
-14
@@ -1,46 +1,40 @@
|
||||
package io.ebean.xtest.config.dbplatform;
|
||||
package io.ebean.platform.hana;
|
||||
|
||||
import io.ebean.platform.hana.HanaHistorySupport;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class HanaHistorySupportTest {
|
||||
class HanaHistorySupportTest {
|
||||
|
||||
private HanaHistorySupport support = new HanaHistorySupport();
|
||||
private final HanaHistorySupport support = new HanaHistorySupport();
|
||||
|
||||
@Test
|
||||
public void getAsOfPredicate() {
|
||||
|
||||
void getAsOfPredicate() {
|
||||
String asOfPredicate = support.getAsOfPredicate("t0", "sys_period");
|
||||
assertNull(asOfPredicate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAsOfViewSuffix() {
|
||||
|
||||
void getAsOfViewSuffix() {
|
||||
String asOfViewSuffix = support.getAsOfViewSuffix("_with_history");
|
||||
assertEquals(asOfViewSuffix, " for system_time as of ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVersionsBetweenSuffix() {
|
||||
|
||||
void getVersionsBetweenSuffix() {
|
||||
String asOfViewSuffix = support.getVersionsBetweenSuffix("_with_history");
|
||||
assertEquals(asOfViewSuffix, " for system_time between ? and ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLower() throws Exception {
|
||||
|
||||
void getLower() {
|
||||
String lower = support.getSysPeriodLower("t0", "sys_period");
|
||||
assertEquals(lower, "t0.sys_period_start");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUpper() throws Exception {
|
||||
|
||||
void getUpper() {
|
||||
String upper = support.getSysPeriodUpper("t0", "sys_period");
|
||||
assertEquals(upper, "t0.sys_period_end");
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ import io.ebean.config.dbplatform.DbStandardHistorySupport;
|
||||
/**
|
||||
* History support for MariaDB.
|
||||
*/
|
||||
public class MariaDbHistorySupport extends DbStandardHistorySupport {
|
||||
final class MariaDbHistorySupport extends DbStandardHistorySupport {
|
||||
|
||||
/**
|
||||
* Return the ' as of timestamp ?' clause appended after the table name.
|
||||
|
||||
@@ -5,14 +5,14 @@ import io.ebean.config.dbplatform.SequenceStepIdGenerator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class MariaDbSequence extends SequenceStepIdGenerator {
|
||||
final class MariaDbSequence extends SequenceStepIdGenerator {
|
||||
|
||||
private final String nextSql;
|
||||
|
||||
/**
|
||||
* Construct where batchSize is the sequence step size.
|
||||
*/
|
||||
public MariaDbSequence(BackgroundExecutor be, DataSource ds, String seqName, int stepSize) {
|
||||
MariaDbSequence(BackgroundExecutor be, DataSource ds, String seqName, int stepSize) {
|
||||
super(be, ds, seqName, stepSize);
|
||||
this.nextSql = "select next value for " + seqName;
|
||||
}
|
||||
|
||||
@@ -9,18 +9,17 @@ import io.ebean.config.dbplatform.DbPlatformType;
|
||||
* If no deployment length is defined longblob is used.
|
||||
* </p>
|
||||
*/
|
||||
public class MySqlBlob extends DbPlatformType {
|
||||
final class MySqlBlob extends DbPlatformType {
|
||||
|
||||
private static final int POWER_2_16 = 65536;
|
||||
private static final int POWER_2_24 = 16777216;
|
||||
|
||||
public MySqlBlob() {
|
||||
MySqlBlob() {
|
||||
super("blob");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String renderType(int deployLength, int deployScale) {
|
||||
|
||||
if (deployLength >= POWER_2_24) {
|
||||
return "longblob";
|
||||
}
|
||||
|
||||
@@ -9,18 +9,17 @@ import io.ebean.config.dbplatform.DbPlatformType;
|
||||
* If no deployment length is defined longtext is used.
|
||||
* </p>
|
||||
*/
|
||||
public class MySqlClob extends DbPlatformType {
|
||||
final class MySqlClob extends DbPlatformType {
|
||||
|
||||
private static final int POWER_2_16 = 65536;
|
||||
private static final int POWER_2_24 = 16777216;
|
||||
|
||||
public MySqlClob() {
|
||||
MySqlClob() {
|
||||
super("text");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String renderType(int deployLength, int deployScale) {
|
||||
|
||||
if (deployLength >= POWER_2_24) {
|
||||
return "longtext";
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import io.ebean.config.dbplatform.DbEncryptFunction;
|
||||
/**
|
||||
* MySql aes_encrypt aes_decrypt based encryption support.
|
||||
*/
|
||||
public class MySqlDbEncrypt extends AbstractDbEncrypt {
|
||||
final class MySqlDbEncrypt extends AbstractDbEncrypt {
|
||||
|
||||
public MySqlDbEncrypt() {
|
||||
MySqlDbEncrypt() {
|
||||
this.varcharEncryptFunction = new MyVarcharFunction();
|
||||
this.dateEncryptFunction = new MyDateFunction();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.ebean.config.dbplatform.DbStandardHistorySupport;
|
||||
/**
|
||||
* Oracle Total recall based history support.
|
||||
*/
|
||||
public class OracleDbHistorySupport extends DbStandardHistorySupport {
|
||||
final class OracleDbHistorySupport extends DbStandardHistorySupport {
|
||||
|
||||
/**
|
||||
* Return the ' as of timestamp ?' clause appended after the table name.
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import io.ebean.config.dbplatform.BasicSqlLimiter;
|
||||
/**
|
||||
* Row limiter for Oracle 9,10,11 using rownum.
|
||||
*/
|
||||
public class OracleRownumBasicLimiter implements BasicSqlLimiter {
|
||||
final class OracleRownumBasicLimiter implements BasicSqlLimiter {
|
||||
|
||||
@Override
|
||||
public String limit(String dbSql, int firstRow, int maxRows) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import io.ebean.config.dbplatform.SqlLimiter;
|
||||
/**
|
||||
* Add ROWNUM column etc around SQL query to limit results.
|
||||
*/
|
||||
class OracleRownumSqlLimiter implements SqlLimiter {
|
||||
final class OracleRownumSqlLimiter implements SqlLimiter {
|
||||
|
||||
@Override
|
||||
public SqlLimitResponse limit(SqlLimitRequest request) {
|
||||
|
||||
+2
-2
@@ -8,14 +8,14 @@ import javax.sql.DataSource;
|
||||
/**
|
||||
* Oracle specific sequence Id Generator.
|
||||
*/
|
||||
public class OracleSequenceIdGenerator extends SequenceBatchIdGenerator {
|
||||
final class OracleSequenceIdGenerator extends SequenceBatchIdGenerator {
|
||||
|
||||
private final String baseSql;
|
||||
|
||||
/**
|
||||
* Construct given a dataSource and sql to return the next sequence value.
|
||||
*/
|
||||
public OracleSequenceIdGenerator(BackgroundExecutor be, DataSource ds, String seqName, int batchSize) {
|
||||
OracleSequenceIdGenerator(BackgroundExecutor be, DataSource ds, String seqName, int batchSize) {
|
||||
super(be, ds, seqName, batchSize);
|
||||
this.baseSql = "select " + seqName + ".nextval, a from (select level as a FROM dual CONNECT BY level <= ";
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import io.ebean.config.dbplatform.DbEncryptFunction;
|
||||
/**
|
||||
* Postgres pgp_sym_encrypt pgp_sym_decrypt based encryption support.
|
||||
*/
|
||||
public class PostgresDbEncrypt extends AbstractDbEncrypt {
|
||||
final class PostgresDbEncrypt extends AbstractDbEncrypt {
|
||||
|
||||
public PostgresDbEncrypt() {
|
||||
PostgresDbEncrypt() {
|
||||
this.varcharEncryptFunction = new PgVarcharFunction();
|
||||
this.dateEncryptFunction = new PgDateFunction();
|
||||
}
|
||||
|
||||
+1
-3
@@ -5,7 +5,7 @@ import io.ebean.config.dbplatform.DbViewHistorySupport;
|
||||
/**
|
||||
* Postgres support for history features.
|
||||
*/
|
||||
public class PostgresHistorySupport extends DbViewHistorySupport {
|
||||
final class PostgresHistorySupport extends DbViewHistorySupport {
|
||||
|
||||
/**
|
||||
* Return 1 as we are using the postgres range type and hence don't need 2 bind variables.
|
||||
@@ -19,11 +19,9 @@ public class PostgresHistorySupport extends DbViewHistorySupport {
|
||||
* Build and return the 'as of' predicate for a given table alias.
|
||||
* <p>
|
||||
* Each @History entity involved in the query has this predicate added using the related table alias.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public String getAsOfPredicate(String asOfTableAlias, String asOfSysPeriod) {
|
||||
|
||||
// for Postgres we are using the 'timestamp with timezone range' data type
|
||||
// as our sys_period column so hence the predicate below
|
||||
return asOfTableAlias + "." + asOfSysPeriod + " @> ?::timestamptz";
|
||||
|
||||
+2
-2
@@ -8,14 +8,14 @@ import javax.sql.DataSource;
|
||||
/**
|
||||
* Postgres specific sequence Id Generator.
|
||||
*/
|
||||
public class PostgresSequenceIdGenerator extends SequenceBatchIdGenerator {
|
||||
final class PostgresSequenceIdGenerator extends SequenceBatchIdGenerator {
|
||||
|
||||
private final String baseSql;
|
||||
|
||||
/**
|
||||
* Construct given a dataSource and sql to return the next sequence value.
|
||||
*/
|
||||
public PostgresSequenceIdGenerator(BackgroundExecutor be, DataSource ds, String seqName, int batchSize) {
|
||||
PostgresSequenceIdGenerator(BackgroundExecutor be, DataSource ds, String seqName, int batchSize) {
|
||||
super(be, ds, seqName, batchSize);
|
||||
this.baseSql = "select nextval('" + seqName + "'), s.generate_series from (select generate_series from generate_series(1,";
|
||||
}
|
||||
|
||||
+7
-12
@@ -1,37 +1,32 @@
|
||||
package io.ebean.xtest.config.dbplatform;
|
||||
package io.ebean.platform.postgres;
|
||||
|
||||
import io.ebean.platform.postgres.PostgresHistorySupport;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class PostgresHistorySupportTest {
|
||||
class PostgresHistorySupportTest {
|
||||
|
||||
private PostgresHistorySupport support = new PostgresHistorySupport();
|
||||
private final PostgresHistorySupport support = new PostgresHistorySupport();
|
||||
|
||||
@Test
|
||||
public void getBindCount() throws Exception {
|
||||
|
||||
void getBindCount() {
|
||||
assertEquals(support.getBindCount(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAsOfPredicate() throws Exception {
|
||||
|
||||
void getAsOfPredicate() {
|
||||
String asOfPredicate = support.getAsOfPredicate("t0", "sys_period");
|
||||
assertEquals(asOfPredicate, "t0.sys_period @> ?::timestamptz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSysPeriodLower() throws Exception {
|
||||
|
||||
void getSysPeriodLower() {
|
||||
String lower = support.getSysPeriodLower("t0", "sys_period");
|
||||
assertEquals(lower, "lower(t0.sys_period)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSysPeriodUpper() throws Exception {
|
||||
|
||||
void getSysPeriodUpper() {
|
||||
String upper = support.getSysPeriodUpper("t0", "sys_period");
|
||||
assertEquals(upper, "upper(t0.sys_period)");
|
||||
}
|
||||
+1
-2
@@ -5,11 +5,10 @@ import io.ebean.config.dbplatform.BasicSqlLimiter;
|
||||
/**
|
||||
* SQL Server 2012 style limiter for raw sql.
|
||||
*/
|
||||
public class SqlServerBasicSqlLimiter implements BasicSqlLimiter {
|
||||
final class SqlServerBasicSqlLimiter implements BasicSqlLimiter {
|
||||
|
||||
@Override
|
||||
public String limit(String dbSql, int firstRow, int maxRows) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(50 + dbSql.length());
|
||||
sb.append(dbSql);
|
||||
if (!dbSql.toLowerCase().contains("order by")) {
|
||||
|
||||
+2
-2
@@ -6,9 +6,9 @@ import io.ebean.config.dbplatform.DbEncryptFunction;
|
||||
/**
|
||||
* SQL Server EncryptByPassPhrase DecryptByPassPhrase based encryption support.
|
||||
*/
|
||||
public class SqlServerDbEncrypt extends AbstractDbEncrypt {
|
||||
final class SqlServerDbEncrypt extends AbstractDbEncrypt {
|
||||
|
||||
public SqlServerDbEncrypt() {
|
||||
SqlServerDbEncrypt() {
|
||||
this.varcharEncryptFunction = new VarcharFunction();
|
||||
this.dateEncryptFunction = new DateFunction();
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import io.ebean.config.dbplatform.DbStandardHistorySupport;
|
||||
*
|
||||
* @author Vilmos Nagy
|
||||
*/
|
||||
public class SqlServerHistorySupport extends DbStandardHistorySupport {
|
||||
final class SqlServerHistorySupport extends DbStandardHistorySupport {
|
||||
|
||||
/**
|
||||
* Return the ' as of timestamp ?' clause appended after the table name.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import io.ebean.config.dbplatform.SqlLimiter;
|
||||
/**
|
||||
* Use ANSI offset rows syntax or top n - SQL Server 2012 onwards.
|
||||
*/
|
||||
public final class SqlServerSqlLimiter implements SqlLimiter {
|
||||
final class SqlServerSqlLimiter implements SqlLimiter {
|
||||
|
||||
@Override
|
||||
public SqlLimitResponse limit(SqlLimitRequest request) {
|
||||
|
||||
+2
-2
@@ -5,14 +5,14 @@ import io.ebean.config.dbplatform.SequenceStepIdGenerator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class SqlServerStepSequence extends SequenceStepIdGenerator {
|
||||
final class SqlServerStepSequence extends SequenceStepIdGenerator {
|
||||
|
||||
private final String nextSql;
|
||||
|
||||
/**
|
||||
* Construct where batchSize is the sequence step size.
|
||||
*/
|
||||
public SqlServerStepSequence(BackgroundExecutor be, DataSource ds, String seqName, int stepSize) {
|
||||
SqlServerStepSequence(BackgroundExecutor be, DataSource ds, String seqName, int stepSize) {
|
||||
super(be, ds, seqName, stepSize);
|
||||
this.nextSql = "select next value for "+seqName;
|
||||
}
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
package io.ebean.xtest.config.dbplatform.sqlserver;
|
||||
package io.ebean.platform.sqlserver;
|
||||
|
||||
import io.ebean.platform.sqlserver.SqlServer17Platform;
|
||||
import io.ebean.platform.sqlserver.SqlServerHistorySupport;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
Reference in New Issue
Block a user