No effective change - change newline char

This commit is contained in:
rbygrave
2015-05-09 00:59:59 +12:00
parent dc86b8b447
commit f306672c6c
19 changed files with 935 additions and 935 deletions
@@ -1,77 +1,77 @@
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
/**
* Base type for DB platform specific Encryption.
* <p>
* DB specific classes that extend this need to set their specific encryption
* functions for varchar, date and timestamp. If they are left null then that is
* treated as though that data type can not be encrypted in the DB and will
* instead use java client encryption.
* </p>
*
* @author rbygrave
*/
public abstract class AbstractDbEncrypt implements DbEncrypt {
/**
* The encryption function for all String types (VARCHAR, CLOB, LONGVARCHAR,
* CHAR).
*/
protected DbEncryptFunction varcharEncryptFunction;
/**
* The encryption function for all Date types (java.sql.Date, Joda Date
* types).
*/
protected DbEncryptFunction dateEncryptFunction;
/**
* The encryption function for all Timestamp types (java.sql.Timestamp,
* java.util.Date, java.util.Calendar, Joda DateTime types etc).
*/
protected DbEncryptFunction timestampEncryptFunction;
/**
* Return the DB encryption function for the given JDBC type.
* <p>
* Null is returned if DB encryption of the type is not supported.
* </p>
*/
public DbEncryptFunction getDbEncryptFunction(int jdbcType) {
switch (jdbcType) {
case Types.VARCHAR:
return varcharEncryptFunction;
case Types.CLOB:
return varcharEncryptFunction;
case Types.CHAR:
return varcharEncryptFunction;
case Types.LONGVARCHAR:
return varcharEncryptFunction;
case Types.DATE:
return dateEncryptFunction;
case Types.TIMESTAMP:
return timestampEncryptFunction;
default:
return null;
}
}
/**
* Return the DB stored type for encrypted properties.
*/
public int getEncryptDbType() {
return Types.VARBINARY;
}
/**
* Generally encrypt function binding the data before the key (except h2).
*/
public boolean isBindEncryptDataFirst() {
return true;
}
}
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
/**
* Base type for DB platform specific Encryption.
* <p>
* DB specific classes that extend this need to set their specific encryption
* functions for varchar, date and timestamp. If they are left null then that is
* treated as though that data type can not be encrypted in the DB and will
* instead use java client encryption.
* </p>
*
* @author rbygrave
*/
public abstract class AbstractDbEncrypt implements DbEncrypt {
/**
* The encryption function for all String types (VARCHAR, CLOB, LONGVARCHAR,
* CHAR).
*/
protected DbEncryptFunction varcharEncryptFunction;
/**
* The encryption function for all Date types (java.sql.Date, Joda Date
* types).
*/
protected DbEncryptFunction dateEncryptFunction;
/**
* The encryption function for all Timestamp types (java.sql.Timestamp,
* java.util.Date, java.util.Calendar, Joda DateTime types etc).
*/
protected DbEncryptFunction timestampEncryptFunction;
/**
* Return the DB encryption function for the given JDBC type.
* <p>
* Null is returned if DB encryption of the type is not supported.
* </p>
*/
public DbEncryptFunction getDbEncryptFunction(int jdbcType) {
switch (jdbcType) {
case Types.VARCHAR:
return varcharEncryptFunction;
case Types.CLOB:
return varcharEncryptFunction;
case Types.CHAR:
return varcharEncryptFunction;
case Types.LONGVARCHAR:
return varcharEncryptFunction;
case Types.DATE:
return dateEncryptFunction;
case Types.TIMESTAMP:
return timestampEncryptFunction;
default:
return null;
}
}
/**
* Return the DB stored type for encrypted properties.
*/
public int getEncryptDbType() {
return Types.VARBINARY;
}
/**
* Generally encrypt function binding the data before the key (except h2).
*/
public boolean isBindEncryptDataFirst() {
return true;
}
}
@@ -1,43 +1,43 @@
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
import javax.sql.DataSource;
import com.avaje.ebean.BackgroundExecutor;
/**
* DB2 specific platform.
*/
public class DB2Platform extends DatabasePlatform {
public DB2Platform() {
super();
this.name = "db2";
// only support getGeneratedKeys with non-batch JDBC
// so generally use SEQUENCE instead for H2
this.sqlLimiter = new Db2SqlLimiter();
this.dbIdentity.setSupportsGetGeneratedKeys(true);
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));
this.dbDdlSyntax.setIdentity("generated by default as identity");
}
/**
* Return a DB2 specific sequence IdGenerator that supports batch fetching
* sequence values.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return new DB2SequenceIdGenerator(be, ds, seqName, batchSize);
}
}
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
import javax.sql.DataSource;
import com.avaje.ebean.BackgroundExecutor;
/**
* DB2 specific platform.
*/
public class DB2Platform extends DatabasePlatform {
public DB2Platform() {
super();
this.name = "db2";
// only support getGeneratedKeys with non-batch JDBC
// so generally use SEQUENCE instead for H2
this.sqlLimiter = new Db2SqlLimiter();
this.dbIdentity.setSupportsGetGeneratedKeys(true);
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));
this.dbDdlSyntax.setIdentity("generated by default as identity");
}
/**
* Return a DB2 specific sequence IdGenerator that supports batch fetching
* sequence values.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return new DB2SequenceIdGenerator(be, ds, seqName, batchSize);
}
}
@@ -1,41 +1,41 @@
package com.avaje.ebean.config.dbplatform;
/**
* Defines DB encryption support for encrypting and decrypting data using DB
* encryption features.
* <p>
* As an alternative to using DB encryption you can encrypt/decrypt in java via
* a special ScalarType but this has the limitation that you can't include that
* property in query where clauses.
* </p>
*
* @author rbygrave
*/
public interface DbEncrypt {
// /**
// * Return the SQL for decrypting a column returning a VARCHAR.
// */
// String getDecryptSql(String columnWithTableAlias);
//
// /**
// * Return the DB function with bind variables used to encrypt a VARCHAR
// * value.
// */
// String getEncryptBindSql();
DbEncryptFunction getDbEncryptFunction(int jdbcType);
/**
* Return the DB type that encrypted Strings are stored in.
* <p>
* This is VARCHAR for MySql and VARBINARY for most others.
* </p>
*/
int getEncryptDbType();
/**
* Return true if the DB encrypt function binds the data before the key.
*/
boolean isBindEncryptDataFirst();
package com.avaje.ebean.config.dbplatform;
/**
* Defines DB encryption support for encrypting and decrypting data using DB
* encryption features.
* <p>
* As an alternative to using DB encryption you can encrypt/decrypt in java via
* a special ScalarType but this has the limitation that you can't include that
* property in query where clauses.
* </p>
*
* @author rbygrave
*/
public interface DbEncrypt {
// /**
// * Return the SQL for decrypting a column returning a VARCHAR.
// */
// String getDecryptSql(String columnWithTableAlias);
//
// /**
// * Return the DB function with bind variables used to encrypt a VARCHAR
// * value.
// */
// String getEncryptBindSql();
DbEncryptFunction getDbEncryptFunction(int jdbcType);
/**
* Return the DB type that encrypted Strings are stored in.
* <p>
* This is VARCHAR for MySql and VARBINARY for most others.
* </p>
*/
int getEncryptDbType();
/**
* Return true if the DB encrypt function binds the data before the key.
*/
boolean isBindEncryptDataFirst();
}
@@ -1,15 +1,15 @@
package com.avaje.ebean.config.dbplatform;
public interface DbEncryptFunction {
/**
* Return the SQL for decrypting a column returning a VARCHAR.
*/
String getDecryptSql(String columnWithTableAlias);
/**
* Return the DB function with bind variables used to encrypt a VARCHAR value.
*/
String getEncryptBindSql();
}
package com.avaje.ebean.config.dbplatform;
public interface DbEncryptFunction {
/**
* Return the SQL for decrypting a column returning a VARCHAR.
*/
String getDecryptSql(String columnWithTableAlias);
/**
* Return the DB function with bind variables used to encrypt a VARCHAR value.
*/
String getEncryptBindSql();
}
@@ -1,48 +1,48 @@
package com.avaje.ebean.config.dbplatform;
/**
* H2 encryption support via encrypt decrypt function.
*
* @author rbygrave
*/
public class H2DbEncrypt extends AbstractDbEncrypt {
public H2DbEncrypt() {
this.varcharEncryptFunction = new H2VarcharFunction();
this.dateEncryptFunction = new H2DateFunction();
}
/**
* For H2 encrypt function returns false binding the key before the data.
*/
public boolean isBindEncryptDataFirst() {
return false;
}
private static class H2VarcharFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
// Hmmm, this looks ugly - checking with H2 Database folks.
return "TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', STRINGTOUTF8(?), "
+ columnWithTableAlias + ")))";
}
public String getEncryptBindSql() {
return "ENCRYPT('AES', STRINGTOUTF8(?), STRINGTOUTF8(?))";
}
}
private static class H2DateFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "PARSEDATETIME(TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', STRINGTOUTF8(?), "
+ columnWithTableAlias + "))),'yyyyMMdd')";
}
public String getEncryptBindSql() {
return "ENCRYPT('AES', STRINGTOUTF8(?), STRINGTOUTF8(FORMATDATETIME(?,'yyyyMMdd')))";
}
}
}
package com.avaje.ebean.config.dbplatform;
/**
* H2 encryption support via encrypt decrypt function.
*
* @author rbygrave
*/
public class H2DbEncrypt extends AbstractDbEncrypt {
public H2DbEncrypt() {
this.varcharEncryptFunction = new H2VarcharFunction();
this.dateEncryptFunction = new H2DateFunction();
}
/**
* For H2 encrypt function returns false binding the key before the data.
*/
public boolean isBindEncryptDataFirst() {
return false;
}
private static class H2VarcharFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
// Hmmm, this looks ugly - checking with H2 Database folks.
return "TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', STRINGTOUTF8(?), "
+ columnWithTableAlias + ")))";
}
public String getEncryptBindSql() {
return "ENCRYPT('AES', STRINGTOUTF8(?), STRINGTOUTF8(?))";
}
}
private static class H2DateFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "PARSEDATETIME(TRIM(CHAR(0) FROM UTF8TOSTRING(DECRYPT('AES', STRINGTOUTF8(?), "
+ columnWithTableAlias + "))),'yyyyMMdd')";
}
public String getEncryptBindSql() {
return "ENCRYPT('AES', STRINGTOUTF8(?), STRINGTOUTF8(FORMATDATETIME(?,'yyyyMMdd')))";
}
}
}
@@ -1,54 +1,54 @@
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
/**
* H2 specific platform.
*/
public class H2Platform extends DatabasePlatform {
public H2Platform() {
super();
this.name = "h2";
this.dbEncrypt = new H2DbEncrypt();
// like ? escape'' not working in the latest version H2 so just using no
// escape clause for now noting that backslash is an escape char for like in H2
this.likeClause = "like ?";
// only support getGeneratedKeys with non-batch JDBC
// so generally use SEQUENCE instead of IDENTITY for H2
this.dbIdentity.setIdType(IdType.SEQUENCE);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsSequence(true);
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "\"";
this.closeQuote = "\"";
// H2 data types match default JDBC types
// so no changes to dbTypeMap required
this.dbDdlSyntax.setDropIfExists("if exists");
this.dbDdlSyntax.setDisableReferentialIntegrity("SET REFERENTIAL_INTEGRITY FALSE");
this.dbDdlSyntax.setEnableReferentialIntegrity("SET REFERENTIAL_INTEGRITY TRUE");
this.dbDdlSyntax.setForeignKeySuffix("on delete restrict on update restrict");
}
/**
* Return a H2 specific sequence IdGenerator that supports batch fetching
* sequence values.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds,
String seqName, int batchSize) {
return new H2SequenceIdGenerator(be, ds, seqName, batchSize);
}
@Override
protected String withForUpdate(String sql) {
return sql + " for update";
}
}
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
/**
* H2 specific platform.
*/
public class H2Platform extends DatabasePlatform {
public H2Platform() {
super();
this.name = "h2";
this.dbEncrypt = new H2DbEncrypt();
// like ? escape'' not working in the latest version H2 so just using no
// escape clause for now noting that backslash is an escape char for like in H2
this.likeClause = "like ?";
// only support getGeneratedKeys with non-batch JDBC
// so generally use SEQUENCE instead of IDENTITY for H2
this.dbIdentity.setIdType(IdType.SEQUENCE);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsSequence(true);
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "\"";
this.closeQuote = "\"";
// H2 data types match default JDBC types
// so no changes to dbTypeMap required
this.dbDdlSyntax.setDropIfExists("if exists");
this.dbDdlSyntax.setDisableReferentialIntegrity("SET REFERENTIAL_INTEGRITY FALSE");
this.dbDdlSyntax.setEnableReferentialIntegrity("SET REFERENTIAL_INTEGRITY TRUE");
this.dbDdlSyntax.setForeignKeySuffix("on delete restrict on update restrict");
}
/**
* Return a H2 specific sequence IdGenerator that supports batch fetching
* sequence values.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds,
String seqName, int batchSize) {
return new H2SequenceIdGenerator(be, ds, seqName, batchSize);
}
@Override
protected String withForUpdate(String sql) {
return sql + " for update";
}
}
@@ -1,47 +1,47 @@
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
import java.sql.Types;
/**
* H2 specific platform.
*/
public class HsqldbPlatform extends DatabasePlatform {
public HsqldbPlatform() {
super();
this.name = "hsqldb";
this.dbEncrypt = new H2DbEncrypt();
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsSequence(true);
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "\"";
this.closeQuote = "\"";
// H2 data types match default JDBC types
// so no changes to dbTypeMap required
dbTypeMap.put(Types.INTEGER, new DbType("integer", false));
this.dbDdlSyntax.setDropIfExists("if exists");
this.dbDdlSyntax.setDisableReferentialIntegrity("SET DATABASE REFERENTIAL INTEGRITY FALSE");
this.dbDdlSyntax.setEnableReferentialIntegrity("SET DATABASE REFERENTIAL INTEGRITY TRUE");
this.dbDdlSyntax.setForeignKeySuffix("on delete restrict on update restrict");
this.dbDdlSyntax.setIdentity("GENERATED BY DEFAULT AS IDENTITY (START WITH 1) ");
}
/**
* Return a H2 specific sequence IdGenerator that supports batch fetching
* sequence values.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return new H2SequenceIdGenerator(be, ds, seqName, batchSize);
}
}
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
import java.sql.Types;
/**
* H2 specific platform.
*/
public class HsqldbPlatform extends DatabasePlatform {
public HsqldbPlatform() {
super();
this.name = "hsqldb";
this.dbEncrypt = new H2DbEncrypt();
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsSequence(true);
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "\"";
this.closeQuote = "\"";
// H2 data types match default JDBC types
// so no changes to dbTypeMap required
dbTypeMap.put(Types.INTEGER, new DbType("integer", false));
this.dbDdlSyntax.setDropIfExists("if exists");
this.dbDdlSyntax.setDisableReferentialIntegrity("SET DATABASE REFERENTIAL INTEGRITY FALSE");
this.dbDdlSyntax.setEnableReferentialIntegrity("SET DATABASE REFERENTIAL INTEGRITY TRUE");
this.dbDdlSyntax.setForeignKeySuffix("on delete restrict on update restrict");
this.dbDdlSyntax.setIdentity("GENERATED BY DEFAULT AS IDENTITY (START WITH 1) ");
}
/**
* Return a H2 specific sequence IdGenerator that supports batch fetching
* sequence values.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return new H2SequenceIdGenerator(be, ds, seqName, batchSize);
}
}
@@ -1,50 +1,50 @@
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.Transaction;
/**
* Generates unique id's for objects. This occurs prior to the actual insert.
* <p>
* Note that many databases have sequences or auto increment features. These can
* be used rather than an IdGenerator and are different in that they occur
* during an insert. IdGenerator is used to generate an id <em>BEFORE</em> the
* actual insert.
* </p>
*/
public interface IdGenerator {
/**
* The name of the default UUID generator.
*/
static final String AUTO_UUID = "auto.uuid";
/**
* Return the name of the IdGenerator. For sequences this is the sequence
* name.
*/
String getName();
/**
* Return true if this is a DB sequence.
*/
boolean isDbSequence();
/**
* return the next unique identity value.
* <p>
* Note the transaction passed in can be null.
* </p>
*/
Object nextId(Transaction transaction);
/**
* Is called prior to inserting OneToMany's as an indication that a number of
* beans are likely to need id's shortly.
* <p>
* Can be used as a performance optimisation to prefetch a number of Id's.
* Especially when the allocateSize is very large.
* </p>
*/
void preAllocateIds(int allocateSize);
}
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.Transaction;
/**
* Generates unique id's for objects. This occurs prior to the actual insert.
* <p>
* Note that many databases have sequences or auto increment features. These can
* be used rather than an IdGenerator and are different in that they occur
* during an insert. IdGenerator is used to generate an id <em>BEFORE</em> the
* actual insert.
* </p>
*/
public interface IdGenerator {
/**
* The name of the default UUID generator.
*/
static final String AUTO_UUID = "auto.uuid";
/**
* Return the name of the IdGenerator. For sequences this is the sequence
* name.
*/
String getName();
/**
* Return true if this is a DB sequence.
*/
boolean isDbSequence();
/**
* return the next unique identity value.
* <p>
* Note the transaction passed in can be null.
* </p>
*/
Object nextId(Transaction transaction);
/**
* Is called prior to inserting OneToMany's as an indication that a number of
* beans are likely to need id's shortly.
* <p>
* Can be used as a performance optimisation to prefetch a number of Id's.
* Especially when the allocateSize is very large.
* </p>
*/
void preAllocateIds(int allocateSize);
}
@@ -1,31 +1,31 @@
package com.avaje.ebean.config.dbplatform;
/**
* The types of Identity generation that can be defined.
*/
public enum IdType {
/**
* Use a Database Identity (autoincrement) to generate the identity.
*/
IDENTITY,
/**
* Use a Database sequence to generate the identity.
* <p>
* Note: Some databases support getGeneratedKeys with sequences and this then
* does not involve an extra statement to return the id.
* </p>
*/
SEQUENCE,
/**
* Use an IdGenerator to generate the identity (prior to insert).
* <p>
* Note: There is a IdGenerator for UUID's and it is automatically assigned to
* id properties of type UUID.
* </p>
*/
GENERATOR;
}
package com.avaje.ebean.config.dbplatform;
/**
* The types of Identity generation that can be defined.
*/
public enum IdType {
/**
* Use a Database Identity (autoincrement) to generate the identity.
*/
IDENTITY,
/**
* Use a Database sequence to generate the identity.
* <p>
* Note: Some databases support getGeneratedKeys with sequences and this then
* does not involve an extra statement to return the id.
* </p>
*/
SEQUENCE,
/**
* Use an IdGenerator to generate the identity (prior to insert).
* <p>
* Note: There is a IdGenerator for UUID's and it is automatically assigned to
* id properties of type UUID.
* </p>
*/
GENERATOR;
}
@@ -1,48 +1,48 @@
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
/**
* Microsoft SQL Server 2000 specific platform.
* <p>
* <ul>
* <li>supportsGetGeneratedKeys = false</li>
* <li>Use select @@IDENTITY to return the generated Id instead</li>
* <li>Uses LIMIT OFFSET clause</li>
* <li>Uses [ & ] for quoted identifiers</li>
* </ul>
* </p>
*/
public class MsSqlServer2000Platform extends DatabasePlatform {
public MsSqlServer2000Platform() {
super();
this.name = "mssqlserver2000";
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(false);
this.dbIdentity.setSelectLastInsertedIdTemplate("select @@IDENTITY as X");
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "[";
this.closeQuote = "]";
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(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(Types.DATE, new DbType("datetime"));
dbTypeMap.put(Types.TIME, new DbType("datetime"));
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime"));
}
}
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
/**
* Microsoft SQL Server 2000 specific platform.
* <p>
* <ul>
* <li>supportsGetGeneratedKeys = false</li>
* <li>Use select @@IDENTITY to return the generated Id instead</li>
* <li>Uses LIMIT OFFSET clause</li>
* <li>Uses [ & ] for quoted identifiers</li>
* </ul>
* </p>
*/
public class MsSqlServer2000Platform extends DatabasePlatform {
public MsSqlServer2000Platform() {
super();
this.name = "mssqlserver2000";
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(false);
this.dbIdentity.setSelectLastInsertedIdTemplate("select @@IDENTITY as X");
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "[";
this.closeQuote = "]";
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(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(Types.DATE, new DbType("datetime"));
dbTypeMap.put(Types.TIME, new DbType("datetime"));
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime"));
}
}
@@ -1,79 +1,79 @@
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
/**
* Microsoft SQL Server 2005 specific platform.
* <p>
* <ul>
* <li>supportsGetGeneratedKeys = true</li>
* <li>Uses LIMIT OFFSET clause</li>
* <li>Uses [ & ] for quoted identifiers</li>
* </ul>
* </p>
*/
public class MsSqlServer2005Platform extends DatabasePlatform {
public MsSqlServer2005Platform() {
super();
this.name = "mssqlserver2005";
// effectively disable persistBatchOnCascade mode for SQL Server
// due to lack of support for getGeneratedKeys in batch mode
this.disallowBatchOnCascade = true;
this.idInExpandedForm = true;
this.sqlLimiter = new MsSqlServer2005SqlLimiter();
this.dbDdlSyntax = new MsDdlSyntax();
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "[";
this.closeQuote = "]";
dbTypeMap.put(Types.BOOLEAN, new DbType("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(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(Types.DATE, new DbType("datetime"));
dbTypeMap.put(Types.TIME, new DbType("datetime"));
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime"));
}
/**
* MS SQL Server specific DDL Syntax.
*/
public class MsDdlSyntax extends DbDdlSyntax {
MsDdlSyntax() {
this.identity = "identity(1,1)";
this.dropKeyConstraints = true;
}
/**
* Return some DDL to disable constraints on the given table.
*/
public String dropKeyConstraintPrefix(String tableName, String fkName) {
return "IF OBJECT_ID('"+fkName+"', 'F') IS NOT NULL";
}
/**
* Return prefix text that goes before drop table.
*/
public String dropTablePrefix(String tableName) {
return "IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL ";
}
}
}
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
/**
* Microsoft SQL Server 2005 specific platform.
* <p>
* <ul>
* <li>supportsGetGeneratedKeys = true</li>
* <li>Uses LIMIT OFFSET clause</li>
* <li>Uses [ & ] for quoted identifiers</li>
* </ul>
* </p>
*/
public class MsSqlServer2005Platform extends DatabasePlatform {
public MsSqlServer2005Platform() {
super();
this.name = "mssqlserver2005";
// effectively disable persistBatchOnCascade mode for SQL Server
// due to lack of support for getGeneratedKeys in batch mode
this.disallowBatchOnCascade = true;
this.idInExpandedForm = true;
this.sqlLimiter = new MsSqlServer2005SqlLimiter();
this.dbDdlSyntax = new MsDdlSyntax();
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsIdentity(true);
this.openQuote = "[";
this.closeQuote = "]";
dbTypeMap.put(Types.BOOLEAN, new DbType("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(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(Types.DATE, new DbType("datetime"));
dbTypeMap.put(Types.TIME, new DbType("datetime"));
dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime"));
}
/**
* MS SQL Server specific DDL Syntax.
*/
public class MsDdlSyntax extends DbDdlSyntax {
MsDdlSyntax() {
this.identity = "identity(1,1)";
this.dropKeyConstraints = true;
}
/**
* Return some DDL to disable constraints on the given table.
*/
public String dropKeyConstraintPrefix(String tableName, String fkName) {
return "IF OBJECT_ID('"+fkName+"', 'F') IS NOT NULL";
}
/**
* Return prefix text that goes before drop table.
*/
public String dropTablePrefix(String tableName) {
return "IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL ";
}
}
}
@@ -1,35 +1,35 @@
package com.avaje.ebean.config.dbplatform;
/**
* Support for blob, mediumblob or longblob selection based on the deployment
* length.
* <p>
* If no deployment length is defined longblob is used.
* </p>
*/
public class MySqlBlob extends DbType {
private static final int POWER_2_16 = 65536;
private static final int POWER_2_24 = 16777216;
public MySqlBlob() {
super("blob");
}
@Override
public String renderType(int deployLength, int deployScale) {
if (deployLength >= POWER_2_24) {
return "longblob";
}
if (deployLength >= POWER_2_16) {
return "mediumblob";
}
if (deployLength < 1) {
// length not explicitly defined
return "longblob";
}
return "blob";
}
}
package com.avaje.ebean.config.dbplatform;
/**
* Support for blob, mediumblob or longblob selection based on the deployment
* length.
* <p>
* If no deployment length is defined longblob is used.
* </p>
*/
public class MySqlBlob extends DbType {
private static final int POWER_2_16 = 65536;
private static final int POWER_2_24 = 16777216;
public MySqlBlob() {
super("blob");
}
@Override
public String renderType(int deployLength, int deployScale) {
if (deployLength >= POWER_2_24) {
return "longblob";
}
if (deployLength >= POWER_2_16) {
return "mediumblob";
}
if (deployLength < 1) {
// length not explicitly defined
return "longblob";
}
return "blob";
}
}
@@ -1,35 +1,35 @@
package com.avaje.ebean.config.dbplatform;
/**
* Support for text, mediumtext or longtext selection based on the deployment
* length.
* <p>
* If no deployment length is defined longtext is used.
* </p>
*/
public class MySqlClob extends DbType {
private static final int POWER_2_16 = 65536;
private static final int POWER_2_24 = 16777216;
public MySqlClob() {
super("text");
}
@Override
public String renderType(int deployLength, int deployScale) {
if (deployLength >= POWER_2_24) {
return "longtext";
}
if (deployLength >= POWER_2_16) {
return "mediumtext";
}
if (deployLength < 1) {
// length not explicitly defined
return "longtext";
}
return "text";
}
}
package com.avaje.ebean.config.dbplatform;
/**
* Support for text, mediumtext or longtext selection based on the deployment
* length.
* <p>
* If no deployment length is defined longtext is used.
* </p>
*/
public class MySqlClob extends DbType {
private static final int POWER_2_16 = 65536;
private static final int POWER_2_24 = 16777216;
public MySqlClob() {
super("text");
}
@Override
public String renderType(int deployLength, int deployScale) {
if (deployLength >= POWER_2_24) {
return "longtext";
}
if (deployLength >= POWER_2_16) {
return "mediumtext";
}
if (deployLength < 1) {
// length not explicitly defined
return "longtext";
}
return "text";
}
}
@@ -1,36 +1,36 @@
package com.avaje.ebean.config.dbplatform;
/**
* MySql aes_encrypt aes_decrypt based encryption support.
*
* @author rbygrave
*/
public class MySqlDbEncrypt extends AbstractDbEncrypt {
public MySqlDbEncrypt() {
this.varcharEncryptFunction = new MyVarcharFunction();
this.dateEncryptFunction = new MyDateFunction();
}
private static class MyVarcharFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "CONVERT(AES_DECRYPT(" + columnWithTableAlias + ",?) USING UTF8)";
}
public String getEncryptBindSql() {
return "AES_ENCRYPT(?,?)";
}
}
private static class MyDateFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "STR_TO_DATE(AES_DECRYPT(" + columnWithTableAlias + ",?),'%Y%d%m')";
}
public String getEncryptBindSql() {
return "AES_ENCRYPT(DATE_FORMAT(?,'%Y%d%m'),?)";
}
}
}
package com.avaje.ebean.config.dbplatform;
/**
* MySql aes_encrypt aes_decrypt based encryption support.
*
* @author rbygrave
*/
public class MySqlDbEncrypt extends AbstractDbEncrypt {
public MySqlDbEncrypt() {
this.varcharEncryptFunction = new MyVarcharFunction();
this.dateEncryptFunction = new MyDateFunction();
}
private static class MyVarcharFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "CONVERT(AES_DECRYPT(" + columnWithTableAlias + ",?) USING UTF8)";
}
public String getEncryptBindSql() {
return "AES_ENCRYPT(?,?)";
}
}
private static class MyDateFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "STR_TO_DATE(AES_DECRYPT(" + columnWithTableAlias + ",?),'%Y%d%m')";
}
public String getEncryptBindSql() {
return "AES_ENCRYPT(DATE_FORMAT(?,'%Y%d%m'),?)";
}
}
}
@@ -1,67 +1,67 @@
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
import java.sql.Types;
/**
* MySQL specific platform.
* <p>
* <ul>
* <li>supportsGetGeneratedKeys = true</li>
* <li>Uses LIMIT OFFSET clause</li>
* <li>Uses ` for quoted identifiers</li>
* </ul>
* </p>
*/
public class MySqlPlatform extends DatabasePlatform {
public MySqlPlatform() {
super();
this.name = "mysql";
this.likeClause = "like ? escape''";
this.selectCountWithAlias = true;
this.dbEncrypt = new MySqlDbEncrypt();
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsIdentity(true);
this.dbIdentity.setSupportsSequence(false);
this.openQuote = "`";
this.closeQuote = "`";
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));
dbDdlSyntax.setMaxConstraintNameLength(64);
dbDdlSyntax.setDisableReferentialIntegrity("SET FOREIGN_KEY_CHECKS=0");
dbDdlSyntax.setEnableReferentialIntegrity("SET FOREIGN_KEY_CHECKS=1");
dbDdlSyntax.setForeignKeySuffix("on delete restrict on update restrict");
}
/**
* Return null in case there is a sequence annotation.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return null;
}
@Override
protected String withForUpdate(String sql) {
return sql + " for update";
}
}
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
import java.sql.Types;
/**
* MySQL specific platform.
* <p>
* <ul>
* <li>supportsGetGeneratedKeys = true</li>
* <li>Uses LIMIT OFFSET clause</li>
* <li>Uses ` for quoted identifiers</li>
* </ul>
* </p>
*/
public class MySqlPlatform extends DatabasePlatform {
public MySqlPlatform() {
super();
this.name = "mysql";
this.likeClause = "like ? escape''";
this.selectCountWithAlias = true;
this.dbEncrypt = new MySqlDbEncrypt();
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(true);
this.dbIdentity.setSupportsIdentity(true);
this.dbIdentity.setSupportsSequence(false);
this.openQuote = "`";
this.closeQuote = "`";
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));
dbDdlSyntax.setMaxConstraintNameLength(64);
dbDdlSyntax.setDisableReferentialIntegrity("SET FOREIGN_KEY_CHECKS=0");
dbDdlSyntax.setEnableReferentialIntegrity("SET FOREIGN_KEY_CHECKS=1");
dbDdlSyntax.setForeignKeySuffix("on delete restrict on update restrict");
}
/**
* Return null in case there is a sequence annotation.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return null;
}
@Override
protected String withForUpdate(String sql) {
return sql + " for update";
}
}
@@ -1,112 +1,112 @@
package com.avaje.ebean.config.dbplatform;
/**
* Oracle encryption support.
*
* <p>
* You will typically need to create your own encryption and decryption
* functions similar to the example ones below.
* </p>
*
* <pre class="code">
*
* // Remember your DB user needs execute privilege on DBMS_CRYPTO
* // as well as your encryption and decryption functions
*
*
* // This is an Example Encryption function only - please create your own.
*
* CREATE OR REPLACE FUNCTION eb_encrypt(data IN VARCHAR, key in VARCHAR) RETURN RAW IS
*
* encryption_mode NUMBER := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
*
* BEGIN
* RETURN DBMS_CRYPTO.ENCRYPT(UTL_I18N.STRING_TO_RAW (data, 'AL32UTF8'),
* encryption_mode, UTL_I18N.STRING_TO_RAW(key, 'AL32UTF8') );
* END;
* /
*
*
*
* // This is an Example Decryption function only - please create your own.
*
* CREATE OR REPLACE FUNCTION eb_decrypt(data IN RAW, key IN VARCHAR) RETURN VARCHAR IS
*
* encryption_mode NUMBER := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
*
* BEGIN
* RETURN UTL_RAW.CAST_TO_VARCHAR2(DBMS_CRYPTO.DECRYPT
* (data, encryption_mode, UTL_I18N.STRING_TO_RAW(key, 'AL32UTF8')));
* END;
* /
* </pre>
*
* @author rbygrave
*/
public class Oracle10DbEncrypt extends AbstractDbEncrypt {
/**
* Constructs the Oracle10DbEncrypt with default encrypt and decrypt stored procedures.
*/
public Oracle10DbEncrypt() {
this("eb_encrypt", "eb_decrypt");
}
/**
* Constructs the Oracle10DbEncrypt specifying encrypt and decrypt stored procedures.
*
* @param encryptfunction the encrypt stored procedure
* @param decryptfunction the decrypt stored procedure
*/
public Oracle10DbEncrypt(String encryptfunction, String decryptfunction) {
this.varcharEncryptFunction = new OraVarcharFunction(encryptfunction, decryptfunction);
this.dateEncryptFunction = new OraDateFunction(encryptfunction, decryptfunction);
}
/**
* VARCHAR encryption/decryption function.
*/
private static class OraVarcharFunction implements DbEncryptFunction {
private final String encryptfunction;
private final String decryptfunction;
public OraVarcharFunction(String encryptfunction, String decryptfunction) {
this.encryptfunction = encryptfunction;
this.decryptfunction = decryptfunction;
}
public String getDecryptSql(String columnWithTableAlias) {
return decryptfunction + "(" + columnWithTableAlias + ",?)";
}
public String getEncryptBindSql() {
return encryptfunction + "(?,?)";
}
}
/**
* DATE encryption/decryption function.
*/
private static class OraDateFunction implements DbEncryptFunction {
private final String encryptfunction;
private final String decryptfunction;
public OraDateFunction(String encryptfunction, String decryptfunction) {
this.encryptfunction = encryptfunction;
this.decryptfunction = decryptfunction;
}
public String getDecryptSql(String columnWithTableAlias) {
return "to_date(" + decryptfunction + "(" + columnWithTableAlias + ",?),'YYYYMMDD')";
}
public String getEncryptBindSql() {
return encryptfunction + "(to_char(?,'YYYYMMDD'),?)";
}
}
}
package com.avaje.ebean.config.dbplatform;
/**
* Oracle encryption support.
*
* <p>
* You will typically need to create your own encryption and decryption
* functions similar to the example ones below.
* </p>
*
* <pre class="code">
*
* // Remember your DB user needs execute privilege on DBMS_CRYPTO
* // as well as your encryption and decryption functions
*
*
* // This is an Example Encryption function only - please create your own.
*
* CREATE OR REPLACE FUNCTION eb_encrypt(data IN VARCHAR, key in VARCHAR) RETURN RAW IS
*
* encryption_mode NUMBER := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
*
* BEGIN
* RETURN DBMS_CRYPTO.ENCRYPT(UTL_I18N.STRING_TO_RAW (data, 'AL32UTF8'),
* encryption_mode, UTL_I18N.STRING_TO_RAW(key, 'AL32UTF8') );
* END;
* /
*
*
*
* // This is an Example Decryption function only - please create your own.
*
* CREATE OR REPLACE FUNCTION eb_decrypt(data IN RAW, key IN VARCHAR) RETURN VARCHAR IS
*
* encryption_mode NUMBER := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
*
* BEGIN
* RETURN UTL_RAW.CAST_TO_VARCHAR2(DBMS_CRYPTO.DECRYPT
* (data, encryption_mode, UTL_I18N.STRING_TO_RAW(key, 'AL32UTF8')));
* END;
* /
* </pre>
*
* @author rbygrave
*/
public class Oracle10DbEncrypt extends AbstractDbEncrypt {
/**
* Constructs the Oracle10DbEncrypt with default encrypt and decrypt stored procedures.
*/
public Oracle10DbEncrypt() {
this("eb_encrypt", "eb_decrypt");
}
/**
* Constructs the Oracle10DbEncrypt specifying encrypt and decrypt stored procedures.
*
* @param encryptfunction the encrypt stored procedure
* @param decryptfunction the decrypt stored procedure
*/
public Oracle10DbEncrypt(String encryptfunction, String decryptfunction) {
this.varcharEncryptFunction = new OraVarcharFunction(encryptfunction, decryptfunction);
this.dateEncryptFunction = new OraDateFunction(encryptfunction, decryptfunction);
}
/**
* VARCHAR encryption/decryption function.
*/
private static class OraVarcharFunction implements DbEncryptFunction {
private final String encryptfunction;
private final String decryptfunction;
public OraVarcharFunction(String encryptfunction, String decryptfunction) {
this.encryptfunction = encryptfunction;
this.decryptfunction = decryptfunction;
}
public String getDecryptSql(String columnWithTableAlias) {
return decryptfunction + "(" + columnWithTableAlias + ",?)";
}
public String getEncryptBindSql() {
return encryptfunction + "(?,?)";
}
}
/**
* DATE encryption/decryption function.
*/
private static class OraDateFunction implements DbEncryptFunction {
private final String encryptfunction;
private final String decryptfunction;
public OraDateFunction(String encryptfunction, String decryptfunction) {
this.encryptfunction = encryptfunction;
this.decryptfunction = decryptfunction;
}
public String getDecryptSql(String columnWithTableAlias) {
return "to_date(" + decryptfunction + "(" + columnWithTableAlias + ",?),'YYYYMMDD')";
}
public String getEncryptBindSql() {
return encryptfunction + "(to_char(?,'YYYYMMDD'),?)";
}
}
}
@@ -1,15 +1,15 @@
package com.avaje.ebean.config.dbplatform;
/**
* Since Ebean v2.2.0 Oracle9 is no different from Oracle10.
* <p>
* This will be removed in the future.
* </p>
*/
public class Oracle9Platform extends Oracle10Platform {
public Oracle9Platform() {
super();
}
}
package com.avaje.ebean.config.dbplatform;
/**
* Since Ebean v2.2.0 Oracle9 is no different from Oracle10.
* <p>
* This will be removed in the future.
* </p>
*/
public class Oracle9Platform extends Oracle10Platform {
public Oracle9Platform() {
super();
}
}
@@ -1,67 +1,67 @@
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
import java.sql.Types;
/**
* Postgres v8.3 specific platform.
* <p>
* No support for getGeneratedKeys.
* </p>
*/
public class Postgres8Platform extends DatabasePlatform {
public Postgres8Platform() {
super();
this.name = "postgres";
this.selectCountWithAlias = true;
this.blobDbType = Types.LONGVARBINARY;
this.clobDbType = Types.VARCHAR;
this.dbEncrypt = new PostgresDbEncrypt();
this.dbIdentity.setSupportsGetGeneratedKeys(false);
this.dbIdentity.setIdType(IdType.SEQUENCE);
this.dbIdentity.setSupportsSequence(true);
this.columnAliasPrefix = "as c";
this.openQuote = "\"";
this.closeQuote = "\"";
// dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
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.BINARY, new DbType("bytea", false));
dbTypeMap.put(Types.VARBINARY, new DbType("bytea", false));
dbTypeMap.put(Types.BLOB, new DbType("bytea", false));
dbTypeMap.put(Types.CLOB, new DbType("text"));
dbTypeMap.put(Types.LONGVARBINARY, new DbType("bytea", false));
dbTypeMap.put(Types.LONGVARCHAR, new DbType("text"));
dbDdlSyntax.setDropTableCascade("cascade");
dbDdlSyntax.setDropIfExists("if exists");
}
/**
* Create a Postgres specific sequence IdGenerator.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds,
String seqName, int batchSize) {
return new PostgresSequenceIdGenerator(be, ds, seqName, batchSize);
}
@Override
protected String withForUpdate(String sql) {
return sql + " for update";
}
}
package com.avaje.ebean.config.dbplatform;
import com.avaje.ebean.BackgroundExecutor;
import javax.sql.DataSource;
import java.sql.Types;
/**
* Postgres v8.3 specific platform.
* <p>
* No support for getGeneratedKeys.
* </p>
*/
public class Postgres8Platform extends DatabasePlatform {
public Postgres8Platform() {
super();
this.name = "postgres";
this.selectCountWithAlias = true;
this.blobDbType = Types.LONGVARBINARY;
this.clobDbType = Types.VARCHAR;
this.dbEncrypt = new PostgresDbEncrypt();
this.dbIdentity.setSupportsGetGeneratedKeys(false);
this.dbIdentity.setIdType(IdType.SEQUENCE);
this.dbIdentity.setSupportsSequence(true);
this.columnAliasPrefix = "as c";
this.openQuote = "\"";
this.closeQuote = "\"";
// dbTypeMap.put(Types.BOOLEAN, new DbType("bit default 0"));
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.BINARY, new DbType("bytea", false));
dbTypeMap.put(Types.VARBINARY, new DbType("bytea", false));
dbTypeMap.put(Types.BLOB, new DbType("bytea", false));
dbTypeMap.put(Types.CLOB, new DbType("text"));
dbTypeMap.put(Types.LONGVARBINARY, new DbType("bytea", false));
dbTypeMap.put(Types.LONGVARCHAR, new DbType("text"));
dbDdlSyntax.setDropTableCascade("cascade");
dbDdlSyntax.setDropIfExists("if exists");
}
/**
* Create a Postgres specific sequence IdGenerator.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds,
String seqName, int batchSize) {
return new PostgresSequenceIdGenerator(be, ds, seqName, batchSize);
}
@Override
protected String withForUpdate(String sql) {
return sql + " for update";
}
}
@@ -1,36 +1,36 @@
package com.avaje.ebean.config.dbplatform;
/**
* Postgres pgp_sym_encrypt pgp_sym_decrypt based encryption support.
*
* @author rbygrave
*/
public class PostgresDbEncrypt extends AbstractDbEncrypt {
public PostgresDbEncrypt() {
this.varcharEncryptFunction = new PgVarcharFunction();
this.dateEncryptFunction = new PgDateFunction();
}
private static class PgVarcharFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "pgp_sym_decrypt(" + columnWithTableAlias + ",?)";
}
public String getEncryptBindSql() {
return "pgp_sym_encrypt(?,?)";
}
}
private static class PgDateFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "to_date(pgp_sym_decrypt(" + columnWithTableAlias + ",?),'YYYYMMDD')";
}
public String getEncryptBindSql() {
return "pgp_sym_encrypt(to_char(?::date,'YYYYMMDD'),?)";
}
}
}
package com.avaje.ebean.config.dbplatform;
/**
* Postgres pgp_sym_encrypt pgp_sym_decrypt based encryption support.
*
* @author rbygrave
*/
public class PostgresDbEncrypt extends AbstractDbEncrypt {
public PostgresDbEncrypt() {
this.varcharEncryptFunction = new PgVarcharFunction();
this.dateEncryptFunction = new PgDateFunction();
}
private static class PgVarcharFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "pgp_sym_decrypt(" + columnWithTableAlias + ",?)";
}
public String getEncryptBindSql() {
return "pgp_sym_encrypt(?,?)";
}
}
private static class PgDateFunction implements DbEncryptFunction {
public String getDecryptSql(String columnWithTableAlias) {
return "to_date(pgp_sym_decrypt(" + columnWithTableAlias + ",?),'YYYYMMDD')";
}
public String getEncryptBindSql() {
return "pgp_sym_encrypt(to_char(?::date,'YYYYMMDD'),?)";
}
}
}