use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class JGeometryProject method buildWrappedSpatialDescriptor.
public ClassDescriptor buildWrappedSpatialDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial.class);
descriptor.addTableName("WRAPPED_SPATIAL");
descriptor.addPrimaryKeyFieldName("WRAPPED_SPATIAL.GID");
// Descriptor Properties.
descriptor.useSoftCacheWeakIdentityMap();
descriptor.setIdentityMapSize(100);
descriptor.useRemoteSoftCacheWeakIdentityMap();
descriptor.setRemoteIdentityMapSize(100);
descriptor.setAlias("WrappedSpatial");
descriptor.setAmendmentClass(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.TopLinkAfterLoad.class);
descriptor.setAmendmentMethodName("afterLoadWrappedSpatial");
// Query Manager.
descriptor.getQueryManager().checkCacheForDoesExist();
// Named Queries.
// Named Query -- findAllWrappedSpatial
ReadAllQuery namedQuery0 = new ReadAllQuery(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial.class);
namedQuery0.setName("findAllWrappedSpatial");
namedQuery0.setQueryTimeout(0);
namedQuery0.setCacheUsage(ObjectLevelReadQuery.CheckCacheByPrimaryKey);
namedQuery0.setLockMode(ObjectLevelReadQuery.NO_LOCK);
descriptor.getQueryManager().addQuery("findAllWrappedSpatial", namedQuery0);
// Event Manager.
// Query keys.
descriptor.addDirectQueryKey("geometry.id", "WRAPPED_SPATIAL.GEOMETRY.ID");
descriptor.addDirectQueryKey("geometry.geom", "WRAPPED_SPATIAL.GEOMETRY.GEOM");
// Mappings.
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("WRAPPED_SPATIAL.GID");
descriptor.addMapping(idMapping);
DirectToFieldMapping geometryMapping = new DirectToFieldMapping();
geometryMapping.setAttributeName("geometry");
ObjectRelationalDatabaseField f = new ObjectRelationalDatabaseField("WRAPPED_SPATIAL.GEOMETRY");
geometryMapping.setField(f);
geometryMapping.setFieldType(java.sql.Types.STRUCT);
descriptor.addMapping(geometryMapping);
descriptor.applyAmendmentMethod();
return descriptor;
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class JGeometryProject method buildSimpleSpatialDescriptor.
public ClassDescriptor buildSimpleSpatialDescriptor() {
RelationalDescriptor descriptor = new RelationalDescriptor();
descriptor.setJavaClass(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial.class);
descriptor.addTableName("SIMPLE_SPATIAL");
descriptor.addPrimaryKeyFieldName("SIMPLE_SPATIAL.GID");
// Descriptor Properties.
descriptor.useSoftCacheWeakIdentityMap();
descriptor.setIdentityMapSize(100);
descriptor.useRemoteSoftCacheWeakIdentityMap();
descriptor.setRemoteIdentityMapSize(100);
descriptor.setAlias("SimpleSpatial");
// Query Manager.
descriptor.getQueryManager().checkCacheForDoesExist();
// Named Queries.
// Named Query -- findAllSimpleSpatial
ReadAllQuery namedQuery0 = new ReadAllQuery(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial.class);
namedQuery0.setName("findAllSimpleSpatial");
namedQuery0.setQueryTimeout(0);
namedQuery0.setCacheUsage(ObjectLevelReadQuery.CheckCacheByPrimaryKey);
namedQuery0.setLockMode(ObjectLevelReadQuery.NO_LOCK);
descriptor.getQueryManager().addQuery("findAllSimpleSpatial", namedQuery0);
// Event Manager.
// Mappings.
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("SIMPLE_SPATIAL.GID");
descriptor.addMapping(idMapping);
DirectToFieldMapping geometryMapping = new DirectToFieldMapping();
geometryMapping.setAttributeName("geometry");
ObjectRelationalDatabaseField f = new ObjectRelationalDatabaseField("SIMPLE_SPATIAL.GEOMETRY");
geometryMapping.setField(f);
geometryMapping.setFieldType(java.sql.Types.STRUCT);
descriptor.addMapping(geometryMapping);
return descriptor;
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class EISOneToManyQueryBasedValueHolder method instantiate.
@Override
protected T instantiate(AbstractSession session) throws DatabaseException {
Vector<AbstractRecord> rows = this.mapping.getForeignKeyRows(this.getRow(), session);
int size = rows.size();
ContainerPolicy cp = ((ReadAllQuery) this.getQuery()).getContainerPolicy();
@SuppressWarnings({ "unchecked" }) T returnValue = (T) cp.containerInstance(size);
for (int i = 0; i < size; i++) {
AbstractRecord nextRow = rows.get(i);
Object results = session.executeQuery(getQuery(), nextRow);
if (results instanceof Collection) {
Iterator<?> iter = ((Collection<?>) results).iterator();
while (iter.hasNext()) {
cp.addInto(iter.next(), returnValue, session);
}
} else if (results instanceof java.util.Map) {
Iterator<?> iter = ((java.util.Map<?, ?>) results).values().iterator();
while (iter.hasNext()) {
cp.addInto(iter.next(), returnValue, session);
}
} else {
cp.addInto(results, returnValue, session);
}
}
return returnValue;
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method readAllObjects.
/**
* PUBLIC:
* Read all of the instances of the class from the database matching the given expression.
* This operation can be customized through using a ReadAllQuery.
*
* @see ReadAllQuery
*/
@Override
public Vector readAllObjects(Class<?> domainClass, Expression expression) throws DatabaseException {
ReadAllQuery query = new ReadAllQuery();
query.setReferenceClass(domainClass);
query.setSelectionCriteria(expression);
query.setIsExecutionClone(true);
return (Vector) executeQuery(query);
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method readAllObjects.
/**
* PUBLIC:
* Read all of the instances of the class from the database.
* This operation can be customized through using a ReadAllQuery,
* or through also passing in a selection criteria.
*
* @see ReadAllQuery
* @see #readAllObjects(Class, Expression)
*/
@Override
public Vector readAllObjects(Class<?> domainClass) throws DatabaseException {
ReadAllQuery query = new ReadAllQuery();
query.setIsExecutionClone(true);
query.setReferenceClass(domainClass);
return (Vector) executeQuery(query);
}
Aggregations