HHH-10073 Removing types methods scheduled for removal in 5.0

This commit is contained in:
Gunnar Morling 2015-09-01 09:55:55 +02:00 committed by Steve Ebersole
parent 78fcfe26a7
commit 1db462f35f
4 changed files with 0 additions and 729 deletions

View File

@ -1,261 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.collection.internal;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.loader.CollectionAliases;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.Type;
import org.dom4j.Element;
/**
* A persistent wrapper for an XML element
*
* @author Gavin King
*
*
* @deprecated To be removed in 5. Removed as part of removing the notion of DOM entity-mode. See Jira issues
* <a href="https://hibernate.onjira.com/browse/HHH-7782">HHH-7782</a> and
* <a href="https://hibernate.onjira.com/browse/HHH-7783">HHH-7783</a> for more information.
*/
@Deprecated
@SuppressWarnings("UnusedDeclaration")
public class PersistentElementHolder extends AbstractPersistentCollection {
protected Element element;
/**
* Constructs a PersistentElementHolder
*
* @param session The session
* @param element The DOM element
*/
@SuppressWarnings("UnusedDeclaration")
public PersistentElementHolder(SessionImplementor session, Element element) {
super( session );
this.element = element;
setInitialized();
}
/**
* Constructs a PersistentElementHolder
*
* @param session The session
* @param persister The collection persister
* @param key The collection key (the fk value)
*/
@SuppressWarnings("UnusedDeclaration")
public PersistentElementHolder(SessionImplementor session, CollectionPersister persister, Serializable key) {
super( session );
final Element owner = (Element) session.getPersistenceContext().getCollectionOwner( key, persister );
if ( owner == null ) {
throw new AssertionFailure("null owner");
}
final String nodeName = persister.getNodeName();
if ( ".".equals( nodeName ) ) {
element = owner;
}
else {
element = owner.element( nodeName );
if ( element == null ) {
element = owner.addElement( nodeName );
}
}
}
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final List subElements = element.elements( persister.getElementNodeName() );
final ArrayList snapshot = new ArrayList( subElements.size() );
for ( Object subElement : subElements ) {
final Element element = (Element) subElement;
final Object value = elementType.fromXMLNode( element, persister.getFactory() );
final Object copy = elementType.deepCopy( value, persister.getFactory() );
snapshot.add( copy );
}
return snapshot;
}
@Override
public Collection getOrphans(Serializable snapshot, String entityName) {
//orphan delete not supported for EntityMode.DOM4J
return Collections.EMPTY_LIST;
}
@Override
public boolean isWrapper(Object collection) {
return element == collection;
}
@Override
@SuppressWarnings("deprecation")
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final ArrayList snapshot = (ArrayList) getSnapshot();
final List elements = element.elements( persister.getElementNodeName() );
if ( snapshot.size() != elements.size() ) {
return false;
}
for ( int i=0; i<snapshot.size(); i++ ) {
final Object old = snapshot.get( i );
final Element elem = (Element) elements.get( i );
final Object current = elementType.fromXMLNode( elem, persister.getFactory() );
if ( elementType.isDirty( old, current, getSession() ) ) {
return false;
}
}
return true;
}
@Override
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (Collection) snapshot ).isEmpty();
}
@Override
public boolean empty() {
return !element.elementIterator().hasNext();
}
@Override
@SuppressWarnings("deprecation")
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
throws HibernateException, SQLException {
final Object object = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() );
final Type elementType = persister.getElementType();
final Element subElement = element.addElement( persister.getElementNodeName() );
elementType.setToXMLNode( subElement, object, persister.getFactory() );
return object;
}
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Iterator entries(CollectionPersister persister) {
final Type elementType = persister.getElementType();
final List subElements = element.elements( persister.getElementNodeName() );
final int length = subElements.size();
final List result = new ArrayList(length);
for ( Object subElementO : subElements ) {
final Element subElement = (Element) subElementO;
final Object object = elementType.fromXMLNode( subElement, persister.getFactory() );
result.add( object );
}
return result.iterator();
}
@Override
public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {
}
@Override
public boolean isDirectlyAccessible() {
return true;
}
@Override
@SuppressWarnings("deprecation")
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
throws HibernateException {
final Type collectionElementType = persister.getElementType();
final Serializable[] cachedSnapshot = (Serializable[]) disassembled;
for ( Serializable cachedItem : cachedSnapshot ) {
final Object object = collectionElementType.assemble( cachedItem, getSession(), owner );
final Element subElement = element.addElement( persister.getElementNodeName() );
collectionElementType.setToXMLNode( subElement, object, persister.getFactory() );
}
}
@Override
@SuppressWarnings("deprecation")
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
final Type collectionElementType = persister.getElementType();
final List elements = element.elements( persister.getElementNodeName() );
final int length = elements.size();
final Serializable[] result = new Serializable[length];
for ( int i=0; i<length; i++ ) {
final Element elem = (Element) elements.get( i );
final Object object = collectionElementType.fromXMLNode( elem, persister.getFactory() );
result[i] = collectionElementType.disassemble( object, getSession(), null );
}
return result;
}
@Override
public Object getValue() {
return element;
}
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
final Type elementType = persister.getElementType();
final ArrayList snapshot = (ArrayList) getSnapshot();
final List elements = element.elements( persister.getElementNodeName() );
final ArrayList result = new ArrayList();
for ( int i=0; i<snapshot.size(); i++ ) {
final Object old = snapshot.get( i );
if ( i >= elements.size() ) {
result.add( old );
}
else {
final Element elem = (Element) elements.get( i );
final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
if ( elementType.isDirty( old, object, getSession() ) ) {
result.add( old );
}
}
}
return result.iterator();
}
@Override
public boolean needsInserting(Object entry, int i, Type elementType) throws HibernateException {
final ArrayList snapshot = (ArrayList) getSnapshot();
return i >= snapshot.size()
|| elementType.isDirty( snapshot.get( i ), entry, getSession() );
}
@Override
public boolean needsUpdating(Object entry, int i, Type elementType) throws HibernateException {
return false;
}
@Override
public Object getIndex(Object entry, int i, CollectionPersister persister) {
throw new UnsupportedOperationException();
}
@Override
public Object getElement(Object entry) {
return entry;
}
@Override
public Object getSnapshotElement(Object entry, int i) {
throw new UnsupportedOperationException();
}
@Override
public boolean entryExists(Object entry, int i) {
return entry!=null;
}
}

