List of usage examples for org.hibernate.collection.spi PersistentCollection isDirty
boolean isDirty();
From source file:org.granite.hibernate4.HibernateExternalizer.java
License:Open Source License
protected AbstractExternalizablePersistentCollection newExternalizableCollection(PersistentCollection value) { final boolean initialized = Hibernate.isInitialized(value); final boolean dirty = value.isDirty(); AbstractExternalizablePersistentCollection coll = null; if (value instanceof PersistentSet) coll = new ExternalizablePersistentSet(initialized ? (Set<?>) value : null, initialized, dirty); else if (value instanceof PersistentList) coll = new ExternalizablePersistentList(initialized ? (List<?>) value : null, initialized, dirty); else if (value instanceof PersistentBag) coll = new ExternalizablePersistentBag(initialized ? (List<?>) value : null, initialized, dirty); else if (value instanceof PersistentMap) coll = new ExternalizablePersistentMap(initialized ? (Map<?, ?>) value : null, initialized, dirty); else//from w w w.ja va2 s. co m throw new UnsupportedOperationException("Unsupported Hibernate collection type: " + value); if (serializeMetadata != SerializeMetadata.NO && (serializeMetadata == SerializeMetadata.YES || !initialized) && value.getRole() != null) { char[] hexKey = StringUtil.bytesToHexChars(serializeSerializable(value.getKey())); char[] hexSnapshot = StringUtil.bytesToHexChars(serializeSerializable(value.getStoredSnapshot())); String metadata = new StringBuilder( hexKey.length + 1 + hexSnapshot.length + 1 + value.getRole().length()).append(hexKey) .append(':').append(hexSnapshot).append(':').append(value.getRole()).toString(); coll.setMetadata(metadata); } return coll; }
From source file:org.granite.hibernate4.jmf.AbstractPersistentCollectionCodec.java
License:Open Source License
public void encode(ExtendedObjectOutput out, Object v) throws IOException, IllegalAccessException { JMFPersistentCollectionSnapshot snapshot = null; PersistentCollection collection = (PersistentCollection) v; if (!collection.wasInitialized()) snapshot = new JMFPersistentCollectionSnapshot( collection instanceof SortedSet || collection instanceof SortedMap, null); else if (collection instanceof Map) snapshot = new JMFPersistentCollectionSnapshot(true, null, collection.isDirty(), (Map<?, ?>) collection); else/*from w ww. j a v a2 s. co m*/ snapshot = new JMFPersistentCollectionSnapshot(true, null, collection.isDirty(), (Collection<?>) collection); snapshot.writeExternal(out); }