Java Code Examples for org.hibernate.EntityMode#DOM4J

The following examples show how to use org.hibernate.EntityMode#DOM4J . 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: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Get an iterator over the element set of the collection, which may not yet be wrapped
 *
 * @param collection The collection to be iterated
 * @param session The session from which the request is originating.
 * @return The iterator.
 */
public Iterator getElementsIterator(Object collection, SessionImplementor session) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		final SessionFactoryImplementor factory = session.getFactory();
		final CollectionPersister persister = factory.getCollectionPersister( getRole() );
		final Type elementType = persister.getElementType();
		
		List elements = ( (Element) collection ).elements( persister.getElementNodeName() );
		ArrayList results = new ArrayList();
		for ( int i=0; i<elements.size(); i++ ) {
			Element value = (Element) elements.get(i);
			results.add( elementType.fromXMLNode( value, factory ) );
		}
		return results.iterator();
	}
	else {
		return getElementsIterator(collection);
	}
}
 
Example 2
Source File: MapType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentMapElementHolder( session, (Element) collection );
	}
	else {
		return new PersistentMap( session, (java.util.Map) collection );
	}
}
 
Example 3
Source File: MapType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentMapElementHolder(session, persister, key);
	}
	else {
		return new PersistentMap(session);
	}
}
 
Example 4
Source File: ListType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentListElementHolder( session, (Element) collection );
	}
	else {
		return new PersistentList( session, (List) collection );
	}
}
 
Example 5
Source File: MyListType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		throw new IllegalStateException("dom4j not supported");
	}
	else {
		return new PersistentMyList( session, (IMyList) collection );
	}
}
 
Example 6
Source File: BagType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentElementHolder( session, (Element) collection );
	}
	else {
		return new PersistentBag( session, (Collection) collection );
	}
}
 
Example 7
Source File: SortedMapType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentMapElementHolder(session, persister, key);
	}
	else {
		PersistentSortedMap map = new PersistentSortedMap(session);
		map.setComparator(comparator);
		return map;
	}
}
 
Example 8
Source File: DefaultableListType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode() == EntityMode.DOM4J ) {
		throw new IllegalStateException( "dom4j not supported" );
	}
	else {
		return new PersistentDefaultableList( session, ( List ) collection );
	}
}
 
Example 9
Source File: Property.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getAccessorPropertyName( EntityMode mode ) {
	if ( mode == EntityMode.DOM4J ) {
		return nodeName;
	}
	else {
		return getName();
	}
}
 
Example 10
Source File: SortedSetType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentElementHolder( session, (Element) collection );
	}
	else {
		return new PersistentSortedSet( session, (java.util.SortedSet) collection );
	}
}
 
Example 11
Source File: SetType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentElementHolder(session, persister, key);
	}
	else {
		return new PersistentSet(session);
	}
}
 
Example 12
Source File: SetType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection wrap(SessionImplementor session, Object collection) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentElementHolder( session, (Element) collection );
	}
	else {
		return new PersistentSet( session, (java.util.Set) collection );
	}
}
 
Example 13
Source File: ListType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PersistentCollection instantiate(SessionImplementor session, CollectionPersister persister, Serializable key) {
	if ( session.getEntityMode()==EntityMode.DOM4J ) {
		return new PersistentListElementHolder(session, persister, key);
	}
	else {
		return new PersistentList(session);
	}
}
 
Example 14
Source File: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean hasHolder(EntityMode entityMode) {
	return entityMode == EntityMode.DOM4J;
}
 
Example 15
Source File: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected boolean initializeImmediately(EntityMode entityMode) {
	return entityMode == EntityMode.DOM4J;
}
 
Example 16
Source File: DefaultLoadEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** 
 * Handle the given load event.
 *
 * @param event The load event to be handled.
 * @throws HibernateException
 */
