org.hibernate.tuple.entity.EntityMetamodel Java Examples
The following examples show how to use
org.hibernate.tuple.entity.EntityMetamodel.
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: AttributeFactory.java From lams with GNU General Public License v2.0 | 6 votes |
private EntityMetamodel getDeclarerEntityMetamodel(AbstractIdentifiableType<?> ownerType) { final Type.PersistenceType persistenceType = ownerType.getPersistenceType(); if ( persistenceType == Type.PersistenceType.ENTITY ) { return context.getSessionFactory() .getMetamodel() .entityPersister( ownerType.getTypeName() ) .getEntityMetamodel(); } else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) { PersistentClass persistentClass = context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType ); return context.getSessionFactory() .getMetamodel() .entityPersister( persistentClass.getClassName() ) .getEntityMetamodel(); } else { throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType ); } }
Example #2
Source File: ClosureEventTriggeringInterceptor.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
private void updateModifiedPropertiesWithAutoTimestamp(Map<String, Object> modifiedProperties, PreUpdateEvent hibernateEvent) { EntityMetamodel entityMetamodel = hibernateEvent.getPersister().getEntityMetamodel(); Integer dateCreatedIdx = entityMetamodel.getPropertyIndexOrNull(AutoTimestampEventListener.DATE_CREATED_PROPERTY); Object[] oldState = hibernateEvent.getOldState(); Object[] state = hibernateEvent.getState(); // Only for "dateCreated" property, "lastUpdated" is handled correctly if (dateCreatedIdx != null && oldState != null && oldState[dateCreatedIdx] != null && !oldState[dateCreatedIdx].equals(state[dateCreatedIdx])) { modifiedProperties.put(AutoTimestampEventListener.DATE_CREATED_PROPERTY, oldState[dateCreatedIdx]); } }
Example #3
Source File: ClosureEventTriggeringInterceptor.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
private void synchronizeHibernateState(EntityPersister persister, Object[] state, Map<String, Object> modifiedProperties) { EntityMetamodel entityMetamodel = persister.getEntityMetamodel(); for(Map.Entry<String,Object> entry : modifiedProperties.entrySet()) { Integer index = entityMetamodel.getPropertyIndexOrNull(entry.getKey()); if(index != null) { state[index] = entry.getValue(); } } }
Example #4
Source File: ClosureEventListener.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
private void synchronizePersisterState(AbstractPreDatabaseOperationEvent event, Object[] state, EntityPersister persister, String[] propertyNames) { Object entity = event.getEntity(); EntityReflector reflector = persistentEntity.getReflector(); HashMap<Integer, Object> changedState= new HashMap<>(); EntityMetamodel entityMetamodel = persister.getEntityMetamodel(); for (int i = 0; i < propertyNames.length; i++) { String p = propertyNames[i]; Integer index = entityMetamodel.getPropertyIndexOrNull(p); if(index == null) continue; PersistentProperty property = persistentEntity.getPropertyByName(p); if (property == null) { continue; } String propertyName = property.getName(); if(GormProperties.VERSION.equals(propertyName)) { continue; } Object value = reflector.getProperty(entity, propertyName); if(state[index] != value) { changedState.put(i, value); } state[index] = value; } synchronizeEntityUpdateActionState(event, entity, changedState); }
Example #5
Source File: PojoEntityTuplizer.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) { super( entityMetamodel, mappedEntity ); this.mappedClass = mappedEntity.getMappedClass(); this.proxyInterface = mappedEntity.getProxyInterface(); this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass ); this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass ); Iterator iter = mappedEntity.getPropertyClosureIterator(); while ( iter.hasNext() ) { Property property = (Property) iter.next(); if ( property.isLazy() ) { lazyPropertyNames.add( property.getName() ); } } String[] getterNames = new String[propertySpan]; String[] setterNames = new String[propertySpan]; Class[] propTypes = new Class[propertySpan]; for ( int i = 0; i < propertySpan; i++ ) { getterNames[i] = getters[i].getMethodName(); setterNames[i] = setters[i].getMethodName(); propTypes[i] = getters[i].getReturnType(); } if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) { optimizer = null; } else { // todo : YUCK!!! optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes ); // optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer( // mappedClass, getterNames, setterNames, propTypes // ); } }
Example #6
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 4 votes |
public EntityMetamodel getEntityMetamodel() { return entityMetamodel; }
Example #7
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 4 votes |
private void collectAttributeDefinitions( Map<String, AttributeDefinition> attributeDefinitionsByName, EntityMetamodel metamodel) { for ( int i = 0; i < metamodel.getPropertySpan(); i++ ) { final AttributeDefinition attributeDefinition = metamodel.getProperties()[i]; // Don't replace an attribute definition if it is already in attributeDefinitionsByName // because the new value will be from a subclass. final AttributeDefinition oldAttributeDefinition = attributeDefinitionsByName.get( attributeDefinition.getName() ); if ( oldAttributeDefinition != null ) { if ( LOG.isTraceEnabled() ) { LOG.tracef( "Ignoring subclass attribute definition [%s.%s] because it is defined in a superclass ", entityMetamodel.getName(), attributeDefinition.getName() ); } } else { attributeDefinitionsByName.put( attributeDefinition.getName(), attributeDefinition ); } } // see if there are any subclass persisters... final Set<String> subClassEntityNames = metamodel.getSubclassEntityNames(); if ( subClassEntityNames == null ) { return; } // see if we can find the persisters... for ( String subClassEntityName : subClassEntityNames ) { if ( metamodel.getName().equals( subClassEntityName ) ) { // skip it continue; } try { final EntityPersister subClassEntityPersister = factory.getEntityPersister( subClassEntityName ); collectAttributeDefinitions( attributeDefinitionsByName, subClassEntityPersister.getEntityMetamodel() ); } catch (MappingException e) { throw new IllegalStateException( String.format( "Could not locate subclass EntityPersister [%s] while processing EntityPersister [%s]", subClassEntityName, metamodel.getName() ), e ); } } }
Example #8
Source File: AbstractEntityPersister.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public EntityMetamodel getEntityMetamodel() { return entityMetamodel; }
Example #9
Source File: CustomPersister.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public EntityMetamodel getEntityMetamodel() { return null; }
Example #10
Source File: MyEntityTuplizer.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public MyEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) { super( entityMetamodel, mappedEntity ); }
Example #11
Source File: EntityPersister.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Retrieve the underlying entity metamodel instance... * *@return The metamodel */ EntityMetamodel getEntityMetamodel();
Example #12
Source File: EntityPersister.java From cacheonix-core with GNU Lesser General Public License v2.1 | 2 votes |
/** * Retrieve the underlying entity metamodel instance... * *@return The metamodel */ public EntityMetamodel getEntityMetamodel();