Java Code Examples for org.hibernate.persister.entity.EntityPersister#setPropertyValues()
The following examples show how to use
org.hibernate.persister.entity.EntityPersister#setPropertyValues() .
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
Source File: DefaultReactiveMergeEventListener.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
protected void copyValues( final EntityPersister persister, final Object entity, final Object target, final SessionImplementor source, final MergeContext copyCache) { final Object[] copiedValues = TypeHelper.replace( persister.getPropertyValues( entity ), persister.getPropertyValues( target ), persister.getPropertyTypes(), source, target, copyCache ); persister.setPropertyValues( target, copiedValues ); }
Example 2
Source File: StatelessSessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void update(String entityName, Object entity) { errorIfClosed(); EntityPersister persister = getEntityPersister(entityName, entity); Serializable id = persister.getIdentifier(entity, EntityMode.POJO); Object[] state = persister.getPropertyValues(entity, EntityMode.POJO); Object oldVersion; if ( persister.isVersioned() ) { oldVersion = persister.getVersion(entity, EntityMode.POJO); Object newVersion = Versioning.increment( oldVersion, persister.getVersionType(), this ); Versioning.setVersion(state, newVersion, persister); persister.setPropertyValues(entity, state, EntityMode.POJO); } else { oldVersion = null; } persister.update(id, state, null, false, null, oldVersion, entity, null, this); }
Example 3
Source File: StatelessSessionImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public Serializable insert(String entityName, Object entity) { errorIfClosed(); EntityPersister persister = getEntityPersister(entityName, entity); Serializable id = persister.getIdentifierGenerator().generate(this, entity); Object[] state = persister.getPropertyValues(entity, EntityMode.POJO); if ( persister.isVersioned() ) { boolean substitute = Versioning.seedVersion(state, persister.getVersionProperty(), persister.getVersionType(), this); if ( substitute ) { persister.setPropertyValues( entity, state, EntityMode.POJO ); } } if ( id == IdentifierGeneratorFactory.POST_INSERT_INDICATOR ) { id = persister.insert(state, entity, this); } else { persister.insert(id, state, entity, this); } persister.setIdentifier(entity, id, EntityMode.POJO); return id; }
Example 4
Source File: DefaultMergeEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected void copyValues( final EntityPersister persister, final Object entity, final Object target, final SessionImplementor source, final Map copyCache ) { final Object[] copiedValues = TypeFactory.replace( persister.getPropertyValues( entity, source.getEntityMode() ), persister.getPropertyValues( target, source.getEntityMode() ), persister.getPropertyTypes(), source, target, copyCache ); persister.setPropertyValues( target, copiedValues, source.getEntityMode() ); }
Example 5
Source File: DefaultMergeEventListener.java From lams with GNU General Public License v2.0 | 6 votes |
protected void copyValues( final EntityPersister persister, final Object entity, final Object target, final SessionImplementor source, final Map copyCache) { final Object[] copiedValues = TypeHelper.replace( persister.getPropertyValues( entity ), persister.getPropertyValues( target ), persister.getPropertyTypes(), source, target, copyCache ); persister.setPropertyValues( target, copiedValues ); }
Example 6
Source File: StatelessSessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void update(String entityName, Object entity) { checkOpen(); EntityPersister persister = getEntityPersister( entityName, entity ); Serializable id = persister.getIdentifier( entity, this ); Object[] state = persister.getPropertyValues( entity ); Object oldVersion; if ( persister.isVersioned() ) { oldVersion = persister.getVersion( entity ); Object newVersion = Versioning.increment( oldVersion, persister.getVersionType(), this ); Versioning.setVersion( state, newVersion, persister ); persister.setPropertyValues( entity, state ); } else { oldVersion = null; } persister.update( id, state, null, false, null, oldVersion, entity, null, this ); }
Example 7
Source File: StatelessSessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Serializable insert(String entityName, Object entity) { checkOpen(); EntityPersister persister = getEntityPersister( entityName, entity ); Serializable id = persister.getIdentifierGenerator().generate( this, entity ); Object[] state = persister.getPropertyValues( entity ); if ( persister.isVersioned() ) { boolean substitute = Versioning.seedVersion( state, persister.getVersionProperty(), persister.getVersionType(), this ); if ( substitute ) { persister.setPropertyValues( entity, state ); } } if ( id == IdentifierGeneratorHelper.POST_INSERT_INDICATOR ) { id = persister.insert( state, entity, this ); } else { persister.insert( id, state, entity, this ); } persister.setIdentifier( entity, id, this ); return id; }
Example 8
Source File: StandardCacheEntryImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Assemble the previously disassembled state represented by this entry into the given entity instance. * * Additionally manages the PreLoadEvent callbacks. * * @param instance The entity instance * @param id The entity identifier * @param persister The entity persister * @param interceptor (currently unused) * @param session The session * * @return The assembled state * * @throws HibernateException Indicates a problem performing assembly or calling the PreLoadEventListeners. * * @see org.hibernate.type.Type#assemble * @see org.hibernate.type.Type#disassemble */ public Object[] assemble( final Object instance, final Serializable id, final EntityPersister persister, final Interceptor interceptor, final EventSource session) throws HibernateException { if ( !persister.getEntityName().equals( subclass ) ) { throw new AssertionFailure( "Tried to assemble a different subclass instance" ); } //assembled state gets put in a new array (we read from cache by value!) final Object[] state = TypeHelper.assemble( disassembledState, persister.getPropertyTypes(), session, instance ); //persister.setIdentifier(instance, id); //before calling interceptor, for consistency with normal load //TODO: reuse the PreLoadEvent final PreLoadEvent preLoadEvent = new PreLoadEvent( session ) .setEntity( instance ) .setState( state ) .setId( id ) .setPersister( persister ); final EventListenerGroup<PreLoadEventListener> listenerGroup = session .getFactory() .getServiceRegistry() .getService( EventListenerRegistry.class ) .getEventListenerGroup( EventType.PRE_LOAD ); for ( PreLoadEventListener listener : listenerGroup.listeners() ) { listener.onPreLoad( preLoadEvent ); } persister.setPropertyValues( instance, state ); return state; }
Example 9
Source File: WrapVisitor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override void process(Object object, EntityPersister persister) throws HibernateException { final Object[] values = persister.getPropertyValues( object ); final Type[] types = persister.getPropertyTypes(); processEntityPropertyValues( values, types ); if ( isSubstitutionRequired() ) { persister.setPropertyValues( object, values ); } }
Example 10
Source File: DefaultFlushEntityEventListener.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Flushes a single entity's state to the database, by scheduling * an update action, if necessary */ public void onFlushEntity(FlushEntityEvent event) throws HibernateException { final Object entity = event.getEntity(); final EntityEntry entry = event.getEntityEntry(); final EventSource session = event.getSession(); final EntityPersister persister = entry.getPersister(); final Status status = entry.getStatus(); final Type[] types = persister.getPropertyTypes(); final boolean mightBeDirty = entry.requiresDirtyCheck( entity ); final Object[] values = getValues( entity, entry, mightBeDirty, session ); event.setPropertyValues( values ); //TODO: avoid this for non-new instances where mightBeDirty==false boolean substitute = wrapCollections( session, persister, types, values ); if ( isUpdateNecessary( event, mightBeDirty ) ) { substitute = scheduleUpdate( event ) || substitute; } if ( status != Status.DELETED ) { // now update the object .. has to be outside the main if block above (because of collections) if ( substitute ) { persister.setPropertyValues( entity, values ); } // Search for collections by reachability, updating their role. // We don't want to touch collections reachable from a deleted object if ( persister.hasCollections() ) { new FlushVisitor( session, entity ).processEntityPropertyValues( values, types ); } } }
Example 11
Source File: DefaultMergeEventListener.java From lams with GNU General Public License v2.0 | 5 votes |
protected void copyValues( final EntityPersister persister, final Object entity, final Object target, final SessionImplementor source, final Map copyCache, final ForeignKeyDirection foreignKeyDirection) { final Object[] copiedValues; if ( foreignKeyDirection == ForeignKeyDirection.TO_PARENT ) { // this is the second pass through on a merge op, so here we limit the // replacement to associations types (value types were already replaced // during the first pass) copiedValues = TypeHelper.replaceAssociations( persister.getPropertyValues( entity ), persister.getPropertyValues( target ), persister.getPropertyTypes(), source, target, copyCache, foreignKeyDirection ); } else { copiedValues = TypeHelper.replace( persister.getPropertyValues( entity ), persister.getPropertyValues( target ), persister.getPropertyTypes(), source, target, copyCache, foreignKeyDirection ); } persister.setPropertyValues( target, copiedValues ); }
Example 12
Source File: CacheEntry.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Object[] assemble( final Serializable[] values, final Object result, final Serializable id, final EntityPersister persister, final Interceptor interceptor, final EventSource session) throws HibernateException { //assembled state gets put in a new array (we read from cache by value!) Object[] assembledProps = TypeFactory.assemble( values, persister.getPropertyTypes(), session, result ); //persister.setIdentifier(result, id); //before calling interceptor, for consistency with normal load //TODO: reuse the PreLoadEvent PreLoadEvent preLoadEvent = new PreLoadEvent( session ) .setEntity(result) .setState(assembledProps) .setId(id) .setPersister(persister); PreLoadEventListener[] listeners = session.getListeners().getPreLoadEventListeners(); for ( int i = 0; i < listeners.length; i++ ) { listeners[i].onPreLoad(preLoadEvent); } persister.setPropertyValues( result, assembledProps, session.getEntityMode() ); return assembledProps; }
Example 13
Source File: WrapVisitor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
void process(Object object, EntityPersister persister) throws HibernateException { EntityMode entityMode = getSession().getEntityMode(); Object[] values = persister.getPropertyValues( object, entityMode ); Type[] types = persister.getPropertyTypes(); processEntityPropertyValues(values, types); if ( isSubstitutionRequired() ) { persister.setPropertyValues( object, values, entityMode ); } }
Example 14
Source File: DefaultFlushEntityEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Flushes a single entity's state to the database, by scheduling * an update action, if necessary */ public void onFlushEntity(FlushEntityEvent event) throws HibernateException { final Object entity = event.getEntity(); final EntityEntry entry = event.getEntityEntry(); final EventSource session = event.getSession(); final EntityPersister persister = entry.getPersister(); final Status status = entry.getStatus(); final EntityMode entityMode = session.getEntityMode(); final Type[] types = persister.getPropertyTypes(); final boolean mightBeDirty = entry.requiresDirtyCheck(entity); final Object[] values = getValues( entity, entry, entityMode, mightBeDirty, session ); event.setPropertyValues(values); //TODO: avoid this for non-new instances where mightBeDirty==false boolean substitute = wrapCollections( session, persister, types, values); if ( isUpdateNecessary( event, mightBeDirty ) ) { substitute = scheduleUpdate( event ) || substitute; } if ( status != Status.DELETED ) { // now update the object .. has to be outside the main if block above (because of collections) if (substitute) persister.setPropertyValues( entity, values, entityMode ); // Search for collections by reachability, updating their role. // We don't want to touch collections reachable from a deleted object if ( persister.hasCollections() ) { new FlushVisitor(session, entity).processEntityPropertyValues(values, types); } } }
Example 15
Source File: DefaultMergeEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
protected void copyValues( final EntityPersister persister, final Object entity, final Object target, final SessionImplementor source, final Map copyCache, final ForeignKeyDirection foreignKeyDirection) { final Object[] copiedValues; if ( foreignKeyDirection == ForeignKeyDirection.FOREIGN_KEY_TO_PARENT ) { // this is the second pass through on a merge op, so here we limit the // replacement to associations types (value types were already replaced // during the first pass) copiedValues = TypeFactory.replaceAssociations( persister.getPropertyValues( entity, source.getEntityMode() ), persister.getPropertyValues( target, source.getEntityMode() ), persister.getPropertyTypes(), source, target, copyCache, foreignKeyDirection ); } else { copiedValues = TypeFactory.replace( persister.getPropertyValues( entity, source.getEntityMode() ), persister.getPropertyValues( target, source.getEntityMode() ), persister.getPropertyTypes(), source, target, copyCache, foreignKeyDirection ); } persister.setPropertyValues( target, copiedValues, source.getEntityMode() ); }
Example 16
Source File: DefaultReactiveMergeEventListener.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
protected void copyValues( final EntityPersister persister, final Object entity, final Object target, final SessionImplementor source, final MergeContext copyCache, final ForeignKeyDirection foreignKeyDirection) { final Object[] copiedValues; if ( foreignKeyDirection == ForeignKeyDirection.TO_PARENT ) { // this is the second pass through on a merge op, so here we limit the // replacement to associations types (value types were already replaced // during the first pass) copiedValues = TypeHelper.replaceAssociations( persister.getPropertyValues( entity ), persister.getPropertyValues( target ), persister.getPropertyTypes(), source, target, copyCache, foreignKeyDirection ); } else { copiedValues = TypeHelper.replace( persister.getPropertyValues( entity ), persister.getPropertyValues( target ), persister.getPropertyTypes(), source, target, copyCache, foreignKeyDirection ); } persister.setPropertyValues( target, copiedValues ); }
Example 17
Source File: DefaultReactiveFlushEntityEventListener.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
/** * Flushes a single entity's state to the database, by scheduling * an update action, if necessary */ public void onFlushEntity(FlushEntityEvent event) throws HibernateException { final Object entity = event.getEntity(); final EntityEntry entry = event.getEntityEntry(); final EventSource session = event.getSession(); final EntityPersister persister = entry.getPersister(); final Status status = entry.getStatus(); final Type[] types = persister.getPropertyTypes(); final boolean mightBeDirty = entry.requiresDirtyCheck( entity ); final Object[] values = getValues( entity, entry, mightBeDirty, session ); event.setPropertyValues( values ); //TODO: avoid this for non-new instances where mightBeDirty==false boolean substitute = wrapCollections( session, persister, types, values ); if ( isUpdateNecessary( event, mightBeDirty ) ) { substitute = scheduleUpdate( event ) || substitute; } if ( status != Status.DELETED ) { // now update the object .. has to be outside the main if block above (because of collections) if ( substitute ) { persister.setPropertyValues( entity, values ); } // Search for collections by reachability, updating their role. // We don't want to touch collections reachable from a deleted object if ( persister.hasCollections() ) { new FlushVisitor( session, entity ).processEntityPropertyValues( values, types ); } } }
Example 18
Source File: AbstractSaveEventListener.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Performs all the actual work needed to save an entity (well to get the save moved to * the execution queue). * * @param entity The entity to be saved * @param key The id to be used for saving the entity (or null, in the case of identity columns) * @param persister The entity's persister instance. * @param useIdentityColumn Should an identity column be used for id generation? * @param anything Generally cascade-specific information. * @param source The session which is the source of the current event. * @param requiresImmediateIdAccess Is access to the identifier required immediately * after the completion of the save? persist(), for example, does not require this... * * @return The id used to save the entity; may be null depending on the * type of id generator used and the requiresImmediateIdAccess value */ protected Serializable performSaveOrReplicate( Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, Object anything, EventSource source, boolean requiresImmediateIdAccess) { Serializable id = key == null ? null : key.getIdentifier(); boolean shouldDelayIdentityInserts = shouldDelayIdentityInserts( requiresImmediateIdAccess, source ); // Put a placeholder in entries, so we don't recurse back and try to save() the // same object again. QUESTION: should this be done before onSave() is called? // likewise, should it be done before onUpdate()? EntityEntry original = source.getPersistenceContext().addEntry( entity, Status.SAVING, null, null, id, null, LockMode.WRITE, useIdentityColumn, persister, false ); cascadeBeforeSave( source, persister, entity, anything ); Object[] values = persister.getPropertyValuesToInsert( entity, getMergeMap( anything ), source ); Type[] types = persister.getPropertyTypes(); boolean substitute = substituteValuesIfNecessary( entity, id, values, persister, source ); if ( persister.hasCollections() ) { substitute = substitute || visitCollectionsBeforeSave( entity, id, values, types, source ); } if ( substitute ) { persister.setPropertyValues( entity, values ); } TypeHelper.deepCopy( values, types, persister.getPropertyUpdateability(), values, source ); AbstractEntityInsertAction insert = addInsertAction( values, id, entity, persister, useIdentityColumn, source, shouldDelayIdentityInserts ); // postpone initializing id in case the insert has non-nullable transient dependencies // that are not resolved until cascadeAfterSave() is executed cascadeAfterSave( source, persister, entity, anything ); if ( useIdentityColumn && insert.isEarlyInsert() ) { if ( !EntityIdentityInsertAction.class.isInstance( insert ) ) { throw new IllegalStateException( "Insert should be using an identity column, but action is of unexpected type: " + insert.getClass().getName() ); } id = ((EntityIdentityInsertAction) insert).getGeneratedId(); insert.handleNaturalIdPostSaveNotifications( id ); } EntityEntry newEntry = source.getPersistenceContext().getEntry( entity ); if ( newEntry != original ) { EntityEntryExtraState extraState = newEntry.getExtraState( EntityEntryExtraState.class ); if ( extraState == null ) { newEntry.addExtraState( original.getExtraState( EntityEntryExtraState.class ) ); } } return id; }