本文整理汇总了Java中com.haulmont.cuba.core.Transaction.end方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.end方法的具体用法?Java Transaction.end怎么用?Java Transaction.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.haulmont.cuba.core.Transaction
的用法示例。
在下文中一共展示了Transaction.end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPermissionValue
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
public Integer getPermissionValue(User user, PermissionType permissionType, String target) {
Integer result;
List<Role> roles = new ArrayList<>();
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
user = em.find(User.class, user.getId());
for (UserRole userRole : user.getUserRoles()) {
if (userRole.getRole() != null) {
roles.add(userRole.getRole());
}
}
UserSession session = new UserSession(uuidSource.createUuid(), user, roles, userSessionSource.getLocale(), false);
compilePermissions(session, roles);
result = session.getPermissionValue(permissionType, target);
tx.commit();
} finally {
tx.end();
}
return result;
}
示例2: testOneToMany_JoinFetchQuery
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testOneToMany_JoinFetchQuery() {
System.out.println("===================== BEGIN testOneToMany_JoinFetchQuery =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q = em.createQuery("select u from sec$User u join fetch u.userRoles where u.id = ?1");
q.setParameter(1, userId);
User user = (User) q.getSingleResult();
List<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToMany_JoinFetchQuery =====================");
}
示例3: migrateAttachmentsBatch
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
protected int migrateAttachmentsBatch() {
List<SendingAttachment> resultList;
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
String qstr = "select a from sys$SendingAttachment a where a.content is not null";
TypedQuery<SendingAttachment> query = em.createQuery(qstr, SendingAttachment.class);
query.setMaxResults(50);
query.setViewName(View.MINIMAL);
resultList = query.getResultList();
tx.commit();
} finally {
tx.end();
}
if (!resultList.isEmpty()) {
emailer.migrateAttachmentsToFileStorage(resultList);
}
return resultList.size();
}
示例4: getAvailableUsers
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public List<String> getAvailableUsers() {
List<String> result = new ArrayList<>();
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery("select u from sec$User u");
List<User> userList = query.getResultList();
for (User user : userList) {
result.add(user.getLogin());
}
tx.commit();
} finally {
tx.end();
}
return result;
}
示例5: testQuery
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testQuery() {
System.out.println("===================== BEGIN testQuery =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query query = em.createQuery("select r from sec$Role r where r.name = ?1");
query.setParameter(1, "roleToBeDeleted");
List<Role> list = query.getResultList();
assertTrue(list.isEmpty());
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testQuery =====================");
}
示例6: testRemoveNotManaged
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testRemoveNotManaged() {
System.out.println("===================== BEGIN testRemoveNotManaged =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
UserRole userRole = em.find(UserRole.class, userRole1Id);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
em.remove(userRole);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
UserRole deletedUserRole = em.find(UserRole.class, userRole1Id);
assertNull(deletedUserRole);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testRemoveNotManaged =====================");
}
示例7: registerExecutionFinish
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
protected void registerExecutionFinish(ScheduledTask task, ScheduledExecution execution, Object result) {
if ((!BooleanUtils.isTrue(task.getLogFinish()) && !BooleanUtils.isTrue(task.getSingleton()) && task.getSchedulingType() != SchedulingType.FIXED_DELAY)
|| execution == null)
return;
log.trace("{}: registering execution finish", task);
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
execution = em.merge(execution);
execution.setFinishTime(timeSource.currentTimestamp());
if (result != null)
execution.setResult(result.toString());
tx.commit();
} finally {
tx.end();
}
}
示例8: checkSequenceExists
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
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();
}
}
示例9: testOneToMany_Query
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testOneToMany_Query() {
System.out.println("===================== BEGIN testOneToMany_Query =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q = em.createQuery("select u from sec$User u where u.id = ?1");
q.setParameter(1, userId);
User user = (User) q.getSingleResult();
List<UserRole> userRoles = user.getUserRoles();
assertEquals(1, userRoles.size());
for (UserRole ur : userRoles) {
assertNotNull(ur.getRole());
}
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testOneToMany_Query =====================");
}
示例10: testUpdateQuery_CleanupMode
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testUpdateQuery_CleanupMode() {
System.out.println("===================== BEGIN testUpdateQuery_CleanupMode =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
em.setSoftDeletion(false);
Query query = em.createQuery("update sec$Role r set r.description = ?1 where r.name = ?2");
query.setParameter(1, "Updated");
query.setParameter(2, "roleToBeDeleted");
int updated = query.executeUpdate();
assertEquals(1, updated);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testUpdateQuery_CleanupMode =====================");
}
示例11: testReloadSameTx
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Test
public void testReloadSameTx() throws Exception {
User originalUser, reloadedUser;
View view = new View(User.class, false)
.addProperty("name");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
originalUser = em.find(User.class, userId, view);
assertNotNull(originalUser);
reloadedUser = em.reload(originalUser, "user.edit");
tx.commit();
} finally {
tx.end();
}
assertTrue(originalUser == reloadedUser);
reloadedUser = reserialize(reloadedUser);
assertNotNull(reloadedUser);
assertNotNull(reloadedUser.getLogin());
assertTrue(PersistenceHelper.isLoaded(reloadedUser, "userRoles"));
}
示例12: createGroups
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
private void createGroups() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group root = new Group();
rootId = root.getId();
root.setName("root");
em.persist(root);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
root = em.find(Group.class, rootId);
Group group1 = new Group();
group1Id = group1.getId();
group1.setName("group1");
group1.setParent(root);
em.persist(group1);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
group1 = em.find(Group.class, group1Id);
Group group2 = new Group();
group2Id = group2.getId();
group2.setName("group2");
group2.setParent(group1);
em.persist(group2);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
root = em.find(Group.class, rootId);
Group group3 = new Group();
group3Id = group3.getId();
group3.setName("group3");
group3.setParent(root);
em.persist(group3);
tx.commit();
} finally {
tx.end();
}
}
示例13: reloadAppFolders
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
log.debug("Reloading AppFolders {}", folders);
StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
stopWatch.start();
try {
if (!folders.isEmpty()) {
Binding binding = new Binding();
binding.setVariable("persistence", persistence);
binding.setVariable("metadata", metadata);
binding.setProperty("userSession", userSessionSource.getUserSession());
for (AppFolder folder : folders) {
Transaction tx = persistence.createTransaction();
try {
if (loadFolderQuantity(binding, folder)) {
tx.commit();
}
} finally {
tx.end();
}
}
}
return folders;
} finally {
stopWatch.stop();
}
}
示例14: tearDown
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q = em.createNativeQuery("delete from SEC_USER_SETTING where USER_ID = ?");
q.setParameter(1, TestUserSessionSource.USER_ID);
q.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
示例15: begin
import com.haulmont.cuba.core.Transaction; //导入方法依赖的package包/类
@Override
public Context begin() {
Transaction tx = persistence.createTransaction();
try {
List<ScheduledTask> tasks = getTasks();
return new ContextImpl(tasks, tx);
} catch (Exception e) {
tx.end();
throw new RuntimeException(e);
}
}