Refactor rename internal methods - io.ebeaninternal.server.query

This commit is contained in:
Rob Bygrave committed 2022-08-18 11:11:12 +12:00
1 parent 1bc9bab988
commit c0a3f7e05d
57 files changed
+198 -232

No files matched your search

@@ -9,7 +9,7 @@ public interface CQueryPlanKey {
* Used by read audit such that we can log read audit entries without the full sql * Used by read audit such that we can log read audit entries without the full sql
* (which would make the read audit logs verbose). * (which would make the read audit logs verbose).
*/ */
String getPartialKey(); String partialKey();
/** /**
* Return a query plan key taking into account persist cascading. * Return a query plan key taking into account persist cascading.
@@ -1330,7 +1330,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
copy.setFutureFetch(true); copy.setFutureFetch(true);
Transaction newTxn = createTransaction(); Transaction newTxn = createTransaction();
QueryFutureRowCount<T> queryFuture = new QueryFutureRowCount<>(new CallableQueryCount<>(this, copy, newTxn)); QueryFutureRowCount<T> queryFuture = new QueryFutureRowCount<>(new CallableQueryCount<>(this, copy, newTxn));
backgroundExecutor.execute(queryFuture.getFutureTask()); backgroundExecutor.execute(queryFuture.futureTask());
return queryFuture; return queryFuture;
} }
@@ -1340,7 +1340,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
copy.setFutureFetch(true); copy.setFutureFetch(true);
Transaction newTxn = createTransaction(); Transaction newTxn = createTransaction();
QueryFutureIds<T> queryFuture = new QueryFutureIds<>(new CallableQueryIds<>(this, copy, newTxn)); QueryFutureIds<T> queryFuture = new QueryFutureIds<>(new CallableQueryIds<>(this, copy, newTxn));
backgroundExecutor.execute(queryFuture.getFutureTask()); backgroundExecutor.execute(queryFuture.futureTask());
return queryFuture; return queryFuture;
} }
@@ -1357,7 +1357,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
// Create a new transaction solely to execute the findList() at some future time // Create a new transaction solely to execute the findList() at some future time
Transaction newTxn = createTransaction(); Transaction newTxn = createTransaction();
QueryFutureList<T> queryFuture = new QueryFutureList<>(new CallableQueryList<>(this, spiQuery, newTxn)); QueryFutureList<T> queryFuture = new QueryFutureList<>(new CallableQueryList<>(this, spiQuery, newTxn));
backgroundExecutor.execute(queryFuture.getFutureTask()); backgroundExecutor.execute(queryFuture.futureTask());
return queryFuture; return queryFuture;
} }
@@ -639,7 +639,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
for (T bean : actualDetails) { for (T bean : actualDetails) {
ids.add(beanDescriptor.idForJson(bean)); ids.add(beanDescriptor.idForJson(bean));
} }
beanDescriptor.readAuditMany(queryPlanKey.getPartialKey(), "l2-query-cache", ids); beanDescriptor.readAuditMany(queryPlanKey.partialKey(), "l2-query-cache", ids);
} }
} }
if (Boolean.FALSE.equals(query.isReadOnly())) { if (Boolean.FALSE.equals(query.isReadOnly())) {
@@ -22,7 +22,7 @@ final class AssocOneHelpRefExported extends AssocOneHelp {
@Override @Override
void appendSelect(DbSqlContext ctx, boolean subQuery) { void appendSelect(DbSqlContext ctx, boolean subQuery) {
// set appropriate tableAlias for the exported id columns // set appropriate tableAlias for the exported id columns
String relativePrefix = ctx.getRelativePrefix(property.name()); String relativePrefix = ctx.relativePrefix(property.name());
ctx.pushTableAlias(relativePrefix); ctx.pushTableAlias(relativePrefix);
property.targetIdBinder.appendSelect(ctx, subQuery); property.targetIdBinder.appendSelect(ctx, subQuery);
ctx.popTableAlias(); ctx.popTableAlias();
@@ -30,7 +30,7 @@ final class AssocOneHelpRefExported extends AssocOneHelp {
@Override @Override
void appendFrom(DbSqlContext ctx, SqlJoinType joinType) { void appendFrom(DbSqlContext ctx, SqlJoinType joinType) {
String relativePrefix = ctx.getRelativePrefix(property.name()); String relativePrefix = ctx.relativePrefix(property.name());
if (softDelete && !ctx.isIncludeSoftDelete()) { if (softDelete && !ctx.isIncludeSoftDelete()) {
property.tableJoin.addJoin(joinType, relativePrefix, ctx, softDeletePredicate); property.tableJoin.addJoin(joinType, relativePrefix, ctx, softDeletePredicate);
} else { } else {
@@ -63,7 +63,7 @@ final class AssocOneHelpRefInherit extends AssocOneHelp {
void appendFrom(DbSqlContext ctx, SqlJoinType joinType) { void appendFrom(DbSqlContext ctx, SqlJoinType joinType) {
// add join to support the discriminator column // add join to support the discriminator column
String relativePrefix = ctx.getRelativePrefix(property.name); String relativePrefix = ctx.relativePrefix(property.name);
ctx.addExtraJoin(new Extra(relativePrefix, joinType)); ctx.addExtraJoin(new Extra(relativePrefix, joinType));
} }
@@ -92,8 +92,8 @@ final class AssocOneHelpRefInherit extends AssocOneHelp {
void appendSelect(DbSqlContext ctx, boolean subQuery) { void appendSelect(DbSqlContext ctx, boolean subQuery) {
if (!subQuery) { if (!subQuery) {
// add discriminator column // add discriminator column
String relativePrefix = ctx.getRelativePrefix(property.name()); String relativePrefix = ctx.relativePrefix(property.name());
String tableAlias = ctx.getTableAlias(relativePrefix); String tableAlias = ctx.tableAlias(relativePrefix);
ctx.appendColumn(tableAlias, property.targetInheritInfo.getDiscriminatorColumn()); ctx.appendColumn(tableAlias, property.targetInheritInfo.getDiscriminatorColumn());
} }
property.importedId.sqlAppend(ctx); property.importedId.sqlAppend(ctx);
@@ -455,7 +455,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
if (formula && sqlFormulaJoin != null) { if (formula && sqlFormulaJoin != null) {
ctx.appendFormulaJoin(sqlFormulaJoin, joinType, manyWhere); ctx.appendFormulaJoin(sqlFormulaJoin, joinType, manyWhere);
} else if (secondaryTableJoin != null) { } else if (secondaryTableJoin != null) {
String relativePrefix = ctx.getRelativePrefix(secondaryTableJoinPrefix); String relativePrefix = ctx.relativePrefix(secondaryTableJoinPrefix);
secondaryTableJoin.addJoin(joinType, relativePrefix, ctx); secondaryTableJoin.addJoin(joinType, relativePrefix, ctx);
} }
} }
@@ -481,7 +481,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
ctx.appendFormulaSelect(sqlFormulaSelect); ctx.appendFormulaSelect(sqlFormulaSelect);
} else if (!isTransient && !ignoreDraftOnlyProperty(ctx.isDraftQuery())) { } else if (!isTransient && !ignoreDraftOnlyProperty(ctx.isDraftQuery())) {
if (secondaryTableJoin != null) { if (secondaryTableJoin != null) {
ctx.pushTableAlias(ctx.getRelativePrefix(secondaryTableJoinPrefix)); ctx.pushTableAlias(ctx.relativePrefix(secondaryTableJoinPrefix));
} }
if (dbEncrypted) { if (dbEncrypted) {
ctx.appendRawColumn(decryptSqlWithColumnAlias(ctx.peekTableAlias())); ctx.appendRawColumn(decryptSqlWithColumnAlias(ctx.peekTableAlias()));
@@ -326,7 +326,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
*/ */
@Override @Override
public void lazyLoadMany(EntityBean current) { public void lazyLoadMany(EntityBean current) {
EntityBean parentBean = childMasterProperty.getValueAsEntityBean(current); EntityBean parentBean = childMasterProperty.valueAsEntityBean(current);
if (parentBean != null) { if (parentBean != null) {
addBeanToCollectionWithCreate(parentBean, current, true); addBeanToCollectionWithCreate(parentBean, current, true);
} }
@@ -155,7 +155,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
* Return the property value as an entity bean. * Return the property value as an entity bean.
*/ */
@Override @Override
public EntityBean getValueAsEntityBean(EntityBean owner) { public EntityBean valueAsEntityBean(EntityBean owner) {
return (EntityBean) getValue(owner); return (EntityBean) getValue(owner);
} }
@@ -31,7 +31,7 @@ public interface DbSqlContext {
/** /**
* Return a list of encrypted properties which require additional binding. * Return a list of encrypted properties which require additional binding.
*/ */
BeanProperty[] getEncryptedProps(); BeanProperty[] encryptedProps();
/** /**
* Append a string directly to the SQL buffer. * Append a string directly to the SQL buffer.
@@ -83,7 +83,7 @@ public interface DbSqlContext {
/** /**
* Return the current context of the sql context. * Return the current context of the sql context.
*/ */
String getContent(); String content();
/** /**
* Push a join node onto the stack. * Push a join node onto the stack.
@@ -99,14 +99,14 @@ public interface DbSqlContext {
* Return a table alias without many where clause joins. Typically this is for * Return a table alias without many where clause joins. Typically this is for
* the select clause (fetch joins). * the select clause (fetch joins).
*/ */
String getTableAlias(String prefix); String tableAlias(String prefix);
/** /**
* Return a table alias that takes into account many where joins. * Return a table alias that takes into account many where joins.
*/ */
String getTableAliasManyWhere(String prefix); String tableAliasManyWhere(String prefix);
String getRelativePrefix(String propName); String relativePrefix(String propName);
/** /**
* Append the lower and upper bound columns into the select clause * Append the lower and upper bound columns into the select clause
@@ -34,7 +34,7 @@ public final class TableJoin {
private final int queryHash; private final int queryHash;
private final PropertyForeignKey foreignKey; private final PropertyForeignKey foreignKey;
private final String extraWhere; private final String extraWhere;
public TableJoin(DeployTableJoin deploy) { public TableJoin(DeployTableJoin deploy) {
@@ -135,21 +135,21 @@ public final class TableJoin {
public void addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx, String predicate) { public void addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx, String predicate) {
String[] names = SplitName.split(prefix); String[] names = SplitName.split(prefix);
String a1 = ctx.getTableAlias(names[0]); String a1 = ctx.tableAlias(names[0]);
String a2 = ctx.getTableAlias(prefix); String a2 = ctx.tableAlias(prefix);
addJoin(joinType, a1, a2, ctx); addJoin(joinType, a1, a2, ctx);
ctx.append(" and ").append(a2).append(predicate); ctx.append(" and ").append(a2).append(predicate);
} }
public SqlJoinType addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx) { public SqlJoinType addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx) {
String[] names = SplitName.split(prefix); String[] names = SplitName.split(prefix);
String a1 = ctx.getTableAlias(names[0]); String a1 = ctx.tableAlias(names[0]);
String a2 = ctx.getTableAlias(prefix); String a2 = ctx.tableAlias(prefix);
return addJoin(joinType, a1, a2, ctx); return addJoin(joinType, a1, a2, ctx);
} }
public SqlJoinType addJoin(SqlJoinType joinType, String a1, String a2, DbSqlContext ctx) { public SqlJoinType addJoin(SqlJoinType joinType, String a1, String a2, DbSqlContext ctx) {
String joinLiteral = joinType.getLiteral(type); String joinLiteral = joinType.literal(type);
ctx.addJoin(joinLiteral, table, columns(), a1, a2, extraWhere); ctx.addJoin(joinLiteral, table, columns(), a1, a2, extraWhere);
return joinType.autoToOuter(type); return joinType.autoToOuter(type);
} }
@@ -57,7 +57,7 @@ final class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreE
@Override @Override
public void prepareExpression(BeanQueryRequest<?> request) { public void prepareExpression(BeanQueryRequest<?> request) {
CQuery<?> subQuery = compileSubQuery(request); CQuery<?> subQuery = compileSubQuery(request);
this.bindParams = subQuery.predicates().getWhereExprBindValues(); this.bindParams = subQuery.predicates().whereExprBindValues();
this.sql = subQuery.generatedSql().replace('\n', ' '); this.sql = subQuery.generatedSql().replace('\n', ' ');
} }
@@ -45,7 +45,7 @@ final class InQueryExpression extends AbstractExpression implements UnsupportedD
public void prepareExpression(BeanQueryRequest<?> request) { public void prepareExpression(BeanQueryRequest<?> request) {
CQuery<?> subQuery = compileSubQuery(request); CQuery<?> subQuery = compileSubQuery(request);
this.bindParams = subQuery.predicates().getWhereExprBindValues(); this.bindParams = subQuery.predicates().whereExprBindValues();
this.sql = subQuery.generatedSql().replace('\n', ' '); this.sql = subQuery.generatedSql().replace('\n', ' ');
} }
@@ -14,7 +14,6 @@ import io.ebeaninternal.server.deploy.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.persistence.PersistenceException;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
@@ -867,7 +866,7 @@ public final class DefaultPersister implements Persister {
for (BeanPropertyAssocOne<?> prop : desc.propertiesOneExportedSave()) { for (BeanPropertyAssocOne<?> prop : desc.propertiesOneExportedSave()) {
// check for partial beans // check for partial beans
if (request.isLoadedProperty(prop)) { if (request.isLoadedProperty(prop)) {
EntityBean detailBean = prop.getValueAsEntityBean(parentBean); EntityBean detailBean = prop.valueAsEntityBean(parentBean);
if (detailBean != null) { if (detailBean != null) {
if (!prop.isSaveRecurseSkippable(detailBean)) { if (!prop.isSaveRecurseSkippable(detailBean)) {
t.depth(+1); t.depth(+1);
@@ -1056,7 +1055,7 @@ public final class DefaultPersister implements Persister {
request.setImportedOrphanForRemoval(prop); request.setImportedOrphanForRemoval(prop);
} }
if (request.isLoadedProperty(prop)) { if (request.isLoadedProperty(prop)) {
EntityBean detailBean = prop.getValueAsEntityBean(request.entityBean()); EntityBean detailBean = prop.valueAsEntityBean(request.entityBean());
if (detailBean != null if (detailBean != null
&& !prop.isSaveRecurseSkippable(detailBean) && !prop.isSaveRecurseSkippable(detailBean)
&& !prop.isReference(detailBean) && !prop.isReference(detailBean)
@@ -190,8 +190,8 @@ public final class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfi
// so its available to the user... // so its available to the user...
query.setGeneratedSql(queryPlan.sql()); query.setGeneratedSql(queryPlan.sql());
SqlTreePlan sqlTree = queryPlan.sqlTree(); SqlTreePlan sqlTree = queryPlan.sqlTree();
this.rootNode = sqlTree.getRootNode(); this.rootNode = sqlTree.rootNode();
this.manyProperty = sqlTree.getManyProperty(); this.manyProperty = sqlTree.manyProperty();
this.sql = queryPlan.sql(); this.sql = queryPlan.sql();
this.rawSql = queryPlan.isRawSql(); this.rawSql = queryPlan.isRawSql();
this.logWhereSql = queryPlan.logWhereSql(); this.logWhereSql = queryPlan.logWhereSql();
@@ -62,14 +62,14 @@ final class CQueryBindCapture implements SpiQueryBindCapture {
* Collect the query plan using already captured bind values. * Collect the query plan using already captured bind values.
*/ */
public boolean collectQueryPlan(CQueryPlanRequest request) { public boolean collectQueryPlan(CQueryPlanRequest request) {
if (bindCapture == null || request.getSince() < lastBindCapture) { if (bindCapture == null || request.since() < lastBindCapture) {
// no bind capture since the last capture // no bind capture since the last capture
return false; return false;
} }
final BindCapture last = this.bindCapture; final BindCapture last = this.bindCapture;
SpiDbQueryPlan queryPlan = manager.collectPlan(request.getConnection(), this.queryPlan, last); SpiDbQueryPlan queryPlan = manager.collectPlan(request.connection(), this.queryPlan, last);
if (queryPlan != null) { if (queryPlan != null) {
request.add(queryPlan.with(queryTimeMicros, captureCount)); request.add(queryPlan.with(queryTimeMicros, captureCount));
// effectively turn off bind capture for this plan // effectively turn off bind capture for this plan
@@ -110,7 +110,7 @@ final class CQueryBuilder {
sql = buildUpdateSql(request, rootTableAlias, predicates, sqlTree); sql = buildUpdateSql(request, rootTableAlias, predicates, sqlTree);
} }
// cache the query plan // cache the query plan
queryPlan = new CQueryPlan(request, sql, sqlTree.plan(), predicates.getLogWhereSql()); queryPlan = new CQueryPlan(request, sql, sqlTree.plan(), predicates.logWhereSql());
request.putQueryPlan(queryPlan); request.putQueryPlan(queryPlan);
return new CQueryUpdate(request, predicates, queryPlan); return new CQueryUpdate(request, predicates, queryPlan);
} }
@@ -149,7 +149,7 @@ final class CQueryBuilder {
if (rootTableAlias != null) { if (rootTableAlias != null) {
sb.append(" ").append(rootTableAlias); sb.append(" ").append(rootTableAlias);
} }
sb.append(" set ").append(predicates.getDbUpdateClause()); sb.append(" set ").append(predicates.dbUpdateClause());
String updateClause = sb.toString(); String updateClause = sb.toString();
if (sqlTree.noJoins() && request.isInlineSqlUpdateLimit()) { if (sqlTree.noJoins() && request.isInlineSqlUpdateLimit()) {
// simple - update table set ... where ... // simple - update table set ... where ...
@@ -196,7 +196,7 @@ final class CQueryBuilder {
SqlTree sqlTree = createSqlTree(request, predicates); SqlTree sqlTree = createSqlTree(request, predicates);
SqlLimitResponse s = buildSql(null, request, predicates, sqlTree); SqlLimitResponse s = buildSql(null, request, predicates, sqlTree);
queryPlan = new CQueryPlan(request, s.getSql(), sqlTree.plan(), predicates.getLogWhereSql()); queryPlan = new CQueryPlan(request, s.getSql(), sqlTree.plan(), predicates.logWhereSql());
request.putQueryPlan(queryPlan); request.putQueryPlan(queryPlan);
return new CQueryFetchSingleAttribute(request, predicates, queryPlan, query.isCountDistinct()); return new CQueryFetchSingleAttribute(request, predicates, queryPlan, query.isCountDistinct());
} }
@@ -217,14 +217,14 @@ final class CQueryBuilder {
/** /**
* Return the history support if this query needs it (is a 'as of' type query). * Return the history support if this query needs it (is a 'as of' type query).
*/ */
<T> CQueryHistorySupport getHistorySupport(SpiQuery<T> query) { <T> CQueryHistorySupport historySupport(SpiQuery<T> query) {
return query.getTemporalMode().isHistory() ? historySupport : null; return query.getTemporalMode().isHistory() ? historySupport : null;
} }
/** /**
* Return the draft support (or null) for a 'asDraft' query. * Return the draft support (or null) for a 'asDraft' query.
*/ */
<T> CQueryDraftSupport getDraftSupport(SpiQuery<T> query) { <T> CQueryDraftSupport draftSupport(SpiQuery<T> query) {
return query.getTemporalMode() == SpiQuery.TemporalMode.DRAFT ? draftSupport : null; return query.getTemporalMode() == SpiQuery.TemporalMode.DRAFT ? draftSupport : null;
} }
@@ -287,7 +287,7 @@ final class CQueryBuilder {
} }
} }
// cache the query plan // cache the query plan
queryPlan = new CQueryPlan(request, sql, sqlTree.plan(), predicates.getLogWhereSql()); queryPlan = new CQueryPlan(request, sql, sqlTree.plan(), predicates.logWhereSql());
request.putQueryPlan(queryPlan); request.putQueryPlan(queryPlan);
return new CQueryRowCount(queryPlan, request, predicates); return new CQueryRowCount(queryPlan, request, predicates);
} }
@@ -340,9 +340,9 @@ final class CQueryBuilder {
SqlLimitResponse res = buildSql(null, request, predicates, sqlTree); SqlLimitResponse res = buildSql(null, request, predicates, sqlTree);
boolean rawSql = request.isRawSql(); boolean rawSql = request.isRawSql();
if (rawSql) { if (rawSql) {
queryPlan = new CQueryPlanRawSql(request, res, sqlTree, predicates.getLogWhereSql()); queryPlan = new CQueryPlanRawSql(request, res, sqlTree, predicates.logWhereSql());
} else { } else {
queryPlan = new CQueryPlan(request, res, sqlTree.plan(), false, predicates.getLogWhereSql()); queryPlan = new CQueryPlan(request, res, sqlTree.plan(), false, predicates.logWhereSql());
} }
BeanDescriptor<T> desc = request.descriptor(); BeanDescriptor<T> desc = request.descriptor();
if (desc.isReadAuditing()) { if (desc.isReadAuditing()) {
@@ -552,7 +552,7 @@ final class CQueryBuilder {
this.select = select; this.select = select;
this.updateStatement = updateStatement; this.updateStatement = updateStatement;
this.distinct = query.isDistinct() || select.isSqlDistinct(); this.distinct = query.isDistinct() || select.isSqlDistinct();
this.dbOrderBy = predicates.getDbOrderBy(); this.dbOrderBy = predicates.dbOrderBy();
this.countSingleAttribute = query.isCountDistinct() && query.isSingleAttribute(); this.countSingleAttribute = query.isCountDistinct() && query.isSingleAttribute();
} }
@@ -560,7 +560,7 @@ final class CQueryBuilder {
if (selectClause != null) { if (selectClause != null) {
sb.append(selectClause); sb.append(selectClause);
} else { } else {
useSqlLimiter = (query.hasMaxRowsOrFirstRow() && (select.getManyProperty() == null || query.isSingleAttribute())); useSqlLimiter = (query.hasMaxRowsOrFirstRow() && (select.manyProperty() == null || query.isSingleAttribute()));
if (!useSqlLimiter) { if (!useSqlLimiter) {
appendSelectDistinct(); appendSelectDistinct();
} }
@@ -578,9 +578,9 @@ final class CQueryBuilder {
sb.append("t0.").append(idProp.dbColumn()).append(", "); sb.append("t0.").append(idProp.dbColumn()).append(", ");
} }
} }
sb.append(select.getSelectSql()).append(" as attribute_"); sb.append(select.selectSql()).append(" as attribute_");
} else { } else {
sb.append(select.getSelectSql()); sb.append(select.selectSql());
} }
if (request.isInlineCountDistinct()) { if (request.isInlineCountDistinct()) {
sb.append(")"); sb.append(")");
@@ -590,7 +590,7 @@ final class CQueryBuilder {
final OrderBy<?> orderBy = query.getOrderBy(); final OrderBy<?> orderBy = query.getOrderBy();
if (orderBy != null && orderBy.supportsSelect()) { if (orderBy != null && orderBy.supportsSelect()) {
String trimmed = DbOrderByTrim.trim(dbOrderBy); String trimmed = DbOrderByTrim.trim(dbOrderBy);
if (query.isSingleAttribute() && select.getSelectSql().startsWith(trimmed)) { if (query.isSingleAttribute() && select.selectSql().startsWith(trimmed)) {
// NOP, already in SQL // NOP, already in SQL
// TODO: what to do if we select("id").orderBy("prop,id")? // TODO: what to do if we select("id").orderBy("prop,id")?
// Can we live with a query like "select t0.id, t0.prop, t0.id from" // Can we live with a query like "select t0.id, t0.prop, t0.id from"
@@ -610,7 +610,7 @@ final class CQueryBuilder {
sb.append("count("); sb.append("count(");
} }
sb.append("distinct "); sb.append("distinct ");
String distinctOn = select.getDistinctOn(); String distinctOn = select.distinctOn();
if (distinctOn != null) { if (distinctOn != null) {
sb.append("on (").append(distinctOn).append(") "); sb.append("on (").append(distinctOn).append(") ");
} }
@@ -620,7 +620,7 @@ final class CQueryBuilder {
private void appendFrom() { private void appendFrom() {
if (selectClause == null || !selectClause.startsWith("update")) { if (selectClause == null || !selectClause.startsWith("update")) {
sb.append(" from "); sb.append(" from ");
sb.append(select.getFromSql()); sb.append(select.fromSql());
} }
} }
@@ -634,7 +634,7 @@ final class CQueryBuilder {
} }
private void appendInheritanceWhere() { private void appendInheritanceWhere() {
String inheritanceWhere = select.getInheritanceWhereSql(); String inheritanceWhere = select.inheritanceWhereSql();
if (!inheritanceWhere.isEmpty()) { if (!inheritanceWhere.isEmpty()) {
sb.append(" where"); sb.append(" where");
sb.append(inheritanceWhere); sb.append(inheritanceWhere);
@@ -647,7 +647,7 @@ final class CQueryBuilder {
query.incrementAsOfTableCount(); query.incrementAsOfTableCount();
if (!historySupport.isStandardsBased()){ if (!historySupport.isStandardsBased()){
appendAndOrWhere(); appendAndOrWhere();
sb.append(historySupport.getAsOfPredicate(request.baseTableAlias())); sb.append(historySupport.asOfPredicate(request.baseTableAlias()));
} }
} }
} }
@@ -696,16 +696,16 @@ final class CQueryBuilder {
appendInheritanceWhere(); appendInheritanceWhere();
appendHistoryAsOfPredicate(); appendHistoryAsOfPredicate();
appendFindId(); appendFindId();
appendToWhere(predicates.getDbWhere()); appendToWhere(predicates.dbWhere());
appendToWhere(predicates.getDbFilterMany()); appendToWhere(predicates.dbFilterMany());
if (!query.isIncludeSoftDeletes()) { if (!query.isIncludeSoftDeletes()) {
appendSoftDelete(); appendSoftDelete();
} }
String groupBy = select.getGroupBy(); String groupBy = select.groupBy();
if (groupBy != null) { if (groupBy != null) {
sb.append(" group by ").append(groupBy); sb.append(" group by ").append(groupBy);
} }
String dbHaving = predicates.getDbHaving(); String dbHaving = predicates.dbHaving();
if (hasValue(dbHaving)) { if (hasValue(dbHaving)) {
sb.append(" having ").append(dbHaving); sb.append(" having ").append(dbHaving);
} }
@@ -25,12 +25,10 @@ final class CQueryBuilderRawSql {
* Build the full SQL Select statement for the request. * Build the full SQL Select statement for the request.
*/ */
SqlLimitResponse buildSql(OrmQueryRequest<?> request, CQueryPredicates predicates, SpiRawSql.Sql rsql) { SqlLimitResponse buildSql(OrmQueryRequest<?> request, CQueryPredicates predicates, SpiRawSql.Sql rsql) {
if (rsql == null) { if (rsql == null) {
// this is a ResultSet based RawSql query - just use some placeholder for the SQL // this is a ResultSet based RawSql query - just use some placeholder for the SQL
return new SqlLimitResponse(CQueryPlan.RESULT_SET_BASED_RAW_SQL); return new SqlLimitResponse(CQueryPlan.RESULT_SET_BASED_RAW_SQL);
} }
if (!rsql.isParsed()) { if (!rsql.isParsed()) {
String sql = rsql.getUnparsedSql(); String sql = rsql.getUnparsedSql();
BindParams bindParams = request.query().getBindParams(); BindParams bindParams = request.query().getBindParams();
@@ -41,16 +39,13 @@ final class CQueryBuilderRawSql {
return new SqlLimitResponse(sql); return new SqlLimitResponse(sql);
} }
String orderBy = getOrderBy(predicates, rsql); String orderBy = orderBy(predicates, rsql);
// build the actual sql String // build the actual sql String
String sql = buildMainQuery(orderBy, request, predicates, rsql); String sql = buildMainQuery(orderBy, request, predicates, rsql);
SpiQuery<?> query = request.query(); SpiQuery<?> query = request.query();
if (query.hasMaxRowsOrFirstRow() && sqlLimiter != null) { if (query.hasMaxRowsOrFirstRow() && sqlLimiter != null) {
// wrap with a limit offset or ROW_NUMBER() etc // wrap with a limit offset or ROW_NUMBER() etc
return sqlLimiter.limit(new OrmQueryLimitRequest(sql, orderBy, query, dbPlatform, rsql.isDistinct() || query.isDistinct())); return sqlLimiter.limit(new OrmQueryLimitRequest(sql, orderBy, query, dbPlatform, rsql.isDistinct() || query.isDistinct()));
} else { } else {
// add back select keyword (it was removed to support sqlQueryLimiter) // add back select keyword (it was removed to support sqlQueryLimiter)
String prefix = "select " + (rsql.isDistinct() ? "distinct " : ""); String prefix = "select " + (rsql.isDistinct() ? "distinct " : "");
@@ -86,7 +81,7 @@ final class CQueryBuilderRawSql {
dynamicWhere = descriptor.idBinderIdSql(null); dynamicWhere = descriptor.idBinderIdSql(null);
} }
String dbWhere = predicates.getDbWhere(); String dbWhere = predicates.dbWhere();
if (hasValue(dbWhere)) { if (hasValue(dbWhere)) {
if (dynamicWhere == null) { if (dynamicWhere == null) {
dynamicWhere = dbWhere; dynamicWhere = dbWhere;
@@ -109,7 +104,7 @@ final class CQueryBuilderRawSql {
sb.append(preHaving).append(" "); sb.append(preHaving).append(" ");
} }
String dbHaving = predicates.getDbHaving(); String dbHaving = predicates.dbHaving();
if (hasValue(dbHaving)) { if (hasValue(dbHaving)) {
if (sql.isAndHavingExpr()) { if (sql.isAndHavingExpr()) {
sb.append(" and "); sb.append(" and ");
@@ -128,8 +123,8 @@ final class CQueryBuilderRawSql {
return s != null && !s.isEmpty(); return s != null && !s.isEmpty();
} }
private String getOrderBy(CQueryPredicates predicates, SpiRawSql.Sql sql) { private String orderBy(CQueryPredicates predicates, SpiRawSql.Sql sql) {
String orderBy = predicates.getDbOrderBy(); String orderBy = predicates.dbOrderBy();
if (orderBy != null) { if (orderBy != null) {
return orderBy; return orderBy;
} else { } else {
@@ -22,7 +22,7 @@ final class CQueryDraftSupport {
* This returns null for entities that are not draftable and in that case * This returns null for entities that are not draftable and in that case
* the usual base table is used. * the usual base table is used.
*/ */
String getDraftTable(String table) { String draftTable(String table) {
return tableMap.get(table); return tableMap.get(table);
} }
} }
@@ -76,11 +76,11 @@ public final class CQueryEngine {
try { try {
int rows = query.execute(); int rows = query.execute();
if (request.logSql()) { if (request.logSql()) {
request.logSql(Str.add(query.getGeneratedSql(), "; --bind(", query.getBindLog(), ") --micros(", query.micros() + ") --rows(", rows + ")")); request.logSql(Str.add(query.generatedSql(), "; --bind(", query.bindLog(), ") --micros(", query.micros() + ") --rows(", rows + ")"));
} }
return rows; return rows;
} catch (SQLException e) { } catch (SQLException e) {
throw translate(request, query.getBindLog(), query.getGeneratedSql(), e); throw translate(request, query.bindLog(), query.generatedSql(), e);
} }
} }
@@ -98,13 +98,13 @@ public final class CQueryEngine {
try { try {
rcQuery.findCollection(collection); rcQuery.findCollection(collection);
if (request.logSql()) { if (request.logSql()) {
logGeneratedSql(request, rcQuery.getGeneratedSql(), rcQuery.getBindLog(), rcQuery.micros()); logGeneratedSql(request, rcQuery.generatedSql(), rcQuery.bindLog(), rcQuery.micros());
} }
if (request.logSummary()) { if (request.logSummary()) {
request.transaction().logSummary(rcQuery.getSummary()); request.transaction().logSummary(rcQuery.summary());
} }
if (request.isQueryCachePut()) { if (request.isQueryCachePut()) {
request.addDependentTables(rcQuery.getDependentTables()); request.addDependentTables(rcQuery.dependentTables());
if (collection instanceof List) { if (collection instanceof List) {
collection = (A) Collections.unmodifiableList((List<?>) collection); collection = (A) Collections.unmodifiableList((List<?>) collection);
request.putToQueryCache(collection); request.putToQueryCache(collection);
@@ -121,7 +121,7 @@ public final class CQueryEngine {
} }
return collection; return collection;
} catch (SQLException e) { } catch (SQLException e) {
throw translate(request, rcQuery.getBindLog(), rcQuery.getGeneratedSql(), e); throw translate(request, rcQuery.bindLog(), rcQuery.generatedSql(), e);
} }
} }
@@ -164,21 +164,21 @@ public final class CQueryEngine {
try { try {
int count = rcQuery.findCount(); int count = rcQuery.findCount();
if (request.logSql()) { if (request.logSql()) {
logGeneratedSql(request, rcQuery.getGeneratedSql(), rcQuery.getBindLog(), rcQuery.micros()); logGeneratedSql(request, rcQuery.generatedSql(), rcQuery.bindLog(), rcQuery.micros());
} }
if (request.logSummary()) { if (request.logSummary()) {
request.transaction().logSummary(rcQuery.getSummary()); request.transaction().logSummary(rcQuery.summary());
} }
if (request.query().isFutureFetch()) { if (request.query().isFutureFetch()) {
request.transaction().end(); request.transaction().end();
} }
if (request.isQueryCachePut()) { if (request.isQueryCachePut()) {
request.addDependentTables(rcQuery.getDependentTables()); request.addDependentTables(rcQuery.dependentTables());
request.putToQueryCache(count); request.putToQueryCache(count);
} }
return count; return count;
} catch (SQLException e) { } catch (SQLException e) {
throw translate(request, rcQuery.getBindLog(), rcQuery.getGeneratedSql(), e); throw translate(request, rcQuery.bindLog(), rcQuery.generatedSql(), e);
} }
} }
@@ -271,9 +271,7 @@ public final class CQueryEngine {
} catch (SQLException e) { } catch (SQLException e) {
throw cquery.createPersistenceException(e); throw cquery.createPersistenceException(e);
} finally { } finally {
if (cquery != null) { cquery.close();
cquery.close();
}
} }
} }
@@ -299,11 +297,11 @@ public final class CQueryEngine {
} }
private <T> String getSysPeriodLower(SpiQuery<T> query) { private <T> String getSysPeriodLower(SpiQuery<T> query) {
return historySupport.getSysPeriodLower(query.getAlias(T0)); return historySupport.sysPeriodLower(query.getAlias(T0));
} }
private <T> String getSysPeriodUpper(SpiQuery<T> query) { private <T> String getSysPeriodUpper(SpiQuery<T> query) {
return historySupport.getSysPeriodUpper(query.getAlias(T0)); return historySupport.sysPeriodUpper(query.getAlias(T0));
} }
/** /**
@@ -373,9 +371,7 @@ public final class CQueryEngine {
} catch (SQLException e) { } catch (SQLException e) {
throw cquery.createPersistenceException(e); throw cquery.createPersistenceException(e);
} finally { } finally {
if (cquery != null) { cquery.close();
cquery.close();
}
} }
} }
@@ -58,12 +58,12 @@ final class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent, Ca
/** /**
* Return a summary description of this query. * Return a summary description of this query.
*/ */
String getSummary() { String summary() {
StringBuilder sb = new StringBuilder(80); StringBuilder sb = new StringBuilder(80);
sb.append("FindAttr exeMicros[").append(executionTimeMicros) sb.append("FindAttr exeMicros[").append(executionTimeMicros)
.append("] rows[").append(rowCount) .append("] rows[").append(rowCount)
.append("] type[").append(desc.name()) .append("] type[").append(desc.name())
.append("] predicates[").append(predicates.getLogWhereSql()) .append("] predicates[").append(predicates.logWhereSql())
.append("] bind[").append(bindLog).append("]"); .append("] bind[").append(bindLog).append("]");
return sb.toString(); return sb.toString();
} }
@@ -75,6 +75,7 @@ final class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent, Ca
/** /**
* Execute the query returning the row count. * Execute the query returning the row count.
*/ */
@SuppressWarnings({"rawtypes", "unchecked"})
void findCollection(Collection result) throws SQLException { void findCollection(Collection result) throws SQLException {
long startNano = System.nanoTime(); long startNano = System.nanoTime();
try { try {
@@ -92,27 +93,27 @@ final class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent, Ca
if (queryPlan.executionTime(executionTimeMicros)) { if (queryPlan.executionTime(executionTimeMicros)) {
queryPlan.captureBindForQueryPlan(predicates, executionTimeMicros); queryPlan.captureBindForQueryPlan(predicates, executionTimeMicros);
} }
getTransaction().profileEvent(this); transaction().profileEvent(this);
} finally { } finally {
close(); close();
} }
} }
private SpiTransaction getTransaction() { private SpiTransaction transaction() {
return request.transaction(); return request.transaction();
} }
/** /**
* Return the bind log. * Return the bind log.
*/ */
String getBindLog() { String bindLog() {
return bindLog; return bindLog;
} }
/** /**
* Return the generated sql. * Return the generated sql.
*/ */
String getGeneratedSql() { String generatedSql() {
return sql; return sql;
} }
@@ -120,7 +121,7 @@ final class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent, Ca
lock.lock(); lock.lock();
try { try {
query.checkCancelled(); query.checkCancelled();
SpiTransaction t = getTransaction(); SpiTransaction t = transaction();
profileOffset = t.profileOffset(); profileOffset = t.profileOffset();
Connection conn = t.getInternalConnection(); Connection conn = t.getInternalConnection();
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
@@ -160,12 +161,12 @@ final class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent, Ca
@Override @Override
public void profile() { public void profile() {
getTransaction() transaction()
.profileStream() .profileStream()
.addQueryEvent(query.profileEventId(), profileOffset, desc.name(), rowCount, query.getProfileId()); .addQueryEvent(query.profileEventId(), profileOffset, desc.name(), rowCount, query.getProfileId());
} }
Set<String> getDependentTables() { Set<String> dependentTables() {
return queryPlan.dependentTables(); return queryPlan.dependentTables();
} }
@@ -40,30 +40,28 @@ final class CQueryHistorySupport {
/** /**
* Return the 'as of' history view for the given base table. * Return the 'as of' history view for the given base table.
*/ */
String getAsOfView(String table) { String asOfView(String table) {
return asOfTableMap.get(table); return asOfTableMap.get(table);
} }
/** /**
* Return the lower bound column. * Return the lower bound column.
*/ */
String getSysPeriodLower(String tableAlias) { String sysPeriodLower(String tableAlias) {
return dbHistorySupport.getSysPeriodLower(tableAlias, sysPeriod); return dbHistorySupport.getSysPeriodLower(tableAlias, sysPeriod);
} }
/** /**
* Return the upper bound column. * Return the upper bound column.
*/ */
String getSysPeriodUpper(String tableAlias) { String sysPeriodUpper(String tableAlias) {
return dbHistorySupport.getSysPeriodUpper(tableAlias, sysPeriod); return dbHistorySupport.getSysPeriodUpper(tableAlias, sysPeriod);
} }
/** /**
* Return the predicate appended to the end of the query. * Return the predicate appended to the end of the query.
* <p>
* Note used for Oracle total recall etc with the more standard approach.
*/ */
String getAsOfPredicate(String tableAlias) { String asOfPredicate(String tableAlias) {
return dbHistorySupport.getAsOfPredicate(tableAlias, sysPeriod); return dbHistorySupport.getAsOfPredicate(tableAlias, sysPeriod);
} }
@@ -11,9 +11,7 @@ import java.sql.SQLException;
final class CQueryIteratorSimple<T> implements QueryIterator<T> { final class CQueryIteratorSimple<T> implements QueryIterator<T> {
private final CQuery<T> cquery; private final CQuery<T> cquery;
private final OrmQueryRequest<T> request; private final OrmQueryRequest<T> request;
private boolean closed; private boolean closed;
CQueryIteratorSimple(CQuery<T> cquery, OrmQueryRequest<T> request) { CQueryIteratorSimple(CQuery<T> cquery, OrmQueryRequest<T> request) {
@@ -16,7 +16,6 @@ import java.util.List;
final class CQueryOrderBy { final class CQueryOrderBy {
private final BeanDescriptor<?> desc; private final BeanDescriptor<?> desc;
private final OrderBy<?> orderBy; private final OrderBy<?> orderBy;
/** /**
@@ -32,9 +31,7 @@ final class CQueryOrderBy {
} }
private String parseInternal() { private String parseInternal() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
List<Property> properties = orderBy.getProperties(); List<Property> properties = orderBy.getProperties();
if (properties.isEmpty()) { if (properties.isEmpty()) {
// order by clause removed by filterMany() // order by clause removed by filterMany()
@@ -52,7 +49,6 @@ final class CQueryOrderBy {
} }
private String parseProperty(Property p) { private String parseProperty(Property p) {
String propName = p.getProperty(); String propName = p.getProperty();
ElPropertyValue el = desc.elGetValue(propName); ElPropertyValue el = desc.elGetValue(propName);
if (el == null) { if (el == null) {
@@ -65,7 +61,6 @@ final class CQueryOrderBy {
IdBinder idBinder = ap.targetDescriptor().idBinder(); IdBinder idBinder = ap.targetDescriptor().idBinder();
return idBinder.getOrderBy(el.elName(), p.isAscending()); return idBinder.getOrderBy(el.elName(), p.isAscending());
} }
return p.toStringFormat(); return p.toStringFormat();
} }
} }
@@ -92,7 +92,7 @@ public class CQueryPlan implements SpiQueryPlan {
this.sqlTree = sqlTree; this.sqlTree = sqlTree;
this.rawSql = rawSql; this.rawSql = rawSql;
this.logWhereSql = logWhereSql; this.logWhereSql = logWhereSql;
this.encryptedProps = sqlTree.getEncryptedProps(); this.encryptedProps = sqlTree.encryptedProps();
this.stats = new CQueryPlanStats(this); this.stats = new CQueryPlanStats(this);
this.dependentTables = sqlTree.dependentTables(); this.dependentTables = sqlTree.dependentTables();
this.bindCapture = initBindCapture(query); this.bindCapture = initBindCapture(query);
@@ -117,7 +117,7 @@ public class CQueryPlan implements SpiQueryPlan {
this.sqlTree = sqlTree; this.sqlTree = sqlTree;
this.rawSql = false; this.rawSql = false;
this.logWhereSql = logWhereSql; this.logWhereSql = logWhereSql;
this.encryptedProps = sqlTree.getEncryptedProps(); this.encryptedProps = sqlTree.encryptedProps();
this.stats = new CQueryPlanStats(this); this.stats = new CQueryPlanStats(this);
this.dependentTables = sqlTree.dependentTables(); this.dependentTables = sqlTree.dependentTables();
this.bindCapture = initBindCaptureRaw(sql, query); this.bindCapture = initBindCaptureRaw(sql, query);
@@ -247,7 +247,7 @@ public class CQueryPlan implements SpiQueryPlan {
private String calcAuditQueryKey() { private String calcAuditQueryKey() {
// rawSql needs to include the MD5 hash of the sql // rawSql needs to include the MD5 hash of the sql
return rawSql ? planKey.getPartialKey() + "_" + hash : planKey.getPartialKey(); return rawSql ? planKey.partialKey() + "_" + hash : planKey.partialKey();
} }
final SqlTreePlan sqlTree() { final SqlTreePlan sqlTree() {
@@ -288,11 +288,11 @@ public class CQueryPlan implements SpiQueryPlan {
* Return the time this query plan was last used. * Return the time this query plan was last used.
*/ */
public final long lastQueryTime() { public final long lastQueryTime() {
return stats.getLastQueryTime(); return stats.lastQueryTime();
} }
final ScalarDataReader<?> singleAttributeScalarType() { final ScalarDataReader<?> singleAttributeScalarType() {
return sqlTree.getRootNode().getSingleAttributeReader(); return sqlTree.rootNode().singleAttributeReader();
} }
/** /**
@@ -62,7 +62,7 @@ public final class CQueryPlanManager implements QueryPlanManager {
while (req.hasNext()) { while (req.hasNext()) {
req.nextCapture(); req.nextCapture();
} }
return req.getPlans(); return req.plans();
} catch (SQLException e) { } catch (SQLException e) {
CoreLog.log.error("Error during query plan collection", e); CoreLog.log.error("Error during query plan collection", e);
return emptyList(); return emptyList();
@@ -34,7 +34,7 @@ final class CQueryPlanRequest {
/** /**
* Return the connection used to collect the db query plan. * Return the connection used to collect the db query plan.
*/ */
Connection getConnection() { Connection connection() {
return connection; return connection;
} }
@@ -48,14 +48,14 @@ final class CQueryPlanRequest {
/** /**
* Return the min epoch time in millis for minimum bind capture age. * Return the min epoch time in millis for minimum bind capture age.
*/ */
long getSince() { long since() {
return since; return since;
} }
/** /**
* Return the captured query plans. * Return the captured query plans.
*/ */
List<MetaQueryPlan> getPlans() { List<MetaQueryPlan> plans() {
return plans; return plans;
} }
@@ -50,7 +50,7 @@ public final class CQueryPlanStats {
/** /**
* Return the last time this query was executed. * Return the last time this query was executed.
*/ */
long getLastQueryTime() { long lastQueryTime() {
return lastQueryTime; return lastQueryTime;
} }
@@ -350,60 +350,60 @@ public final class CQueryPredicates {
/** /**
* Return the bind values for the where expression. * Return the bind values for the where expression.
*/ */
public List<Object> getWhereExprBindValues() { public List<Object> whereExprBindValues() {
return where == null ? Collections.emptyList() : where.getBindValues(); return where == null ? Collections.emptyList() : where.getBindValues();
} }
/** /**
* Return the db update set clause for an UpdateQuery. * Return the db update set clause for an UpdateQuery.
*/ */
String getDbUpdateClause() { String dbUpdateClause() {
return dbUpdateClause; return dbUpdateClause;
} }
/** /**
* Return the db column version of the combined where clause. * Return the db column version of the combined where clause.
*/ */
String getDbHaving() { String dbHaving() {
return dbHaving; return dbHaving;
} }
/** /**
* Return the db column version of the combined where clause. * Return the db column version of the combined where clause.
*/ */
String getDbWhere() { String dbWhere() {
return dbWhere; return dbWhere;
} }
/** /**
* Return a db filter for filtering many fetch joins. * Return a db filter for filtering many fetch joins.
*/ */
String getDbFilterMany() { String dbFilterMany() {
return dbFilterMany; return dbFilterMany;
} }
/** /**
* Return the db column version of the order by clause. * Return the db column version of the order by clause.
*/ */
String getDbOrderBy() { String dbOrderBy() {
return dbOrderBy; return dbOrderBy;
} }
/** /**
* Return the includes required for the where and order by clause. * Return the includes required for the where and order by clause.
*/ */
Set<String> getPredicateIncludes() { Set<String> predicateIncludes() {
return predicateIncludes; return predicateIncludes;
} }
/** /**
* Return the orderBy includes. * Return the orderBy includes.
*/ */
Set<String> getOrderByIncludes() { Set<String> orderByIncludes() {
return orderByIncludes; return orderByIncludes;
} }
String getLogWhereSql() { String logWhereSql() {
if (dbWhere == null && dbFilterMany == null) { if (dbWhere == null && dbFilterMany == null) {
return ""; return "";
} }
@@ -51,13 +51,13 @@ final class CQueryRowCount implements SpiProfileTransactionEvent, CancelableQuer
/** /**
* Return a summary description of this query. * Return a summary description of this query.
*/ */
public String getSummary() { public String summary() {
//noinspection StringBufferReplaceableByString //noinspection StringBufferReplaceableByString
StringBuilder sb = new StringBuilder(80); StringBuilder sb = new StringBuilder(80);
sb.append("FindCount exeMicros[").append(executionTimeMicros) sb.append("FindCount exeMicros[").append(executionTimeMicros)
.append("] rows[").append(rowCount) .append("] rows[").append(rowCount)
.append("] type[").append(desc.fullName()) .append("] type[").append(desc.fullName())
.append("] predicates[").append(predicates.getLogWhereSql()) .append("] predicates[").append(predicates.logWhereSql())
.append("] bind[").append(bindLog).append("]"); .append("] bind[").append(bindLog).append("]");
return sb.toString(); return sb.toString();
@@ -66,14 +66,14 @@ final class CQueryRowCount implements SpiProfileTransactionEvent, CancelableQuer
/** /**
* Return the bind log. * Return the bind log.
*/ */
public String getBindLog() { public String bindLog() {
return bindLog; return bindLog;
} }
/** /**
* Return the generated sql. * Return the generated sql.
*/ */
public String getGeneratedSql() { public String generatedSql() {
return sql; return sql;
} }
@@ -87,7 +87,7 @@ final class CQueryRowCount implements SpiProfileTransactionEvent, CancelableQuer
public int findCount() throws SQLException { public int findCount() throws SQLException {
long startNano = System.nanoTime(); long startNano = System.nanoTime();
try { try {
SpiTransaction t = getTransaction(); SpiTransaction t = transaction();
profileOffset = t.profileOffset(); profileOffset = t.profileOffset();
Connection conn = t.getInternalConnection(); Connection conn = t.getInternalConnection();
lock.lock(); lock.lock();
@@ -119,7 +119,7 @@ final class CQueryRowCount implements SpiProfileTransactionEvent, CancelableQuer
} }
} }
private SpiTransaction getTransaction() { private SpiTransaction transaction() {
return request.transaction(); return request.transaction();
} }
@@ -135,12 +135,12 @@ final class CQueryRowCount implements SpiProfileTransactionEvent, CancelableQuer
@Override @Override
public void profile() { public void profile() {
getTransaction() transaction()
.profileStream() .profileStream()
.addQueryEvent(query.profileEventId(), profileOffset, desc.name(), rowCount, query.getProfileId()); .addQueryEvent(query.profileEventId(), profileOffset, desc.name(), rowCount, query.getProfileId());
} }
Set<String> getDependentTables() { Set<String> dependentTables() {
return queryPlan.dependentTables(); return queryPlan.dependentTables();
} }
@@ -47,14 +47,14 @@ final class CQueryUpdate implements SpiProfileTransactionEvent, CancelableQuery
/** /**
* Return the bind log. * Return the bind log.
*/ */
public String getBindLog() { public String bindLog() {
return bindLog; return bindLog;
} }
/** /**
* Return the generated sql. * Return the generated sql.
*/ */
public String getGeneratedSql() { public String generatedSql() {
return sql; return sql;
} }
@@ -64,7 +64,7 @@ final class CQueryUpdate implements SpiProfileTransactionEvent, CancelableQuery
public int execute() throws SQLException { public int execute() throws SQLException {
long startNano = System.nanoTime(); long startNano = System.nanoTime();
try { try {
SpiTransaction t = getTransaction(); SpiTransaction t = transaction();
profileOffset = t.profileOffset(); profileOffset = t.profileOffset();
Connection conn = t.getInternalConnection(); Connection conn = t.getInternalConnection();
lock.lock(); lock.lock();
@@ -97,7 +97,7 @@ final class CQueryUpdate implements SpiProfileTransactionEvent, CancelableQuery
return executionTimeMicros; return executionTimeMicros;
} }
private SpiTransaction getTransaction() { private SpiTransaction transaction() {
return request.transaction(); return request.transaction();
} }
@@ -111,7 +111,7 @@ final class CQueryUpdate implements SpiProfileTransactionEvent, CancelableQuery
@Override @Override
public void profile() { public void profile() {
getTransaction() transaction()
.profileStream() .profileStream()
.addQueryEvent(query.profileEventId(), profileOffset, desc.name(), rowCount, query.getProfileId()); .addQueryEvent(query.profileEventId(), profileOffset, desc.name(), rowCount, query.getProfileId());
} }
@@ -94,7 +94,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
} }
@Override @Override
public BeanProperty[] getEncryptedProps() { public BeanProperty[] encryptedProps() {
if (encryptedProps == null) { if (encryptedProps == null) {
return null; return null;
} }
@@ -125,13 +125,13 @@ final class DefaultDbSqlContext implements DbSqlContext {
sb.append(" ").append(type); sb.append(" ").append(type);
boolean addAsOfOnClause = false; boolean addAsOfOnClause = false;
if (draftSupport != null) { if (draftSupport != null) {
appendTable(table, draftSupport.getDraftTable(table)); appendTable(table, draftSupport.draftTable(table));
} else if (!historyQuery) { } else if (!historyQuery) {
sb.append(" ").append(table).append(" "); sb.append(" ").append(table).append(" ");
} else { } else {
// check if there is an associated history table and if so // check if there is an associated history table and if so
// use the unionAll view - we expect an additional predicate to match // use the unionAll view - we expect an additional predicate to match
String asOfView = historySupport.getAsOfView(table); String asOfView = historySupport.asOfView(table);
appendTable(table, asOfView); appendTable(table, asOfView);
if (asOfView != null) { if (asOfView != null) {
if (historySupport.isStandardsBased()) { if (historySupport.isStandardsBased()) {
@@ -161,7 +161,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
} }
} }
if (addAsOfOnClause) { if (addAsOfOnClause) {
sb.append(" and ").append(historySupport.getAsOfPredicate(a2)); sb.append(" and ").append(historySupport.asOfPredicate(a2));
asOfTableCount++; asOfTableCount++;
} }
if (extraWhere != null && !extraWhere.isEmpty()) { if (extraWhere != null && !extraWhere.isEmpty()) {
@@ -191,17 +191,17 @@ final class DefaultDbSqlContext implements DbSqlContext {
} }
@Override @Override
public String getTableAlias(String prefix) { public String tableAlias(String prefix) {
return alias.getTableAlias(prefix); return alias.tableAlias(prefix);
} }
@Override @Override
public String getTableAliasManyWhere(String prefix) { public String tableAliasManyWhere(String prefix) {
return alias.getTableAliasManyWhere(prefix); return alias.tableAliasManyWhere(prefix);
} }
@Override @Override
public String getRelativePrefix(String propName) { public String relativePrefix(String propName) {
return currentPrefix == null ? propName : currentPrefix + "." + propName; return currentPrefix == null ? propName : currentPrefix + "." + propName;
} }
@@ -209,7 +209,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
public void pushTableAlias(String prefix) { public void pushTableAlias(String prefix) {
prefixStack.push(currentPrefix); prefixStack.push(currentPrefix);
currentPrefix = prefix; currentPrefix = prefix;
tableAliasStack.push(getTableAlias(prefix)); tableAliasStack.push(tableAlias(prefix));
} }
@Override @Override
@@ -227,7 +227,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
@Override @Override
public void appendFormulaJoin(String sqlFormulaJoin, SqlJoinType joinType, String manyWhere) { public void appendFormulaJoin(String sqlFormulaJoin, SqlJoinType joinType, String manyWhere) {
// replace ${ta} placeholder with the real table alias... // replace ${ta} placeholder with the real table alias...
String tableAlias = manyWhere == null ? tableAliasStack.peek() : getTableAliasManyWhere(manyWhere); String tableAlias = manyWhere == null ? tableAliasStack.peek() : tableAliasManyWhere(manyWhere);
String converted = sqlFormulaJoin.replace(tableAliasPlaceHolder, tableAlias); String converted = sqlFormulaJoin.replace(tableAliasPlaceHolder, tableAlias);
if (formulaJoins == null) { if (formulaJoins == null) {
formulaJoins = new HashSet<>(); formulaJoins = new HashSet<>();
@@ -272,10 +272,10 @@ final class DefaultDbSqlContext implements DbSqlContext {
public void appendHistorySysPeriod() { public void appendHistorySysPeriod() {
String tableAlias = tableAliasStack.peek(); String tableAlias = tableAliasStack.peek();
sb.append(COMMA); sb.append(COMMA);
sb.append(historySupport.getSysPeriodLower(tableAlias)); sb.append(historySupport.sysPeriodLower(tableAlias));
appendColumnAlias(); appendColumnAlias();
sb.append(COMMA); sb.append(COMMA);
sb.append(historySupport.getSysPeriodUpper(tableAlias)); sb.append(historySupport.sysPeriodUpper(tableAlias));
appendColumnAlias(); appendColumnAlias();
} }
@@ -325,7 +325,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
} }
@Override @Override
public String getContent() { public String content() {
String s = sb.toString(); String s = sb.toString();
sb = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); sb = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY);
return s; return s;
@@ -48,9 +48,7 @@ import java.util.stream.Stream;
final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQueryFetch { final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQueryFetch {
private static final FetchConfig FETCH_CACHE = FetchConfig.ofCache(); private static final FetchConfig FETCH_CACHE = FetchConfig.ofCache();
private static final FetchConfig FETCH_QUERY = FetchConfig.ofQuery(); private static final FetchConfig FETCH_QUERY = FetchConfig.ofQuery();
private static final FetchConfig FETCH_LAZY = FetchConfig.ofLazy(); private static final FetchConfig FETCH_LAZY = FetchConfig.ofLazy();
private OrmQueryDetail detail = new OrmQueryDetail(); private OrmQueryDetail detail = new OrmQueryDetail();
@@ -26,11 +26,8 @@ import java.util.function.Predicate;
public final class DefaultRelationalQueryEngine implements RelationalQueryEngine { public final class DefaultRelationalQueryEngine implements RelationalQueryEngine {
private final Binder binder; private final Binder binder;
private final String dbTrueValue; private final String dbTrueValue;
private final boolean binaryOptimizedUUID; private final boolean binaryOptimizedUUID;
private final TimedMetricMap timedMetricMap; private final TimedMetricMap timedMetricMap;
public DefaultRelationalQueryEngine(Binder binder, String dbTrueValue, boolean binaryOptimizedUUID) { public DefaultRelationalQueryEngine(Binder binder, String dbTrueValue, boolean binaryOptimizedUUID) {
@@ -10,7 +10,7 @@ public final class ExtraJoin {
this.containsMany = containsMany; this.containsMany = containsMany;
} }
public STreePropertyAssoc getProperty() { public STreePropertyAssoc property() {
return property; return property;
} }
@@ -15,19 +15,13 @@ import java.util.concurrent.locks.ReentrantLock;
public final class LimitOffsetPagedList<T> implements PagedList<T> { public final class LimitOffsetPagedList<T> implements PagedList<T> {
private final transient SpiEbeanServer server; private final transient SpiEbeanServer server;
private final transient ReentrantLock lock = new ReentrantLock(); private final transient ReentrantLock lock = new ReentrantLock();
private final SpiQuery<T> query; private final SpiQuery<T> query;
private final int firstRow; private final int firstRow;
private final int maxRows; private final int maxRows;
private int foregroundTotalRowCount = -1; private int foregroundTotalRowCount = -1;
private Future<Integer> futureRowCount; private Future<Integer> futureRowCount;
private List<T> list; private List<T> list;
/** /**
@@ -15,7 +15,7 @@ public class NativeSqlQueryPlanKey implements CQueryPlanKey {
@Override @Override
public String toString() { public String toString() {
return getPartialKey(); return partialKey();
} }
@Override @Override
@@ -29,7 +29,7 @@ public class NativeSqlQueryPlanKey implements CQueryPlanKey {
* can be used as a short form proxy for the actual sql. * can be used as a short form proxy for the actual sql.
*/ */
@Override @Override
public String getPartialKey() { public String partialKey() {
return hashCode() + "_n"; return hashCode() + "_n";
} }
@@ -17,7 +17,6 @@ final class OrderVersionDesc implements Comparator<Version<?>>, Serializable {
@Override @Override
public int compare(Version<?> o1, Version<?> o2) { public int compare(Version<?> o1, Version<?> o2) {
Timestamp v1 = o1.getStart(); Timestamp v1 = o1.getStart();
if (v1 == null) { if (v1 == null) {
return 1; return 1;
@@ -19,11 +19,11 @@ public final class QueryFutureIds<T> extends BaseFuture<List<Object>> implements
this.call = call; this.call = call;
} }
public FutureTask<List<Object>> getFutureTask() { public FutureTask<List<Object>> futureTask() {
return futureTask; return futureTask;
} }
public Transaction getTransaction() { public Transaction transaction() {
return call.transaction; return call.transaction;
} }
@@ -23,11 +23,11 @@ public final class QueryFutureList<T> extends BaseFuture<List<T>> implements Fut
this.call = call; this.call = call;
} }
public FutureTask<List<T>> getFutureTask() { public FutureTask<List<T>> futureTask() {
return futureTask; return futureTask;
} }
public Transaction getTransaction() { public Transaction transaction() {
return call.transaction; return call.transaction;
} }
@@ -17,11 +17,11 @@ public final class QueryFutureRowCount<T> extends BaseFuture<Integer> implements
this.call = call; this.call = call;
} }
public FutureTask<Integer> getFutureTask() { public FutureTask<Integer> futureTask() {
return futureTask; return futureTask;
} }
public Transaction getTransaction() { public Transaction transaction() {
return call.transaction; return call.transaction;
} }
@@ -21,7 +21,7 @@ final class RawSqlQueryPlanKey implements CQueryPlanKey {
@Override @Override
public String toString() { public String toString() {
return getPartialKey() + ":r"; return partialKey() + ":r";
} }
@Override @Override
@@ -35,7 +35,7 @@ final class RawSqlQueryPlanKey implements CQueryPlanKey {
* can be used as a short form proxy for the actual sql. * can be used as a short form proxy for the actual sql.
*/ */
@Override @Override
public String getPartialKey() { public String partialKey() {
return hashCode() + "_0"; return hashCode() + "_0";
} }
@@ -23,5 +23,5 @@ public interface STreePropertyAssocOne extends STreePropertyAssoc {
/** /**
* Return the property value as an entity bean from the parent. * Return the property value as an entity bean from the parent.
*/ */
EntityBean getValueAsEntityBean(EntityBean parentBean); EntityBean valueAsEntityBean(EntityBean parentBean);
} }
@@ -136,10 +136,8 @@ public interface STreeType {
/** /**
* Mark the bean as deleted by setting the softDelete property to true. * Mark the bean as deleted by setting the softDelete property to true.
*
* This works also, if there is only a virtual softDelete property computed by a formula. * This works also, if there is only a virtual softDelete property computed by a formula.
* * If there is no soft delete property, it sets the lazyLoadFailure flag in EBI.
* If there is no softdelete property, it sets the lazyLoadFailure flag in EBI.
*/ */
void markAsDeleted(EntityBean bean); void markAsDeleted(EntityBean bean);
@@ -30,7 +30,7 @@ public enum SqlJoinType {
* Return the actual SQL join literal taking into account the current join type and the 'default * Return the actual SQL join literal taking into account the current join type and the 'default
* join type as per deployment cardinality and optionality'. * join type as per deployment cardinality and optionality'.
*/ */
public String getLiteral(SqlJoinType deploymentJoinType) { public String literal(SqlJoinType deploymentJoinType) {
if (this == SqlJoinType.AUTO) { if (this == SqlJoinType.AUTO) {
return deploymentJoinType.literal; return deploymentJoinType.literal;
} }
@@ -88,33 +88,33 @@ final class SqlTree {
return list; return list;
} }
String getDistinctOn() { String distinctOn() {
return distinctOn; return distinctOn;
} }
/** /**
* Return the String for the actual SQL. * Return the String for the actual SQL.
*/ */
String getSelectSql() { String selectSql() {
assert selectSql != null : "selectSql was null"; assert selectSql != null : "selectSql was null";
return selectSql; return selectSql;
} }
String getFromSql() { String fromSql() {
return fromSql; return fromSql;
} }
/** /**
* Return the groupBy clause. * Return the groupBy clause.
*/ */
String getGroupBy() { String groupBy() {
return groupBy; return groupBy;
} }
/** /**
* Return the where clause for inheritance. * Return the where clause for inheritance.
*/ */
String getInheritanceWhereSql() { String inheritanceWhereSql() {
return inheritanceWhereSql; return inheritanceWhereSql;
} }
@@ -122,7 +122,7 @@ final class SqlTree {
* Return the property that is associated with the many. There can only be one * Return the property that is associated with the many. There can only be one
* per SqlSelect. This can be null. * per SqlSelect. This can be null.
*/ */
STreePropertyAssocMany getManyProperty() { STreePropertyAssocMany manyProperty() {
return manyProperty; return manyProperty;
} }
@@ -89,7 +89,7 @@ final class SqlTreeAlias {
for (String propJoin : embeddedPropertyJoins) { for (String propJoin : embeddedPropertyJoins) {
String[] split = SplitName.split(propJoin); String[] split = SplitName.split(propJoin);
// the table alias of the parent path // the table alias of the parent path
String alias = getTableAlias(split[0]); String alias = tableAlias(split[0]);
aliasMap.put(propJoin, alias); aliasMap.put(propJoin, alias);
} }
} }
@@ -109,7 +109,7 @@ final class SqlTreeAlias {
/** /**
* Return the table alias for a given property name. * Return the table alias for a given property name.
*/ */
String getTableAlias(String prefix) { String tableAlias(String prefix) {
if (prefix == null) { if (prefix == null) {
return rootTableAlias; return rootTableAlias;
} else { } else {
@@ -124,7 +124,7 @@ final class SqlTreeAlias {
/** /**
* Return an alias using "Many where joins". * Return an alias using "Many where joins".
*/ */
String getTableAliasManyWhere(String prefix) { String tableAliasManyWhere(String prefix) {
if (prefix == null) { if (prefix == null) {
return rootTableAlias; return rootTableAlias;
} }
@@ -104,8 +104,8 @@ public final class SqlTreeBuilder {
this.distinctOnPlatform = builder.isPlatformDistinctOn(); this.distinctOnPlatform = builder.isPlatformDistinctOn();
this.distinctNoLobs = builder.isPlatformDistinctNoLobs(); this.distinctNoLobs = builder.isPlatformDistinctNoLobs();
String fromForUpdate = builder.fromForUpdate(query); String fromForUpdate = builder.fromForUpdate(query);
CQueryHistorySupport historySupport = builder.getHistorySupport(query); CQueryHistorySupport historySupport = builder.historySupport(query);
CQueryDraftSupport draftSupport = builder.getDraftSupport(query); CQueryDraftSupport draftSupport = builder.draftSupport(query);
String colAlias = subQuery ? null : columnAliasPrefix; String colAlias = subQuery ? null : columnAliasPrefix;
this.ctx = new DefaultDbSqlContext(alias, colAlias, historySupport, draftSupport, fromForUpdate); this.ctx = new DefaultDbSqlContext(alias, colAlias, historySupport, draftSupport, fromForUpdate);
} }
@@ -129,7 +129,7 @@ public final class SqlTreeBuilder {
inheritanceWhereSql = buildWhereClause(); inheritanceWhereSql = buildWhereClause();
groupBy = buildGroupByClause(); groupBy = buildGroupByClause();
distinctOn = buildDistinctOn(); distinctOn = buildDistinctOn();
encryptedProps = ctx.getEncryptedProps(); encryptedProps = ctx.encryptedProps();
query.incrementAsOfTableCount(ctx.asOfTableCount()); query.incrementAsOfTableCount(ctx.asOfTableCount());
} }
@@ -146,7 +146,7 @@ public final class SqlTreeBuilder {
return "1"; return "1";
} }
rootNode.appendSelect(ctx, subQuery); rootNode.appendSelect(ctx, subQuery);
return trimComma(ctx.getContent()); return trimComma(ctx.content());
} }
private String buildGroupByClause() { private String buildGroupByClause() {
@@ -155,7 +155,7 @@ public final class SqlTreeBuilder {
} }
ctx.startGroupBy(); ctx.startGroupBy();
rootNode.appendGroupBy(ctx, subQuery); rootNode.appendGroupBy(ctx, subQuery);
return trimComma(ctx.getContent()); return trimComma(ctx.content());
} }
private String buildDistinctOn() { private String buildDistinctOn() {
@@ -164,8 +164,8 @@ public final class SqlTreeBuilder {
} }
ctx.startGroupBy(); ctx.startGroupBy();
rootNode.appendDistinctOn(ctx, subQuery); rootNode.appendDistinctOn(ctx, subQuery);
String idCols = trimComma(ctx.getContent()); String idCols = trimComma(ctx.content());
return idCols == null ? null : mergeOnDistinct(idCols, predicates.getDbOrderBy()); return idCols == null ? null : mergeOnDistinct(idCols, predicates.dbOrderBy());
} }
static String mergeOnDistinct(String idCols, String dbOrderBy) { static String mergeOnDistinct(String idCols, String dbOrderBy) {
@@ -201,7 +201,7 @@ public final class SqlTreeBuilder {
return "Not Used"; return "Not Used";
} }
rootNode.appendWhere(ctx); rootNode.appendWhere(ctx);
return ctx.getContent(); return ctx.content();
} }
private String buildFromClause() { private String buildFromClause() {
@@ -209,14 +209,14 @@ public final class SqlTreeBuilder {
return "Not Used"; return "Not Used";
} }
rootNode.appendFrom(ctx, SqlJoinType.AUTO); rootNode.appendFrom(ctx, SqlJoinType.AUTO);
return ctx.getContent(); return ctx.content();
} }
private void buildRoot(STreeType desc) { private void buildRoot(STreeType desc) {
rootNode = buildSelectChain(null, null, desc, null); rootNode = buildSelectChain(null, null, desc, null);
if (!rawSql) { if (!rawSql) {
alias.addJoin(queryDetail.getFetchPaths(), desc); alias.addJoin(queryDetail.getFetchPaths(), desc);
alias.addJoin(predicates.getPredicateIncludes(), desc); alias.addJoin(predicates.predicateIncludes(), desc);
alias.addManyWhereJoins(manyWhereJoins.getPropertyNames()); alias.addManyWhereJoins(manyWhereJoins.getPropertyNames());
// build set of table alias // build set of table alias
alias.buildAlias(); alias.buildAlias();
@@ -348,7 +348,7 @@ public final class SqlTreeBuilder {
if (rawSql) { if (rawSql) {
return; return;
} }
Set<String> predicateIncludes = predicates.getPredicateIncludes(); Set<String> predicateIncludes = predicates.predicateIncludes();
if (predicateIncludes == null) { if (predicateIncludes == null) {
return; return;
} }
@@ -360,7 +360,7 @@ public final class SqlTreeBuilder {
// remove ManyWhereJoins from the predicateIncludes // remove ManyWhereJoins from the predicateIncludes
predicateIncludes.removeAll(manyWhereJoins.getPropertyNames()); predicateIncludes.removeAll(manyWhereJoins.getPropertyNames());
predicateIncludes.addAll(predicates.getOrderByIncludes()); predicateIncludes.addAll(predicates.orderByIncludes());
// look for predicateIncludes that are not in selectIncludes and add // look for predicateIncludes that are not in selectIncludes and add
// them as extra joins to the query // them as extra joins to the query
@@ -641,7 +641,7 @@ public final class SqlTreeBuilder {
SqlTreeNodeExtraJoin root = findExtraJoinRoot(includeProp, extraJoin); SqlTreeNodeExtraJoin root = findExtraJoinRoot(includeProp, extraJoin);
// register the root because these are the only ones we // register the root because these are the only ones we
// return back. // return back.
rootRegister.put(root.getName(), root); rootRegister.put(root.name(), root);
} }
} }
@@ -653,7 +653,7 @@ public final class SqlTreeBuilder {
if (extra == null) { if (extra == null) {
return null; return null;
} else { } else {
SqlTreeNodeExtraJoin extraJoin = new SqlTreeNodeExtraJoin(propertyName, extra.getProperty(), extra.isContainsMany(), temporalMode); SqlTreeNodeExtraJoin extraJoin = new SqlTreeNodeExtraJoin(propertyName, extra.property(), extra.isContainsMany(), temporalMode);
joinRegister.put(propertyName, extraJoin); joinRegister.put(propertyName, extraJoin);
return extraJoin; return extraJoin;
} }
@@ -23,6 +23,6 @@ interface SqlTreeLoad {
/** /**
* Return the reader for the single attribute query. * Return the reader for the single attribute query.
*/ */
ScalarDataReader<?> getSingleAttributeReader(); ScalarDataReader<?> singleAttributeReader();
} }
@@ -73,14 +73,14 @@ class SqlTreeLoadBean implements SqlTreeLoad {
} }
@Override @Override
public final ScalarDataReader<?> getSingleAttributeReader() { public final ScalarDataReader<?> singleAttributeReader() {
if (properties == null || properties.length == 0) { if (properties == null || properties.length == 0) {
// if we have no property ask first children (in a distinct select with join) // if we have no property ask first children (in a distinct select with join)
if (children.length == 0) { if (children.length == 0) {
// expected to be a findIds query // expected to be a findIds query
return desc.idBinder().getBeanProperty(); return desc.idBinder().getBeanProperty();
} }
return children[0].getSingleAttributeReader(); return children[0].singleAttributeReader();
} }
if (properties[0] instanceof STreePropertyAssocOne) { if (properties[0] instanceof STreePropertyAssocOne) {
STreePropertyAssocOne assocOne = (STreePropertyAssocOne)properties[0]; STreePropertyAssocOne assocOne = (STreePropertyAssocOne)properties[0];
@@ -208,7 +208,7 @@ class SqlTreeLoadBean implements SqlTreeLoad {
localBean = null; localBean = null;
// ... but there may exist as reference bean in parent which has to be marked as deleted. // ... but there may exist as reference bean in parent which has to be marked as deleted.
if (parentBean != null && nodeBeanProp instanceof STreePropertyAssocOne) { if (parentBean != null && nodeBeanProp instanceof STreePropertyAssocOne) {
contextBean = ((STreePropertyAssocOne)nodeBeanProp).getValueAsEntityBean(parentBean); contextBean = ((STreePropertyAssocOne)nodeBeanProp).valueAsEntityBean(parentBean);
if (contextBean != null) { if (contextBean != null) {
desc.markAsDeleted(contextBean); desc.markAsDeleted(contextBean);
} }
@@ -94,7 +94,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
this.disableLazyLoad = disableLazyLoad || !readIdNormal || desc.isRawSqlBased(); this.disableLazyLoad = disableLazyLoad || !readIdNormal || desc.isRawSqlBased();
this.readOnly = readOnly; this.readOnly = readOnly;
this.partialObject = props.isPartialObject(); this.partialObject = props.isPartialObject();
this.properties = props.getProps(); this.properties = props.props();
this.children = myChildren == null ? Collections.emptyList() : myChildren; this.children = myChildren == null ? Collections.emptyList() : myChildren;
this.pathMap = createPathMap(prefix, desc); this.pathMap = createPathMap(prefix, desc);
} }
@@ -248,7 +248,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
if (ctx.length() > 0) { if (ctx.length() > 0) {
ctx.append(" and"); ctx.append(" and");
} }
ctx.append(" ").append(ctx.getTableAlias(prefix)).append("."); ctx.append(" ").append(ctx.tableAlias(prefix)).append(".");
ctx.append(inheritInfo.getWhere()); ctx.append(inheritInfo.getWhere());
} }
} }
@@ -263,7 +263,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
if (ctx.length() > 0) { if (ctx.length() > 0) {
ctx.append(" and"); ctx.append(" and");
} }
String ta = ctx.getTableAlias(prefix); String ta = ctx.tableAlias(prefix);
ctx.append(" ").append(extraWhere.replace("${ta}", ta)); ctx.append(" ").append(extraWhere.replace("${ta}", ta));
} }
} }
@@ -280,7 +280,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
ctx.pushJoin(prefix); ctx.pushJoin(prefix);
ctx.pushTableAlias(prefix); ctx.pushTableAlias(prefix);
baseTableAlias = ctx.getTableAlias(prefix); baseTableAlias = ctx.tableAlias(prefix);
// join and return SqlJoinType to use for child joins // join and return SqlJoinType to use for child joins
joinType = appendFromBaseTable(ctx, joinType); joinType = appendFromBaseTable(ctx, joinType);
for (STreeProperty property : properties) { for (STreeProperty property : properties) {
@@ -325,7 +325,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
appendJoinDiscriminator(ctx); appendJoinDiscriminator(ctx);
} }
if (desc.isSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) { if (desc.isSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) {
ctx.append(" and ").append(desc.softDeletePredicate(ctx.getTableAlias(prefix))); ctx.append(" and ").append(desc.softDeletePredicate(ctx.tableAlias(prefix)));
} }
return sqlJoinType; return sqlJoinType;
} }
@@ -335,9 +335,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
STreePropertyAssocMany manyProp = (STreePropertyAssocMany) nodeBeanProp; STreePropertyAssocMany manyProp = (STreePropertyAssocMany) nodeBeanProp;
if (manyProp.hasJoinTable()) { if (manyProp.hasJoinTable()) {
String alias = ctx.getTableAlias(prefix); String alias = ctx.tableAlias(prefix);
String[] split = SplitName.split(prefix); String[] split = SplitName.split(prefix);
String parentAlias = ctx.getTableAlias(split[0]); String parentAlias = ctx.tableAlias(split[0]);
String alias2 = alias + "z_"; String alias2 = alias + "z_";
// adding the additional join to the intersection table // adding the additional join to the intersection table
@@ -354,7 +354,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
void appendJoinDiscriminator(DbSqlContext ctx) { void appendJoinDiscriminator(DbSqlContext ctx) {
if (inheritInfo.getWhere() == null) return; if (inheritInfo.getWhere() == null) return;
String alias = ctx.getTableAlias(prefix); String alias = ctx.tableAlias(prefix);
ctx.append(" and ").append(alias).append(".").append(inheritInfo.getWhere()); ctx.append(" and ").append(alias).append(".").append(inheritInfo.getWhere());
} }
@@ -85,7 +85,7 @@ final class SqlTreeNodeExtraJoin implements SqlTreeNode {
return manyJoin; return manyJoin;
} }
public String getName() { public String name() {
return prefix; return prefix;
} }
@@ -115,9 +115,9 @@ final class SqlTreeNodeExtraJoin implements SqlTreeNode {
manyToMany = true; manyToMany = true;
String alias = ctx.getTableAlias(prefix); String alias = ctx.tableAlias(prefix);
String[] split = SplitName.split(prefix); String[] split = SplitName.split(prefix);
String parentAlias = ctx.getTableAlias(split[0]); String parentAlias = ctx.tableAlias(split[0]);
String alias2 = alias + "z_"; String alias2 = alias + "z_";
TableJoin manyToManyJoin = manyProp.intersectionTableJoin(); TableJoin manyToManyJoin = manyProp.intersectionTableJoin();
@@ -146,7 +146,7 @@ final class SqlTreeNodeExtraJoin implements SqlTreeNode {
} }
joinType = assocBeanProperty.addJoin(joinType, prefix, ctx); joinType = assocBeanProperty.addJoin(joinType, prefix, ctx);
if (!oneToOneExported && assocBeanProperty.isTargetSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) { if (!oneToOneExported && assocBeanProperty.isTargetSoftDelete() && temporalMode != SpiQuery.TemporalMode.SOFT_DELETED) {
ctx.append(" and ").append(assocBeanProperty.softDeletePredicate(ctx.getTableAlias(prefix))); ctx.append(" and ").append(assocBeanProperty.softDeletePredicate(ctx.tableAlias(prefix)));
} }
} }
@@ -73,7 +73,6 @@ final class SqlTreeNodeManyWhereJoin implements SqlTreeNode {
*/ */
@Override @Override
public void appendFrom(DbSqlContext ctx, SqlJoinType currentJoinType) { public void appendFrom(DbSqlContext ctx, SqlJoinType currentJoinType) {
// always use the join type as per this many where join // always use the join type as per this many where join
// (OUTER for disjunction and otherwise INNER) // (OUTER for disjunction and otherwise INNER)
appendFromBaseTable(ctx, manyJoinType); appendFromBaseTable(ctx, manyJoinType);
@@ -84,9 +83,8 @@ final class SqlTreeNodeManyWhereJoin implements SqlTreeNode {
* intersection table if this is a ManyToMany node. * intersection table if this is a ManyToMany node.
*/ */
private void appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) { private void appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) {
String alias = ctx.tableAliasManyWhere(prefix);
String alias = ctx.getTableAliasManyWhere(prefix); String parentAlias = ctx.tableAliasManyWhere(parentPrefix);
String parentAlias = ctx.getTableAliasManyWhere(parentPrefix);
if (nodeBeanProp instanceof STreePropertyAssocOne) { if (nodeBeanProp instanceof STreePropertyAssocOne) {
nodeBeanProp.addJoin(joinType, parentAlias, alias, ctx); nodeBeanProp.addJoin(joinType, parentAlias, alias, ctx);
@@ -16,7 +16,7 @@ final class SqlTreePlan {
this.dependentTables = dependentTables; this.dependentTables = dependentTables;
} }
SqlTreeRoot getRootNode() { SqlTreeRoot rootNode() {
return (SqlTreeRoot)rootNode; return (SqlTreeRoot)rootNode;
} }
@@ -24,11 +24,11 @@ final class SqlTreePlan {
* Return the property that is associated with the many. There can only be one * Return the property that is associated with the many. There can only be one
* per SqlSelect. This can be null. * per SqlSelect. This can be null.
*/ */
STreePropertyAssocMany getManyProperty() { STreePropertyAssocMany manyProperty() {
return manyProperty; return manyProperty;
} }
STreeProperty[] getEncryptedProps() { STreeProperty[] encryptedProps() {
return encryptedProps; return encryptedProps;
} }
@@ -53,7 +53,7 @@ public final class SqlTreeProperties {
} }
} }
public STreeProperty[] getProps() { public STreeProperty[] props() {
return propsList.toArray(new STreeProperty[0]); return propsList.toArray(new STreeProperty[0]);
} }
@@ -29,6 +29,6 @@ interface SqlTreeRoot {
/** /**
* Return a Scalar single attribute reader based on the first property. * Return a Scalar single attribute reader based on the first property.
*/ */
ScalarDataReader<?> getSingleAttributeReader(); ScalarDataReader<?> singleAttributeReader();
} }
@@ -33,7 +33,7 @@ final class OrmQueryPlanKey implements CQueryPlanKey {
} }
@Override @Override
public String getPartialKey() { public String partialKey() {
return description; return description;
} }
@@ -30,7 +30,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
FutureRowCount<Customer> futureRowCount = query.findFutureCount(); FutureRowCount<Customer> futureRowCount = query.findFutureCount();
QueryFutureRowCount<Customer> internalRowCount = (QueryFutureRowCount<Customer>) futureRowCount; QueryFutureRowCount<Customer> internalRowCount = (QueryFutureRowCount<Customer>) futureRowCount;
Transaction t = internalRowCount.getTransaction(); Transaction t = internalRowCount.transaction();
try { try {
futureRowCount.get(); futureRowCount.get();
@@ -57,7 +57,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
FutureIds<Customer> futureIds = query.findFutureIds(); FutureIds<Customer> futureIds = query.findFutureIds();
QueryFutureIds<Customer> internalFuture = (QueryFutureIds<Customer>) futureIds; QueryFutureIds<Customer> internalFuture = (QueryFutureIds<Customer>) futureIds;
Transaction t = internalFuture.getTransaction(); Transaction t = internalFuture.transaction();
try { try {
internalFuture.get(); internalFuture.get();
@@ -85,7 +85,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
FutureList<Customer> futureList = query.findFutureList(); FutureList<Customer> futureList = query.findFutureList();
QueryFutureList<Customer> internalFuture = (QueryFutureList<Customer>) futureList; QueryFutureList<Customer> internalFuture = (QueryFutureList<Customer>) futureList;
Transaction t = internalFuture.getTransaction(); Transaction t = internalFuture.transaction();
try { try {
internalFuture.get(); internalFuture.get();