#1747 - Refactor ebeaninternal/server/persist access, switch

This commit is contained in:
rob bygrave committed 2019-07-02 21:39:07 +12:00
1 parent bc5db1e46a
commit f4a7d0b6ad
25 files changed
+54 -94

No files matched your search

@@ -191,7 +191,7 @@ public final class BatchControl {
/**
* Add the request to the batch and return true if we should flush.
*/
private boolean addToBatch(PersistRequestBean<?> request) throws BatchedSqlException {
private boolean addToBatch(PersistRequestBean<?> request) {
Object alreadyInBatch = persistedBeans.put(request.getEntityBean(), DUMMY);
if (alreadyInBatch != null) {
@@ -26,7 +26,7 @@ class BatchDepthOrder {
int count;
public int increment() {
int increment() {
return count++;
}
}
@@ -18,7 +18,7 @@ import java.util.ArrayList;
* executed. The lowest depth is executed first.
* </p>
*/
public class BatchedBeanHolder {
class BatchedBeanHolder {
/**
* The owning queue.
@@ -5,9 +5,9 @@ import java.util.ArrayList;
/**
* Holds a list of bind values for binding to a PreparedStatement.
*/
public class BindValues {
class BindValues {
final ArrayList<Value> list = new ArrayList<>();
private final ArrayList<Value> list = new ArrayList<>();
/**
* Create with a Binder.
@@ -53,7 +53,7 @@ public class BindValues {
/**
* Create the value.
*/
public Value(Object value, int dbType, String name) {
Value(Object value, int dbType, String name) {
this.value = value;
this.dbType = dbType;
this.name = name;
@@ -124,7 +124,7 @@ public class Binder {
/**
* Bind the list of positionedParameters in BindParams.
*/
public String bind(BindParams bindParams, DataBind dataBind) throws SQLException {
private String bind(BindParams bindParams, DataBind dataBind) throws SQLException {
StringBuilder bindLog = new StringBuilder();
bind(bindParams, dataBind, bindLog);
@@ -142,7 +142,7 @@ public class Binder {
/**
* Bind the list of parameters..
*/
public void bind(List<BindParams.Param> list, DataBind dataBind, StringBuilder bindLog) throws SQLException {
private void bind(List<BindParams.Param> list, DataBind dataBind, StringBuilder bindLog) throws SQLException {
CallableStatement cstmt = null;
@@ -261,7 +261,7 @@ public class Binder {
* default is that both are converted to java.sql.Timestamp.
* </p>
*/
public void bindObject(DataBind dataBind, Object data, int dbType) throws SQLException {
private void bindObject(DataBind dataBind, Object data, int dbType) throws SQLException {
if (data == null) {
dataBind.setNull(dbType);
@@ -298,8 +298,6 @@ public class Binder {
try {
switch (dataType) {
case java.sql.Types.BOOLEAN:
b.setBoolean((Boolean) data);
break;
case java.sql.Types.BIT:
// Types.BIT should map to Java Boolean
b.setBoolean((Boolean) data);
@@ -334,18 +332,12 @@ public class Binder {
break;
case java.sql.Types.FLOAT:
case java.sql.Types.DOUBLE:
// DB Float in theory maps to Java Double type
b.setDouble((Double) data);
break;
case java.sql.Types.DOUBLE:
b.setDouble((Double) data);
break;
case java.sql.Types.NUMERIC:
b.setBigDecimal((BigDecimal) data);
break;
case java.sql.Types.DECIMAL:
b.setBigDecimal((BigDecimal) data);
break;
@@ -363,14 +355,13 @@ public class Binder {
break;
case java.sql.Types.BINARY:
b.setBytes((byte[]) data);
break;
case java.sql.Types.VARBINARY:
b.setBytes((byte[]) data);
break;
case DbPlatformType.UUID:
case java.sql.Types.JAVA_OBJECT:
// Not too sure about this.
// native UUID support in H2 and Postgres
b.setObject(data);
break;
@@ -384,11 +375,6 @@ public class Binder {
b.setObject(data, dataType);
break;
case java.sql.Types.JAVA_OBJECT:
// Not too sure about this.
b.setObject(data);
break;
default:
String msg = Message.msg("persist.bind.datatype", String.valueOf(dataType), String.valueOf(b.currentPos()));
throw new SQLException(msg);
@@ -440,12 +426,9 @@ public class Binder {
private boolean isLob(int dbType) {
switch (dbType) {
case Types.CLOB:
return true;
case Types.LONGVARCHAR:
return true;
case Types.BLOB:
return true;
case Types.LONGVARBINARY:
case Types.BLOB:
case Types.LONGVARCHAR:
return true;
default:
@@ -18,7 +18,7 @@ class MergeContext {
private final List<EntityBean> deleteBeans = new ArrayList<>();
private boolean clientGeneratedIds;
private final boolean clientGeneratedIds;
MergeContext(SpiEbeanServer server, SpiTransaction transaction, boolean clientGeneratedIds) {
this.server = server;
@@ -135,7 +135,7 @@ class MergeHandler {
static MergeNode createMergeNode(String fullPath, BeanDescriptor<?> targetDesc, String path) {
BeanProperty prop = targetDesc.getBeanProperty(path);
if (prop == null || !(prop instanceof BeanPropertyAssoc)) {
if (!(prop instanceof BeanPropertyAssoc)) {
throw new PersistenceException("merge path [" + path + "] is not a ToMany or ToOne property of " + targetDesc.getFullName());
}
if (prop instanceof BeanPropertyAssocMany<?>) {
@@ -16,9 +16,9 @@ import java.util.Map;
*/
abstract class MergeNode {
protected final String fullPath;
protected final BeanDescriptor<?> targetDescriptor;
protected Map<String,MergeNode> children;
private final String fullPath;
final BeanDescriptor<?> targetDescriptor;
private Map<String,MergeNode> children;
MergeNode(String fullPath, BeanPropertyAssoc<?> property) {
this.fullPath = fullPath;
@@ -80,7 +80,7 @@ abstract class MergeNode {
/**
* Cascade the merge processing if this has child nodes.
*/
protected void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
if (children != null && !children.isEmpty()) {
MergeRequest sub = request.sub(entityBean, outlineBean);
@@ -13,7 +13,7 @@ import java.sql.SQLException;
* Meta data for delete handler. The meta data is for a particular bean type. It
* is considered immutable and is thread safe.
*/
public final class DeleteMeta {
final class DeleteMeta {
private final String sqlVersion;
private final String sqlNone;
@@ -30,33 +30,30 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
/**
* The originating request.
*/
protected final PersistRequestBean<?> persistRequest;
final PersistRequestBean<?> persistRequest;
protected final StringBuilder bindLog;
private final StringBuilder bindLog;
protected final SpiTransaction transaction;
final SpiTransaction transaction;
protected final boolean emptyStringToNull;
private final boolean logLevelSql;
protected final boolean logLevelSql;
protected final long now;
private final long now;
/**
* The PreparedStatement used for the dml.
*/
protected DataBind dataBind;
DataBind dataBind;
protected BatchedPstmt batchedPstmt;
BatchedPstmt batchedPstmt;
protected String sql;
String sql;
private short batchedStatus;
protected DmlHandler(PersistRequestBean<?> persistRequest, boolean emptyStringToNull) {
DmlHandler(PersistRequestBean<?> persistRequest, boolean emptyStringToNull) {
this.now = System.currentTimeMillis();
this.persistRequest = persistRequest;
this.emptyStringToNull = emptyStringToNull;
this.transaction = persistRequest.getTransaction();
this.logLevelSql = transaction.isLogSql();
if (logLevelSql) {
@@ -79,7 +76,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
/**
* Bind to the statement returning the DataBind.
*/
protected DataBind bind(PreparedStatement stmt) {
DataBind bind(PreparedStatement stmt) {
return new DataBind(persistRequest.getDataTimeZone(), stmt, transaction.getInternalConnection());
}
@@ -98,7 +95,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
/**
* Check the rowCount.
*/
protected void checkRowCount(int rowCount) throws OptimisticLockException {
void checkRowCount(int rowCount) throws OptimisticLockException {
try {
persistRequest.checkRowCount(rowCount);
persistRequest.postExecute();
@@ -132,14 +129,6 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
}
}
/**
* Return the bind log.
*/
@Override
public String getBindLog() {
return bindLog == null ? "" : bindLog.toString();
}
/**
* Set the Id value that was bound. This value is used for logging summary
* level information.
@@ -152,7 +141,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
/**
* Log the sql to the transaction log.
*/
protected void logSql(String sql) {
void logSql(String sql) {
if (logLevelSql) {
switch (batchedStatus) {
case BATCHED_FIRST: {
@@ -185,7 +174,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
} else {
String sval = value.toString();
if (sval.length() > 50) {
bindLog.append(sval.substring(0, 47)).append("...");
bindLog.append(sval, 0, 47).append("...");
} else {
bindLog.append(sval);
}
@@ -244,7 +233,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
/**
* Check with useGeneratedKeys to get appropriate PreparedStatement.
*/
protected PreparedStatement getPstmt(SpiTransaction t, String sql, boolean genKeys) throws SQLException {
PreparedStatement getPstmt(SpiTransaction t, String sql, boolean genKeys) throws SQLException {
Connection conn = t.getInternalConnection();
if (genKeys) {
@@ -261,7 +250,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
/**
* Return a prepared statement taking into account batch requirements.
*/
protected PreparedStatement getPstmt(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
PreparedStatement getPstmt(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder();
batchedPstmt = batch.getBatchedPstmt(sql, request);
@@ -64,12 +64,12 @@ class GeneratedProperties {
this.generatedProperty = property.getGeneratedProperty();
}
public void preInsert(EntityBean bean, long now) {
void preInsert(EntityBean bean, long now) {
Object value = generatedProperty.getInsertValue(property, bean, now);
property.setValue(bean, value);
}
public void preUpdate(EntityBean bean, long now) {
void preUpdate(EntityBean bean, long now) {
Object value = generatedProperty.getUpdateValue(property, bean, now);
property.setValue(bean, value);
}
@@ -25,7 +25,7 @@ class GeneratedPropertyCollector {
return new GeneratedProperties(preInsert, preUpdate);
}
void add(BeanProperty prop) {
private void add(BeanProperty prop) {
GeneratedProperty gen = prop.getGeneratedProperty();
if (gen != null) {
if (gen.includeInInsert()) {
@@ -16,7 +16,7 @@ import java.sql.SQLException;
* Meta data for insert handler. The meta data is for a particular bean type. It
* is considered immutable and is thread safe.
*/
public final class InsertMeta {
final class InsertMeta {
private final String sqlNullId;
private final String sqlWithId;
@@ -22,7 +22,7 @@ import java.util.List;
/**
* Factory for creating InsertMeta UpdateMeta and DeleteMeta.
*/
public class MetaFactory {
class MetaFactory {
private final FactoryBaseProperties baseFact;
private final FactoryEmbedded embeddedFact;
@@ -5,12 +5,7 @@ import java.sql.SQLException;
/**
* Implementation API for insert update and delete handlers.
*/
public interface PersistHandler {
/**
* Return the bind log.
*/
String getBindLog();
interface PersistHandler {
/**
* Get the sql and bind the statement.
@@ -17,7 +17,7 @@ import java.util.List;
* Meta data for update handler. The meta data is for a particular bean type. It
* is considered immutable and is thread safe.
*/
public final class UpdateMeta {
final class UpdateMeta {
private final BindableList set;
private final BindableId id;
@@ -53,13 +53,6 @@ public final class UpdateMeta {
return emptyStringAsNull;
}
/**
* Return the base table name.
*/
public String getTableName() {
return tableName;
}
/**
* Bind the request based on the concurrency mode.
*/
@@ -10,7 +10,7 @@ import java.sql.SQLException;
/**
* Plan for executing bean updates for a given set of changed properties.
*/
public class UpdatePlan implements SpiUpdatePlan {
class UpdatePlan implements SpiUpdatePlan {
private final String key;
@@ -14,9 +14,9 @@ import java.util.List;
*/
class BindableAssocOne implements Bindable {
protected final BeanPropertyAssocOne<?> assocOne;
final BeanPropertyAssocOne<?> assocOne;
protected final ImportedId importedId;
final ImportedId importedId;
BindableAssocOne(BeanPropertyAssocOne<?> assocOne) {
this.assocOne = assocOne;
@@ -55,7 +55,7 @@ class BindableAssocOne implements Bindable {
/**
* Bind and register a deferred relationship value.
*/
void registerDeferred(BindableRequest request, EntityBean bean, EntityBean assocBean) throws SQLException {
private void registerDeferred(BindableRequest request, EntityBean bean, EntityBean assocBean) throws SQLException {
Object boundValue = importedId.bind(request, assocBean);
if (boundValue == null && assocBean != null) {
// this is the scenario for a derived foreign key
@@ -30,7 +30,7 @@ public class BindableIdEmpty implements BindableId {
}
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
public void dmlBind(BindableRequest request, EntityBean bean) {
// nothing
}
@@ -13,7 +13,7 @@ import java.util.List;
*/
public class BindableProperty implements Bindable {
protected final BeanProperty prop;
final BeanProperty prop;
public BindableProperty(BeanProperty prop) {
this.prop = prop;
@@ -13,7 +13,7 @@ import java.util.List;
*/
public class BindablePropertyVersion implements Bindable {
protected final BeanProperty prop;
private final BeanProperty prop;
public BindablePropertyVersion(BeanProperty prop) {
this.prop = prop;
@@ -11,7 +11,7 @@ import io.ebeaninternal.server.persist.dml.DmlMode;
* and BindablePropertyUpdateGenerated as required.
* </p>
*/
public class FactoryProperty {
class FactoryProperty {
private final boolean bindEncryptDataFirst;
@@ -9,7 +9,7 @@ class MatchedImportedFactory {
/**
* Create the array of matchedImportedProperty based on the properties and descriptor.
*/
protected static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
@@ -52,7 +52,7 @@ abstract class AbstractMultiValueBind extends MultiValueBind {
}
}
protected String getArrayType(int dbType) {
String getArrayType(int dbType) {
switch(dbType) {
case TINYINT:
case SMALLINT:
@@ -17,7 +17,7 @@ public class MultiValueBind {
void bind(Object value) throws SQLException;
}
protected Object[] toArray(Collection<?> values, ScalarType<?> type) {
Object[] toArray(Collection<?> values, ScalarType<?> type) {
Object[] array = new Object[values.size()];
int i = 0;
for (Object value : values) {