mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1747 - Refactor DeleteMeta and UpdateMeta to extract common appendWhere() code
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package io.ebeaninternal.server.persist.dml;
|
||||
|
||||
import io.ebeaninternal.api.ConcurrencyMode;
|
||||
import io.ebeaninternal.server.persist.dmlbind.Bindable;
|
||||
import io.ebeaninternal.server.persist.dmlbind.BindableId;
|
||||
|
||||
class BaseMeta {
|
||||
|
||||
final BindableId id;
|
||||
final Bindable version;
|
||||
final Bindable tenantId;
|
||||
|
||||
BaseMeta(BindableId id, Bindable version, Bindable tenantId) {
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
String appendWhere(GenerateDmlRequest request, ConcurrencyMode conMode) {
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
}
|
||||
}
|
||||
@@ -13,21 +13,15 @@ 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.
|
||||
*/
|
||||
final class DeleteMeta {
|
||||
final class DeleteMeta extends BaseMeta {
|
||||
|
||||
private final String sqlVersion;
|
||||
private final String sqlNone;
|
||||
private final String sqlDraftVersion;
|
||||
private final String sqlDraftNone;
|
||||
|
||||
private final BindableId id;
|
||||
private final Bindable version;
|
||||
private final Bindable tenantId;
|
||||
|
||||
DeleteMeta(BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) {
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
this.tenantId = tenantId;
|
||||
super(id, version, tenantId);
|
||||
|
||||
String tableName = desc.getBaseTable();
|
||||
this.sqlNone = genSql(ConcurrencyMode.NONE, tableName);
|
||||
@@ -87,20 +81,7 @@ final class DeleteMeta {
|
||||
GenerateDmlRequest request = new GenerateDmlRequest();
|
||||
request.append("delete from ").append(table);
|
||||
request.append(" where ");
|
||||
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
return appendWhere(request, conMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,25 +17,18 @@ 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.
|
||||
*/
|
||||
final class UpdateMeta {
|
||||
final class UpdateMeta extends BaseMeta {
|
||||
|
||||
private final BindableList set;
|
||||
private final BindableId id;
|
||||
private final Bindable version;
|
||||
private final Bindable tenantId;
|
||||
|
||||
private final UpdatePlan modeNoneUpdatePlan;
|
||||
private final UpdatePlan modeVersionUpdatePlan;
|
||||
|
||||
UpdateMeta(BeanDescriptor<?> desc, BindableList set, BindableId id, Bindable version, Bindable tenantId) {
|
||||
super(id, version, tenantId);
|
||||
this.set = set;
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
this.tenantId = tenantId;
|
||||
|
||||
String sqlNone = genSql(ConcurrencyMode.NONE, set, desc.getBaseTable());
|
||||
String sqlVersion = genSql(ConcurrencyMode.VERSION, set, desc.getBaseTable());
|
||||
|
||||
this.modeNoneUpdatePlan = new UpdatePlan(ConcurrencyMode.NONE, sqlNone, set);
|
||||
this.modeVersionUpdatePlan = new UpdatePlan(ConcurrencyMode.VERSION, sqlVersion, set);
|
||||
}
|
||||
@@ -115,7 +108,6 @@ final class UpdateMeta {
|
||||
|
||||
GenerateDmlRequest request = new GenerateDmlRequest();
|
||||
request.append("update ").append(tableName).append(" set ");
|
||||
|
||||
request.setUpdateSetMode();
|
||||
bindableList.dmlAppend(request);
|
||||
|
||||
@@ -126,19 +118,7 @@ final class UpdateMeta {
|
||||
}
|
||||
|
||||
request.append(" where ");
|
||||
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
return appendWhere(request, conMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user