#1747 - Refactor ebeaninternal/server/persist remove unused emptyStringAsNull

- remove unused emptyStringAsNull
- tighten access
This commit is contained in:
rob bygrave
2019-07-02 21:47:53 +12:00
parent f4a7d0b6ad
commit d9efeac0a1
10 changed files with 21 additions and 65 deletions
@@ -15,7 +15,7 @@ public class DeleteHandler extends DmlHandler {
private final DeleteMeta meta;
DeleteHandler(PersistRequestBean<?> persist, DeleteMeta meta) {
super(persist, meta.isEmptyStringAsNull());
super(persist);
this.meta = meta;
}
@@ -26,10 +26,7 @@ final class DeleteMeta {
private final String tableName;
private final boolean emptyStringAsNull;
DeleteMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) {
this.emptyStringAsNull = emptyStringAsNull;
DeleteMeta(BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) {
this.tableName = desc.getBaseTable();
this.id = id;
this.version = version;
@@ -49,10 +46,6 @@ final class DeleteMeta {
}
}
boolean isEmptyStringAsNull() {
return emptyStringAsNull;
}
/**
* Return the table name.
*/
@@ -26,7 +26,7 @@ public final class DmlBeanPersister implements BeanPersister {
private final DeleteMeta deleteMeta;
public DmlBeanPersister(DatabasePlatform dbPlatform, UpdateMeta updateMeta, InsertMeta insertMeta, DeleteMeta deleteMeta) {
DmlBeanPersister(DatabasePlatform dbPlatform, UpdateMeta updateMeta, InsertMeta insertMeta, DeleteMeta deleteMeta) {
this.dbPlatform = dbPlatform;
this.updateMeta = updateMeta;
this.insertMeta = insertMeta;
@@ -51,7 +51,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
private short batchedStatus;
DmlHandler(PersistRequestBean<?> persistRequest, boolean emptyStringToNull) {
DmlHandler(PersistRequestBean<?> persistRequest) {
this.now = System.currentTimeMillis();
this.persistRequest = persistRequest;
this.transaction = persistRequest.getTransaction();
@@ -5,8 +5,6 @@ package io.ebeaninternal.server.persist.dml;
*/
public class GenerateDmlRequest {
private static final String IS_NULL = " is null";
private final StringBuilder sb = new StringBuilder(100);
private StringBuilder insertBindBuffer;
@@ -57,11 +55,11 @@ public class GenerateDmlRequest {
}
}
public int getBindColumnCount() {
int getBindColumnCount() {
return bindColumnCount;
}
public String getInsertBindBuffer() {
String getInsertBindBuffer() {
return insertBindBuffer.toString();
}
@@ -70,19 +68,19 @@ public class GenerateDmlRequest {
return sb.toString();
}
public void setWhereIdMode() {
void setWhereIdMode() {
this.prefix = "";
this.prefix2 = " and ";
}
public void setInsertSetMode() {
void setInsertSetMode() {
this.insertBindBuffer = new StringBuilder(100);
this.insertMode = 1;
this.prefix = "";
this.prefix2 = ", ";
}
public void setUpdateSetMode() {
void setUpdateSetMode() {
this.prefix = "";
this.prefix2 = ", ";
}
@@ -45,7 +45,7 @@ public class InsertHandler extends DmlHandler {
* Create to handle the insert execution.
*/
public InsertHandler(PersistRequestBean<?> persist, InsertMeta meta) {
super(persist, meta.isEmptyStringToNull());
super(persist);
this.meta = meta;
this.concatinatedKey = meta.isConcatenatedKey();
}
@@ -44,11 +44,7 @@ final class InsertMeta {
private final String[] identityDbColumns;
private final boolean emptyStringToNull;
public InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
this.emptyStringToNull = dbPlatform.isTreatEmptyStringsAsNull();
InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
this.discriminator = getDiscriminator(desc);
this.id = id;
this.all = all;
@@ -57,7 +53,6 @@ final class InsertMeta {
String tableName = desc.getBaseTable();
String draftTableName = desc.getDraftTable();
this.sqlWithId = genSql(false, tableName, false);
this.sqlDraftWithId = desc.isDraftable() ? genSql(false, draftTableName, true) : sqlWithId;
@@ -90,28 +85,17 @@ final class InsertMeta {
private static Bindable getDiscriminator(BeanDescriptor<?> desc) {
InheritInfo inheritInfo = desc.getInheritInfo();
if (inheritInfo != null) {
return new BindableDiscriminator(inheritInfo);
} else {
return null;
}
}
/**
* Return true if empty strings should be treated as null.
*/
public boolean isEmptyStringToNull() {
return emptyStringToNull;
return inheritInfo != null ? new BindableDiscriminator(inheritInfo) : null;
}
/**
* Return true if this is a concatenated key.
*/
public boolean isConcatenatedKey() {
boolean isConcatenatedKey() {
return concatinatedKey;
}
public String[] getIdentityDbColumns() {
String[] getIdentityDbColumns() {
return identityDbColumns;
}
@@ -119,7 +103,7 @@ final class InsertMeta {
* Return true if we should use a SQL query to return the generated key.
* This can not be used with JDBC batch mode.
*/
public boolean supportsSelectLastInsertedId() {
boolean supportsSelectLastInsertedId() {
return supportsSelectLastInsertedId;
}
@@ -127,14 +111,14 @@ final class InsertMeta {
* Return true if getGeneratedKeys is supported by the underlying jdbc
* driver and database.
*/
public boolean supportsGetGeneratedKeys() {
boolean supportsGetGeneratedKeys() {
return supportsGetGeneratedKeys;
}
/**
* Return true if the Id can be derived from other property values.
*/
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
return id.deriveConcatenatedId(persist);
}
@@ -39,16 +39,11 @@ class MetaFactory {
private final DatabasePlatform dbPlatform;
private final boolean emptyStringAsNull;
MetaFactory(DatabasePlatform dbPlatform) {
this.dbPlatform = dbPlatform;
this.emptyStringAsNull = dbPlatform.isTreatEmptyStringsAsNull();
// to bind encryption data before or after the encryption key
DbEncrypt dbEncrypt = dbPlatform.getDbEncrypt();
boolean bindEncryptDataFirst = dbEncrypt == null || dbEncrypt.isBindEncryptDataFirst();
this.baseFact = new FactoryBaseProperties(bindEncryptDataFirst);
this.embeddedFact = new FactoryEmbedded(bindEncryptDataFirst);
}
@@ -75,7 +70,7 @@ class MetaFactory {
BindableList setBindable = new BindableList(setList);
return new UpdateMeta(emptyStringAsNull, desc, setBindable, id, version, tenantId);
return new UpdateMeta(desc, setBindable, id, version, tenantId);
}
/**
@@ -86,8 +81,7 @@ class MetaFactory {
BindableId id = idFact.createId(desc);
Bindable version = versionFact.createForDelete(desc);
Bindable tenantId = versionFact.createTenantId(desc);
return new DeleteMeta(emptyStringAsNull, desc, id, version, tenantId);
return new DeleteMeta(desc, id, version, tenantId);
}
/**
@@ -18,7 +18,7 @@ public class UpdateHandler extends DmlHandler {
private boolean emptySetClause;
UpdateHandler(PersistRequestBean<?> persist, UpdateMeta meta) {
super(persist, meta.isEmptyStringAsNull());
super(persist);
this.meta = meta;
}
@@ -24,16 +24,10 @@ final class UpdateMeta {
private final Bindable version;
private final Bindable tenantId;
private final String tableName;
private final UpdatePlan modeNoneUpdatePlan;
private final UpdatePlan modeVersionUpdatePlan;
private final boolean emptyStringAsNull;
UpdateMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableList set, BindableId id, Bindable version, Bindable tenantId) {
this.emptyStringAsNull = emptyStringAsNull;
this.tableName = desc.getBaseTable();
UpdateMeta(BeanDescriptor<?> desc, BindableList set, BindableId id, Bindable version, Bindable tenantId) {
this.set = set;
this.id = id;
this.version = version;
@@ -46,13 +40,6 @@ final class UpdateMeta {
this.modeVersionUpdatePlan = new UpdatePlan(ConcurrencyMode.VERSION, sqlVersion, set);
}
/**
* Return true if empty strings should be treated as null.
*/
boolean isEmptyStringAsNull() {
return emptyStringAsNull;
}
/**
* Bind the request based on the concurrency mode.
*/