Search in sources :

Example 76 with ReadAllQuery

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;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery)

Example 77 with ReadAllQuery

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;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ObjectRelationalDatabaseField(org.eclipse.persistence.mappings.structures.ObjectRelationalDatabaseField) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery)

Example 78 with ReadAllQuery

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;
}
Also used : AbstractRecord(org.eclipse.persistence.internal.sessions.AbstractRecord) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 79 with ReadAllQuery

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);
}
Also used : ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) Vector(java.util.Vector)

Example 80 with ReadAllQuery

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);
}
Also used : ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) Vector(java.util.Vector)

Aggregations

ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)440 Expression (org.eclipse.persistence.expressions.Expression)278 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)265 List (java.util.List)202 EntityManager (jakarta.persistence.EntityManager)135 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)119 Vector (java.util.Vector)112 ArrayList (java.util.ArrayList)88 Spatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial)82 SpatialParameters (org.eclipse.persistence.expressions.spatial.SpatialParameters)81 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)62 ReportQuery (org.eclipse.persistence.queries.ReportQuery)57 SimpleSpatial (org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial)47 WrappedSpatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial)44 SQLReader (org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader)41 JGeometry (oracle.spatial.geometry.JGeometry)30 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)29 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)28 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)27 Query (jakarta.persistence.Query)25