Java Code Examples for org.hibernate.EntityMode#DOM4J

The following examples show how to use org.hibernate.EntityMode#DOM4J . These examples are extracted from open source projects. 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
/**
 * 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
public String getAccessorPropertyName( EntityMode mode ) {
	if ( mode == EntityMode.DOM4J ) {
		return nodeName;
	}
	else {
		return getName();
	}
}
 
Example 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
public EntityMode getEntityMode() {
	return EntityMode.DOM4J;
}
 
Example 15
private boolean cascadeAssociationNow(AssociationType associationType) {
	return associationType.getForeignKeyDirection().cascadeNow(cascadeTo) &&
		( eventSource.getEntityMode()!=EntityMode.DOM4J || associationType.isEmbeddedInXML() );
}
 
Example 16
/**
 * 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 17
protected boolean isNotEmbedded(SessionImplementor session) {
	return !isEmbeddedInXML && session.getEntityMode()==EntityMode.DOM4J;
}
 
Example 18
/** 
 * 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 19
public boolean hasHolder(EntityMode entityMode) {
	return entityMode == EntityMode.DOM4J;
}
 
Example 20
protected boolean initializeImmediately(EntityMode entityMode) {
	return entityMode == EntityMode.DOM4J;
}