Search in sources :

Example 1 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project cuba by cuba-platform.

the class QueryImpl method preExecute.

protected void preExecute(JpaQuery jpaQuery) {
    // copying behaviour of org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery()
    DatabaseQuery elDbQuery = ((EJBQueryImpl) jpaQuery).getDatabaseQueryInternal();
    boolean isObjectLevelReadQuery = elDbQuery.isObjectLevelReadQuery();
    if (jpaQuery.getFlushMode() == FlushModeType.AUTO && (!isObjectLevelReadQuery || !((ObjectLevelReadQuery) elDbQuery).isReadOnly())) {
        // flush is expected
        entityChangedEventManager.beforeFlush(support.getInstances(entityManager));
        support.processFlush(entityManager, true);
    }
}
Also used : ObjectLevelReadQuery(org.eclipse.persistence.queries.ObjectLevelReadQuery) DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) EJBQueryImpl(org.eclipse.persistence.internal.jpa.EJBQueryImpl)

Example 2 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project jmix by jmix-framework.

the class JmixEclipseLinkQuery method executeUpdate.

@Override
public int executeUpdate() {
    JpaQuery<E> jpaQuery = getQuery();
    DatabaseQuery databaseQuery = jpaQuery.getDatabaseQuery();
    Class referenceClass = databaseQuery.getReferenceClass();
    boolean isDeleteQuery = databaseQuery.isDeleteObjectQuery() || databaseQuery.isDeleteAllQuery();
    boolean enableDeleteInSoftDeleteMode = Boolean.parseBoolean(environment.getProperty("jmix.data.enable-delete-statement-in-soft-delete-mode"));
    if (!enableDeleteInSoftDeleteMode && PersistenceHints.isSoftDeletion(entityManager) && isDeleteQuery) {
        if (metadataTools.isSoftDeletable(referenceClass)) {
            throw new UnsupportedOperationException("Delete queries are not supported with enabled soft deletion. " + "Use 'cuba.enableDeleteStatementInSoftDeleteMode' application property to roll back to legacy behavior.");
        }
    }
    // In some cache configurations (in particular, when shared cache is on, but for some entities cache is set to ISOLATED),
    // EclipseLink does not evict updated entities from cache automatically.
    Cache cache = jpaQuery.getEntityManager().getEntityManagerFactory().getCache();
    if (referenceClass != null) {
        cache.evict(referenceClass);
        queryCacheMgr.invalidate(referenceClass);
    } else {
        cache.evictAll();
        queryCacheMgr.invalidateAll();
    }
    preExecute(jpaQuery);
    return jpaQuery.executeUpdate();
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) MetaClass(io.jmix.core.metamodel.model.MetaClass) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass)

Example 3 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class JPAQuery method processJPQLQuery.

/**
 * INTERNAL:
 * Convert the JPA query into a DatabaseQuery.
 */
public DatabaseQuery processJPQLQuery(Session session) {
    ClassLoader classloader = session.getDatasourcePlatform().getConversionManager().getLoader();
    LockModeType lockModeEnum = null;
    // Must handle errors if a JPA 2.0 option is used in JPA 1.0.
    try {
        lockModeEnum = LockModeType.valueOf(lockMode);
    } catch (Exception ignore) {
    // Ignore JPA 2.0 in JPA 1.0, reverts to no lock.
    }
    DatabaseQuery ejbquery = EJBQueryImpl.buildEJBQLDatabaseQuery(getName(), jpqlString, (AbstractSession) session, lockModeEnum, hints, classloader);
    ejbquery.setName(getName());
    return ejbquery;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) LockModeType(jakarta.persistence.LockModeType) OptimisticLockException(org.eclipse.persistence.exceptions.OptimisticLockException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException)

Example 4 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class JPAQuery method processStoredProcedureQuery.

/**
 * INTERNAL:
 * Convert the StoredProc call into a DatabaseQuery.
 */
