org.hibernate.ReplicationMode Java Examples

The following examples show how to use org.hibernate.ReplicationMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultReplicateEventListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void cascadeAfterReplicate(
		Object entity,
		EntityPersister persister,
		ReplicationMode replicationMode,
		EventSource source) {
	source.getPersistenceContext().incrementCascadeLevel();
	try {
		Cascade.cascade(
				CascadingActions.REPLICATE,
				CascadePoint.AFTER_UPDATE,
				source,
				persister,
				entity,
				replicationMode
		);
	}
	finally {
		source.getPersistenceContext().decrementCascadeLevel();
	}
}
 
Example #2
Source File: ReplicateEvent.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: ReplicateEvent.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example #4
Source File: HibernateTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void replicate(final Object entity, final ReplicationMode replicationMode)
		throws DataAccessException {

	executeWithNativeSession(session -> {
		checkWriteOperationAllowed(session);
		session.replicate(entity, replicationMode);
		return null;
	});
}
 
Example #5
Source File: DefaultPersistManager.java    From onedev with MIT License 5 votes vote down vote up
@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) {
			Transaction transaction = session.beginTransaction();
			try {
				logger.info("Importing from data file '" + file.getName() + "'...");
				VersionedXmlDoc dom = VersionedXmlDoc.fromFile(file);
				
				for (Element element: dom.getRootElement().elements()) {
					element.detach();
					AbstractEntity entity = (AbstractEntity) new VersionedXmlDoc(DocumentHelper.createDocument(element)).toBean();
					session.replicate(entity, ReplicationMode.EXCEPTION);
				}
				session.flush();
				session.clear();
				transaction.commit();
			} catch (Exception e) {
				transaction.rollback();
				throw ExceptionUtils.unchecked(e);
			}
		}
	}	
}
 
Example #6
Source File: HibernateTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void replicate(final String entityName, final Object entity, final ReplicationMode replicationMode)
		throws DataAccessException {

	executeWithNativeSession(session -> {
		checkWriteOperationAllowed(session);
		session.replicate(entityName, entity, replicationMode);
		return null;
	});
}
 
Example #7
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #8
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #9
Source File: HibernateTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void replicate(final Object entity, final ReplicationMode replicationMode)
		throws DataAccessException {

	executeWithNativeSession(session -> {
		checkWriteOperationAllowed(session);
		session.replicate(entity, replicationMode);
		return null;
	});
}
 
Example #10
Source File: HibernateTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void replicate(final String entityName, final Object entity, final ReplicationMode replicationMode)
		throws DataAccessException {

	executeWithNativeSession(session -> {
		checkWriteOperationAllowed(session);
		session.replicate(entityName, entity, replicationMode);
		return null;
	});
}
 
Example #11
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #12
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #13
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #14
Source File: CascadingAction.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
}
 
Example #15
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #16
Source File: ParentChildTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
}
 
Example #17
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #18
Source File: HibernateTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #19
Source File: HibernateTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #20
Source File: DefaultReplicateEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
	}
}
 
Example #21
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #22
Source File: DefaultReplicateEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 );
}
 
Example #23
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #24
Source File: HibernateTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #25
Source File: HibernateTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #26
Source File: CascadingActions.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 );
}
 
Example #27
Source File: HibernateTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #28
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #29
Source File: HibernateTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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;
		}
	});
}
 
Example #30
Source File: DefaultReplicateEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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
	);

	cascadeAfterReplicate( entity, persister, replicationMode, source );
}