List of usage examples for org.hibernate LockMode READ
LockMode READ
To view the source code for org.hibernate LockMode READ.
Click Source Link
From source file:org.bedework.carddav.server.dirHandlers.db.HibSessionImpl.java
License:Apache License
/** * @param o//from ww w .ja va 2s . c om * @throws WebdavException */ public void lockRead(final Object o) throws WebdavException { if (exc != null) { // Didn't hear me last time? throw new WebdavException(exc); } try { sess.lock(o, LockMode.READ); } catch (Throwable t) { handleException(t); } }
From source file:org.bedework.dumprestore.HibSession.java
License:Apache License
/** * @param o/*from w w w . j ava2s .c om*/ * @throws CalFacadeException */ public void lockRead(Object o) throws CalFacadeException { if (exc != null) { // Didn't hear me last time? throw new CalFacadeException(exc); } try { sess.lock(o, LockMode.READ); } catch (Throwable t) { handleException(t); } }
From source file:org.bedework.util.hibernate.HibSessionImpl.java
License:Apache License
/** * @param o/*from w w w . j ava 2 s. c o m*/ * @throws HibException */ @Override public void lockRead(final Object o) throws HibException { if (exc != null) { // Didn't hear me last time? throw new HibException(exc); } try { sess.lock(o, LockMode.READ); } catch (Throwable t) { handleException(t); } }
From source file:org.jbpm.graph.node.JoinDbTest.java
License:Open Source License
public void testParentLockMode() { ProcessDefinition processDefinition = ProcessDefinition .parseXmlString("<process-definition name='lock mode'>" + " <join name='read' lock='READ' />" + " <join name='nowait' lock='UPGRADE_NOWAIT' />" + " <join name='upgrade' lock='pessimistic' />" + "</process-definition>"); deployProcessDefinition(processDefinition); processDefinition = graphSession.findLatestProcessDefinition("lock mode"); Join join = (Join) processDefinition.getNode("read"); assertEquals(LockMode.READ.toString(), join.getParentLockMode()); join = (Join) processDefinition.getNode("nowait"); assertEquals(LockMode.UPGRADE_NOWAIT.toString(), join.getParentLockMode()); join = (Join) processDefinition.getNode("upgrade"); assertEquals(LockMode.UPGRADE.toString(), join.getParentLockMode()); }
From source file:org.projectforge.business.fibu.datev.DatevImportDao.java
License:Open Source License
private Object get(final Class<?> clazz, final Integer id) { if (id == null) { return null; }/*from w w w. jav a2 s . com*/ return hibernateTemplate.get(clazz, id, LockMode.READ); }
From source file:org.projectforge.business.multitenancy.TenantDao.java
License:Open Source License
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public void internalAssignTenants(final PFUserDO user, final Set<TenantDO> tenantsToAssign, final Set<TenantDO> tenantsToUnassign, boolean checkAccess, boolean createHistoryEntry) throws AccessException { getHibernateTemplate().refresh(user, LockMode.READ); if (checkAccess) { if (TenantChecker.isSuperAdmin(ThreadLocalUserContext.getUser()) == false) { log.warn("User has now access right to change assigned users of a tenant! Skipping assignment."); return; }//from w ww.ja v a2 s. c o m } final List<TenantDO> assignedTenants = new ArrayList<TenantDO>(); if (tenantsToAssign != null) { for (final TenantDO tenant : tenantsToAssign) { final TenantDO dbTenant = getHibernateTemplate().get(clazz, tenant.getId(), LockMode.PESSIMISTIC_WRITE); Set<PFUserDO> assignedUsers = dbTenant.getAssignedUsers(); if (assignedUsers == null) { assignedUsers = new HashSet<PFUserDO>(); dbTenant.setAssignedUsers(assignedUsers); } if (assignedUsers.contains(user) == false) { log.info("Assigning user '" + user.getUsername() + "' to tenant '" + dbTenant.getName() + "'."); assignedUsers.add(user); assignedTenants.add(dbTenant); dbTenant.setLastUpdate(); // Needed, otherwise TenantDO is not detected for hibernate history! } else { log.info("User '" + user.getUsername() + "' already assigned to tenant '" + dbTenant.getName() + "'."); } } } final List<TenantDO> unassignedTenants = new ArrayList<TenantDO>(); if (tenantsToUnassign != null) { for (final TenantDO tenant : tenantsToUnassign) { final TenantDO dbTenant = getHibernateTemplate().get(clazz, tenant.getId(), LockMode.PESSIMISTIC_WRITE); final Set<PFUserDO> assignedUsers = dbTenant.getAssignedUsers(); if (assignedUsers != null && assignedUsers.contains(user) == true) { log.info("Unassigning user '" + user.getUsername() + "' from tenant '" + dbTenant.getName() + "'."); assignedUsers.remove(user); unassignedTenants.add(dbTenant); dbTenant.setLastUpdate(); // Needed, otherwise TenantDO is not detected for hibernate history! } else { log.info("User '" + user.getUsername() + "' is not assigned to tenant '" + dbTenant.getName() + "' (can't unassign)."); } } } flushSession(); if (createHistoryEntry) { createHistoryEntry(user, unassignedTenants, assignedTenants); } }
From source file:org.projectforge.business.user.GroupDao.java
License:Open Source License
/** * Assigns groups to and unassigns groups from given user. * * @param user//from w w w.java 2 s.c om * @param groupsToAssign Groups to assign (nullable). * @param groupsToUnassign Groups to unassign (nullable). * @throws AccessException */ @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ) public void assignGroups(final PFUserDO user, final Set<GroupDO> groupsToAssign, final Set<GroupDO> groupsToUnassign, final boolean updateUserGroupCache) { getHibernateTemplate().refresh(user, LockMode.READ); final List<GroupDO> assignedGroups = new ArrayList<>(); if (groupsToAssign != null) { for (final GroupDO group : groupsToAssign) { final GroupDO dbGroup = getHibernateTemplate().get(clazz, group.getId(), LockMode.PESSIMISTIC_WRITE); HistoryBaseDaoAdapter.wrappHistoryUpdate(dbGroup, () -> { Set<PFUserDO> assignedUsers = dbGroup.getAssignedUsers(); if (assignedUsers == null) { assignedUsers = new HashSet<>(); dbGroup.setAssignedUsers(assignedUsers); } if (assignedUsers.contains(user) == false) { log.info("Assigning user '" + user.getUsername() + "' to group '" + dbGroup.getName() + "'."); assignedUsers.add(user); assignedGroups.add(dbGroup); dbGroup.setLastUpdate(); // Needed, otherwise GroupDO is not detected for hibernate history! } else { log.info("User '" + user.getUsername() + "' already assigned to group '" + dbGroup.getName() + "'."); } return null; }); } } final List<GroupDO> unassignedGroups = new ArrayList<>(); if (groupsToUnassign != null) { for (final GroupDO group : groupsToUnassign) { final GroupDO dbGroup = getHibernateTemplate().get(clazz, group.getId(), LockMode.PESSIMISTIC_WRITE); HistoryBaseDaoAdapter.wrappHistoryUpdate(dbGroup, () -> { final Set<PFUserDO> assignedUsers = dbGroup.getAssignedUsers(); if (assignedUsers != null && assignedUsers.contains(user) == true) { log.info("Unassigning user '" + user.getUsername() + "' from group '" + dbGroup.getName() + "'."); assignedUsers.remove(user); unassignedGroups.add(dbGroup); dbGroup.setLastUpdate(); // Needed, otherwise GroupDO is not detected for hibernate history! } else { log.info("User '" + user.getUsername() + "' is not assigned to group '" + dbGroup.getName() + "' (can't unassign)."); } return null; }); } } flushSession(); createHistoryEntry(user, unassignedGroups, assignedGroups); if (updateUserGroupCache) { getUserGroupCache().setExpired(); } }
From source file:org.projectforge.core.BaseDao.java
License:Open Source License
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public O internalGetById(final Serializable id) { if (id == null) { return null; }/*from w ww . j a va 2 s.c o m*/ final O obj = getHibernateTemplate().get(clazz, id, LockMode.READ); afterLoad(obj); return obj; }
From source file:org.projectforge.fibu.datev.DatevImportDao.java
License:Open Source License
private Object get(final Class<?> clazz, final Integer id) { if (id == null) { return null; }//from w w w . ja va 2s.com return getHibernateTemplate().get(clazz, id, LockMode.READ); }
From source file:org.projectforge.framework.persistence.api.BaseDao.java
License:Open Source License
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public O internalGetById(final Serializable id) { if (id == null) { return null; }//from w w w . j av a 2 s. com final O obj = hibernateTemplate.get(clazz, id, LockMode.READ); afterLoad(obj); return obj; }