public DatabaseQuery processStoredProcedureQuery(Session session) {
    DatabaseQuery query = null;
    ClassLoader loader = session.getDatasourcePlatform().getConversionManager().getLoader();
    if (resultClassNames != null) {
        List<SQLResultSetMapping> resultSetMappings = new ArrayList<>();
        for (String resultClass : resultClassNames) {
            SQLResultSetMapping mapping = new SQLResultSetMapping(resultClass);
            EntityResult entityResult = new EntityResult(resultClass);
            mapping.addResult(entityResult);
            resultSetMappings.add(mapping);
        }
        query = StoredProcedureQueryImpl.buildResultSetMappingQuery(resultSetMappings, call, hints, loader, (AbstractSession) session);
    } else if (resultSetMappingNames != null) {
        query = StoredProcedureQueryImpl.buildResultSetMappingNameQuery(resultSetMappingNames, call, hints, loader, (AbstractSession) session);
    } else if (resultClassName != null) {
        Class<?> clazz = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(resultClassName);
        query = StoredProcedureQueryImpl.buildStoredProcedureQuery(clazz, call, hints, loader, (AbstractSession) session);
    } else {
        // Neither a resultClass or resultSetMapping is specified so place in a temp query on the session.
        if (call.isStoredFunctionCall() || call.isStoredPLSQLProcedureCall()) {
            // If it is a function (plsql or not) or plsql procedure use the data read query.
            query = StoredProcedureQueryImpl.buildStoredProcedureQuery(call, hints, loader, (AbstractSession) session);
        } else {
            // Otherwise use a result set mapping query for stored procedure calls so users can use the execute
            // method on it (JPA 2.1 API). Will return the same result, that is, Object[] in this case.
            query = StoredProcedureQueryImpl.buildResultSetMappingQuery(new ArrayList<>(), call, hints, loader, (AbstractSession) session);
        }
    }
    query.setName(getName());
    return query;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) SQLResultSetMapping(org.eclipse.persistence.queries.SQLResultSetMapping) ArrayList(java.util.ArrayList) EntityResult(org.eclipse.persistence.queries.EntityResult) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 5 with DatabaseQuery

use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.

the class StoredProcedureQueryImpl method buildStoredProcedureQuery.

/**
 * Build a DataReadQuery with the stored procedure call given.
 */
public static DatabaseQuery buildStoredProcedureQuery(StoredProcedureCall call, Map<String, Object> hints, ClassLoader classLoader, AbstractSession session) {
    DataReadQuery query = new DataReadQuery();
    query.setResultType(DataReadQuery.AUTO);
    query.setCall(call);
    query.setIsUserDefined(true);
    // apply any query hints
    DatabaseQuery hintQuery = applyHints(hints, query, classLoader, session);
    // apply any query arguments
    applyArguments(call, hintQuery);
    return hintQuery;
}
Also used : DatabaseQuery(org.eclipse.persistence.queries.DatabaseQuery) DataReadQuery(org.eclipse.persistence.queries.DataReadQuery)

Aggregations

DatabaseQuery (org.eclipse.persistence.queries.DatabaseQuery)86 ArrayList (java.util.ArrayList)18 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)15 List (java.util.List)14 Vector (java.util.Vector)12 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 ObjectLevelReadQuery (org.eclipse.persistence.queries.ObjectLevelReadQuery)12 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)8 EntityManager (jakarta.persistence.EntityManager)6 HashMap (java.util.HashMap)6 QName (javax.xml.namespace.QName)6 EJBQueryImpl (org.eclipse.persistence.internal.jpa.EJBQueryImpl)6 PersistenceContext (org.eclipse.persistence.jpa.rs.PersistenceContext)6 DataReadQuery (org.eclipse.persistence.queries.DataReadQuery)6 Session (org.eclipse.persistence.sessions.Session)6 Test (org.junit.Test)6 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)5 ReadQuery (org.eclipse.persistence.queries.ReadQuery)5 ReportQuery (org.eclipse.persistence.queries.ReportQuery)5 PersistenceException (jakarta.persistence.PersistenceException)4