use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class EntitySnapshotManager method getSnapshots.
@Override
public List<EntitySnapshot> getSnapshots(MetaClass metaClass, Object id) {
metaClass = extendedEntities.getOriginalOrThisMetaClass(metaClass);
Entity entity = dataManager.load(new LoadContext<>(metaClass).setId(id).setView(View.LOCAL));
checkCompositePrimaryKey(entity);
List<EntitySnapshot> resultList = null;
View view = metadata.getViewRepository().getView(EntitySnapshot.class, "entitySnapshot.browse");
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
TypedQuery<EntitySnapshot> query = em.createQuery(format("select s from sys$EntitySnapshot s where s.entity.%s = :entityId and s.entityMetaClass = :metaClass " + "order by s.snapshotDate desc", referenceToEntitySupport.getReferenceIdPropertyName(metaClass)), EntitySnapshot.class);
query.setParameter("entityId", referenceToEntitySupport.getReferenceId(entity));
query.setParameter("metaClass", metaClass.getName());
query.setView(view);
resultList = query.getResultList();
tx.commit();
} finally {
tx.end();
}
return resultList;
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class FoldersServiceBean method loadSearchFolders.
@Override
public List<SearchFolder> loadSearchFolders() {
log.debug("Loading SearchFolders");
StopWatch stopWatch = new Slf4JStopWatch("SearchFolders");
stopWatch.start();
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
MetaClass effectiveMetaClass = metadata.getExtendedEntities().getEffectiveMetaClass(SearchFolder.class);
TypedQuery<SearchFolder> q = em.createQuery("select f from " + effectiveMetaClass.getName() + " f " + "left join fetch f.user u on u.id = ?1 " + "left join fetch f.presentation " + "where (u.id = ?1 or u is null) " + "order by f.sortOrder, f.name", SearchFolder.class);
q.setParameter(1, userSessionSource.currentOrSubstitutedUserId());
List<SearchFolder> list = q.getResultList();
// fetch parents
for (SearchFolder folder : list) {
folder.getParent();
}
tx.commit();
return list;
} finally {
tx.end();
stopWatch.stop();
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class LockManager method getConfig.
private Map<String, LockDescriptor> getConfig() {
if (this.config == null) {
synchronized (this) {
if (this.config == null) {
Map<String, LockDescriptor> config = new ConcurrentHashMap<>();
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
TypedQuery<LockDescriptor> q = em.createQuery("select d from sys$LockDescriptor d", LockDescriptor.class);
List<LockDescriptor> list = q.getResultList();
for (LockDescriptor ld : list) {
config.put(ld.getName(), ld);
}
tx.commit();
} finally {
tx.end();
}
this.config = config;
}
}
}
return config;
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class NumberIdWorker method checkSequenceExists.
protected void checkSequenceExists(String entityName, long startValue, long increment) {
String seqName = getSequenceName(entityName);
if (existingSequences.contains(seqName))
return;
// Create sequence in separate transaction because it's name is cached and we want to be sure it is created
// regardless of possible errors in the invoking code
Transaction tx = persistence.createTransaction(getDataStore(entityName));
try {
EntityManager em = persistence.getEntityManager(getDataStore(entityName));
SequenceSupport sequenceSupport = getSequenceSupport(entityName);
Query query = em.createNativeQuery(sequenceSupport.sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(sequenceSupport.createSequenceSql(seqName, startValue, increment));
query.executeUpdate();
}
existingSequences.add(seqName);
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.core.EntityManager in project cuba by cuba-platform.
the class TestingServiceBean method clearScheduledTasks.
@Override
public void clearScheduledTasks() {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createNativeQuery("delete from SYS_SCHEDULED_EXECUTION");
query.executeUpdate();
query = em.createNativeQuery("delete from SYS_SCHEDULED_TASK");
query.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
Aggregations