View File

@ -1,283 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.collection.internal;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.loader.CollectionAliases;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.StringRepresentableType;
import org.hibernate.type.Type;
import org.dom4j.Element;
/**
* A persistent wrapper for an XML element
*
* @author Gavin King
*
* @deprecated To be removed in 5. Removed as part of removing the notion of DOM entity-mode. See Jira issues
* <a href="https://hibernate.onjira.com/browse/HHH-7782">HHH-7782</a> and
* <a href="https://hibernate.onjira.com/browse/HHH-7783">HHH-7783</a> for more information.
*/
@Deprecated
public abstract class PersistentIndexedElementHolder extends AbstractPersistentCollection {
protected Element element;
/**
* Constructs a PersistentIndexedElementHolder.
*
* @param session The session
* @param element The DOM element being wrapped
*/
public PersistentIndexedElementHolder(SessionImplementor session, Element element) {
super( session );
this.element = element;
setInitialized();
}
/**
* Constructs a PersistentIndexedElementHolder.
*
* @param session The session
* @param persister The collection persister
* @param key The collection key (fk value)@throws HibernateException
*/
public PersistentIndexedElementHolder(SessionImplementor session, CollectionPersister persister, Serializable key) {
super( session );
final Element owner = (Element) session.getPersistenceContext().getCollectionOwner( key, persister );
if ( owner == null ) {
throw new AssertionFailure( "null owner" );
}
final String nodeName = persister.getNodeName();
if ( ".".equals( nodeName ) ) {
element = owner;
}
else {
element = owner.element( nodeName );
if ( element == null ) {
element = owner.addElement( nodeName );
}
}
}
/**
* A struct representing the index/value pair.
*/
public static final class IndexedValue {
final String index;
final Object value;
IndexedValue(String index, Object value) {
this.index = index;
this.value = value;
}
}
protected static String getIndex(Element element, String indexNodeName, int i) {
if ( indexNodeName != null ) {
return element.attributeValue( indexNodeName );
}
else {
return Integer.toString( i );
}
}
protected static void setIndex(Element element, String indexNodeName, String index) {
if ( indexNodeName != null ) {
element.addAttribute( indexNodeName, index );
}
}
protected static String getIndexAttributeName(CollectionPersister persister) {
final String node = persister.getIndexNodeName();
return node == null ? null : node.substring( 1 );
}
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final String indexNode = getIndexAttributeName( persister );
final List elements = element.elements( persister.getElementNodeName() );
final HashMap snapshot = new HashMap( elements.size() );
for ( int i=0; i<elements.size(); i++ ) {
final Element elem = (Element) elements.get( i );
final Object value = elementType.fromXMLNode( elem, persister.getFactory() );
final Object copy = elementType.deepCopy( value, persister.getFactory() );
snapshot.put( getIndex( elem, indexNode, i ), copy );
}
return snapshot;
}
@Override
public Collection getOrphans(Serializable snapshot, String entityName) {
//orphan delete not supported for EntityMode.DOM4J
return Collections.EMPTY_LIST;
}
@Override
public boolean isWrapper(Object collection) {
return element==collection;
}
@Override
@SuppressWarnings("deprecation")
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final String indexNode = getIndexAttributeName( persister );
final HashMap snapshot = (HashMap) getSnapshot();
final List elements = element.elements( persister.getElementNodeName() );
if ( snapshot.size() != elements.size() ) {
return false;
}
for ( int i=0; i<snapshot.size(); i++ ) {
final Element elem = (Element) elements.get( i );
final Object old = snapshot.get( getIndex( elem, indexNode, i ) );
final Object current = elementType.fromXMLNode( elem, persister.getFactory() );
if ( elementType.isDirty( old, current, getSession() ) ) {
return false;
}
}
return true;
}
@Override
public boolean isSnapshotEmpty(Serializable snapshot) {
return ( (HashMap) snapshot ).isEmpty();
}
@Override
public boolean empty() {
return !element.elementIterator().hasNext();
}
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner)
throws HibernateException, SQLException {
final Object object = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() );
final Type elementType = persister.getElementType();
final SessionFactoryImplementor factory = persister.getFactory();
final String indexNode = getIndexAttributeName( persister );
final Element elem = element.addElement( persister.getElementNodeName() );
elementType.setToXMLNode( elem, object, factory );
final Type indexType = persister.getIndexType();
final Object indexValue = persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() );
final String index = ( (StringRepresentableType) indexType ).toString( indexValue );
setIndex( elem, indexNode, index );
return object;
}
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Iterator entries(CollectionPersister persister) {
final Type elementType = persister.getElementType();
final String indexNode = getIndexAttributeName( persister );
final List elements = element.elements( persister.getElementNodeName() );
final int length = elements.size();
final List result = new ArrayList( length );
for ( int i=0; i<length; i++ ) {
final Element elem = (Element) elements.get( i );
final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
result.add( new IndexedValue( getIndex( elem, indexNode, i ), object ) );
}
return result.iterator();
}
@Override
public void beforeInitialize(CollectionPersister persister, int anticipatedSize) {
}
@Override
public boolean isDirectlyAccessible() {
return true;
}
@Override
public Object getValue() {
return element;
}
@Override
@SuppressWarnings({"deprecation", "unchecked"})
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
final Type indexType = persister.getIndexType();
final HashMap snapshot = (HashMap) getSnapshot();
final HashMap deletes = (HashMap) snapshot.clone();
deletes.keySet().removeAll( ( (HashMap) getSnapshot( persister ) ).keySet() );
final ArrayList deleteList = new ArrayList( deletes.size() );
for ( Object o : deletes.entrySet() ) {
final Map.Entry me = (Map.Entry) o;
final Object object = indexIsFormula
? me.getValue()
: ( (StringRepresentableType) indexType ).fromStringValue( (String) me.getKey() );
if ( object != null ) {
deleteList.add( object );
}
}
return deleteList.iterator();
}
@Override
public boolean needsInserting(Object entry, int i, Type elementType) throws HibernateException {
final HashMap snapshot = (HashMap) getSnapshot();
final IndexedValue iv = (IndexedValue) entry;
return iv.value!=null && snapshot.get( iv.index )==null;
}
@Override
public boolean needsUpdating(Object entry, int i, Type elementType) throws HibernateException {
final HashMap snapshot = (HashMap) getSnapshot();
final IndexedValue iv = (IndexedValue) entry;
final Object old = snapshot.get( iv.index );
return old!=null && elementType.isDirty( old, iv.value, getSession() );
}
@Override
@SuppressWarnings("deprecation")
public Object getIndex(Object entry, int i, CollectionPersister persister) {
final String index = ( (IndexedValue) entry ).index;
final Type indexType = persister.getIndexType();
return ( (StringRepresentableType) indexType ).fromStringValue( index );
}
@Override
public Object getElement(Object entry) {
return ( (IndexedValue) entry ).value;
}
@Override
public Object getSnapshotElement(Object entry, int i) {
return ( (HashMap) getSnapshot() ).get( ( (IndexedValue) entry ).index );
}
@Override
public boolean entryExists(Object entry, int i) {
return entry!=null;
}
}

