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);
}
}
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();
}
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;
}
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;
}
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;
}
Aggregations