Skip to content

Commit

Permalink
Merge pull request #3018 from ebean-orm/refactor/add-final-remove-pub…
Browse files Browse the repository at this point in the history
…lic-platformHelpers

Refactor platforms adding final and removing public from sequence, history, encryption helpers
  • Loading branch information
rbygrave authored Apr 6, 2023
2 parents 85b7007 + 505f87c commit 02f7815
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 121 deletions.

This file was deleted.

7 changes: 7 additions & 0 deletions platforms/hana/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

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);
Expand All @@ -18,7 +17,6 @@ public String limit(String dbSql, int firstRow, int maxRows) {
sb.append(firstRow);
}
}

return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.ebean.config.dbplatform.DbStandardHistorySupport;

public class HanaHistorySupport extends DbStandardHistorySupport {
final class HanaHistorySupport extends DbStandardHistorySupport {

@Override
public String getAsOfViewSuffix(String asOfViewSuffix) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
* 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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
* 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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/**
* 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* 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 <= ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/**
* 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* 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.
Expand All @@ -19,11 +19,9 @@ public int getBindCount() {
* 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* 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,";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
/**
* 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")) {
Expand Down
Loading

0 comments on commit 02f7815

Please sign in to comment.