com.force.sdk.jpa.query
Class ForceQueryUtils

java.lang.Object
  extended by com.force.sdk.jpa.query.ForceQueryUtils

public class ForceQueryUtils
extends Object

This class contains the bulk of the logic for building SOQL queries based on the java query object.

Author:
Fiaz Hossain

Constructor Summary
ForceQueryUtils(org.datanucleus.store.ExecutionContext ec, ForceManagedConnection mconn, org.datanucleus.store.query.AbstractJavaQuery query, Map<Object,Object> parameters, Map<String,QueryListener> listeners, Map<String,Object> hints)
          Create the query util for a specific query.
 
Method Summary
 void appendRelationshipFields(ExpressionBuilderHelper helper, ColumnImpl col, String prefix)
          Append the fields in the default fetch group for the entity in the relationship to the query.
 void appendRelationshipQuery(ExpressionBuilderHelper helper, org.datanucleus.metadata.AbstractMemberMetaData ammd, ColumnImpl col)
          helper method to handle joining a relationship field to a query that is currently being built.
 String buildQuery(TableImpl table, org.datanucleus.metadata.AbstractClassMetaData acmd, Set<Integer> fieldsToLoad, org.datanucleus.query.compiler.QueryCompilation compilation, boolean skipId, long maxLimit, org.datanucleus.FetchPlan fetchPlan, int fetchDepth, String tableName, boolean isTopLevel, boolean isJoin, String joinAlias, ExpressionBuilderHelper parentHelper)
          Build a query for fetching multiple objects, whether top level or part of a join query.
 String buildQuery(TableImpl table, org.datanucleus.metadata.AbstractClassMetaData acmd, Set<Integer> fieldsToLoad, org.datanucleus.query.compiler.QueryCompilation compilation, boolean skipId, long maxLimit, org.datanucleus.FetchPlan fetchPlan, String tableName)
          Build a query for fetching multiple top level objects.
 String buildQueryWithPK(TableImpl table, org.datanucleus.metadata.AbstractClassMetaData acmd, int[] fieldNumbers, String pkValue, int fetchDepth)
          This is used for single item fetch by ID.
static org.datanucleus.store.FieldValues2 getFieldValues2(org.datanucleus.metadata.AbstractClassMetaData acmd, int[] fieldsToLoad, ForceManagedConnection mconn, ForceStoreManager storeManager, com.sforce.ws.bind.XmlObject sobject, org.datanucleus.store.query.Query query)
          Constructs the proper interface for fetching fields on sobjects.
static Object getIdFromObject(javax.jdo.spi.PersistenceCapable entity, org.datanucleus.metadata.AbstractClassMetaData acmd)
          convenience method for getting the id value from an entity.
static com.force.sdk.jpa.query.ForceQueryUtils.LimitType getLimitType(org.datanucleus.store.query.Query query)
          See if there is a limit set and if we can use SOQL to do our job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ForceQueryUtils

public ForceQueryUtils(org.datanucleus.store.ExecutionContext ec,
                       ForceManagedConnection mconn,
                       org.datanucleus.store.query.AbstractJavaQuery query,
                       Map<Object,Object> parameters,
                       Map<String,QueryListener> listeners,
                       Map<String,Object> hints)
Create the query util for a specific query.

Parameters:
ec - the ExecutionContext
mconn - the managed connection to connect to Force.com
query - - parsed query
parameters - - query parameters
listeners - - query listeners
hints - - query hints
Method Detail

getLimitType

public static com.force.sdk.jpa.query.ForceQueryUtils.LimitType getLimitType(org.datanucleus.store.query.Query query)
See if there is a limit set and if we can use SOQL to do our job.

Parameters:
query - Query
Returns:
the limit type of Soql, Java, or None

getFieldValues2

public static org.datanucleus.store.FieldValues2 getFieldValues2(org.datanucleus.metadata.AbstractClassMetaData acmd,
                                                                 int[] fieldsToLoad,
                                                                 ForceManagedConnection mconn,
                                                                 ForceStoreManager storeManager,
                                                                 com.sforce.ws.bind.XmlObject sobject,
                                                                 org.datanucleus.store.query.Query query)
