/** * Locate the property-indices of all properties considered to be dirty. * * @param currentState The current state of the entity (the state to be checked). * @param previousState The previous state of the entity (the state to be checked against). * @param entity The entity for which we are checking state dirtiness. * @param session The session in which the check is occurring. * * @return <tt>null</tt> or the indices of the dirty properties * * @throws HibernateException */ public int[] findDirty(Object[] currentState, Object[] previousState, Object entity, SharedSessionContractImplementor session) throws HibernateException { int[] props = TypeHelper.findDirty( entityMetamodel.getProperties(), currentState, previousState, propertyColumnUpdateable, session ); if ( props == null ) { return null; } else { logDirtyProperties( props ); return props; } }
/** * Locate the property-indices of all properties considered to be dirty. * * @param old The old state of the entity. * @param current The current state of the entity. * @param entity The entity for which we are checking state modification. * @param session The session in which the check is occurring. * * @return <tt>null</tt> or the indices of the modified properties * * @throws HibernateException */ public int[] findModified(Object[] old, Object[] current, Object entity, SharedSessionContractImplementor session) throws HibernateException { int[] props = TypeHelper.findModified( entityMetamodel.getProperties(), current, old, propertyColumnUpdateable, getPropertyUpdateability(), session ); if ( props == null ) { return null; } else { logDirtyProperties( props ); return props; } }
private void logDirtyProperties(int[] props) { if ( LOG.isTraceEnabled() ) { for ( int i = 0; i < props.length; i++ ) { String propertyName = entityMetamodel.getProperties()[props[i]].getName(); LOG.trace( StringHelper.qualify( getEntityName(), propertyName ) + " is dirty" ); } } }
@Override public AnyMappingDefinition toAnyDefinition() { return new StandardAnyTypeDefinition( (AnyType) getType(), getSource().getEntityMetamodel().getProperties()[ attributeNumber() ].isLazy() ); }
@Override public Object[] getPropertyValues(Object entity) { final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata(); final int span = entityMetamodel.getPropertySpan(); final Object[] result = new Object[span]; for ( int j = 0; j < span; j++ ) { NonIdentifierAttribute property = entityMetamodel.getProperties()[j]; if ( !property.isLazy() || enhancementMetadata.isAttributeLoaded( entity, property.getName() ) ) { result[j] = getters[j].get( entity ); } else { result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY; } } return result; }
EntityMetamodel metamodel) { for ( int i = 0; i < metamodel.getPropertySpan(); i++ ) { final AttributeDefinition attributeDefinition = metamodel.getProperties()[i];
@Test public void testTypeSelection() { int index = sessionFactory().getEntityPersister( MaterializedBlobEntity.class.getName() ).getEntityMetamodel().getPropertyIndex( "theBytes" ); Type type = sessionFactory().getEntityPersister( MaterializedBlobEntity.class.getName() ).getEntityMetamodel().getProperties()[index].getType(); assertEquals( MaterializedBlobType.INSTANCE, type ); }
@Test public void test() { doInHibernate( this::sessionFactory, s -> { TestEntity entity = s.get( TestEntity.class, entityId ); Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); EntityPersister entityPersister = sessionFactory().getMetamodel().entityPersister( TestEntity.class ); boolean[] propertyLaziness = entityPersister.getPropertyLaziness(); assertEquals( 1, propertyLaziness.length ); assertTrue( propertyLaziness[0] ); // Make sure NonIdentifierAttribute#isLazy is consistent (HHH-10551) NonIdentifierAttribute[] properties = entityPersister.getEntityMetamodel().getProperties(); assertEquals( 1, properties.length ); assertTrue( properties[0].isLazy() ); } ); }
for ( NonIdentifierAttribute attribute : entityMetamodel.getProperties() ) { propertyIndex++; if ( isValueGenerationRequired( attribute, matchTiming ) ) {
public Object[] getPropertyValues(Object entity) throws HibernateException { boolean getAll = shouldGetAllProperties( entity ); final int span = entityMetamodel.getPropertySpan(); final Object[] result = new Object[span]; for ( int j = 0; j < span; j++ ) { StandardProperty property = entityMetamodel.getProperties()[j]; if ( getAll || !property.isLazy() ) { result[j] = getters[j].get( entity ); } else { result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY; } } return result; }
/** * Locate the property-indices of all properties considered to be dirty. * * @param old The old state of the entity. * @param current The current state of the entity. * @param entity The entity for which we are checking state modification. * @param session The session in which the check is occurring. * @return <tt>null</tt> or the indices of the modified properties * @throws HibernateException */ public int[] findModified(Object[] old, Object[] current, Object entity, SessionImplementor session) throws HibernateException { int[] props = TypeHelper.findModified( entityMetamodel.getProperties(), current, old, propertyColumnUpdateable, hasUninitializedLazyProperties( entity ), session ); if ( props == null ) { return null; } else { logDirtyProperties( props ); return props; } }
/** * Locate the property-indices of all properties considered to be dirty. * * @param currentState The current state of the entity (the state to be checked). * @param previousState The previous state of the entity (the state to be checked against). * @param entity The entity for which we are checking state dirtiness. * @param session The session in which the check is occurring. * @return <tt>null</tt> or the indices of the dirty properties * @throws HibernateException */ public int[] findDirty(Object[] currentState, Object[] previousState, Object entity, SessionImplementor session) throws HibernateException { int[] props = TypeHelper.findDirty( entityMetamodel.getProperties(), currentState, previousState, propertyColumnUpdateable, hasUninitializedLazyProperties( entity ), session ); if ( props == null ) { return null; } else { logDirtyProperties( props ); return props; } }
public Object[] getPropertyValues(Object entity) throws HibernateException { boolean getAll = shouldGetAllProperties( entity ); final int span = entityMetamodel.getPropertySpan(); final Object[] result = new Object[span]; for ( int j = 0; j < span; j++ ) { StandardProperty property = entityMetamodel.getProperties()[j]; if ( getAll || !property.isLazy() ) { result[j] = getters[j].get( entity ); } else { result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY; } } return result; }
/** * Locate the property-indices of all properties considered to be dirty. * * @param currentState The current state of the entity (the state to be checked). * @param previousState The previous state of the entity (the state to be checked against). * @param entity The entity for which we are checking state dirtiness. * @param session The session in which the check is occurring. * @return <tt>null</tt> or the indices of the dirty properties * @throws HibernateException */ public int[] findDirty(Object[] currentState, Object[] previousState, Object entity, SessionImplementor session) throws HibernateException { int[] props = TypeHelper.findDirty( entityMetamodel.getProperties(), currentState, previousState, propertyColumnUpdateable, hasUninitializedLazyProperties( entity ), session ); if ( props == null ) { return null; } else { logDirtyProperties( props ); return props; } }
private void logDirtyProperties(int[] props) { if ( LOG.isTraceEnabled() ) { for ( int i = 0; i < props.length; i++ ) { String propertyName = entityMetamodel.getProperties()[ props[i] ].getName(); LOG.trace( StringHelper.qualify( getEntityName(), propertyName ) + " is dirty" ); } } }
private void logDirtyProperties(int[] props) { if ( LOG.isTraceEnabled() ) { for ( int i = 0; i < props.length; i++ ) { String propertyName = entityMetamodel.getProperties()[ props[i] ].getName(); LOG.trace( StringHelper.qualify( getEntityName(), propertyName ) + " is dirty" ); } } }
public CacheEntry<T> assertEquals(T other) { Assert.assertFalse("Comparing the same instance doesn't make sense!", this.entity == other); for (StandardProperty property : entityPersister.getEntityMetamodel().getProperties()) { Type type = property.getType(); if (!type.isCollectionType()) { Object value = entityPersister.getPropertyValue(this.entity, property.getName(), entityMode); if (value != null) { if(type.isEntityType()) { Class toOneClass = property.getType().getReturnedClass(); EntityPersister toOnePersister = getEntityPersister(toOneClass); Serializable serializable = toOnePersister.getIdentifier(value, entityMode); Assert.assertEquals(toOnePersister.getIdentifier(other, entityMode), serializable); } else { Assert.assertEquals(entityPersister.getPropertyValue(this.entity, property.getName(), entityMode), entityPersister.getPropertyValue(other, property.getName(), entityMode)); } } else { Assert.assertNull(entityPersister.getPropertyValue(other, property.getName(), entityMode)); } } } return this; }
private boolean hasImplicitCollectionJoins1(String entityName, Map<String, Boolean> contextMap) { EntityPersister persister = this.factory.getEntityPersister(entityName); for (NonIdentifierAttribute nonIdAttribute : persister.getEntityMetamodel().getProperties()) { Type propertyType = nonIdAttribute.getType(); if (nonIdAttribute.getFetchMode() == FetchMode.JOIN) { if (propertyType.isCollectionType()) { //find collection with {fetch = "join"} return true; } if (propertyType instanceof AssociationType) { String childEntityName = ((AssociationType)propertyType).getAssociatedEntityName(this.factory); if (this.hasImplicitCollectionJoins0(childEntityName, contextMap)) { return true; } } } else if (propertyType instanceof CompositeType) { if (this.hasImplicitCollectionJoins0((CompositeType)propertyType, contextMap)) { return true; } } } return false; }
@Override public Object[] getPropertyValues(Object entity) throws HibernateException { Object[] arr = super.getPropertyValues(entity); FieldInterceptor fieldInterceptor = FieldInterceptionHelper.extractFieldInterceptor(entity); if (fieldInterceptor instanceof HibernateScalarLoader) { HibernateScalarLoader hibernateScalarLoader = (HibernateScalarLoader)fieldInterceptor; ObjectModel objectModel = hibernateScalarLoader.getObjectModel(); ModelClass modelClass = objectModel.getModelClass(); NonIdentifierAttribute[] attributes = this.getEntityMetamodel().getProperties(); for (int i = attributes.length - 1; i >= 0; i--) { if (arr[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY) { ModelProperty modelProperty = modelClass.getProperties().get(attributes[i].getName()); int propertyId = modelProperty.getId(); if (modelProperty.getPropertyType() == PropertyType.SCALAR && objectModel.isEnabed(propertyId) && objectModel.isLoaded(propertyId)) { arr[i] = objectModel.get(propertyId); } } } } return arr; } }
/** * Re-reads the given entity, refreshing any properties updated on the server-side during insert or update. */ private void processGeneratedProperties( Serializable id, Object entity, Object[] state, SharedSessionContractImplementor session, GenerationTiming matchTiming) { Tuple tuple = getFreshTuple( EntityKeyBuilder.fromPersister( this, id, session ), session ); saveSharedTuple( entity, tuple, session ); if ( tuple == null || tuple.getSnapshot().isEmpty() ) { throw log.couldNotRetrieveEntityForRetrievalOfGeneratedProperties( getEntityName(), id ); } int propertyIndex = -1; for ( NonIdentifierAttribute attribute : getEntityMetamodel().getProperties() ) { propertyIndex++; final ValueGeneration valueGeneration = attribute.getValueGenerationStrategy(); if ( isReadRequired( valueGeneration, matchTiming ) ) { Object hydratedState = gridPropertyTypes[propertyIndex].hydrate( tuple, getPropertyAliases( "", propertyIndex ), session, entity ); state[propertyIndex] = gridPropertyTypes[propertyIndex].resolve( hydratedState, session, entity ); setPropertyValue( entity, propertyIndex, state[propertyIndex] ); } } }