public void onLoad(LoadEvent event, LoadEventListener.LoadType loadType) throws HibernateException {

	final SessionImplementor source = event.getSession();

	EntityPersister persister;
	if ( event.getInstanceToLoad() != null ) {
		persister = source.getEntityPersister( null, event.getInstanceToLoad() ); //the load() which takes an entity does not pass an entityName
		event.setEntityClassName( event.getInstanceToLoad().getClass().getName() );
	}
	else {
		persister = source.getFactory().getEntityPersister( event.getEntityClassName() );
	}

	if ( persister == null ) {
		throw new HibernateException( 
				"Unable to locate persister: " + 
				event.getEntityClassName() 
			);
	}

	if ( persister.getIdentifierType().isComponentType() && EntityMode.DOM4J == event.getSession().getEntityMode() ) {
		// skip this check for composite-ids relating to dom4j entity-mode;
		// alternatively, we could add a check to make sure the incoming id value is
		// an instance of Element...
	}
	else {
		Class idClass = persister.getIdentifierType().getReturnedClass();
		if ( idClass != null && ! idClass.isInstance( event.getEntityId() ) ) {
			throw new TypeMismatchException(
					"Provided id of the wrong type. Expected: " + idClass + ", got " + event.getEntityId().getClass()
			);
		}
	}

	EntityKey keyToLoad = new EntityKey( event.getEntityId(), persister, source.getEntityMode()  );

	try {
		if ( loadType.isNakedEntityReturned() ) {
			//do not return a proxy!
			//(this option indicates we are initializing a proxy)
			event.setResult( load(event, persister, keyToLoad, loadType) );
		}
		else {
			//return a proxy if appropriate
			if ( event.getLockMode() == LockMode.NONE ) {
				event.setResult( proxyOrLoad(event, persister, keyToLoad, loadType) );
			}
			else {
				event.setResult( lockAndLoad(event, persister, keyToLoad, loadType, source) );
			}
		}
	}
	catch(HibernateException e) {
		log.info("Error performing load command", e);
		throw e;
	}
}
 
Example 17
Source File: EntityType.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected boolean isNotEmbedded(SessionImplementor session) {
	return !isEmbeddedInXML && session.getEntityMode()==EntityMode.DOM4J;
}
 
Example 18
Source File: Cascade.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Cascade to the collection elements
 */
private void cascadeCollectionElements(
		final Object child,
		final CollectionType collectionType,
		final CascadeStyle style,
		final Type elemType,
		final Object anything,
		final boolean isCascadeDeleteEnabled) throws HibernateException {
	// we can't cascade to non-embedded elements
	boolean embeddedElements = eventSource.getEntityMode()!=EntityMode.DOM4J ||
			( (EntityType) collectionType.getElementType( eventSource.getFactory() ) ).isEmbeddedInXML();

	boolean reallyDoCascade = style.reallyDoCascade(action) &&
		embeddedElements && child!=CollectionType.UNFETCHED_COLLECTION;

	if ( reallyDoCascade ) {
		if ( log.isTraceEnabled() ) {
			log.trace( "cascade " + action + " for collection: " + collectionType.getRole() );
		}

		Iterator iter = action.getCascadableChildrenIterator(eventSource, collectionType, child);
		while ( iter.hasNext() ) {
			cascadeProperty(
					iter.next(),
					elemType,
					style,
					anything,
					isCascadeDeleteEnabled
				);
		}

		if ( log.isTraceEnabled() ) {
			log.trace( "done cascade " + action + " for collection: " + collectionType.getRole() );
		}
	}

	final boolean deleteOrphans = style.hasOrphanDelete() &&
			action.deleteOrphans() &&
			elemType.isEntityType() &&
			child instanceof PersistentCollection; //a newly instantiated collection can't have orphans

	if ( deleteOrphans ) { // handle orphaned entities!!
		if ( log.isTraceEnabled() ) {
			log.trace( "deleting orphans for collection: " + collectionType.getRole() );
		}

		// we can do the cast since orphan-delete does not apply to:
		// 1. newly instantiated collections
		// 2. arrays (we can't track orphans for detached arrays)
		final String entityName = collectionType.getAssociatedEntityName( eventSource.getFactory() );
		deleteOrphans( entityName, (PersistentCollection) child );

		if ( log.isTraceEnabled() ) {
			log.trace( "done deleting orphans for collection: " + collectionType.getRole() );
		}
	}
}
 
Example 19
Source File: Cascade.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean cascadeAssociationNow(AssociationType associationType) {
	return associationType.getForeignKeyDirection().cascadeNow(cascadeTo) &&
		( eventSource.getEntityMode()!=EntityMode.DOM4J || associationType.isEmbeddedInXML() );
}
 
Example 20
Source File: Dom4jEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public EntityMode getEntityMode() {
	return EntityMode.DOM4J;
}