Java Code Examples for org.hibernate.persister.entity.EntityPersister#getPropertyUpdateability()
The following examples show how to use
org.hibernate.persister.entity.EntityPersister#getPropertyUpdateability() .
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: StatefulPersistenceContext.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Object[] getNaturalIdSnapshot(Serializable id, EntityPersister persister) throws HibernateException { if ( !persister.hasNaturalIdentifier() ) { return null; } // if the natural-id is marked as non-mutable, it is not retrieved during a // normal database-snapshot operation... int[] props = persister.getNaturalIdentifierProperties(); boolean[] updateable = persister.getPropertyUpdateability(); boolean allNatualIdPropsAreUpdateable = true; for ( int i = 0; i < props.length; i++ ) { if ( !updateable[ props[i] ] ) { allNatualIdPropsAreUpdateable = false; break; } } if ( allNatualIdPropsAreUpdateable ) { // do this when all the properties are updateable since there is // a certain likelihood that the information will already be // snapshot-cached. Object[] entitySnapshot = getDatabaseSnapshot( id, persister ); if ( entitySnapshot == NO_ROW ) { return null; } Object[] naturalIdSnapshot = new Object[ props.length ]; for ( int i = 0; i < props.length; i++ ) { naturalIdSnapshot[i] = entitySnapshot[ props[i] ]; } return naturalIdSnapshot; } else { return persister.getNaturalIdentifierSnapshot( id, session ); } }
Example 2
Source File: DefaultFlushEntityEventListener.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void checkNaturalId( EntityPersister persister, Serializable identifier, Object[] current, Object[] loaded, EntityMode entityMode, SessionImplementor session) { if ( persister.hasNaturalIdentifier() ) { Object[] snapshot = null; Type[] types = persister.getPropertyTypes(); int[] props = persister.getNaturalIdentifierProperties(); boolean[] updateable = persister.getPropertyUpdateability(); for ( int i=0; i<props.length; i++ ) { int prop = props[i]; if ( !updateable[prop] ) { Object loadedVal; if ( loaded == null ) { if ( snapshot == null) { snapshot = session.getPersistenceContext().getNaturalIdSnapshot( identifier, persister ); } loadedVal = snapshot[i]; } else { loadedVal = loaded[prop]; } if ( !types[prop].isEqual( current[prop], loadedVal, entityMode ) ) { throw new HibernateException( "immutable natural identifier of an instance of " + persister.getEntityName() + " was altered" ); } } } } }
Example 3
Source File: DefaultReactiveFlushEntityEventListener.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
private void checkNaturalId( EntityPersister persister, EntityEntry entry, Object[] current, Object[] loaded, SessionImplementor session) { if ( persister.hasNaturalIdentifier() && entry.getStatus() != Status.READ_ONLY ) { if ( !persister.getEntityMetamodel().hasImmutableNaturalId() ) { // SHORT-CUT: if the natural id is mutable (!immutable), no need to do the below checks // EARLY EXIT!!! return; } final int[] naturalIdentifierPropertiesIndexes = persister.getNaturalIdentifierProperties(); final Type[] propertyTypes = persister.getPropertyTypes(); final boolean[] propertyUpdateability = persister.getPropertyUpdateability(); final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final Object[] snapshot = loaded == null ? persistenceContext.getNaturalIdSnapshot( entry.getId(), persister ) : persistenceContext.getNaturalIdHelper().extractNaturalIdValues( loaded, persister ); for ( int i = 0; i < naturalIdentifierPropertiesIndexes.length; i++ ) { final int naturalIdentifierPropertyIndex = naturalIdentifierPropertiesIndexes[i]; if ( propertyUpdateability[naturalIdentifierPropertyIndex] ) { // if the given natural id property is updatable (mutable), there is nothing to check continue; } final Type propertyType = propertyTypes[naturalIdentifierPropertyIndex]; if ( !propertyType.isEqual( current[naturalIdentifierPropertyIndex], snapshot[i] ) ) { throw new HibernateException( String.format( "An immutable natural identifier of entity %s was altered from %s to %s", persister.getEntityName(), propertyTypes[naturalIdentifierPropertyIndex].toLoggableString( snapshot[i], session.getFactory() ), propertyTypes[naturalIdentifierPropertyIndex].toLoggableString( current[naturalIdentifierPropertyIndex], session.getFactory() ) ) ); } } } }
Example 4
Source File: Nullability.java From lams with GNU General Public License v2.0 | 4 votes |
public void checkNullability( final Object[] values, final EntityPersister persister, final NullabilityCheckType checkType) { /* * Typically when Bean Validation is on, we don't want to validate null values * at the Hibernate Core level. Hence the checkNullability setting. */ if ( checkNullability ) { /* * Algorithm * Check for any level one nullability breaks * Look at non null components to * recursively check next level of nullability breaks * Look at Collections containing components to * recursively check next level of nullability breaks * * * In the previous implementation, not-null stuffs where checked * filtering by level one only updateable * or insertable columns. So setting a sub component as update="false" * has no effect on not-null check if the main component had good checkeability * In this implementation, we keep this feature. * However, I never see any documentation mentioning that, but it's for * sure a limitation. */ final boolean[] nullability = persister.getPropertyNullability(); final boolean[] checkability = checkType == NullabilityCheckType.CREATE ? persister.getPropertyInsertability() : persister.getPropertyUpdateability(); final Type[] propertyTypes = persister.getPropertyTypes(); for ( int i = 0; i < values.length; i++ ) { if ( checkability[i] && values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY ) { final Object value = values[i]; if ( !nullability[i] && value == null ) { //check basic level one nullablilty throw new PropertyValueException( "not-null property references a null or transient value", persister.getEntityName(), persister.getPropertyNames()[i] ); } else if ( value != null ) { //values is not null and is checkable, we'll look deeper final String breakProperties = checkSubElementsNullability( propertyTypes[i], value ); if ( breakProperties != null ) { throw new PropertyValueException( "not-null property references a null or transient value", persister.getEntityName(), buildPropertyPath( persister.getPropertyNames()[i], breakProperties ) ); } } } } } }
Example 5
Source File: DefaultFlushEntityEventListener.java From lams with GNU General Public License v2.0 | 4 votes |
private void checkNaturalId( EntityPersister persister, EntityEntry entry, Object[] current, Object[] loaded, SessionImplementor session) { if ( persister.hasNaturalIdentifier() && entry.getStatus() != Status.READ_ONLY ) { if ( !persister.getEntityMetamodel().hasImmutableNaturalId() ) { // SHORT-CUT: if the natural id is mutable (!immutable), no need to do the below checks // EARLY EXIT!!! return; } final int[] naturalIdentifierPropertiesIndexes = persister.getNaturalIdentifierProperties(); final Type[] propertyTypes = persister.getPropertyTypes(); final boolean[] propertyUpdateability = persister.getPropertyUpdateability(); final Object[] snapshot = loaded == null ? session.getPersistenceContext().getNaturalIdSnapshot( entry.getId(), persister ) : session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( loaded, persister ); for ( int i = 0; i < naturalIdentifierPropertiesIndexes.length; i++ ) { final int naturalIdentifierPropertyIndex = naturalIdentifierPropertiesIndexes[i]; if ( propertyUpdateability[naturalIdentifierPropertyIndex] ) { // if the given natural id property is updatable (mutable), there is nothing to check continue; } final Type propertyType = propertyTypes[naturalIdentifierPropertyIndex]; if ( !propertyType.isEqual( current[naturalIdentifierPropertyIndex], snapshot[i] ) ) { throw new HibernateException( String.format( "An immutable natural identifier of entity %s was altered from %s to %s", persister.getEntityName(), propertyTypes[naturalIdentifierPropertyIndex].toLoggableString( snapshot[i], session.getFactory() ), propertyTypes[naturalIdentifierPropertyIndex].toLoggableString( current[naturalIdentifierPropertyIndex], session.getFactory() ) ) ); } } } }
Example 6
Source File: Nullability.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Check nullability of the class persister properties * * @param values entity properties * @param persister class persister * @param isUpdate wether it is intended to be updated or saved * @throws org.hibernate.PropertyValueException Break the nullability of one property * @throws HibernateException error while getting Component values */ public void checkNullability( final Object[] values, final EntityPersister persister, final boolean isUpdate) throws PropertyValueException, HibernateException { /* * Algorithm * Check for any level one nullability breaks * Look at non null components to * recursively check next level of nullability breaks * Look at Collections contraining component to * recursively check next level of nullability breaks * * * In the previous implementation, not-null stuffs where checked * filtering by level one only updateable * or insertable columns. So setting a sub component as update="false" * has no effect on not-null check if the main component had good checkeability * In this implementation, we keep this feature. * However, I never see any documentation mentioning that, but it's for * sure a limitation. */ final boolean[] nullability = persister.getPropertyNullability(); final boolean[] checkability = isUpdate ? persister.getPropertyUpdateability() : persister.getPropertyInsertability(); final Type[] propertyTypes = persister.getPropertyTypes(); for ( int i = 0; i < values.length; i++ ) { if ( checkability[i] && values[i]!=LazyPropertyInitializer.UNFETCHED_PROPERTY ) { final Object value = values[i]; if ( !nullability[i] && value == null ) { //check basic level one nullablilty throw new PropertyValueException( "not-null property references a null or transient value", persister.getEntityName(), persister.getPropertyNames()[i] ); } else if ( value != null ) { //values is not null and is checkable, we'll look deeper String breakProperties = checkSubElementsNullability( propertyTypes[i], value ); if ( breakProperties != null ) { throw new PropertyValueException( "not-null property references a null or transient value", persister.getEntityName(), buildPropertyPath( persister.getPropertyNames()[i], breakProperties ) ); } } } } }