View File

@ -1,89 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.collection.internal;
import java.io.Serializable;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.IntegerType;
import org.hibernate.type.Type;
import org.dom4j.Element;
/**
* Wraps a collection of DOM sub-elements as a List
*
* @author Gavin King
*
* @deprecated To be removed in 5. Removed as part of removing the notion of DOM entity-mode. See Jira issues
* <a href="https://hibernate.onjira.com/browse/HHH-7782">HHH-7782</a> and
* <a href="https://hibernate.onjira.com/browse/HHH-7783">HHH-7783</a> for more information.
*/
@Deprecated
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
public class PersistentListElementHolder extends PersistentIndexedElementHolder {
/**
* Constructs a PersistentListElementHolder.
*
* @param session The session
* @param element The owning DOM element
*/
@SuppressWarnings("UnusedDeclaration")
public PersistentListElementHolder(SessionImplementor session, Element element) {
super( session, element );
}
/**
* Constructs a PersistentListElementHolder.
*
* @param session The session
* @param persister The collection persister
* @param key The collection key (fk value)
*/
@SuppressWarnings("UnusedDeclaration")
public PersistentListElementHolder(SessionImplementor session, CollectionPersister persister, Serializable key) {
super( session, persister, key );
}
@Override
@SuppressWarnings("deprecation")
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner)
throws HibernateException {
final Type elementType = persister.getElementType();
final String indexNodeName = getIndexAttributeName( persister );
final Serializable[] cached = (Serializable[]) disassembled;
for ( int i=0; i<cached.length; i++ ) {
final Object object = elementType.assemble( cached[i], getSession(), owner );
final Element subelement = element.addElement( persister.getElementNodeName() );
elementType.setToXMLNode( subelement, object, persister.getFactory() );
setIndex( subelement, indexNodeName, Integer.toString( i ) );
}
}
@Override
@SuppressWarnings("deprecation")
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final String indexNodeName = getIndexAttributeName( persister );
final List elements = element.elements( persister.getElementNodeName() );
final int length = elements.size();
final Serializable[] result = new Serializable[length];
for ( int i=0; i<length; i++ ) {
final Element elem = (Element) elements.get( i );
final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
final Integer index = IntegerType.INSTANCE.fromString( getIndex( elem, indexNodeName, i ) );
result[index] = elementType.disassemble( object, getSession(), null );
}
return result;
}
}

