#2312 - Refactor internals - make more classes final in persist packages

This commit is contained in:
rbygrave
2021-08-15 14:50:43 +12:00
parent ebc0fabbdb
commit 82c12b1565
64 changed files with 85 additions and 192 deletions
@@ -12,7 +12,7 @@ import java.util.Comparator;
* keys from inserts. These values are required to persist the 'detail' beans.
* </p>
*/
class BatchDepthComparator implements Comparator<BatchedBeanHolder>, Serializable {
final class BatchDepthComparator implements Comparator<BatchedBeanHolder>, Serializable {
private static final long serialVersionUID = 264611821665757991L;
@@ -6,7 +6,7 @@ import java.util.Map;
/**
* Helper to determine batch execution order for BatchedBeanHolders.
*/
class BatchDepthOrder {
final class BatchDepthOrder {
private final Map<Integer, Counter> map = new HashMap<>();
@@ -22,7 +22,7 @@ class BatchDepthOrder {
map.clear();
}
private static class Counter {
private static final class Counter {
int count;
@@ -18,7 +18,7 @@ import java.util.ArrayList;
* executed. The lowest depth is executed first.
* </p>
*/
class BatchedBeanHolder {
final class BatchedBeanHolder {
/**
* The owning queue.
@@ -20,7 +20,7 @@ import java.util.List;
* This can hold CallableStatements as well.
* </p>
*/
public class BatchedPstmt implements SpiProfileTransactionEvent {
public final class BatchedPstmt implements SpiProfileTransactionEvent {
private static final Logger log = LoggerFactory.getLogger(BatchedPstmt.class);
@@ -15,7 +15,7 @@ import java.util.Map;
* statements of a single 'depth' at any given time.
* </p>
*/
public class BatchedPstmtHolder {
public final class BatchedPstmtHolder {
/**
* A Map of the statements using a String key. This is used so that the same
@@ -31,7 +31,7 @@ import java.util.List;
/**
* Binds bean values to a PreparedStatement.
*/
public class Binder {
public final class Binder {
private static final Logger logger = LoggerFactory.getLogger(Binder.class);
@@ -5,7 +5,7 @@ import io.ebean.Transaction;
import io.ebean.event.BeanDeleteIdRequest;
import io.ebeaninternal.api.SpiEbeanServer;
class DeleteIdRequest implements BeanDeleteIdRequest {
final class DeleteIdRequest implements BeanDeleteIdRequest {
private final EbeanServer server;
private final Transaction transaction;
@@ -21,7 +21,7 @@ import java.util.List;
* helps fetch the foreign keys and delete the appropriate rows.
* </p>
*/
class DeleteUnloadedForeignKeys {
final class DeleteUnloadedForeignKeys {
private final List<BeanPropertyAssocOne<?>> propList = new ArrayList<>(4);
@@ -4,7 +4,7 @@ package io.ebeaninternal.server.persist;
/**
* Utility object with helper methods for DML.
*/
public class DmlUtil {
public final class DmlUtil {
/**
* Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty.
@@ -13,10 +13,9 @@ import java.sql.SQLException;
/**
* Handles the execution of CallableSql requests.
*/
class ExeCallableSql {
final class ExeCallableSql {
private final Binder binder;
private final PstmtFactory pstmtFactory;
ExeCallableSql(Binder binder) {
@@ -28,9 +27,7 @@ class ExeCallableSql {
* execute the CallableSql requests.
*/
public int execute(PersistRequestCallableSql request) {
boolean batchThisRequest = request.isBatchThisRequest();
CallableStatement cstmt = null;
try {
cstmt = bindStmt(request, batchThisRequest);
@@ -58,18 +55,15 @@ class ExeCallableSql {
private CallableStatement bindStmt(PersistRequestCallableSql request, boolean batchThisRequest) throws SQLException {
request.startBind(batchThisRequest);
SpiCallableSql callableSql = request.getCallableSql();
SpiTransaction t = request.getTransaction();
String sql = callableSql.getSql();
BindParams bindParams = callableSql.getBindParams();
// process named parameters if required
sql = BindParamsParser.parse(bindParams, sql);
boolean logSql = request.isLogSql();
CallableStatement cstmt;
@@ -90,9 +84,7 @@ class ExeCallableSql {
if (!bindParams.isEmpty()) {
bindLog = binder.bind(bindParams, cstmt, t.getInternalConnection());
}
request.setBindLog(bindLog);
// required to read OUT params later
request.setBound(bindParams, cstmt);
return cstmt;
@@ -15,15 +15,11 @@ import java.sql.SQLException;
/**
* Executes the UpdateSql requests.
*/
class ExeOrmUpdate {
final class ExeOrmUpdate {
private final Binder binder;
private final PstmtFactory pstmtFactory;
/**
* Create with a given binder.
*/
ExeOrmUpdate(Binder binder) {
this.pstmtFactory = new PstmtFactory();
this.binder = binder;
@@ -33,9 +29,7 @@ class ExeOrmUpdate {
* Execute the orm update request.
*/
public int execute(PersistRequestOrmUpdate request) {
boolean batchThisRequest = request.isBatchThisRequest();
PreparedStatement pstmt = null;
try {
pstmt = bindStmt(request, batchThisRequest);
@@ -68,13 +62,11 @@ class ExeOrmUpdate {
* Convert bean and property names to db table and columns.
*/
private String translate(PersistRequestOrmUpdate request, String sql) {
BeanDescriptor<?> descriptor = request.getBeanDescriptor();
return descriptor.convertOrmUpdateToSql(sql);
}
private PreparedStatement bindStmt(PersistRequestOrmUpdate request, boolean batchThisRequest) throws SQLException {
request.startBind(batchThisRequest);
SpiUpdate<?> ormUpdate = request.getOrmUpdate();
SpiTransaction t = request.getTransaction();
@@ -16,15 +16,11 @@ import java.sql.SQLException;
/**
* Executes the UpdateSql requests.
*/
class ExeUpdateSql {
final class ExeUpdateSql {
private final Binder binder;
private final PstmtFactory pstmtFactory;
/**
* Create with a given binder.
*/
ExeUpdateSql(Binder binder) {
this.binder = binder;
this.pstmtFactory = new PstmtFactory();
@@ -34,14 +30,10 @@ class ExeUpdateSql {
* Execute the UpdateSql request.
*/
public int execute(PersistRequestUpdateSql request) {
boolean batchThisRequest = request.isBatchThisRequest();
PreparedStatement pstmt = null;
try {
pstmt = bindStmt(request, batchThisRequest);
if (batchThisRequest) {
pstmt.addBatch();
// return -1 to indicate batch mode
@@ -66,7 +58,6 @@ class ExeUpdateSql {
}
private void readGeneratedKeys(PreparedStatement stmt, PersistRequestUpdateSql request) {
ResultSet resultSet = null;
try {
resultSet = stmt.getGeneratedKeys();
@@ -82,7 +73,6 @@ class ExeUpdateSql {
}
private PreparedStatement bindStmt(PersistRequestUpdateSql request, boolean batchThisRequest) throws SQLException {
request.startBind(batchThisRequest);
SpiSqlUpdate updateSql = request.getUpdateSql();
SpiTransaction t = request.getTransaction();
@@ -121,7 +111,6 @@ class ExeUpdateSql {
private void determineType(String word1, String word2, String word3, PersistRequestUpdateSql request) {
if (word1.equalsIgnoreCase("UPDATE")) {
request.setType(SqlType.SQL_UPDATE, word2);
@@ -137,7 +126,6 @@ class ExeUpdateSql {
}
private void parseUpdate(String sql, PersistRequestUpdateSql request) {
int[] pos = new int[3];
int spaceCount = 0;
@@ -10,7 +10,7 @@ import java.util.List;
/**
* Context used for merge processing.
*/
class MergeContext {
final class MergeContext {
private final SpiEbeanServer server;
@@ -24,7 +24,7 @@ import java.util.regex.Pattern;
/**
* Drives the merge processing.
*/
class MergeHandler {
final class MergeHandler {
private static final Pattern PATH_SPLIT = Pattern.compile("\\.");
@@ -33,10 +33,8 @@ class MergeHandler {
private final EntityBean bean;
private final MergeOptions options;
private final SpiTransaction transaction;
private final Map<String, MergeNode> nodes = new LinkedHashMap<>();
MergeHandler(SpiEbeanServer server, BeanDescriptor<?> desc, EntityBean bean, MergeOptions options, SpiTransaction transaction) {
this.server = server;
this.desc = desc;
@@ -49,7 +47,6 @@ class MergeHandler {
* Fetch the Ids for the graph and use them to determine inserts, updates and deletes for the merge paths.
*/
List<EntityBean> merge() {
Set<String> paths = options.paths();
if (desc.isIdGeneratedValue() && paths.isEmpty() && !options.isClientGeneratedIds()) {
// just do a single insert or update based on Id value present
@@ -76,7 +73,6 @@ class MergeHandler {
for (MergeNode value : nodes.values()) {
value.merge(request);
}
return context.getDeletedBeans();
}
@@ -86,9 +82,7 @@ class MergeHandler {
* We use the Id values to determine what are inserts, updates and deletes as part of the merge.
*/
private EntityBean fetchOutline(Set<String> paths) {
Query<?> query = server.find(desc.getBeanType());
query.setBeanCacheMode(CacheMode.OFF);
query.setPersistenceContextScope(PersistenceContextScope.QUERY);
query.setId(desc.getId(bean));
@@ -126,14 +120,12 @@ class MergeHandler {
}
private MergeNode addRootLevelNode(String rootPath) {
MergeNode node = createMergeNode(rootPath, desc, rootPath);
nodes.put(rootPath, node);
return node;
}
static MergeNode createMergeNode(String fullPath, BeanDescriptor<?> targetDesc, String path) {
BeanProperty prop = targetDesc.getBeanProperty(path);
if (!(prop instanceof BeanPropertyAssoc)) {
throw new PersistenceException("merge path [" + path + "] is not a ToMany or ToOne property of " + targetDesc.getFullName());
@@ -33,7 +33,7 @@ abstract class MergeNode {
/**
* Add a child node given the fullPath and relative path.
*/
MergeNode addChild(String fullPath, String path) {
final MergeNode addChild(String fullPath, String path) {
MergeNode childNode = MergeHandler.createMergeNode(fullPath, targetDescriptor, path);
if (children == null) {
children = new LinkedHashMap<>();
@@ -45,7 +45,7 @@ abstract class MergeNode {
/**
* Return the node given the relative path.
*/
MergeNode get(String path) {
final MergeNode get(String path) {
if (children != null) {
return children.get(path);
}
@@ -55,8 +55,7 @@ abstract class MergeNode {
/**
* Return the outline beans as a map keyed by Id values.
*/
Map<Object, EntityBean> toMap(Collection outlines) {
final Map<Object, EntityBean> toMap(Collection outlines) {
Map<Object, EntityBean> outlineMap = new HashMap<>();
if (outlines != null) {
for (Object out : outlines) {
@@ -71,8 +70,7 @@ abstract class MergeNode {
/**
* Add to the query to fetch the Ids values for the foreign keys basically.
*/
void addSelectId(Query<?> query) {
final void addSelectId(Query<?> query) {
BeanProperty idProperty = targetDescriptor.getIdProperty();
query.fetch(fullPath, idProperty.getName());
}
@@ -80,8 +78,7 @@ abstract class MergeNode {
/**
* Cascade the merge processing if this has child nodes.
*/
void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
final void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
if (children != null && !children.isEmpty()) {
MergeRequest sub = request.sub(entityBean, outlineBean);
for (MergeNode node : children.values()) {
@@ -15,7 +15,7 @@ import java.util.Map;
/**
* Node for processing merge on ManyToMany properties.
*/
class MergeNodeAssocManyToMany extends MergeNode {
final class MergeNodeAssocManyToMany extends MergeNode {
private final BeanPropertyAssocMany<?> many;
@@ -26,14 +26,11 @@ class MergeNodeAssocManyToMany extends MergeNode {
@Override
public void merge(MergeRequest request) {
EntityBean parentBean = request.getBean();
Collection beans = many.getRawCollection(parentBean);
Collection outlines = many.getRawCollection(request.getOutline());
Map<Object, EntityBean> outlineIds = toMap(outlines);
List<EntityBean> additions = new ArrayList<>();
if (beans != null) {
for (Object bean : beans) {
@@ -57,7 +54,6 @@ class MergeNodeAssocManyToMany extends MergeNode {
if (!deletions.isEmpty()) {
transaction.flush();
SqlUpdate delete = intersectionTable.delete(server, false);
for (EntityBean deletion : deletions) {
many.intersectionBind(delete, parentBean, deletion);
@@ -68,7 +64,6 @@ class MergeNodeAssocManyToMany extends MergeNode {
if (!additions.isEmpty()) {
transaction.flush();
SqlUpdate insert = intersectionTable.insert(server, false);
for (EntityBean addition : additions) {
many.intersectionBind(insert, parentBean, addition);
@@ -76,7 +71,6 @@ class MergeNodeAssocManyToMany extends MergeNode {
}
insert.execute();
}
many.resetMany(parentBean);
}
@@ -8,7 +8,7 @@ import java.util.Objects;
/**
* Node for processing merge on ToOne properties.
*/
class MergeNodeAssocOne extends MergeNode {
final class MergeNodeAssocOne extends MergeNode {
private final BeanPropertyAssocOne<?> one;
@@ -19,7 +19,6 @@ class MergeNodeAssocOne extends MergeNode {
@Override
public void merge(MergeRequest request) {
EntityBean entityBean = getEntityBean(request.getBean());
if (entityBean == null) {
checkOrphanRemoval(request);
@@ -9,7 +9,7 @@ import java.util.Map;
/**
* Node for processing merge on ToMany properties.
*/
class MergeNodeAssocOneToMany extends MergeNode {
final class MergeNodeAssocOneToMany extends MergeNode {
private final BeanPropertyAssocMany<?> many;
@@ -20,12 +20,10 @@ class MergeNodeAssocOneToMany extends MergeNode {
@Override
public void merge(MergeRequest request) {
Collection beans = many.getRawCollection(request.getBean());
Collection outlines = many.getRawCollection(request.getOutline());
Map<Object, EntityBean> outlineIds = toMap(outlines);
if (beans != null) {
for (Object bean : beans) {
EntityBean entityBean = (EntityBean) bean;
@@ -40,7 +38,6 @@ class MergeNodeAssocOneToMany extends MergeNode {
}
}
}
// any remaining are considered deletes
for (EntityBean outlineBean : outlineIds.values()) {
request.addDelete(outlineBean);
@@ -7,11 +7,10 @@ import io.ebeaninternal.api.SpiTransaction;
/**
* Request object used for processing the merge.
*/
class MergeRequest {
final class MergeRequest {
private final EntityBean bean;
private final EntityBean outline;
private final MergeContext context;
MergeRequest(MergeContext context, EntityBean bean, EntityBean outline) {
@@ -6,7 +6,7 @@ import java.util.Collection;
* Wraps the multi values that are used for "property in (...)" queries
* @author Roland Praml, FOCONIS AG
*/
public class MultiValueWrapper {
public final class MultiValueWrapper {
private final Collection<?> values;
private final Class<?> type;
@@ -15,10 +15,7 @@ import java.sql.Statement;
* getGeneratedKeys.
* </p>
*/
class PstmtFactory {
PstmtFactory() {
}
final class PstmtFactory {
/**
* Get a callable statement without any batching.
@@ -46,20 +46,20 @@ abstract class SaveManyBase implements SaveMany {
*/
abstract void save();
void preElementCollectionUpdate() {
final void preElementCollectionUpdate() {
if (!insertedParent) {
request.preElementCollectionUpdate();
persister.addToFlushQueue(many.deleteByParentId(request.getBeanId(), null), transaction, 1);
}
}
void resetModifyState() {
final void resetModifyState() {
if (value instanceof BeanCollection<?>) {
modifyListenReset((BeanCollection<?>) value);
}
}
void modifyListenReset(BeanCollection<?> c) {
final void modifyListenReset(BeanCollection<?> c) {
if (insertedParent) {
// after insert set the modify listening mode for private owned etc
c.setModifyListening(many.getModifyListenMode());
@@ -67,7 +67,7 @@ abstract class SaveManyBase implements SaveMany {
c.modifyReset();
}
void postElementCollectionUpdate() {
final void postElementCollectionUpdate() {
if (!insertedParent) {
if (request.isNotifyCache()) {
try {
@@ -26,7 +26,7 @@ import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
/**
* Saves the details for a OneToMany or ManyToMany relationship (entity beans).
*/
public class SaveManyBeans extends SaveManyBase {
public final class SaveManyBeans extends SaveManyBase {
private static final Logger log = LoggerFactory.getLogger(SaveManyBeans.class);
@@ -11,7 +11,7 @@ import java.util.Collection;
/**
* Save details for a simple scalar element collection.
*/
class SaveManyElementCollection extends SaveManyBase {
final class SaveManyElementCollection extends SaveManyBase {
private Collection<?> collection;
@@ -12,7 +12,7 @@ import java.util.Set;
/**
* Save details for a simple scalar map element collection.
*/
class SaveManyElementCollectionMap extends SaveManyBase {
final class SaveManyElementCollectionMap extends SaveManyBase {
private Set<Map.Entry<?, ?>> entries;
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.persist;
/**
* Utility to improve logging of raw SQL that contains new line characters.
*/
public class TrimLogSql {
public final class TrimLogSql {
/**
* Replace new line chars for nicer logging of multi-line sql strings.
@@ -16,19 +16,17 @@ class BaseMeta {
this.tenantId = tenantId;
}
String appendWhere(GenerateDmlRequest request, ConcurrencyMode conMode) {
final 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();
}
}
@@ -10,7 +10,7 @@ import java.sql.SQLException;
/**
* Delete bean handler.
*/
public class DeleteHandler extends DmlHandler {
final class DeleteHandler extends DmlHandler {
private final DeleteMeta meta;
@@ -30,7 +30,6 @@ final class DeleteMeta extends BaseMeta {
String draftTableName = desc.getDraftTable();
this.sqlDraftNone = genSql(ConcurrencyMode.NONE, draftTableName);
this.sqlDraftVersion = genSql(ConcurrencyMode.VERSION, draftTableName);
} else {
this.sqlDraftNone = sqlNone;
this.sqlDraftVersion = sqlVersion;
@@ -16,7 +16,7 @@ import java.sql.SQLException;
* a flat list of Bindable objects.
* </p>
*/
public final class DmlBeanPersister implements BeanPersister {
final class DmlBeanPersister implements BeanPersister {
private final DatabasePlatform dbPlatform;
private final UpdateMeta updateMeta;
@@ -8,7 +8,7 @@ import io.ebeaninternal.server.persist.BeanPersisterFactory;
/**
* Factory for creating a DmlBeanPersister for a bean type.
*/
public class DmlBeanPersisterFactory implements BeanPersisterFactory {
public final class DmlBeanPersisterFactory implements BeanPersisterFactory {
private final DatabasePlatform dbPlatform;
private final MetaFactory metaFactory;
@@ -8,7 +8,7 @@ import javax.persistence.PersistenceException;
/**
* Document store based BeanPersister.
*/
class DocStoreBeanPersister implements BeanPersister {
final class DocStoreBeanPersister implements BeanPersister {
private final GeneratedProperties generatedProperties;
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.persist.dml;
/**
* Helper to support the generation of DML statements.
*/
public class GenerateDmlRequest {
public final class GenerateDmlRequest {
private final StringBuilder sb = new StringBuilder(100);
private StringBuilder insertBindBuffer;
@@ -12,13 +12,7 @@ public class GenerateDmlRequest {
private int insertMode;
private int bindColumnCount;
/**
* Create from a PersistRequestBean.
*/
public GenerateDmlRequest() {
}
public GenerateDmlRequest append(String s) {
GenerateDmlRequest append(String s) {
sb.append(s);
return this;
}
@@ -30,7 +24,6 @@ public class GenerateDmlRequest {
public void appendColumn(String column, String bind) {
++bindColumnCount;
sb.append(prefix);
sb.append(column);
//sb.append(expr);
@@ -43,7 +36,6 @@ public class GenerateDmlRequest {
sb.append("=");
sb.append(bind);
}
if (prefix2 != null) {
prefix = prefix2;
prefix2 = null;
@@ -10,7 +10,7 @@ import java.util.List;
/**
* Executes the generated property (like WhenCreated, WhoCreated etc) for doc store persisting.
*/
class GeneratedProperties {
final class GeneratedProperties {
/**
* Create the GeneratedProperties for the given bean type.
@@ -10,7 +10,7 @@ import java.util.List;
/**
* Collects the generated properties for inserts and updates for a given bean type.
*/
class GeneratedPropertyCollector {
final class GeneratedPropertyCollector {
private final List<BeanProperty> preInsert = new ArrayList<>();
private final List<BeanProperty> preUpdate = new ArrayList<>();
@@ -18,7 +18,7 @@ import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero;
/**
* Insert bean handler.
*/
public class InsertHandler extends DmlHandler {
public final class InsertHandler extends DmlHandler {
private final InsertMeta meta;
private final boolean concatenatedKey;
@@ -22,7 +22,7 @@ import java.util.List;
/**
* Factory for creating InsertMeta UpdateMeta and DeleteMeta.
*/
class MetaFactory {
final class MetaFactory {
/**
* Include Lobs in the base statement. Generally true. Oracle9 used to require
@@ -11,7 +11,7 @@ import java.sql.SQLException;
/**
* Update bean handler.
*/
public class UpdateHandler extends DmlHandler {
public final class UpdateHandler extends DmlHandler {
private final UpdateMeta meta;
private boolean emptySetClause;
@@ -10,7 +10,7 @@ import java.sql.SQLException;
/**
* Plan for executing bean updates for a given set of changed properties.
*/
class UpdatePlan implements SpiUpdatePlan {
final class UpdatePlan implements SpiUpdatePlan {
private final String key;
private final ConcurrencyMode mode;
@@ -24,30 +24,29 @@ class BindableAssocOne implements Bindable {
}
@Override
public String toString() {
public final String toString() {
return "BindableAssocOne " + assocOne;
}
@Override
public boolean isDraftOnly() {
public final boolean isDraftOnly() {
return assocOne.isDraftOnly();
}
@Override
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
public final void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(assocOne)) {
list.add(this);
}
}
@Override
public void dmlAppend(GenerateDmlRequest request) {
public final void dmlAppend(GenerateDmlRequest request) {
importedId.dmlAppend(request);
}
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
EntityBean assocBean = (EntityBean) assocOne.getValue(bean);
registerDeferred(request, bean, assocBean);
}
@@ -5,7 +5,7 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import java.sql.SQLException;
class BindableAssocTenant extends BindableAssocOne {
final class BindableAssocTenant extends BindableAssocOne {
BindableAssocTenant(BeanPropertyAssocOne<?> assocOne) {
super(assocOne);
@@ -13,7 +13,6 @@ class BindableAssocTenant extends BindableAssocOne {
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
EntityBean assocBean = (EntityBean) assocOne.getValue(bean);
importedId.bind(request, assocBean);
}
@@ -12,7 +12,7 @@ import java.util.List;
/**
* Bindable for inserting a discriminator value.
*/
public class BindableDiscriminator implements Bindable {
public final class BindableDiscriminator implements Bindable {
private final String columnName;
private final Object discValue;
@@ -10,15 +10,15 @@ import java.util.Arrays;
import java.util.List;
/**
* Bindable for a Embedded bean.
* Bindable for an Embedded bean.
*/
public class BindableEmbedded implements Bindable {
final class BindableEmbedded implements Bindable {
private final Bindable[] items;
private final BeanPropertyAssocOne<?> embProp;
public BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> bindList) {
BindableEmbedded(BeanPropertyAssocOne<?> embProp, List<Bindable> bindList) {
this.embProp = embProp;
this.items = bindList.toArray(new Bindable[0]);
}
@@ -12,13 +12,13 @@ import java.util.List;
/**
* Bindable for a DB encrypted BeanProperty.
*/
public class BindableEncryptedProperty implements Bindable {
final class BindableEncryptedProperty implements Bindable {
private final BeanProperty prop;
private final boolean bindEncryptDataFirst;
public BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
BindableEncryptedProperty(BeanProperty prop, boolean bindEncryptDataFirst) {
this.prop = prop;
this.bindEncryptDataFirst = bindEncryptDataFirst;
}
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.persist.dml.GenerateDmlRequest;
import java.util.List;
public class BindableIdEmpty implements BindableId {
final class BindableIdEmpty implements BindableId {
@Override
public boolean isEmpty() {
@@ -12,11 +12,11 @@ import java.util.List;
/**
* Bindable for a single scalar id property.
*/
public final class BindableIdScalar implements BindableId {
final class BindableIdScalar implements BindableId {
private final BeanProperty uidProp;
public BindableIdScalar(BeanProperty uidProp) {
BindableIdScalar(BeanProperty uidProp) {
this.uidProp = uidProp;
}
@@ -12,7 +12,7 @@ import java.util.List;
/**
* List of Bindable items.
*/
public class BindableList implements Bindable {
public final class BindableList implements Bindable {
private final Bindable[] items;
@@ -10,7 +10,7 @@ import java.util.List;
/**
* Bindable for the synthetic order column.
*/
public class BindableOrderColumn extends BindableProperty {
public final class BindableOrderColumn extends BindableProperty {
public BindableOrderColumn(BeanProperty prop) {
super(prop);
@@ -29,7 +29,6 @@ public class BindableOrderColumn extends BindableProperty {
*/
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
int sortOrder = bean._ebean_getIntercept().getSortOrder();
request.bind(sortOrder, prop);
}
@@ -11,21 +11,21 @@ import java.util.List;
/**
* Bindable for a single BeanProperty.
*/
public class BindableProperty implements Bindable {
class BindableProperty implements Bindable {
final BeanProperty prop;
public BindableProperty(BeanProperty prop) {
BindableProperty(BeanProperty prop) {
this.prop = prop;
}
@Override
public String toString() {
public final String toString() {
return prop.toString();
}
@Override
public boolean isDraftOnly() {
public final boolean isDraftOnly() {
return prop.isDraftOnly();
}
@@ -37,7 +37,7 @@ public class BindableProperty implements Bindable {
}
@Override
public void dmlAppend(GenerateDmlRequest request) {
public final void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(prop.getDbColumn());
}
@@ -46,7 +46,6 @@ public class BindableProperty implements Bindable {
*/
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
@@ -9,7 +9,7 @@ import java.sql.SQLException;
/**
* For JSON Jackson properties - dirty detection via MD5 of json content.
*/
class BindablePropertyJsonInsert extends BindableProperty {
final class BindablePropertyJsonInsert extends BindableProperty {
private final int propertyIndex;
@@ -8,7 +8,7 @@ import java.sql.SQLException;
/**
* For JSON Jackson properties - dirty detection via MD5 of json content.
*/
class BindablePropertyJsonUpdate extends BindableProperty {
final class BindablePropertyJsonUpdate extends BindableProperty {
private final int propertyIndex;
@@ -11,11 +11,11 @@ import java.util.List;
/**
* Bindable for a Version BeanProperty. Obtains value from 'old values'.
*/
public class BindablePropertyVersion implements Bindable {
final class BindablePropertyVersion implements Bindable {
private final BeanProperty prop;
public BindablePropertyVersion(BeanProperty prop) {
BindablePropertyVersion(BeanProperty prop) {
this.prop = prop;
}
@@ -18,19 +18,16 @@ import java.util.List;
* parentBean.
* </p>
*/
public class BindableUnidirectional implements Bindable {
public final class BindableUnidirectional implements Bindable {
private final BeanPropertyAssocOne<?> unidirectional;
private final ImportedId importedId;
private final BeanDescriptor<?> desc;
public BindableUnidirectional(BeanDescriptor<?> desc, BeanPropertyAssocOne<?> unidirectional) {
this.desc = desc;
this.unidirectional = unidirectional;
this.importedId = unidirectional.getImportedId();
}
@Override
@@ -54,13 +51,10 @@ public class BindableUnidirectional implements Bindable {
importedId.dmlAppend(request);
}
@Override
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
PersistRequestBean<?> persistRequest = request.getPersistRequest();
Object parentBean = persistRequest.getParentBean();
if (parentBean == null) {
Class<?> localType = desc.getBeanType();
Class<?> targetType = unidirectional.getTargetType();
@@ -69,7 +63,6 @@ public class BindableUnidirectional implements Bindable {
msg += "For inserts you must use cascade save on the master bean [" + targetType + "].";
throw new PersistenceException(msg);
}
importedId.bind(request, (EntityBean) parentBean);
}
@@ -9,16 +9,12 @@ import java.util.List;
/**
* A factory that builds Bindable for BeanPropertyAssocOne properties.
*/
public class FactoryAssocOnes {
public FactoryAssocOnes() {
}
public final class FactoryAssocOnes {
/**
* Add foreign key columns from associated one beans.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode) {
for (BeanPropertyAssocOne<?> one : desc.propertiesOneImported()) {
if (!one.isImportedPrimaryKey()) {
switch (mode) {
@@ -12,11 +12,10 @@ import java.util.List;
* This excludes unique embedded and associated properties.
* </p>
*/
public class FactoryBaseProperties {
public final class FactoryBaseProperties {
private final FactoryProperty factoryProperty;
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
@@ -25,7 +24,6 @@ public class FactoryBaseProperties {
* Add Bindable for the base properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
for (BeanProperty prop : desc.propertiesBaseScalar()) {
if (!prop.isImportedPrimaryKey()) {
Bindable item = factoryProperty.create(prop, mode, withLobs, false);
@@ -11,7 +11,7 @@ import java.util.List;
/**
* A factory that builds Bindable for embedded bean properties.
*/
public class FactoryEmbedded {
public final class FactoryEmbedded {
private final FactoryProperty factoryProperty;
@@ -23,7 +23,6 @@ public class FactoryEmbedded {
* Add bindable for the embedded properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
for (BeanPropertyAssocOne<?> anEmbedded : desc.propertiesEmbedded()) {
BeanProperty[] props = anEmbedded.getProperties();
List<Bindable> bindList = new ArrayList<>(props.length);
@@ -7,23 +7,18 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Create a Bindable for the ids of a bean type.
*/
public class FactoryId {
public FactoryId() {
}
public final class FactoryId {
/**
* Add uniqueId properties.
*/
public BindableId createId(BeanDescriptor<?> desc) {
BeanProperty id = desc.getIdProperty();
if (id == null) {
return new BindableIdEmpty();
}
if (!id.isEmbedded()) {
return new BindableIdScalar(id);
} else {
BeanPropertyAssocOne<?> embId = (BeanPropertyAssocOne<?>) id;
MatchedImportedProperty[] matches = MatchedImportedFactory.build(embId.getProperties(), desc);
@@ -12,7 +12,7 @@ import io.ebeaninternal.server.persist.dml.DmlMode;
* and BindablePropertyUpdateGenerated as required.
* </p>
*/
class FactoryProperty {
final class FactoryProperty {
private final boolean bindEncryptDataFirst;
@@ -7,17 +7,12 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Creates a Bindable to support version concurrency where clauses.
*/
public class FactoryVersion {
public FactoryVersion() {
}
public final class FactoryVersion {
/**
* Create a Bindable for the version property(s) for a bean type.
*/
public Bindable create(BeanDescriptor<?> desc) {
BeanProperty versionProperty = desc.getVersionProperty();
return (versionProperty == null) ? null : new BindablePropertyVersion(versionProperty);
}
@@ -26,7 +21,6 @@ public class FactoryVersion {
* Create a Bindable for the version property(s) for a bean type.
*/
public Bindable createForDelete(BeanDescriptor<?> desc) {
BeanProperty versionProperty = desc.getVersionProperty();
return (versionProperty == null) ? null : new BindableProperty(versionProperty);
}
@@ -35,7 +29,6 @@ public class FactoryVersion {
* Create a Bindable for TenantId If multi-tenant with partitioning is on this bean type.
*/
public Bindable createTenantId(BeanDescriptor<?> desc) {
BeanProperty tenant = desc.getTenantProperty();
if (tenant == null) {
return null;
@@ -8,12 +8,10 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
* Matches local embedded id properties to 'matching' properties from a
* ManyToOne associated bean that is a 'imported primary key'.
*/
class MatchedImportedEmbedded implements MatchedImportedProperty {
final class MatchedImportedEmbedded implements MatchedImportedProperty {
private final BeanProperty localProp;
private final BeanPropertyAssocOne<?> assocOne;
private final BeanProperty foreignProp;
MatchedImportedEmbedded(BeanProperty localProp, BeanPropertyAssocOne<?> assocOne, BeanProperty foreignProp) {
@@ -4,15 +4,13 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
class MatchedImportedFactory {
final class MatchedImportedFactory {
/**
* Create the array of matchedImportedProperty based on the properties and descriptor.
*/
static MatchedImportedProperty[] build(BeanProperty[] props, BeanDescriptor<?> desc) {
MatchedImportedProperty[] matches = new MatchedImportedProperty[props.length];
for (int i = 0; i < props.length; i++) {
// find matching assoc one property for dbColumn
matches[i] = findMatch(props[i], desc);
@@ -25,12 +23,9 @@ class MatchedImportedFactory {
}
private static MatchedImportedProperty findMatch(BeanProperty prop, BeanDescriptor<?> desc) {
// find matching against the local database column
String dbColumn = prop.getDbColumn();
BeanPropertyAssocOne<?>[] assocOnes = desc.propertiesOne();
for (BeanPropertyAssocOne<?> assocOne1 : assocOnes) {
for (BeanPropertyAssocOne<?> assocOne1 : desc.propertiesOne()) {
if (assocOne1.isImportedPrimaryKey()) {
// search using the ImportedId from the assoc one
BeanProperty foreignMatch = assocOne1.getImportedId().findMatchImport(dbColumn);
@@ -39,14 +34,11 @@ class MatchedImportedFactory {
}
}
}
BeanProperty[] scalar = desc.propertiesBaseScalar();
for (BeanProperty beanProperty : scalar) {
for (BeanProperty beanProperty : desc.propertiesBaseScalar()) {
if (dbColumn.equals(beanProperty.getDbColumn())) {
return new MatchedImportedScalar(prop, beanProperty);
}
}
// there was no matching assoc one property.
// example UserRole bean missing assoc one to User?
return null;
@@ -6,10 +6,9 @@ import io.ebeaninternal.server.deploy.BeanProperty;
/**
* Matches local embedded id properties to 'matching' imported primary key scalar properties.
*/
class MatchedImportedScalar implements MatchedImportedProperty {
final class MatchedImportedScalar implements MatchedImportedProperty {
private final BeanProperty localProp;
private final BeanProperty foreignProp;
MatchedImportedScalar(BeanProperty localProp, BeanProperty foreignProp) {
@@ -19,7 +18,6 @@ class MatchedImportedScalar implements MatchedImportedProperty {
@Override
public void populate(EntityBean sourceBean, EntityBean embeddedId) {
Object value = foreignProp.getValue(sourceBean);
localProp.setValue(embeddedId, value);
}
@@ -11,7 +11,6 @@ import java.util.Collection;
*/
public class MultiValueBind {
@FunctionalInterface
public interface BindOne {
void bind(Object value) throws SQLException;
@@ -6,7 +6,7 @@ import io.ebean.core.type.ScalarType;
/**
* Multi value binder that uses Postgres Array.
*/
public class PostgresMultiValueBind extends AbstractMultiValueBind {
public final class PostgresMultiValueBind extends AbstractMultiValueBind {
@Override
public String getInExpression(boolean not, ScalarType<?> type, int size) {