mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No functional change, tidy in persist.dml and dmlbind packages only
This commit is contained in:
@@ -33,9 +33,9 @@ final class DeleteHandler extends DmlHandler {
|
||||
SpiTransaction t = persistRequest.transaction();
|
||||
PreparedStatement pstmt;
|
||||
if (persistRequest.isBatched()) {
|
||||
pstmt = getPstmtBatch(t, sql, persistRequest, false);
|
||||
pstmt = pstmtBatch(t, sql, persistRequest, false);
|
||||
} else {
|
||||
pstmt = getPstmt(t, sql, false);
|
||||
pstmt = pstmt(t, sql, false);
|
||||
}
|
||||
dataBind = bind(pstmt);
|
||||
meta.bind(persistRequest, this);
|
||||
|
||||
@@ -39,7 +39,7 @@ final class DeleteMeta extends BaseMeta {
|
||||
/**
|
||||
* Bind the request based on the concurrency mode.
|
||||
*/
|
||||
public void bind(PersistRequestBean<?> persist, DmlHandler bind) throws SQLException {
|
||||
void bind(PersistRequestBean<?> persist, DmlHandler bind) throws SQLException {
|
||||
EntityBean bean = persist.entityBean();
|
||||
id.dmlBind(bind, bean);
|
||||
if (tenantId != null) {
|
||||
@@ -54,7 +54,7 @@ final class DeleteMeta extends BaseMeta {
|
||||
/**
|
||||
* get or generate the sql based on the concurrency mode.
|
||||
*/
|
||||
public String getSql(PersistRequestBean<?> request) {
|
||||
String getSql(PersistRequestBean<?> request) {
|
||||
if (id.isEmpty()) {
|
||||
throw new IllegalStateException("Can not deleteById on " + request.fullName() + " as no @Id property");
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistRequestBean<?> getPersistRequest() {
|
||||
public PersistRequestBean<?> persistRequest() {
|
||||
return persistRequest;
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Check with useGeneratedKeys to get appropriate PreparedStatement.
|
||||
*/
|
||||
PreparedStatement getPstmt(SpiTransaction t, String sql, boolean genKeys) throws SQLException {
|
||||
PreparedStatement pstmt(SpiTransaction t, String sql, boolean genKeys) throws SQLException {
|
||||
Connection conn = t.internalConnection();
|
||||
if (genKeys) {
|
||||
// the Id generated is always the first column
|
||||
@@ -248,7 +248,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Return a prepared statement taking into account batch requirements.
|
||||
*/
|
||||
PreparedStatement getPstmtBatch(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
|
||||
PreparedStatement pstmtBatch(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
|
||||
BatchedPstmtHolder batch = t.batchControl().pstmtHolder();
|
||||
batchedPstmt = batch.batchedPstmt(sql);
|
||||
if (batchedPstmt != null) {
|
||||
@@ -256,7 +256,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
return batchedPstmt.statement(request);
|
||||
}
|
||||
batchedStatus = BATCHED_FIRST;
|
||||
PreparedStatement stmt = getPstmt(t, sql, genKeys);
|
||||
PreparedStatement stmt = pstmt(t, sql, genKeys);
|
||||
batchedPstmt = new BatchedPstmt(stmt, genKeys, sql, t);
|
||||
batch.addStmt(batchedPstmt, request);
|
||||
return stmt;
|
||||
|
||||
+2
-2
@@ -42,11 +42,11 @@ public final class GenerateDmlRequest {
|
||||
}
|
||||
}
|
||||
|
||||
int getBindColumnCount() {
|
||||
int bindColumnCount() {
|
||||
return bindColumnCount;
|
||||
}
|
||||
|
||||
String getInsertBindBuffer() {
|
||||
String insertBindBuffer() {
|
||||
return insertBindBuffer.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ public final class InsertHandler extends DmlHandler {
|
||||
sql = meta.getSql(withId, persistRequest.isPublish());
|
||||
PreparedStatement pstmt;
|
||||
if (persistRequest.isBatched()) {
|
||||
pstmt = getPstmtBatch(t, sql, persistRequest, useGeneratedKeys);
|
||||
pstmt = pstmtBatch(t, sql, persistRequest, useGeneratedKeys);
|
||||
} else {
|
||||
pstmt = getPstmt(t, sql, useGeneratedKeys);
|
||||
pstmt = pstmt(t, sql, useGeneratedKeys);
|
||||
}
|
||||
dataBind = bind(pstmt);
|
||||
meta.bind(this, bean, withId, persistRequest.isPublish());
|
||||
@@ -88,11 +88,10 @@ public final class InsertHandler extends DmlHandler {
|
||||
* Check with useGeneratedKeys to get appropriate PreparedStatement.
|
||||
*/
|
||||
@Override
|
||||
PreparedStatement getPstmt(SpiTransaction t, String sql, boolean useGeneratedKeys) throws SQLException {
|
||||
PreparedStatement pstmt(SpiTransaction t, String sql, boolean useGeneratedKeys) throws SQLException {
|
||||
Connection conn = t.internalConnection();
|
||||
if (useGeneratedKeys) {
|
||||
return conn.prepareStatement(sql, meta.getIdentityDbColumns());
|
||||
|
||||
return conn.prepareStatement(sql, meta.identityDbColumns());
|
||||
} else {
|
||||
return conn.prepareStatement(sql);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ final class InsertMeta {
|
||||
|
||||
InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
|
||||
this.platform = dbPlatform.platform();
|
||||
this.discriminator = getDiscriminator(desc);
|
||||
this.discriminator = discriminator(desc);
|
||||
this.id = id;
|
||||
this.all = all;
|
||||
this.allExcludeDraftOnly = all.excludeDraftOnly();
|
||||
@@ -77,7 +77,7 @@ final class InsertMeta {
|
||||
}
|
||||
}
|
||||
|
||||
private static Bindable getDiscriminator(BeanDescriptor<?> desc) {
|
||||
private static Bindable discriminator(BeanDescriptor<?> desc) {
|
||||
InheritInfo inheritInfo = desc.inheritInfo();
|
||||
return inheritInfo != null ? new BindableDiscriminator(inheritInfo) : null;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ final class InsertMeta {
|
||||
return concatenatedKey;
|
||||
}
|
||||
|
||||
String[] getIdentityDbColumns() {
|
||||
String[] identityDbColumns() {
|
||||
return identityDbColumns;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ final class InsertMeta {
|
||||
allExcludeDraftOnly.dmlAppend(request);
|
||||
}
|
||||
request.append(") values (");
|
||||
request.append(request.getInsertBindBuffer());
|
||||
request.append(request.insertBindBuffer());
|
||||
request.append(")");
|
||||
return request.toString();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class UpdateHandler extends DmlHandler {
|
||||
*/
|
||||
@Override
|
||||
public void bind() throws SQLException {
|
||||
SpiUpdatePlan updatePlan = meta.getUpdatePlan(persistRequest);
|
||||
SpiUpdatePlan updatePlan = meta.updatePlan(persistRequest);
|
||||
if (updatePlan.isEmptySetClause()) {
|
||||
emptySetClause = true;
|
||||
return;
|
||||
@@ -41,9 +41,9 @@ public final class UpdateHandler extends DmlHandler {
|
||||
SpiTransaction t = persistRequest.transaction();
|
||||
PreparedStatement pstmt;
|
||||
if (persistRequest.isBatched()) {
|
||||
pstmt = getPstmtBatch(t, sql, persistRequest, false);
|
||||
pstmt = pstmtBatch(t, sql, persistRequest, false);
|
||||
} else {
|
||||
pstmt = getPstmt(t, sql, false);
|
||||
pstmt = pstmt(t, sql, false);
|
||||
}
|
||||
dataBind = bind(pstmt);
|
||||
meta.bind(persistRequest, this, updatePlan);
|
||||
|
||||
@@ -44,11 +44,11 @@ final class UpdateMeta extends BaseMeta {
|
||||
/**
|
||||
* get or generate the sql based on the concurrency mode.
|
||||
*/
|
||||
SpiUpdatePlan getUpdatePlan(PersistRequestBean<?> request) {
|
||||
return getDynamicUpdatePlan(request);
|
||||
SpiUpdatePlan updatePlan(PersistRequestBean<?> request) {
|
||||
return dynamicUpdatePlan(request);
|
||||
}
|
||||
|
||||
private SpiUpdatePlan getDynamicUpdatePlan(PersistRequestBean<?> persistRequest) {
|
||||
private SpiUpdatePlan dynamicUpdatePlan(PersistRequestBean<?> persistRequest) {
|
||||
String key = persistRequest.updatePlanHash();
|
||||
// check if we can use a cached UpdatePlan
|
||||
BeanDescriptor<?> beanDescriptor = persistRequest.descriptor();
|
||||
@@ -80,7 +80,7 @@ final class UpdateMeta extends BaseMeta {
|
||||
request.setUpdateSetMode();
|
||||
bindableList.dmlAppend(request);
|
||||
|
||||
if (request.getBindColumnCount() == 0) {
|
||||
if (request.bindColumnCount() == 0) {
|
||||
// update properties must have been updatable=false
|
||||
// with the result that nothing is in the set clause
|
||||
return null;
|
||||
|
||||
+1
-6
@@ -23,11 +23,6 @@ class BindableAssocOne implements Bindable {
|
||||
this.importedId = assocOne.importedId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return "BindableAssocOne " + assocOne;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isDraftOnly() {
|
||||
return assocOne.isDraftOnly();
|
||||
@@ -61,7 +56,7 @@ class BindableAssocOne implements Bindable {
|
||||
// which will require an additional update
|
||||
// register for post insert of assocBean
|
||||
// update of bean set importedId
|
||||
request.getPersistRequest().deferredRelationship(assocBean, importedId, bean);
|
||||
request.persistRequest().deferredRelationship(assocBean, importedId, bean);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-6
@@ -24,11 +24,6 @@ public final class BindableDiscriminator implements Bindable {
|
||||
this.sqlType = inheritInfo.getDiscriminatorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return columnName + " = " + discValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDraftOnly() {
|
||||
return false;
|
||||
@@ -46,7 +41,6 @@ public final class BindableDiscriminator implements Bindable {
|
||||
|
||||
@Override
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
bindRequest.bind(discValue, sqlType);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,6 @@ final class BindableEmbedded implements Bindable {
|
||||
this.items = bindList.toArray(new Bindable[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BindableEmbedded " + embProp + " items:" + Arrays.toString(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDraftOnly() {
|
||||
return embProp.isDraftOnly();
|
||||
@@ -35,7 +30,6 @@ final class BindableEmbedded implements Bindable {
|
||||
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
for (Bindable item : items) {
|
||||
item.dmlAppend(request);
|
||||
}
|
||||
@@ -50,7 +44,6 @@ final class BindableEmbedded implements Bindable {
|
||||
|
||||
@Override
|
||||
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
|
||||
|
||||
// get the embedded bean
|
||||
EntityBean embBean = (EntityBean) embProp.getValue(bean);
|
||||
if (embBean == null) {
|
||||
|
||||
-13
@@ -23,11 +23,6 @@ final class BindableEncryptedProperty implements Bindable {
|
||||
this.bindEncryptDataFirst = bindEncryptDataFirst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return prop.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDraftOnly() {
|
||||
return prop.isDraftOnly();
|
||||
@@ -42,18 +37,12 @@ final class BindableEncryptedProperty implements Bindable {
|
||||
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
|
||||
// columnName = AES_ENCRYPT(?,?)
|
||||
request.appendColumn(prop.dbColumn(), prop.dbBind());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bind a value in a Insert SET clause.
|
||||
*/
|
||||
@Override
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
Object value = null;
|
||||
if (bean != null) {
|
||||
value = prop.getValue(bean);
|
||||
@@ -61,13 +50,11 @@ final class BindableEncryptedProperty implements Bindable {
|
||||
|
||||
// get Encrypt key
|
||||
String encryptKeyValue = prop.encryptKey().getStringValue();
|
||||
|
||||
if (!bindEncryptDataFirst) {
|
||||
// H2 encrypt function ... different parameter order
|
||||
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.name() + "=****");
|
||||
}
|
||||
request.bindNoLog(value, prop);
|
||||
|
||||
if (bindEncryptDataFirst) {
|
||||
// MySql, Postgres, Oracle
|
||||
request.bindNoLog(encryptKeyValue, Types.VARCHAR, prop.name() + "=****");
|
||||
|
||||
@@ -8,10 +8,8 @@ import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
* Specifically if the concatenated id object is null on insert this can be
|
||||
* built from the matching ManyToOne associated beans. For example RoleUserId
|
||||
* embeddedId object could be built from the associated Role and User beans.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is only attempted if the id is null when it gets to the insert.
|
||||
* </p>
|
||||
*/
|
||||
public interface BindableId extends Bindable {
|
||||
|
||||
@@ -35,7 +33,6 @@ public interface BindableId extends Bindable {
|
||||
* <p>
|
||||
* Really only where there are ManyToOne assoc beans that make up the
|
||||
* primary key and the values can be got from those.
|
||||
* </p>
|
||||
*/
|
||||
boolean deriveConcatenatedId(PersistRequestBean<?> persist);
|
||||
|
||||
|
||||
-10
@@ -49,11 +49,6 @@ final class BindableIdEmbedded implements BindableId {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return embId + " props:" + Arrays.toString(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing for BindableId.
|
||||
*/
|
||||
@@ -94,18 +89,13 @@ final class BindableIdEmbedded implements BindableId {
|
||||
+ " not have ManyToOne assoc beans matching the primary key columns?";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
|
||||
EntityBean bean = persist.entityBean();
|
||||
|
||||
// create the new id
|
||||
EntityBean newId = (EntityBean) embId.createEmbeddedId();
|
||||
|
||||
// populate it from the assoc one id values...
|
||||
for (MatchedImportedProperty match : matches) {
|
||||
match.populate(bean, newId);
|
||||
}
|
||||
|
||||
// support PropertyChangeSupport
|
||||
embId.setValueIntercept(bean, newId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,6 @@ final class BindableIdScalar implements BindableId {
|
||||
return uidProp.dbColumn();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return uidProp.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDraftOnly() {
|
||||
return false;
|
||||
|
||||
@@ -19,11 +19,6 @@ class BindableProperty implements Bindable {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return prop.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isDraftOnly() {
|
||||
return prop.isDraftOnly();
|
||||
|
||||
-3
@@ -18,9 +18,6 @@ final class BindablePropertyJsonInsert extends BindableProperty {
|
||||
this.propertyIndex = prop.propertyIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal binding of a property value from the bean.
|
||||
*/
|
||||
@Override
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
if (bean == null) {
|
||||
|
||||
-1
@@ -46,7 +46,6 @@ final class BindablePropertyVersion implements Bindable {
|
||||
*/
|
||||
@Override
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
|
||||
// get prior version value from 'old values'
|
||||
Object value = bean._ebean_getIntercept().origValue(prop.propertyIndex());
|
||||
request.bind(value, prop);
|
||||
|
||||
+1
-3
@@ -19,11 +19,9 @@ public interface BindableRequest {
|
||||
* Bind the value to a PreparedStatement.
|
||||
* <p>
|
||||
* Takes into account logicalType to dbType conversion if required.
|
||||
* </p>
|
||||
* <p>
|
||||
* Returns the value that was bound (and was potentially converted from
|
||||
* logicalType to dbType.
|
||||
* </p>
|
||||
*/
|
||||
void bind(Object value, BeanProperty prop) throws SQLException;
|
||||
|
||||
@@ -45,7 +43,7 @@ public interface BindableRequest {
|
||||
/**
|
||||
* Return the original PersistRequest.
|
||||
*/
|
||||
PersistRequestBean<?> getPersistRequest();
|
||||
PersistRequestBean<?> persistRequest();
|
||||
|
||||
/**
|
||||
* Return the system current time in millis. This is expected to the same time used
|
||||
|
||||
+1
-8
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
* <p>
|
||||
* This inserts the foreign key value that is retrieved from the id of the
|
||||
* parentBean.
|
||||
* </p>
|
||||
*/
|
||||
public final class BindableUnidirectional implements Bindable {
|
||||
|
||||
@@ -30,11 +29,6 @@ public final class BindableUnidirectional implements Bindable {
|
||||
this.importedId = unidirectional.importedId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BindableShadowFKey " + unidirectional;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDraftOnly() {
|
||||
return false;
|
||||
@@ -53,12 +47,11 @@ public final class BindableUnidirectional implements Bindable {
|
||||
|
||||
@Override
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
PersistRequestBean<?> persistRequest = request.getPersistRequest();
|
||||
PersistRequestBean<?> persistRequest = request.persistRequest();
|
||||
Object parentBean = persistRequest.parentBean();
|
||||
if (parentBean == null) {
|
||||
Class<?> localType = desc.type();
|
||||
Class<?> targetType = unidirectional.targetType();
|
||||
|
||||
String msg = "Error inserting bean [" + localType + "] with unidirectional relationship. ";
|
||||
msg += "For inserts you must use cascade save on the master bean [" + targetType + "].";
|
||||
throw new PersistenceException(msg);
|
||||
|
||||
-1
@@ -10,7 +10,6 @@ import java.util.List;
|
||||
* Add base properties to the BindableList for a bean type.
|
||||
* <p>
|
||||
* This excludes unique embedded and associated properties.
|
||||
* </p>
|
||||
*/
|
||||
public final class FactoryBaseProperties {
|
||||
|
||||
|
||||
@@ -36,5 +36,4 @@ public final class FactoryEmbedded {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import io.ebeaninternal.server.persist.dml.DmlMode;
|
||||
* <p>
|
||||
* Lob properties can be excluded and it creates BindablePropertyInsertGenerated
|
||||
* and BindablePropertyUpdateGenerated as required.
|
||||
* </p>
|
||||
*/
|
||||
final class FactoryProperty {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user