/** * Custom deserialization routine used during deserialization of a * Session/PersistenceContext for increased performance. * * @param ois The stream from which to read the entry. * @param session The session being deserialized. * * @return The deserialized CollectionKey * * @throws IOException * @throws ClassNotFoundException */ public static CollectionKey deserialize( ObjectInputStream ois, SessionImplementor session) throws IOException, ClassNotFoundException { return new CollectionKey( (String) ois.readObject(), (Serializable) ois.readObject(), (Type) ois.readObject(), EntityMode.parse( (String) ois.readObject() ), (session == null ? null : session.getFactory()) ); } }
rtn.collectionsByKey.put( CollectionKey.deserialize( ois, session ), (PersistentCollection) ois.readObject() );
private CollectionKey( String role, Serializable key, Type keyType, EntityMode entityMode, SessionFactoryImplementor factory) { this.role = role; this.key = key; this.keyType = keyType; this.entityMode = entityMode; this.factory = factory; //cache the hash-code this.hashCode = generateHashCode(); }
entry.getKey().serialize( oos ); oos.writeObject( entry.getValue() );
@Override public void resolveKey(RowProcessingState rowProcessingState) { keyContainerValue = keyTargetAssembler.assemble( rowProcessingState, rowProcessingState.getJdbcValuesSourceProcessingState().getProcessingOptions() ); if ( keyCollectionAssembler == null ) { keyCollectionValue = keyContainerValue; } else { keyCollectionValue = keyCollectionAssembler.assemble( rowProcessingState, rowProcessingState.getJdbcValuesSourceProcessingState().getProcessingOptions() ); } collectionKey = new CollectionKey( getFetchedAttribute().getPersistentCollectionDescriptor(), getKeyContainerValue() ); if ( CollectionLoadingLogger.DEBUG_ENABLED ) { CollectionLoadingLogger.INSTANCE.debugf( "(%s) Current row collection key : %s", StringHelper.collapse( this.getClass().getName() ), LoggingHelper.toLoggableString( getNavigablePath(), collectionKey.getKey() ) ); } }
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; DB db = (DB) ctx.get(TxnConstants.DB); Session session = db.session(); SessionStatistics statistics = session.getStatistics(); Set<EntityKey> entityKeys = statistics.getEntityKeys(); ctx.log (String.format ("ENTITIES: (%d)", statistics.getEntityCount())); for (EntityKey ek : entityKeys) { Object obj = session.get(ek.getEntityName(), ek.getIdentifier()); LockMode lockMode = session.getCurrentLockMode(obj); ctx.log(String.format("[%s] %s %s", ek.getIdentifier(), ek.getEntityName(), lockMode)); } ctx.log ("==== COLLECTIONS ===="); Set<CollectionKey> collectionKeys = statistics.getCollectionKeys(); for (CollectionKey ck : collectionKeys) { ctx.log(String.format("[%s] %s", ck.getKey(), ck.getRole())); } ctx.log("====================="); return PREPARED | READONLY | NO_JOIN; }
protected void takeResponsibility(RowProcessingState rowProcessingState, CollectionKey collectionKey) { rowProcessingState.getJdbcValuesSourceProcessingState().registerLoadingCollection( collectionKey, new LoadingCollectionEntry( getCollectionDescriptor(), this, collectionKey.getKey(), collectionInstance ) ); responsible = true; }
public static String toLoggableString(CollectionKey collectionKey) { return toLoggableString( toLoggableString( collectionKey.getNavigableRole() ), collectionKey.getKey() ); }
while ( itr.hasNext() ) { Map.Entry entry = ( Map.Entry ) itr.next(); ( ( CollectionKey ) entry.getKey() ).serialize( oos ); oos.writeObject( entry.getValue() );
@Override public void initializeInstance(RowProcessingState rowProcessingState) { if ( !responsible ) { return; } // the LHS key value of the association final CollectionKey collectionKey = resolveCollectionKey( rowProcessingState ); // the RHS key value of the association final Object keyCollectionValue = getKeyCollectionValue(); if ( keyCollectionValue != null ) { // the row contains an element in the collection... if ( CollectionLoadingLogger.DEBUG_ENABLED ) { CollectionLoadingLogger.INSTANCE.debugf( "(%s) Reading element from row for collection [%s] -> %s", StringHelper.collapse( this.getClass().getName() ), LoggingHelper.toLoggableString( getNavigablePath(), collectionKey.getKey() ), LoggingHelper.toLoggableString( collectionInstance ) ); } readCollectionRow( rowProcessingState ); } }
/** * Add a collection to the cache, with a given collection entry. * * @param coll The collection for which we are adding an entry. * @param entry The entry representing the collection. * @param key The key of the collection's entry. */ private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) { collectionEntries.put( coll, entry ); final CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key ); final PersistentCollection old = collectionsByKey.put( collectionKey, coll ); if ( old != null ) { if ( old == coll ) { throw new AssertionFailure( "bug adding collection twice" ); } // or should it actually throw an exception? old.unsetSession( session ); collectionEntries.remove( old ); // watch out for a case where old is still referenced // somewhere in the object graph! (which is a user error) } }
private CollectionKey( NavigableRole role, Object key, JavaTypeDescriptor keyType) { this.role = role; this.key = key; this.keyType = keyType; //cache the hash-code this.hashCode = generateHashCode(); }
while ( itr.hasNext() ) { Map.Entry entry = ( Map.Entry ) itr.next(); ( ( CollectionKey ) entry.getKey() ).serialize( oos ); oos.writeObject( entry.getValue() );
rtn.collectionsByKey = new HashMap<CollectionKey,PersistentCollection>( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count ); for ( int i = 0; i < count; i++ ) { rtn.collectionsByKey.put( CollectionKey.deserialize( ois, session ), (PersistentCollection) ois.readObject() );
@Override public void resolveInstance(RowProcessingState rowProcessingState) { final CollectionKey collectionKey = resolveCollectionKey( rowProcessingState ); final SharedSessionContractImplementor session = rowProcessingState.getSession(); final PersistenceContext persistenceContext = session.getPersistenceContext(); final PersistentCollectionDescriptor collectionDescriptor = getFetchedAttribute().getPersistentCollectionDescriptor(); // todo (6.0) : look for LoadingCollectionEntry? final PersistentCollection existing = persistenceContext.getCollection( collectionKey ); if ( existing != null ) { collectionInstance = existing; } else { collectionInstance = collectionDescriptor.instantiateWrapper( session, collectionKey.getKey() ); getParentAccess().registerResolutionListener( owner -> collectionInstance.setOwner( owner ) ); persistenceContext.addUninitializedCollection( collectionDescriptor, collectionInstance, collectionKey.getKey() ); final CollectionEntry collectionEntry = persistenceContext.getCollectionEntry( collectionInstance ); collectionEntry.setCurrentKey( collectionKey.getKey() ); if ( getCollectionDescriptor().getSemantics().getCollectionClassification() == CollectionClassification.ARRAY ) { session.getPersistenceContext().addCollectionHolder( collectionInstance ); } } }
CollectionKey collectionKey = new CollectionKey( collectionEntry.getLoadedPersister(), collectionEntry.getLoadedKey()
private CollectionKey( String role, Serializable key, Type keyType, EntityMode entityMode, SessionFactoryImplementor factory) { this.role = role; this.key = key; this.keyType = keyType; this.entityMode = entityMode; this.factory = factory; this.hashCode = generateHashCode(); //cache the hashcode }
entry.getKey().serialize( oos ); oos.writeObject( entry.getValue() );
rtn.collectionsByKey = new HashMap<CollectionKey,PersistentCollection>( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count ); for ( int i = 0; i < count; i++ ) { rtn.collectionsByKey.put( CollectionKey.deserialize( ois, session ), (PersistentCollection) ois.readObject() );