This is an automated email from the ASF dual-hosted git repository. ntimofeev pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push: new e62c319 CAY-2644 Use Property interface instead of BaseProperty new ff21bcf Merge pull request #409 from stariy95/4.2-IMPROVEMENT-property-interface e62c319 is described below commit e62c31998403d9d407aa372bcd4ccdbe4430b3cc Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Mon Dec 23 17:02:54 2019 +0300 CAY-2644 Use Property interface instead of BaseProperty --- .../select/CustomColumnSetExtractor.java | 20 +++++------ .../translator/select/FluentSelectWrapper.java | 4 +-- .../translator/select/QualifierTranslator.java | 3 +- .../translator/select/ResultNodeDescriptor.java | 8 ++--- .../translator/select/SelectQueryWrapper.java | 3 +- .../select/TranslatableQueryWrapper.java | 4 +-- .../translator/select/TranslatorContext.java | 6 ++-- .../main/java/org/apache/cayenne/exp/Property.java | 4 +-- .../org/apache/cayenne/exp/property/Property.java | 5 +++ .../org/apache/cayenne/query/ColumnSelect.java | 36 +++++++++---------- .../apache/cayenne/query/ColumnSelectMetadata.java | 8 ++--- .../org/apache/cayenne/query/FluentSelect.java | 4 +-- .../org/apache/cayenne/query/ObjectSelect.java | 40 +++++++++++----------- .../apache/cayenne/query/ObjectSelectMetadata.java | 4 +-- .../java/org/apache/cayenne/query/SelectQuery.java | 14 ++++---- .../apache/cayenne/query/SelectQueryMetadata.java | 10 +++--- .../select/CustomColumnSetExtractorTest.java | 3 +- .../translator/select/MockQueryWrapperBuilder.java | 7 ++-- .../org/apache/cayenne/query/ColumnSelectTest.java | 8 ++--- 19 files changed, 100 insertions(+), 91 deletions(-) diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java index 1519b60..8224c1b 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java @@ -29,7 +29,7 @@ import org.apache.cayenne.access.sqlbuilder.sqltree.Node; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; import org.apache.cayenne.exp.parser.ASTDbPath; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.EmbeddedAttribute; import org.apache.cayenne.map.EmbeddedResult; import org.apache.cayenne.map.JoinType; @@ -43,16 +43,16 @@ import org.apache.cayenne.util.Util; class CustomColumnSetExtractor implements ColumnExtractor { private final TranslatorContext context; - private final Collection<BaseProperty<?>> columns; + private final Collection<Property<?>> columns; - CustomColumnSetExtractor(TranslatorContext context, Collection<BaseProperty<?>> columns) { + CustomColumnSetExtractor(TranslatorContext context, Collection<Property<?>> columns) { this.context = context; this.columns = columns; } @Override public void extract(String prefix) { - for (BaseProperty<?> property : columns) { + for (Property<?> property : columns) { if (isFullObjectProp(property)) { extractFullObject(prefix, property); } else if(isEmbeddedProp(property)) { @@ -63,14 +63,14 @@ class CustomColumnSetExtractor implements ColumnExtractor { } } - private void extractSimpleProperty(BaseProperty<?> property) { + private void extractSimpleProperty(Property<?> property) { Node sqlNode = context.getQualifierTranslator().translate(property); context.addResultNode(sqlNode, true, property, property.getAlias()); String name = property.getName() == null ? property.getExpression().expName() : property.getName(); context.getSqlResult().addColumnResult(name); } - private boolean isFullObjectProp(BaseProperty<?> property) { + private boolean isFullObjectProp(Property<?> property) { int expressionType = property.getExpression().getType(); // forbid direct selection of toMany relationships columns @@ -88,11 +88,11 @@ class CustomColumnSetExtractor implements ColumnExtractor { && Persistent.class.isAssignableFrom(property.getType())); } - private boolean isEmbeddedProp(BaseProperty<?> property) { + private boolean isEmbeddedProp(Property<?> property) { return EmbeddableObject.class.isAssignableFrom(property.getType()); } - private void extractEmbeddedObject(String prefix, BaseProperty<?> property) { + private void extractEmbeddedObject(String prefix, Property<?> property) { Object o = property.getExpression().evaluate(context.getMetadata().getObjEntity()); if(!(o instanceof EmbeddedAttribute)) { throw new CayenneRuntimeException("EmbeddedAttribute expected, %s found", o); @@ -107,7 +107,7 @@ class CustomColumnSetExtractor implements ColumnExtractor { context.getSqlResult().addEmbeddedResult(result); } - private void extractFullObject(String prefix, BaseProperty<?> property) { + private void extractFullObject(String prefix, Property<?> property) { prefix = calculatePrefix(prefix, property); ensureJoin(prefix); @@ -137,7 +137,7 @@ class CustomColumnSetExtractor implements ColumnExtractor { * Extracts prefix for this extractor from property. * This will be just a db path for this property, if any exists. */ - private String calculatePrefix(String prefix, BaseProperty<?> property) { + private String calculatePrefix(String prefix, Property<?> property) { Expression exp = property.getExpression(); int expressionType = exp.getType(); if(expressionType == Expression.FULL_OBJECT && exp.getOperandCount() > 0) { diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/FluentSelectWrapper.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/FluentSelectWrapper.java index 45c8e8b..3c4bed7 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/FluentSelectWrapper.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/FluentSelectWrapper.java @@ -23,7 +23,7 @@ import java.util.Collection; import java.util.Objects; import org.apache.cayenne.exp.Expression; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.query.FluentSelect; import org.apache.cayenne.query.Ordering; @@ -61,7 +61,7 @@ public class FluentSelectWrapper implements TranslatableQueryWrapper { } @Override - public Collection<BaseProperty<?>> getColumns() { + public Collection<Property<?>> getColumns() { return select.getColumns(); } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java index 1308091..64ae657 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/QualifierTranslator.java @@ -56,6 +56,7 @@ import org.apache.cayenne.exp.parser.ASTSubquery; import org.apache.cayenne.exp.parser.PatternMatchNode; import org.apache.cayenne.exp.parser.SimpleNode; import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DbAttribute; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.DbRelationship; @@ -86,7 +87,7 @@ class QualifierTranslator implements TraversalHandler { this.nodeStack = new ArrayDeque<>(); } - Node translate(BaseProperty<?> property) { + Node translate(Property<?> property) { if(property == null) { return null; } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/ResultNodeDescriptor.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/ResultNodeDescriptor.java index acb0ca5..4eb03d7 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/ResultNodeDescriptor.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/ResultNodeDescriptor.java @@ -25,7 +25,7 @@ import org.apache.cayenne.access.sqlbuilder.sqltree.NodeType; import org.apache.cayenne.access.sqlbuilder.sqltree.SimpleNodeTreeVisitor; import org.apache.cayenne.dba.TypesMapping; import org.apache.cayenne.exp.parser.ASTAggregateFunctionCall; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DbAttribute; /** @@ -35,13 +35,13 @@ class ResultNodeDescriptor { private final Node node; private final boolean inDataRow; private final boolean isAggregate; - private final BaseProperty<?> property; + private final Property<?> property; private String dataRowKey; private DbAttribute dbAttribute; private String javaType; - ResultNodeDescriptor(Node node, boolean inDataRow, BaseProperty<?> property, String dataRowKey) { + ResultNodeDescriptor(Node node, boolean inDataRow, Property<?> property, String dataRowKey) { this.node = node; this.inDataRow = inDataRow; this.property = property; @@ -58,7 +58,7 @@ class ResultNodeDescriptor { return inDataRow; } - public BaseProperty<?> getProperty() { + public Property<?> getProperty() { return property; } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/SelectQueryWrapper.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/SelectQueryWrapper.java index dfc8183..5c95718 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/SelectQueryWrapper.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/SelectQueryWrapper.java @@ -24,6 +24,7 @@ import java.util.Objects; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.query.Ordering; import org.apache.cayenne.query.QueryMetadata; @@ -61,7 +62,7 @@ public class SelectQueryWrapper implements TranslatableQueryWrapper { } @Override - public Collection<BaseProperty<?>> getColumns() { + public Collection<Property<?>> getColumns() { return selectQuery.getColumns(); } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatableQueryWrapper.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatableQueryWrapper.java index fae21d7..2c96978 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatableQueryWrapper.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatableQueryWrapper.java @@ -22,7 +22,7 @@ package org.apache.cayenne.access.translator.select; import java.util.Collection; import org.apache.cayenne.exp.Expression; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.query.Ordering; import org.apache.cayenne.query.QueryMetadata; @@ -44,7 +44,7 @@ public interface TranslatableQueryWrapper { Collection<Ordering> getOrderings(); - Collection<BaseProperty<?>> getColumns(); + Collection<Property<?>> getColumns(); Expression getHavingQualifier(); diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatorContext.java b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatorContext.java index 388f1ee..2928257 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatorContext.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/TranslatorContext.java @@ -32,7 +32,7 @@ import org.apache.cayenne.access.sqlbuilder.sqltree.Node; import org.apache.cayenne.access.translator.DbAttributeBinding; import org.apache.cayenne.dba.DbAdapter; import org.apache.cayenne.dba.QuotingStrategy; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.map.EntityResult; @@ -128,7 +128,7 @@ public class TranslatorContext implements SQLGenerationContext { /** * Mark start of a new class descriptor, to be able to process result columns properly. * @param type of a descriptor - * @see #addResultNode(Node, boolean, BaseProperty, String) + * @see #addResultNode(Node, boolean, Property, String) */ void markDescriptorStart(DescriptorType type) { if(type == DescriptorType.PREFETCH) { @@ -224,7 +224,7 @@ public class TranslatorContext implements SQLGenerationContext { return addResultNode(node, true, null, dataRowKey); } - ResultNodeDescriptor addResultNode(Node node, boolean inDataRow, BaseProperty<?> property, String dataRowKey) { + ResultNodeDescriptor addResultNode(Node node, boolean inDataRow, Property<?> property, String dataRowKey) { ResultNodeDescriptor resultNode = new ResultNodeDescriptor(node, inDataRow, property, dataRowKey); if(appendResultToRoot) { resultNodeList.add(rootSegmentEnd + 1, resultNode); diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java index 47ced76..f214a07 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java @@ -266,8 +266,8 @@ public class Property<E> extends BaseProperty<E> implements ComparableProperty<E int i = 0; exp[i++] = path(); for(Object arg : args) { - if(arg instanceof BaseProperty) { - exp[i++] = ((BaseProperty) arg).getExpression(); + if(arg instanceof org.apache.cayenne.exp.property.Property) { + exp[i++] = ((org.apache.cayenne.exp.property.Property<?>) arg).getExpression(); } else if(arg instanceof Expression) { exp[i++] = (Expression) arg; } else if(arg != null) { diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/property/Property.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/property/Property.java index c7ba636..f92dacb 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/exp/property/Property.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/property/Property.java @@ -33,6 +33,11 @@ public interface Property<E> { String getName(); /** + * @return alias of this property, can be null + */ + String getAlias(); + + /** * @return expression that defines this property, not null */ Expression getExpression(); diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelect.java index 5521700..4a0e040 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelect.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelect.java @@ -32,7 +32,7 @@ import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; import org.apache.cayenne.exp.property.ComparableProperty; import org.apache.cayenne.exp.property.NumericProperty; -import org.apache.cayenne.exp.Property; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.EntityResolver; @@ -61,13 +61,13 @@ import org.apache.cayenne.map.ObjEntity; * </pre> * </p> * <p><b>Note: this class can't be instantiated directly. Use {@link ObjectSelect}.</b></p> - * @see ObjectSelect#columnQuery(Class, BaseProperty) + * @see ObjectSelect#columnQuery(Class, Property) * * @since 4.0 */ public class ColumnSelect<T> extends FluentSelect<T> { - private Collection<BaseProperty<?>> columns; + private Collection<Property<?>> columns; // package private for tests boolean singleColumn = true; boolean distinct; @@ -386,11 +386,11 @@ public class ColumnSelect<T> extends FluentSelect<T> { * </pre> * * @param properties array of properties to select - * @see ColumnSelect#column(BaseProperty) + * @see ColumnSelect#column(Property) * @see ColumnSelect#columns(Collection) */ @SuppressWarnings("unchecked") - public ColumnSelect<Object[]> columns(BaseProperty<?>... properties) { + public ColumnSelect<Object[]> columns(Property<?>... properties) { if (properties.length == 0) { throw new IllegalArgumentException("properties must contain at least one element"); } @@ -408,10 +408,10 @@ public class ColumnSelect<T> extends FluentSelect<T> { * (root entity properties, function call expressions, properties of relationships, etc).</p> * <p> * @param properties collection of properties, <b>must</b> contain at least one element - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) */ @SuppressWarnings("unchecked") - public ColumnSelect<Object[]> columns(Collection<BaseProperty<?>> properties) { + public ColumnSelect<Object[]> columns(Collection<Property<?>> properties) { if (properties == null){ throw new NullPointerException("properties is null"); } @@ -429,7 +429,7 @@ public class ColumnSelect<T> extends FluentSelect<T> { } @SuppressWarnings("unchecked") - protected <E> ColumnSelect<E> column(BaseProperty<E> property) { + protected <E> ColumnSelect<E> column(Property<E> property) { if (this.columns == null) { this.columns = new ArrayList<>(1); } else { @@ -440,7 +440,7 @@ public class ColumnSelect<T> extends FluentSelect<T> { } /** - * <p>Shortcut for {@link #columns(BaseProperty[])} columns}(Property.COUNT)</p> + * <p>Shortcut for {@link #columns(Property[])} columns}(Property.COUNT)</p> */ public ColumnSelect<Object[]> count() { return columns(PropertyFactory.COUNT); @@ -457,7 +457,7 @@ public class ColumnSelect<T> extends FluentSelect<T> { /** * <p>Select minimum value of property</p> - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) */ public ColumnSelect<Object[]> min(ComparableProperty<?> property) { return columns(property.min()); @@ -465,7 +465,7 @@ public class ColumnSelect<T> extends FluentSelect<T> { /** * <p>Select maximum value of property</p> - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) */ public ColumnSelect<Object[]> max(ComparableProperty<?> property) { return columns(property.max()); @@ -473,17 +473,17 @@ public class ColumnSelect<T> extends FluentSelect<T> { /** * <p>Select average value of property</p> - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) * @deprecated since 4.2 use {@link #avg(NumericProperty)} */ @Deprecated - public ColumnSelect<Object[]> avg(Property<?> property) { + public ColumnSelect<Object[]> avg(org.apache.cayenne.exp.Property<?> property) { return columns(property.avg()); } /** * <p>Select average value of property</p> - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) */ public ColumnSelect<Object[]> avg(NumericProperty<?> property) { return columns(property.avg()); @@ -491,17 +491,17 @@ public class ColumnSelect<T> extends FluentSelect<T> { /** * <p>Select sum of values</p> - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) * @deprecated since 4.2 use {@link #sum(NumericProperty)} */ @Deprecated - public <E extends Number> ColumnSelect<Object[]> sum(Property<E> property) { + public <E extends Number> ColumnSelect<Object[]> sum(org.apache.cayenne.exp.Property<E> property) { return columns(property.sum()); } /** * <p>Select sum of values</p> - * @see ColumnSelect#columns(BaseProperty[]) + * @see ColumnSelect#columns(Property[]) */ public <E extends Number> ColumnSelect<Object[]> sum(NumericProperty<E> property) { return columns(property.sum()); @@ -600,7 +600,7 @@ public class ColumnSelect<T> extends FluentSelect<T> { } @Override - public Collection<BaseProperty<?>> getColumns() { + public Collection<Property<?>> getColumns() { return columns; } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelectMetadata.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelectMetadata.java index 1222346..365853d 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelectMetadata.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/ColumnSelectMetadata.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.function.Function; import org.apache.cayenne.exp.Expression; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DefaultEntityResultSegment; import org.apache.cayenne.map.DefaultScalarResultSegment; import org.apache.cayenne.map.EntityResolver; @@ -71,9 +71,9 @@ class ColumnSelectMetadata extends ObjectSelectMetadata { } protected void resolveColumnsAliases(FluentSelect<?> query) { - Collection<BaseProperty<?>> columns = query.getColumns(); + Collection<Property<?>> columns = query.getColumns(); if(columns != null) { - for(BaseProperty<?> property : columns) { + for(Property<?> property : columns) { Expression propertyExpression = property.getExpression(); if(propertyExpression != null) { resolveAutoAliases(propertyExpression); @@ -101,7 +101,7 @@ class ColumnSelectMetadata extends ObjectSelectMetadata { } resultSetMapping = new ArrayList<>(query.getColumns().size()); - for(BaseProperty<?> column : query.getColumns()) { + for(Property<?> column : query.getColumns()) { // for each column we need only to know if it's entity or scalar Expression exp = column.getExpression(); boolean fullObject = false; diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/FluentSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/FluentSelect.java index 42a055b..d11c491 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/FluentSelect.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/FluentSelect.java @@ -28,7 +28,7 @@ import org.apache.cayenne.ResultBatchIterator; import org.apache.cayenne.ResultIterator; import org.apache.cayenne.ResultIteratorCallback; import org.apache.cayenne.exp.Expression; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.map.ObjEntity; @@ -204,7 +204,7 @@ public abstract class FluentSelect<T> extends AbstractQuery implements Select<T> /** * @since 4.2 */ - public Collection<BaseProperty<?>> getColumns() { + public Collection<Property<?>> getColumns() { return null; } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java index 6638d9a..d20b5d8 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelect.java @@ -29,10 +29,10 @@ import org.apache.cayenne.DataRow; import org.apache.cayenne.ObjectContext; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; -import org.apache.cayenne.exp.Property; import org.apache.cayenne.exp.property.BaseProperty; import org.apache.cayenne.exp.property.ComparableProperty; import org.apache.cayenne.exp.property.NumericProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.EntityResolver; @@ -135,7 +135,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { * @param entityType base persistent class that will be used as a root for this query * @param column single column to select */ - public static <E> ColumnSelect<E> columnQuery(Class<?> entityType, BaseProperty<E> column) { + public static <E> ColumnSelect<E> columnQuery(Class<?> entityType, Property<E> column) { return new ColumnSelect<>().entityType(entityType).column(column); } @@ -145,7 +145,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { * @param entityType base persistent class that will be used as a root for this query * @param columns columns to select */ - public static ColumnSelect<Object[]> columnQuery(Class<?> entityType, BaseProperty<?>... columns) { + public static ColumnSelect<Object[]> columnQuery(Class<?> entityType, Property<?>... columns) { return new ColumnSelect<Object[]>().entityType(entityType).columns(columns); } @@ -540,9 +540,9 @@ public class ObjectSelect<T> extends FluentSelect<T> { * </pre> * * @param properties array of properties to select - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ - public ColumnSelect<Object[]> columns(BaseProperty<?>... properties) { + public ColumnSelect<Object[]> columns(Property<?>... properties) { return new ColumnSelect<>(this).columns(properties); } @@ -550,7 +550,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { * <p>Select one specific property.</p> * <p>Can be any property that can be resolved against root entity type * (root entity's property, function call expression, property of relationships, etc)</p> - * <p>If you need several columns use {@link ObjectSelect#columns(BaseProperty[])} method.</p> + * <p>If you need several columns use {@link ObjectSelect#columns(Property[])} method.</p> * <p> * <pre> * {@code @@ -561,15 +561,15 @@ public class ObjectSelect<T> extends FluentSelect<T> { * </pre> * </p> * @param property single property to select - * @see ObjectSelect#columns(BaseProperty[]) + * @see ObjectSelect#columns(Property[]) */ - public <E> ColumnSelect<E> column(BaseProperty<E> property) { + public <E> ColumnSelect<E> column(Property<E> property) { return new ColumnSelect<>(this).column(property); } /** * Select COUNT(*) - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public ColumnSelect<Long> count() { return column(PropertyFactory.COUNT); @@ -579,7 +579,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { * <p>Select COUNT(property)</p> * <p>Can return different result than COUNT(*) as it will count only non null values</p> * @see ObjectSelect#count() - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public ColumnSelect<Long> count(BaseProperty<?> property) { return column(property.count()); @@ -587,7 +587,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { /** * <p>Select minimum value of property</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public <E> ColumnSelect<E> min(ComparableProperty<E> property) { return column(property.min()); @@ -595,7 +595,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { /** * <p>Select minimum value of property</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public <E extends Number> ColumnSelect<E> min(NumericProperty<E> property) { return column(property.min()); @@ -603,7 +603,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { /** * <p>Select maximum value of property</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public <E> ColumnSelect<E> max(ComparableProperty<E> property) { return column(property.max()); @@ -611,7 +611,7 @@ public class ObjectSelect<T> extends FluentSelect<T> { /** * <p>Select maximum value of property</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public <E extends Number> ColumnSelect<E> max(NumericProperty<E> property) { return column(property.max()); @@ -619,17 +619,17 @@ public class ObjectSelect<T> extends FluentSelect<T> { /** * <p>Select average value of property</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) * @deprecated since 4.2 use {@link #avg(NumericProperty)} */ @Deprecated - public <E> ColumnSelect<E> avg(Property<E> property) { + public <E> ColumnSelect<E> avg(org.apache.cayenne.exp.Property<E> property) { return column(property.avg()); } /** * <p>Select average value of property</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public <E extends Number> ColumnSelect<E> avg(NumericProperty<E> property) { return column(property.avg()); @@ -637,17 +637,17 @@ public class ObjectSelect<T> extends FluentSelect<T> { /** * <p>Select sum of values</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) * @deprecated since 4.2 use {@link #sum(NumericProperty)} */ @Deprecated - public <E extends Number> ColumnSelect<E> sum(Property<E> property) { + public <E extends Number> ColumnSelect<E> sum(org.apache.cayenne.exp.Property<E> property) { return column(property.sum()); } /** * <p>Select sum of values</p> - * @see ObjectSelect#column(BaseProperty) + * @see ObjectSelect#column(Property) */ public <E extends Number> ColumnSelect<E> sum(NumericProperty<E> property) { return column(property.sum()); diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelectMetadata.java b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelectMetadata.java index fd1fc67..164a7af 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelectMetadata.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/ObjectSelectMetadata.java @@ -21,7 +21,7 @@ package org.apache.cayenne.query; import org.apache.cayenne.CayenneRuntimeException; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.TraversalHandler; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.map.ObjEntity; @@ -77,7 +77,7 @@ class ObjectSelectMetadata extends BaseQueryMetadata { if (query.getColumns() != null && !query.getColumns().isEmpty()) { traversalHandler = new ToCacheKeyTraversalHandler(resolver.getValueObjectTypeRegistry(), key); - for (BaseProperty<?> property : query.getColumns()) { + for (Property<?> property : query.getColumns()) { key.append("/c:"); property.getExpression().traverse(traversalHandler); } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java index ea2eeea..189cb30 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQuery.java @@ -33,7 +33,7 @@ import org.apache.cayenne.ResultIterator; import org.apache.cayenne.ResultIteratorCallback; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DbEntity; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.map.ObjEntity; @@ -43,8 +43,8 @@ import org.apache.cayenne.map.ObjEntity; * DataRows). Supports expression qualifier, multiple orderings and a number of * other parameters that serve as runtime hints to Cayenne on how to optimize * the fetch and result processing. - * @deprecated since 4.2 - * use {@link org.apache.cayenne.query.ObjectSelect} + * + * @deprecated since 4.2, use {@link org.apache.cayenne.query.ObjectSelect} */ @Deprecated public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, Select<T> { @@ -61,7 +61,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, /** * @since 4.0 */ - protected Collection<BaseProperty<?>> columns; + protected Collection<Property<?>> columns; /** * @since 4.0 @@ -758,14 +758,14 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, * @since 4.0 * @see SelectQuery#setCanReturnScalarValue(boolean) */ - public void setColumns(Collection<BaseProperty<?>> columns) { + public void setColumns(Collection<Property<?>> columns) { this.columns = columns; } /** * @since 4.0 */ - public void setColumns(BaseProperty<?>... columns) { + public void setColumns(Property<?>... columns) { if(columns == null || columns.length == 0) { return; } @@ -795,7 +795,7 @@ public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, /** * @since 4.0 */ - public Collection<BaseProperty<?>> getColumns() { + public Collection<Property<?>> getColumns() { return columns; } diff --git a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java index d78e681..30b135e 100644 --- a/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java +++ b/cayenne-server/src/main/java/org/apache/cayenne/query/SelectQueryMetadata.java @@ -21,7 +21,7 @@ package org.apache.cayenne.query; import org.apache.cayenne.CayenneRuntimeException; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.TraversalHandler; -import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.DefaultEntityResultSegment; import org.apache.cayenne.map.DefaultScalarResultSegment; import org.apache.cayenne.map.EntityResolver; @@ -94,7 +94,7 @@ class SelectQueryMetadata extends BaseQueryMetadata { if(query.getColumns() != null && !query.getColumns().isEmpty()) { traversalHandler = new ToCacheKeyTraversalHandler(resolver.getValueObjectTypeRegistry(), key); - for(BaseProperty<?> property : query.getColumns()) { + for(Property<?> property : query.getColumns()) { key.append("/c:"); property.getExpression().traverse(traversalHandler); } @@ -163,9 +163,9 @@ class SelectQueryMetadata extends BaseQueryMetadata { } private void resolveColumnsAliases(SelectQuery<?> query) { - Collection<BaseProperty<?>> columns = query.getColumns(); + Collection<Property<?>> columns = query.getColumns(); if(columns != null) { - for(BaseProperty<?> property : columns) { + for(Property<?> property : columns) { Expression propertyExpression = property.getExpression(); if(propertyExpression != null) { resolveAutoAliases(propertyExpression); @@ -259,7 +259,7 @@ class SelectQueryMetadata extends BaseQueryMetadata { } resultSetMapping = new ArrayList<>(query.getColumns().size()); - for(BaseProperty<?> column : query.getColumns()) { + for(Property<?> column : query.getColumns()) { // for each column we need only to know if it's entity or scalar Expression exp = column.getExpression(); boolean fullObject = false; diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractorTest.java index e5697bd..13c5f8e 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractorTest.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractorTest.java @@ -26,6 +26,7 @@ import java.util.Collections; import org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode; import org.apache.cayenne.exp.ExpressionFactory; import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.map.DataMap; import org.apache.cayenne.map.DbEntity; @@ -73,7 +74,7 @@ public class CustomColumnSetExtractorTest extends BaseColumnExtractorTest { resolver.addDataMap(dataMap); BaseProperty<?> property0 = PropertyFactory.createBase(ExpressionFactory.dbPathExp("name"), String.class); - Collection<BaseProperty<?>> properties = Collections.singleton(property0); + Collection<Property<?>> properties = Collections.singleton(property0); CustomColumnSetExtractor extractor = new CustomColumnSetExtractor(context, properties); extractor.extract(); diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/MockQueryWrapperBuilder.java b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/MockQueryWrapperBuilder.java index 62c8603..2752265 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/MockQueryWrapperBuilder.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/access/translator/select/MockQueryWrapperBuilder.java @@ -23,6 +23,7 @@ import java.util.Collection; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.property.BaseProperty; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.map.EntityResolver; import org.apache.cayenne.query.MockQueryMetadata; import org.apache.cayenne.query.Ordering; @@ -45,7 +46,7 @@ class MockQueryWrapperBuilder { private Collection<Ordering> orderings; - private Collection<BaseProperty<?>> columns; + private Collection<Property<?>> columns; private Expression havingQualifier; @@ -77,7 +78,7 @@ class MockQueryWrapperBuilder { return this; } - MockQueryWrapperBuilder withColumns(Collection<BaseProperty<?>> columns) { + MockQueryWrapperBuilder withColumns(Collection<Property<?>> columns) { this.columns = columns; return this; } @@ -120,7 +121,7 @@ class MockQueryWrapperBuilder { } @Override - public Collection<BaseProperty<?>> getColumns() { + public Collection<Property<?>> getColumns() { return columns; } diff --git a/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectTest.java b/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectTest.java index bd2061a..21872a3 100644 --- a/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectTest.java +++ b/cayenne-server/src/test/java/org/apache/cayenne/query/ColumnSelectTest.java @@ -24,9 +24,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import org.apache.cayenne.exp.property.BaseProperty; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.exp.ExpressionFactory; +import org.apache.cayenne.exp.property.Property; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.testdo.testmap.Artist; import org.apache.cayenne.testdo.testmap.Painting; @@ -205,7 +205,7 @@ public class ColumnSelectTest { q.columns(Artist.DATE_OF_BIRTH); q.columns(Artist.PAINTING_ARRAY); - Collection<BaseProperty<?>> properties = Arrays.asList(Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH, Artist.PAINTING_ARRAY); + Collection<Property<?>> properties = Arrays.asList(Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH, Artist.PAINTING_ARRAY); assertEquals(properties, q.getColumns()); } @@ -218,7 +218,7 @@ public class ColumnSelectTest { q.columns(Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH, Artist.PAINTING_ARRAY); q.columns(Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH, Artist.PAINTING_ARRAY); - Collection<BaseProperty<?>> properties = Arrays.asList( + Collection<Property<?>> properties = Arrays.asList( Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH, Artist.PAINTING_ARRAY, Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH, Artist.PAINTING_ARRAY); // should it be Set instead of List? assertEquals(properties, q.getColumns()); @@ -234,7 +234,7 @@ public class ColumnSelectTest { q.column(Artist.DATE_OF_BIRTH); q.column(Artist.PAINTING_ARRAY); - Collection<BaseProperty<?>> properties = Collections.singletonList(Artist.PAINTING_ARRAY); + Collection<Property<?>> properties = Collections.singletonList(Artist.PAINTING_ARRAY); assertEquals(properties, q.getColumns()); }