public ReplicateEvent(String entityName, Object object, ReplicationMode replicationMode, EventSource source) { super(source); this.entityName = entityName; if ( object == null ) { throw new IllegalArgumentException( "attempt to create replication strategy with null entity" ); } if ( replicationMode == null ) { throw new IllegalArgumentException( "attempt to create replication strategy with null replication mode" ); } this.object = object; this.replicationMode = replicationMode; }
private void cascadeAfterReplicate( Object entity, EntityPersister persister, ReplicationMode replicationMode, EventSource source) { source.getPersistenceContext().incrementCascadeLevel(); try { new Cascade( CascadingActions.REPLICATE, CascadePoint.AFTER_UPDATE, source ).cascade( persister, entity, replicationMode ); } finally { source.getPersistenceContext().decrementCascadeLevel(); } }
@Override public void execute() { Transaction tx = session.beginTransaction(); try{ for (Object item : list){ session.replicate(item, ReplicationMode.IGNORE); } tx.commit(); success = true; log.info("saving objects successfully: " + list.get(0).getClass()); } catch (HibernateException e) { tx.rollback(); log.error("saving objects failed: " + list.get(0).getClass()); log.error(e); message = e.getMessage(); } }
/** * same thing as addDefaultRoles(Integer organisationId, Integer moduleId) but using the same session */ public void addDefaultRoles(Integer organisationId, Integer moduleId, Session session){ logger.debug("Add default roles DAO IMPL - START- "); List<RoleWeb> roles = getDefaultRolesByModule(moduleId); for(RoleWeb role:roles){ role.setOrganisationId(organisationId); role.setModuleId(moduleId); Localization description = new Localization(); description.setLocalizationId(0); description.setEn(role.getDescription().getEn()); description.setRo(role.getDescription().getRo()); logger.debug("description role = " + role.getDescription()); session.save(IModelConstant.localizationEntity, description); role.setDescription(description); //session.evict(IModelConstant.roleWebEntity); //logger.debug("After evict " + role); role.setRoleId(0); logger.debug("Role " + role); session.replicate(IModelConstant.roleWebEntity, role, ReplicationMode.IGNORE); logger.debug("�fter save " + role); } logger.debug("Add default roles DAO IMPL - END- "); }
@Override public void replicate(final Object entity, final ReplicationMode replicationMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { @Override public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); session.replicate(entity, replicationMode); return null; } }); }
@Override public void replicate(final String entityName, final Object entity, final ReplicationMode replicationMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { @Override public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); session.replicate(entityName, entity, replicationMode); return null; } }); }
@Override public void cascade( EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled) throws HibernateException { LOG.tracev( "Cascading to replicate: {0}", entityName ); session.replicate( entityName, child, (ReplicationMode) anything ); }
private void performReplication( Object entity, Serializable id, Object version, EntityPersister persister, ReplicationMode replicationMode, EventSource source) throws HibernateException { if ( LOG.isTraceEnabled() ) { LOG.tracev( "Replicating changes to {0}", MessageHelper.infoString( persister, id, source.getFactory() ) ); } new OnReplicateVisitor( source, id, entity, true ).process( entity, persister ); source.getPersistenceContext().addEntity( entity, ( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ), null, source.generateEntityKey( id, persister ), version, LockMode.NONE, true, persister, true, false ); cascadeAfterReplicate( entity, persister, replicationMode, source ); }
@Sessional @Override public void importData(Metadata metadata, File dataDir) { Session session = dao.getSession(); List<Class<?>> entityTypes = getEntityTypes(sessionFactory); Collections.reverse(entityTypes); for (Class<?> entityType: entityTypes) { File[] dataFiles = dataDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith(entityType.getSimpleName() + "s.xml"); } }); for (File file: dataFiles) { try { logger.info("Importing from data file '" + file.getName() + "'..."); session.beginTransaction(); VersionedDocument dom = VersionedDocument.fromFile(file); for (Element element: dom.getRootElement().elements()) { element.detach(); AbstractEntity entity = (AbstractEntity) new VersionedDocument(DocumentHelper.createDocument(element)).toBean(); session.replicate(entity, ReplicationMode.EXCEPTION); } session.flush(); session.clear(); session.getTransaction().commit(); } catch (Throwable e) { session.getTransaction().rollback(); throw Throwables.propagate(e); } } } }
@Test public void testReplicate() throws HibernateException { TestBean tb = new TestBean(); given(session.getFlushMode()).willReturn(FlushMode.AUTO); hibernateTemplate.replicate(tb, ReplicationMode.LATEST_VERSION); verify(session).replicate(tb, ReplicationMode.LATEST_VERSION); verify(session).flush(); verify(session).close(); }
@Test public void testReplicateWithEntityName() throws HibernateException { TestBean tb = new TestBean(); given(session.getFlushMode()).willReturn(FlushMode.AUTO); hibernateTemplate.replicate("myEntity", tb, ReplicationMode.LATEST_VERSION); verify(session).replicate("myEntity", tb, ReplicationMode.LATEST_VERSION); verify(session).flush(); verify(session).close(); }
@Test public void testReplicate() { TestBean tb = new TestBean(); given(session.getFlushMode()).willReturn(FlushMode.AUTO); hibernateTemplate.replicate(tb, ReplicationMode.LATEST_VERSION); verify(session).replicate(tb, ReplicationMode.LATEST_VERSION); }
@Test public void testReplicateWithEntityName() { TestBean tb = new TestBean(); given(session.getFlushMode()).willReturn(FlushMode.AUTO); hibernateTemplate.replicate("myEntity", tb, ReplicationMode.LATEST_VERSION); verify(session).replicate("myEntity", tb, ReplicationMode.LATEST_VERSION); }
public void cascade(EventSource session, Object child, String entityName, Object anything, boolean isCascadeDeleteEnabled) throws HibernateException { if ( log.isTraceEnabled() ) { log.trace( "cascading to replicate: " + entityName ); } session.replicate( entityName, child, (ReplicationMode) anything ); }
private void performReplication( Object entity, Serializable id, Object version, EntityPersister persister, ReplicationMode replicationMode, EventSource source) throws HibernateException { if ( log.isTraceEnabled() ) { log.trace( "replicating changes to " + MessageHelper.infoString( persister, id, source.getFactory() ) ); } new OnReplicateVisitor( source, id, entity, true ).process( entity, persister ); source.getPersistenceContext().addEntity( entity, Status.MANAGED, null, new EntityKey( id, persister, source.getEntityMode() ), version, LockMode.NONE, true, persister, true, false ); cascadeAfterReplicate( entity, persister, replicationMode, source ); }
private void cascadeAfterReplicate( Object entity, EntityPersister persister, ReplicationMode replicationMode, EventSource source) { source.getPersistenceContext().incrementCascadeLevel(); try { new Cascade( CascadingAction.REPLICATE, Cascade.AFTER_UPDATE, source ) .cascade( persister, entity, replicationMode ); } finally { source.getPersistenceContext().decrementCascadeLevel(); } }
public void testReplicate() throws Exception { Session s = openSession(); Container baz = new Container(); Contained f = new Contained(); List list = new ArrayList(); list.add(baz); f.setBag(list); List list2 = new ArrayList(); list2.add(f); baz.setBag(list2); s.save(f); s.save(baz); s.flush(); s.connection().commit(); s.close(); s = openSession(); s.replicate(baz, ReplicationMode.OVERWRITE); // HHH-2378 SessionImpl x = (SessionImpl)s; EntityEntry entry = x.getPersistenceContext().getEntry( baz ); assertNull(entry.getVersion()); s.flush(); s.connection().commit(); s.close(); s = openSession(); s.replicate(baz, ReplicationMode.IGNORE); s.flush(); s.connection().commit(); s.close(); s = openSession(); s.delete(baz); s.delete(f); s.flush(); s.connection().commit(); s.close(); }
/** * Persist the state of the given detached instance according to the given replication mode, reusing the current identifier value. * * @param entity the persistent object to replicate * @param replicationMode the Hibernate ReplicationMode * @throws DataAccessException in case of Hibernate errors * @see org.hibernate.Session#replicate(Object, org.hibernate.ReplicationMode) */ @Override public void replicate(final Object entity, final ReplicationMode replicationMode) throws DataAccessException { executeWithNativeSession(session -> { checkWriteOperationAllowed(session); session.replicate(entity, replicationMode); return null; }); }
public void replicate(final Object entity, final ReplicationMode replicationMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); session.replicate(entity, replicationMode); return null; } }); }
public void replicate(final String entityName, final Object entity, final ReplicationMode replicationMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); session.replicate(entityName, entity, replicationMode); return null; } }); }
@Override public void replicate(Object object, ReplicationMode replicationMode) { session.replicate( object, replicationMode ); }
@Override public void replicate(String entityName, Object object, ReplicationMode replicationMode) { session.replicate( entityName, object, replicationMode ); }
@Override public void replicate(Object obj, ReplicationMode replicationMode) throws HibernateException { fireReplicate( new ReplicateEvent( obj, replicationMode, this ) ); }
@Override public void replicate(String entityName, Object obj, ReplicationMode replicationMode) throws HibernateException { fireReplicate( new ReplicateEvent( entityName, obj, replicationMode, this ) ); }
public ReplicateEvent(Object object, ReplicationMode replicationMode, EventSource source) { this(null, object, replicationMode, source); }
public ReplicationMode getReplicationMode() { return replicationMode; }
public void setReplicationMode(ReplicationMode replicationMode) { this.replicationMode = replicationMode; }
@Override public void replicate(Object o, ReplicationMode replicationMode) throws DataAccessException { }