Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
* 04/01/2011-2.3 Guy Pelletier
* - 337323: Multi-tenant with shared schema support (part 2)
* 09/09/2011-2.3.1 Guy Pelletier
* - 356197: Add new VPD type to MultitenantType
******************************************************************************/
package org.eclipse.persistence.queries;
import java.util.*;
import java.sql.*;
import org.eclipse.persistence.internal.databaseaccess.*;
import org.eclipse.persistence.internal.helper.*;
import org.eclipse.persistence.internal.descriptors.ObjectBuilder;
import org.eclipse.persistence.internal.queries.*;
import org.eclipse.persistence.internal.sessions.remote.*;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl;
import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.expressions.*;
import org.eclipse.persistence.sessions.SessionProfiler;
import org.eclipse.persistence.sessions.remote.*;
import org.eclipse.persistence.tools.profiler.QueryMonitor;
/**
*
Purpose:
* Concrete class for all read queries involving a collection of objects.
*
*
Responsibilities:
* Return a container of the objects generated by the query.
* Implements the inheritance feature when dealing with abstract descriptors
*
* @author Yvon Lavoie
* @since TOPLink/Java 1.0
*/
public class ReadAllQuery extends ObjectLevelReadQuery {
/** Used for collection and stream support. */
protected ContainerPolicy containerPolicy;
/** Used for Oracle HierarchicalQuery support */
protected Expression startWithExpression;
protected Expression connectByExpression;
protected List orderSiblingsByExpressions;
/**
* PUBLIC:
* Return a new read all query.
* A reference class must be specified before execution.
* It is better to provide the class and expression builder on construction to ensure a single expression builder is used.
* If no selection criteria is specified this will read all objects of the class from the database.
*/
public ReadAllQuery() {
super();
setContainerPolicy(ContainerPolicy.buildDefaultPolicy());
}
/**
* PUBLIC:
* Return a new read all query.
* It is better to provide the class and expression builder on construction to ensure a single expression builder is used.
* If no selection criteria is specified this will read all objects of the class from the database.
*/
public ReadAllQuery(Class classToRead) {
this();
this.referenceClass = classToRead;
}
/**
* PUBLIC:
* Return a new read all query for the class and the selection criteria.
*/
public ReadAllQuery(Class classToRead, Expression selectionCriteria) {
this();
this.referenceClass = classToRead;
setSelectionCriteria(selectionCriteria);
}
/**
* PUBLIC:
* Return a new read all query for the class.
* The expression builder must be used for all associated expressions used with the query.
*/
public ReadAllQuery(Class classToRead, ExpressionBuilder builder) {
this();
this.defaultBuilder = builder;
this.referenceClass = classToRead;
}
/**
* PUBLIC:
* Return a new read all query.
* The call represents a database interaction such as SQL, Stored Procedure.
*/
public ReadAllQuery(Class classToRead, Call call) {
this();
this.referenceClass = classToRead;
setCall(call);
}
/**
* PUBLIC:
* Return a query by example query to find all objects matching the attributes of the example object.
*/
public ReadAllQuery(Object exampleObject, QueryByExamplePolicy policy) {
this();
setExampleObject(exampleObject);
setQueryByExamplePolicy(policy);
}
/**
* PUBLIC:
* The expression builder should be provide on creation to ensure only one is used.
*/
public ReadAllQuery(ExpressionBuilder builder) {
this();
this.defaultBuilder = builder;
}
/**
* PUBLIC:
* Create a read all query with the database call.
*/
public ReadAllQuery(Call call) {
this();
setCall(call);
}
/**
* PUBLIC:
* Order the query results by the object's attribute or query key name.
*/
public void addAscendingOrdering(String queryKeyName) {
addOrdering(getExpressionBuilder().get(queryKeyName).ascending());
}
/**
* INTERNAL:
*
This method is called by the object builder when building an original.
* It will cause the original to be cached in the query results if the query
* is set to do so.
*/
@Override
public void cacheResult(Object unwrappedOriginal) {
Collection container = (Collection)getTemporaryCachedQueryResults();
if (container == null) {
container = (Collection)getContainerPolicy().containerInstance();
setTemporaryCachedQueryResults(container);
}
getContainerPolicy().addInto(unwrappedOriginal, container, getSession());
}
/**
* INTERNAL:
* The cache check is done before the prepare as a hit will not require the work to be done.
*/
@Override
protected Object checkEarlyReturnLocal(AbstractSession session, AbstractRecord translationRow) {
// Check for in-memory only query.
if (shouldCheckCacheOnly()) {
// assert !isReportQuery();
if (shouldUseWrapperPolicy()) {
getContainerPolicy().setElementDescriptor(this.descriptor);
}
// PERF: Fixed to not query each unit of work cache (is not conforming),
// avoid hashtable and primary key indexing.
// At some point we may need to support some kind of in-memory with conforming option,
// but we do not currently allow this.
AbstractSession rootSession = session;
while (rootSession.isUnitOfWork()) {
rootSession = ((UnitOfWorkImpl)rootSession).getParent();
}
Vector allCachedVector = rootSession.getIdentityMapAccessor().getAllFromIdentityMap(getSelectionCriteria(), getReferenceClass(), translationRow, getInMemoryQueryIndirectionPolicyState(), false);
// Must ensure that all of the objects returned are correctly registered in the unit of work.
if (session.isUnitOfWork()) {
allCachedVector = ((UnitOfWorkImpl)session).registerAllObjects(allCachedVector);
}
this.isCacheCheckComplete = true;
return getContainerPolicy().buildContainerFromVector(allCachedVector, session);
} else {
return null;
}
}
/**
* INTERNAL:
* Check to see if a custom query should be used for this query.
* This is done before the query is copied and prepared/executed.
* null means there is none.
*/
@Override
protected DatabaseQuery checkForCustomQuery(AbstractSession session, AbstractRecord translationRow) {
checkDescriptor(session);
// Check if user defined a custom query.
if (isCustomQueryUsed() == null) {
setIsCustomQueryUsed((!isUserDefined()) && isExpressionQuery() && (getSelectionCriteria() == null) && isDefaultPropertiesQuery() && (!hasOrderByExpressions()) && (this.descriptor.getQueryManager().hasReadAllQuery()));
}
if (isCustomQueryUsed().booleanValue()) {
return this.descriptor.getQueryManager().getReadAllQuery();
} else {
return null;
}
}
/**
* INTERNAL:
* Clone the query.
*/
@Override
public Object clone() {
ReadAllQuery cloneQuery = (ReadAllQuery)super.clone();
// Don't use setters as that will trigger unprepare
cloneQuery.containerPolicy = this.containerPolicy.clone(cloneQuery);
return cloneQuery;
}
/**
* INTERNAL:
* Conform the result if specified.
*/
protected Object conformResult(Object result, UnitOfWorkImpl unitOfWork, AbstractRecord arguments, boolean buildDirectlyFromRows) {
if (getSelectionCriteria() != null) {
ExpressionBuilder builder = getSelectionCriteria().getBuilder();
builder.setSession(unitOfWork.getRootSession(null));
builder.setQueryClass(getReferenceClass());
}
// If the query is redirected then the collection returned might no longer
// correspond to the original container policy. CR#2342-S.M.
ContainerPolicy cp;
if (getRedirector() != null) {
cp = ContainerPolicy.buildPolicyFor(result.getClass());
} else {
cp = getContainerPolicy();
}
// This code is now a great deal different... For one, registration is done
// as part of conforming. Also, this should only be called if one actually
// is conforming.
// First scan the UnitOfWork for conforming instances.
// This will walk through the entire cache of registered objects.
// Let p be objects from result not in the cache.
// Let c be objects from cache.
// Presently p intersect c = empty set, but later p subset c.
// By checking cache now doesConform will be called p fewer times.
Map