/** * set the properties to include on the base / root entity. */ public void select(String columns) { baseProps = new OrmQueryProperties(null, columns); }
boolean match = lazyQuery ? chunk.isLazyFetch() : chunk.isQueryFetch(); if (match) { matchingPaths.add(chunk.getPath()); while (pass2It.hasNext()) { OrmQueryProperties pass2Prop = pass2It.next(); if (secQuery.isChild(pass2Prop)) { secQuery.add(pass2Prop); String path = prop.getPath(); chunk.addSecondaryQueryJoin(split[1]);
/** * Return true if the query detail has neither select properties specified or any joins defined. */ public boolean isEmpty() { return fetchPaths.isEmpty() && baseProps.allProperties(); }
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail) { boolean tuned = false; OrmQueryProperties tunedRoot = tunedDetail.getChunk(null, false); if (tunedRoot != null && tunedRoot.hasProperties()) { tuned = true; baseProps.setTunedProperties(tunedRoot); for (OrmQueryProperties tunedChunk : tunedDetail.fetchPaths.values()) { OrmQueryProperties chunk = getChunk(tunedChunk.getPath(), false); if (chunk != null) { // set the properties to select chunk.setTunedProperties(tunedChunk); } else { // add a missing join putFetchPath(tunedChunk.copy()); } } } return tuned; }
/** * Define the select and joins for this query. */ @SuppressWarnings("unchecked") public void configureManyQuery(SpiQuery<?> query) { if (trimmedProperties != null && trimmedProperties.length() > 0) { query.fetch(query.getLazyLoadManyPath(), trimmedProperties); } if (filterMany != null){ query.setFilterMany(path, filterMany); } if (secondaryChildren != null) { int trimlen = path.length() - query.getLazyLoadManyPath().length(); for (int i = 0; i < secondaryChildren.size(); i++) { OrmQueryProperties p = secondaryChildren.get(i); String path = p.getPath(); path = path.substring(trimlen); query.fetch(path, p.getProperties(), p.getFetchConfig()); query.setFilterMany(path, p.getFilterManyTrimPath(trimlen)); } } if (orderBy != null){ query.setOrder(orderBy); } }
private void sortFetchPaths(BeanDescriptor<?> d, OrmQueryProperties p, LinkedHashMap<String, OrmQueryProperties> sorted) { String path = p.getPath(); if (!sorted.containsKey(path)) { String parentPath = p.getParentPath(); if (parentPath == null || sorted.containsKey(parentPath)) { // off root path or parent already ahead in fetch order sorted.put(path, p); } else { OrmQueryProperties parentProp = fetchPaths.get(parentPath); if (parentProp == null) { ElPropertyValue el = d.getElGetValue(parentPath); if (el == null) { throw new PersistenceException("Path [" + parentPath + "] not valid from " + d.getFullName()); } // add a missing parent path just fetching the Id property BeanPropertyAssoc<?> assocOne = (BeanPropertyAssoc<?>) el.getBeanProperty(); parentProp = new OrmQueryProperties(parentPath, assocOne.getTargetIdProperty()); } sortFetchPaths(d, parentProp, sorted); sorted.put(path, p); } } }
/** * Set any default select clauses for the main bean and any joins that have * not explicitly defined a select clause. * <p> * That is this will use FetchType.LAZY to exclude some properties by * default. * </p> */ public void setDefaultSelectClause(BeanDescriptor<?> desc) { if (desc.hasDefaultSelectClause() && !hasSelectClause()) { if (baseProps == null) { baseProps = new OrmQueryProperties(); } baseProps.setDefaultProperties(desc.getDefaultSelectClause(), desc.getDefaultSelectClauseSet()); } for (OrmQueryProperties joinProps : fetchPaths.values()) { if (!joinProps.hasSelectClause()) { BeanDescriptor<?> assocDesc = desc.getBeanDescriptor(joinProps.getPath()); if (assocDesc.hasDefaultSelectClause()) { // use the default select clause joinProps.setDefaultProperties(assocDesc.getDefaultSelectClause(), assocDesc.getDefaultSelectClauseSet()); } } } }
/** * Set any default select clauses for the main bean and any joins that have not explicitly defined * a select clause. * <p> * That is this will use FetchType.LAZY to exclude some properties by default. * </p> */ public void setDefaultSelectClause(BeanDescriptor<?> desc) { if (desc.hasDefaultSelectClause() && !hasSelectClause()) { baseProps = new OrmQueryProperties(null, desc.getDefaultSelectClause()); } for (OrmQueryProperties joinProps : fetchPaths.values()) { if (!joinProps.hasSelectClause()) { BeanDescriptor<?> assocDesc = desc.getBeanDescriptor(joinProps.getPath()); if (assocDesc.hasDefaultSelectClause()) { fetch(joinProps.getPath(), assocDesc.getDefaultSelectClause(), joinProps.getFetchConfig()); } } } }
private List<OrmQueryProperties> removeQueryJoins() { List<OrmQueryProperties> queryJoins = detail.removeSecondaryQueries(); if (queryJoins != null) { if (orderBy != null) { // remove any orderBy properties that relate to // paths of the secondary queries for (OrmQueryProperties joinPath : queryJoins) { // loop through the orderBy properties and // move any ones related to the query join List<Property> properties = orderBy.getProperties(); Iterator<Property> it = properties.iterator(); while (it.hasNext()) { Property property = it.next(); if (property.getProperty().startsWith(joinPath.getPath())) { // remove this orderBy segment and // add it to the secondary join it.remove(); joinPath.addSecJoinOrderProperty(property); } } } } } return queryJoins; }
private SqlTreeProperties getBaseSelect(BeanDescriptor<?> desc, OrmQueryProperties queryProps) { boolean partial = queryProps != null && !queryProps.allProperties(); if (partial) { return getBaseSelectPartial(desc, queryProps); } SqlTreeProperties selectProps = new SqlTreeProperties(); selectProps.setAllProperties(); // normal simple properties of the bean selectProps.add(desc.propertiesBaseScalar()); selectProps.add(desc.propertiesEmbedded()); BeanPropertyAssocOne<?>[] propertiesOne = desc.propertiesOne(); for (BeanPropertyAssocOne<?> aPropertiesOne : propertiesOne) { //noinspection StatementWithEmptyBody if (queryProps != null && queryProps.isIncludedBeanJoin(aPropertiesOne.getName())) { // if it is a joined bean... then don't add the property // as it will have its own entire Node in the SqlTree } else { selectProps.add(aPropertiesOne); } } InheritInfo inheritInfo = desc.getInheritInfo(); if (inheritInfo != null) { // add sub type properties inheritInfo.addChildrenProperties(selectProps); } return selectProps; }
public String[] getSelectedProperties() { OrmQueryProperties chunk = query.getDetail().getChunk(null, false); if (chunk.allProperties()) { return null; } // convert to array of String[] for setReturningAttributes(); ArrayList<String> ldapSelectProps = new ArrayList<String>(); Iterator<String> selectProperties = chunk.getSelectProperties(); while (selectProperties.hasNext()) { String propName = selectProperties.next(); BeanProperty p = desc.getBeanProperty(propName); if (p != null) { propName = p.getDbColumn(); } ldapSelectProps.add(propName); } return ldapSelectProps.toArray(new String[ldapSelectProps.size()]); }
if (manyProperty != null) { OrmQueryProperties chunk = query.getDetail().getChunk(manyProperty.getName(), false); SpiExpressionList<?> filterManyExpr = chunk.getFilterMany(); if (filterManyExpr != null) { this.filterMany = new DefaultExpressionRequest(request, deployParser, binder, filterManyExpr);
public void configureQuery(SpiQuery<?> query) { parent.propagateQueryState(query, docStoreMapped); query.setParentNode(objectGraphNode); if (queryProps != null) { queryProps.configureBeanQuery(query); } }
/** * Return a deep copy of the OrmQueryDetail. */ public OrmQueryDetail copy() { OrmQueryDetail copy = new OrmQueryDetail(); copy.baseProps = baseProps.copy(); for (Map.Entry<String, OrmQueryProperties> entry : fetchPaths.entrySet()) { copy.fetchPaths.put(entry.getKey(), entry.getValue().copy()); } return copy; }
@Override public ExpressionList<T> filterMany(String prop) { OrmQueryProperties chunk = detail.getChunk(prop, true); return chunk.filterMany(this); }
private int initSecondaryBatchSize(int defaultBatchSize, int firstBatchSize, OrmQueryProperties queryProps) { if (queryProps == null) { return defaultBatchSize; } FetchConfig fetchConfig = queryProps.getFetchConfig(); if (fetchConfig.isQueryAll()) { return firstBatchSize; } int lazyBatchSize = fetchConfig.getLazyBatchSize(); return (lazyBatchSize > 1) ? lazyBatchSize : defaultBatchSize; }
/** * Define the select and joins for this query. */ @SuppressWarnings("unchecked") public void configureManyQuery(SpiQuery<?> query) { if (trimmedProperties != null && trimmedProperties.length() > 0) { query.fetch(query.getLazyLoadManyPath(), trimmedProperties); } if (filterMany != null){ query.setFilterMany(path, filterMany); } if (secondaryChildren != null) { int trimlen = path.length() - query.getLazyLoadManyPath().length(); for (int i = 0; i < secondaryChildren.size(); i++) { OrmQueryProperties p = secondaryChildren.get(i); String path = p.getPath(); path = path.substring(trimlen); query.fetch(path, p.getProperties(), p.getFetchConfig()); query.setFilterMany(path, p.getFilterManyTrimPath(trimlen)); } } if (orderBy != null){ query.setOrder(orderBy); } }
private void sortFetchPaths(BeanDescriptor<?> d, OrmQueryProperties p, LinkedHashMap<String, OrmQueryProperties> sorted) { String path = p.getPath(); if (!sorted.containsKey(path)) { String parentPath = p.getParentPath(); if (parentPath == null || sorted.containsKey(parentPath)) { // off root path or parent already ahead in fetch order sorted.put(path, p); } else { OrmQueryProperties parentProp = fetchPaths.get(parentPath); if (parentProp == null) { ElPropertyValue el = d.getElGetValue(parentPath); if (el == null) { String msg = "Path [" + parentPath + "] not valid from " + d.getFullName(); throw new PersistenceException(msg); } // add a missing parent path just fetching the Id property BeanPropertyAssoc<?> assocOne = (BeanPropertyAssoc<?>) el.getBeanProperty(); parentProp = new OrmQueryProperties(parentPath, assocOne.getTargetIdProperty()); } if (parentProp != null) { sortFetchPaths(d, parentProp, sorted); } sorted.put(path, p); } } }
/** * Set any default select clauses for the main bean and any joins that have * not explicitly defined a select clause. * <p> * That is this will use FetchType.LAZY to exclude some properties by * default. * </p> */ public void setDefaultSelectClause(BeanDescriptor<?> desc) { if (desc.hasDefaultSelectClause() && !hasSelectClause()) { if (baseProps == null) { baseProps = new OrmQueryProperties(); } baseProps.setDefaultProperties(desc.getDefaultSelectClause(), desc.getDefaultSelectClauseSet()); } for (OrmQueryProperties joinProps : fetchPaths.values()) { if (!joinProps.hasSelectClause()) { BeanDescriptor<?> assocDesc = desc.getBeanDescriptor(joinProps.getPath()); if (assocDesc.hasDefaultSelectClause()) { // use the default select clause joinProps.setDefaultProperties(assocDesc.getDefaultSelectClause(), assocDesc.getDefaultSelectClauseSet()); } } } }
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail) { boolean tuned = false; OrmQueryProperties tunedRoot = tunedDetail.getChunk(null, false); if (tunedRoot != null && tunedRoot.hasProperties()) { tuned = true; baseProps.setTunedProperties(tunedRoot); for (OrmQueryProperties tunedChunk : tunedDetail.fetchPaths.values()) { OrmQueryProperties chunk = getChunk(tunedChunk.getPath(), false); if (chunk != null) { // set the properties to select chunk.setTunedProperties(tunedChunk); } else { // add a missing join putFetchPath(tunedChunk.copy()); } } } return tuned; }