List of usage examples for org.hibernate ReplicationMode OVERWRITE
ReplicationMode OVERWRITE
To view the source code for org.hibernate ReplicationMode OVERWRITE.
Click Source Link
From source file:com.axway.academy.addressbook.core.AccountManagerImpl.java
License:Open Source License
/** * Persist a new account and a user associated with the account. * * @param account the new {@code Account} object that holds the account's attributes. * @param user the new {@code User} object that holds the user's attributes to be created along with the account. * May be set to {@code null} to create an account without a user. * @return An array of the newly persisted {@code Account} and {@code User} objects. * @throws DuplicateAccountException if the specified account already exists. * @throws DuplicateUserException if the specified user already exists. * @throws PasswordPolicyException if the passphrase set for the user does not fulfill the password policy * requirements./*from ww w .j ava2 s .com*/ * @throws AccountConstraintException if the account home folder is not valid. */ private Account persistAccount(Account account) throws DuplicateAccountException, PasswordPolicyException, AccountConstraintException { if (account.getId() != null) { throw new IllegalArgumentException("Instantiated from Template"); } Session session = mSessionFactoryManager.getSessionFactory().openSession(); try { ConstraintValidationUtil.validateNewAccount(session, (AccountBean) account); Transaction tx = session.beginTransaction(); Account persistedAccount = account; try { if (account.getId() == null) { // If object does not have an id, persist a copy so if exception is thrown original object is // unchanged. persistedAccount = ((AccountBean) account).copy(); session.save(persistedAccount); } else { session.replicate(persistedAccount, ReplicationMode.OVERWRITE); } } catch (ConstraintViolationException ex) { // Assume this is a uniqueness violation on the name since that is the only constraint in this bean. throw new DuplicateAccountExceptionImpl(account, "Duplicate account: " + account.getLoginname(), ex); } catch (HibernateException e) { final String message = "Database error creating account"; throw new RuntimeException(message, e); } session.flush(); tx.commit(); if (sLogger.isDebugEnabled()) { sLogger.debug("76568:createAccount : " + account); } return persistedAccount; } finally { SessionManagerFactory.closeSession(session); } }
From source file:com.axway.academy.addressbook.core.AccountManagerImpl.java
License:Open Source License
@Override public void updateAccount(Account account) throws NoSuchAccountException, DuplicateAccountException, PasswordPolicyException, AccountConstraintException { Session session = mSessionFactoryManager.getSessionFactory().openSession(); try {/*from w w w . j ava 2s .c o m*/ ConstraintValidationUtil.validateUpdateAccount(session, (AccountBean) account); Transaction tx = session.beginTransaction(); try { session.replicate(account, ReplicationMode.OVERWRITE); session.flush(); } catch (UnresolvableObjectException ex) { throw new NoSuchAccountException(account.getLoginname(), ex); } catch (ConstraintViolationException ex) { throw new DuplicateAccountExceptionImpl(account, "Duplicate account: " + account.getLoginname(), ex); } tx.commit(); if (sLogger.isDebugEnabled()) { sLogger.debug("76568: updateAccount updated: " + account, new Throwable("trace caller")); } } finally { SessionManagerFactory.closeSession(session); } }
From source file:com.github.jmnarloch.hstreams.internal.SessionDelegateTest.java
License:Apache License
@Test public void testReplicate() throws Exception { // given/* www. ja v a 2 s. c o m*/ final Object object = new Object(); final ReplicationMode replicationMode = ReplicationMode.OVERWRITE; // then verifyMethodCall(s -> s.replicate(object, replicationMode)); }
From source file:com.github.jmnarloch.hstreams.internal.SessionDelegateTest.java
License:Apache License
@Test public void testReplicate1() throws Exception { // given//from w w w. ja va2s . c om final String entityName = "entityName"; final Object object = new Object(); final ReplicationMode replicationMode = ReplicationMode.OVERWRITE; // then verifyMethodCall(s -> s.replicate(entityName, object, replicationMode)); }
From source file:org.tolweb.dao.PageDAOImpl.java
public void copyPageToDB(MappedPage page) { getSession().replicate(page, ReplicationMode.OVERWRITE); }