use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class DatasourceCallQueryMechanism method prepareCall.
/**
* INTERNAL:
* This is different from 'prepareForExecution' in that this is called on the original query,
* and the other is called on the copy of the query.
* This query is copied for concurrency so this prepare can only setup things that
* will apply to any future execution of this query.
*/
public void prepareCall() throws QueryException {
DatabaseQuery query = getQuery();
AbstractSession executionSession = query.getExecutionSession();
if (hasMultipleCalls()) {
for (DatasourceCall call : (List<DatasourceCall>) getCalls()) {
call.prepare(executionSession);
}
} else if (getCall() != null) {
getCall().prepare(executionSession);
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class TestTimestampVersionLocking method testLocalTimestampProperty.
/**
* Check that setting the property "true" will get the local system time
* instead of the default behavior of contacting the server.
*/
@Test
public void testLocalTimestampProperty() throws Exception {
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
// Get the session for this transaction
Session session = ((EntityManagerImpl) em).getActiveSession();
// Get the TimestampQuery that would be used by the platform to get the current time
DatabaseQuery query = session.getDatasourcePlatform().getTimestampQuery();
// Add a Listener to the session
QueryListener listener = new QueryListener(query);
session.getEventManager().addListener(listener);
// Persist an Entity that will use Timestamp version locking and will trigger QueryListener
TimestampDog dog = new TimestampDog();
em.persist(dog);
em.getTransaction().commit();
// Make sure the query was not executed
Assert.assertTrue("Query (" + listener.getQuery().getSQLString() + ") was executed unexpectedly.", !listener.wasQueryExecuted());
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project cuba by cuba-platform.
the class QueryImpl method executeUpdate.
@Override
public int executeUpdate() {
JpaQuery<T> jpaQuery = getQuery();
DatabaseQuery databaseQuery = jpaQuery.getDatabaseQuery();
Class referenceClass = databaseQuery.getReferenceClass();
boolean isDeleteQuery = databaseQuery.isDeleteObjectQuery() || databaseQuery.isDeleteAllQuery();
boolean enableDeleteInSoftDeleteMode = Boolean.parseBoolean(AppContext.getProperty("cuba.enableDeleteStatementInSoftDeleteMode"));
if (!enableDeleteInSoftDeleteMode && entityManager.isSoftDeletion() && isDeleteQuery) {
if (SoftDelete.class.isAssignableFrom(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, true);
} else {
cache.evictAll();
queryCacheMgr.invalidateAll(true);
}
preExecute(jpaQuery);
return jpaQuery.executeUpdate();
}
use of org.eclipse.persistence.queries.DatabaseQuery in project jmix by jmix-framework.
the class JmixEclipseLinkQuery method preExecute.
private void preExecute(JpaQuery<E> 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
support.processFlush(entityManager, true);
entityChangedEventManager.beforeFlush(support.getInstances(entityManager));
}
}
use of org.eclipse.persistence.queries.DatabaseQuery in project eclipselink by eclipse-ee4j.
the class XRServiceFactory method updateFindQueryNames.
/**
* <p>INTERNAL:
*
* Legacy projects have 'findAll' and 'findByPrimaryKey' queries, whereas we now
* expect these to have the descriptor alias appended (preceded with underscore),
* + 'Type'. For example, if we have an Employee descriptor, the find queries
* would be: 'findAll_employeeType' and 'findByPrimaryKey_employeeType'.
*/
@SuppressWarnings("rawtypes")
protected static void updateFindQueryNames(Project orProject) {
for (ClassDescriptor orDesc : orProject.getDescriptors().values()) {
Vector queries = orDesc.getQueryManager().getAllQueries();
for (int i = 0; i < queries.size(); i++) {
DatabaseQuery query = (DatabaseQuery) queries.get(i);
String qName = query.getName();
String END_PART = UNDERSCORE_STR + query.getDescriptor().getAlias() + TYPE_STR;
if ((PK_QUERYNAME.equals(qName) || ALL_QUERYNAME.equals(qName)) && !qName.endsWith(END_PART)) {
orDesc.getQueryManager().addQuery(qName + END_PART, query);
}
}
}
}
Aggregations