Constructs the proper interface for fetching fields on sobjects.

Parameters:
acmd - the class metadata for the entity being queried
fieldsToLoad - the fields selected by the query (or selected by the fetch group)
mconn - the managed connection to Force.com APIs
storeManager - the store manager
sobject - the sobject being queried
query - the query for retrieving objects
Returns:
an interface for retrieving field values

buildQueryWithPK

public String buildQueryWithPK(TableImpl table,
                               org.datanucleus.metadata.AbstractClassMetaData acmd,
                               int[] fieldNumbers,
                               String pkValue,
                               int fetchDepth)
This is used for single item fetch by ID.

Parameters:
table - the table for the entity being queried
acmd - the class metadata for the entity being queried
fieldNumbers - the fields to fetch
pkValue - the id of the object being fetched
fetchDepth - the maximum depth that can be traversed by a query involving relationships
Returns:
the SOQL query

buildQuery

public String buildQuery(TableImpl table,
                         org.datanucleus.metadata.AbstractClassMetaData acmd,
                         Set<Integer> fieldsToLoad,
                         org.datanucleus.query.compiler.QueryCompilation compilation,
                         boolean skipId,
                         long maxLimit,
                         org.datanucleus.FetchPlan fetchPlan,
                         String tableName)
Build a query for fetching multiple top level objects.

Parameters:
table - the table representing the object being queried
acmd - the class metadata for the object being queried
fieldsToLoad - the set of fields to load
compilation - the compile query
skipId - true if the id field should be skipped which might be necessary during joins
maxLimit - the max number of entities that can be retrieved by this query
fetchPlan - the fetch plan used for this query
tableName - the name of the entity in Force.com
Returns:
the SOQL query

buildQuery

public String buildQuery(TableImpl table,
                         org.datanucleus.metadata.AbstractClassMetaData acmd,
                         Set<Integer> fieldsToLoad,
                         org.datanucleus.query.compiler.QueryCompilation compilation,
                         boolean skipId,
                         long maxLimit,
                         org.datanucleus.FetchPlan fetchPlan,
                         int fetchDepth,
                         String tableName,
                         boolean isTopLevel,
                         boolean isJoin,
                         String joinAlias,
                         ExpressionBuilderHelper parentHelper)
Build a query for fetching multiple objects, whether top level or part of a join query.

Parameters:
table - the table representing the object being queried
acmd - the class metadata for the object being queried
fieldsToLoad - the set of fields to load
compilation - the compile query
skipId - true if the id field should be skipped which might be necessary during joins
maxLimit - the max number of entities that can be retrieved by this query
fetchPlan - the fetch plan used for this query
fetchDepth - the depth that fetches should go (i.e. how many relationships can be traversed)
tableName - the name of the entity in Force.com
isTopLevel - whether this object is the top level entity being queried or is part of a subquery
isJoin - whether this is part of a join call
joinAlias - the alias for a join query
parentHelper - the expression builder for the parent query
Returns:
the SOQL query

getIdFromObject

public static Object getIdFromObject(javax.jdo.spi.PersistenceCapable entity,
                                     org.datanucleus.metadata.AbstractClassMetaData acmd)
convenience method for getting the id value from an entity.

Parameters:
entity - the entity containing the id
acmd - the class metadata (for discovering the id field)
Returns:
the id value of the object

appendRelationshipQuery

public void appendRelationshipQuery(ExpressionBuilderHelper helper,
                                    org.datanucleus.metadata.AbstractMemberMetaData ammd,
                                    ColumnImpl col)
helper method to handle joining a relationship field to a query that is currently being built.

Parameters:
helper - the expression builder with the in progress query
ammd - the member metadata for the relationship being appended
col - the column data for the relationship field

appendRelationshipFields

public void appendRelationshipFields(ExpressionBuilderHelper helper,
                                     ColumnImpl col,
                                     String prefix)
Append the fields in the default fetch group for the entity in the relationship to the query.

Parameters:
helper - the expression builder with the in progress query
col - the column data for the relationship field
prefix - the prefix to add to the relationship field


Copyright © 2011. All Rights Reserved.