Java Code Examples for org.hibernate.type.Type.isSame()

The following are Jave code examples for showing how to use isSame() of the org.hibernate.type.Type class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lams   File: PersistentBag.java   Source Code and License Vote up 6 votes
@Override
public boolean needsInserting(Object entry, int i, Type elemType) throws HibernateException {
	final List sn = (List) getSnapshot();
	if ( sn.size() > i && elemType.isSame( sn.get( i ), entry ) ) {
		//a shortcut if its location didn't change!
		return false;
	}
	else {
		//search for it
		//note that this code is incorrect for other than one-to-many
		for ( Object old : sn ) {
			if ( elemType.isSame( old, entry ) ) {
				return false;
			}
		}
		return true;
	}
}
 
Example 2
Project: lams   File: PersistentBag.java   Source Code and License Vote up 5 votes
private int countOccurrences(Object element, List list, Type elementType)
		throws HibernateException {
	final Iterator iter = list.iterator();
	int result = 0;
	while ( iter.hasNext() ) {
		if ( elementType.isSame( element, iter.next() ) ) {
			result++;
		}
	}
	return result;
}
 
Example 3
Project: lams   File: PersistentBag.java   Source Code and License Vote up 5 votes
@Override
@SuppressWarnings("unchecked")
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException {
	final Type elementType = persister.getElementType();
	final ArrayList deletes = new ArrayList();
	final List sn = (List) getSnapshot();
	final Iterator olditer = sn.iterator();
	int i=0;
	while ( olditer.hasNext() ) {
		final Object old = olditer.next();
		final Iterator newiter = bag.iterator();
		boolean found = false;
		if ( bag.size()>i && elementType.isSame( old, bag.get( i++ ) ) ) {
		//a shortcut if its location didn't change!
			found = true;
		}
		else {
			//search for it
			//note that this code is incorrect for other than one-to-many
			while ( newiter.hasNext() ) {
				if ( elementType.isSame( old, newiter.next() ) ) {
					found = true;
					break;
				}
			}
		}
		if ( !found ) {
			deletes.add( old );
		}
	}
	return deletes.iterator();
}