View File

@ -1,96 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.collection.internal;
import java.io.Serializable;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.StringRepresentableType;
import org.hibernate.type.Type;
import org.dom4j.Element;
/**
* Wraps a collection of DOM sub-elements as a Map
*
* @author Gavin King
*
* @deprecated To be removed in 5. Removed as part of removing the notion of DOM entity-mode. See Jira issues
* <a href="https://hibernate.onjira.com/browse/HHH-7782">HHH-7782</a> and
* <a href="https://hibernate.onjira.com/browse/HHH-7783">HHH-7783</a> for more information.
*/
@SuppressWarnings({"UnusedDeclaration", "deprecation"})
@Deprecated
public class PersistentMapElementHolder extends PersistentIndexedElementHolder {
/**
* Constructs a PersistentMapElementHolder.
*
* @param session The session
* @param element The owning DOM element
*/
public PersistentMapElementHolder(SessionImplementor session, Element element) {
super( session, element );
}
/**
* Constructs a PersistentMapElementHolder.
*
* @param session The session
* @param persister The collection persister
* @param key The collection key (fk value)
*/
public PersistentMapElementHolder(SessionImplementor session, CollectionPersister persister, Serializable key) {
super( session, persister, key );
}
@Override
@SuppressWarnings("unchecked")
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) {
final Type elementType = persister.getElementType();
final Type indexType = persister.getIndexType();
final String indexNodeName = getIndexAttributeName( persister );
final Serializable[] cached = (Serializable[]) disassembled;
int i = 0;
while ( i < cached.length ) {
final Object index = indexType.assemble( cached[i++], getSession(), owner );
final Object object = elementType.assemble( cached[i++], getSession(), owner );
final Element subElement = element.addElement( persister.getElementNodeName() );
elementType.setToXMLNode( subElement, object, persister.getFactory() );
final String indexString = ( (StringRepresentableType) indexType ).toString( index );
setIndex( subElement, indexNodeName, indexString );
}
}
@Override
@SuppressWarnings("unchecked")
public Serializable disassemble(CollectionPersister persister) throws HibernateException {
final Type elementType = persister.getElementType();
final Type indexType = persister.getIndexType();
final String indexNodeName = getIndexAttributeName( persister );
final List elements = element.elements( persister.getElementNodeName() );
final int length = elements.size();
final Serializable[] result = new Serializable[length*2];
int i = 0;
while ( i < length*2 ) {
final Element elem = (Element) elements.get( i/2 );
final Object object = elementType.fromXMLNode( elem, persister.getFactory() );
final String indexString = getIndex( elem, indexNodeName, i );
final Object index = ( (StringRepresentableType) indexType ).fromStringValue( indexString );
result[i++] = indexType.disassemble( index, getSession(), null );
result[i++] = elementType.disassemble( object, getSession(), null );
}
return result;
}
}