private ModificationStore getDefaultAudited(XClass clazz) { final Audited defaultAudited = clazz.getAnnotation( Audited.class ); if ( defaultAudited != null ) { return defaultAudited.modStore(); } else { return null; } }
private static void getListeners(XClass currentClazz, List<Class> orderedListeners) { EntityListeners entityListeners = currentClazz.getAnnotation( EntityListeners.class ); if ( entityListeners != null ) { Class[] classes = entityListeners.value(); int size = classes.length; for ( int index = size - 1; index >= 0; index-- ) { orderedListeners.add( classes[index] ); } } if ( useAnnotationAnnotatedByListener ) { Annotation[] annotations = currentClazz.getAnnotations(); for ( Annotation annot : annotations ) { entityListeners = annot.getClass().getAnnotation( EntityListeners.class ); if ( entityListeners != null ) { Class[] classes = entityListeners.value(); int size = classes.length; for ( int index = size - 1; index >= 0; index-- ) { orderedListeners.add( classes[index] ); } } } } } }
/** * @param clazz Class which properties are currently being added. * * @return {@link Audited} annotation of specified class. If processed type hasn't been explicitly marked, method * checks whether given class exists in {@link AuditedPropertiesReader#overriddenAuditedClasses} collection. * In case of success, {@link Audited} configuration of currently mapped entity is returned, otherwise * {@code null}. If processed type exists in {@link AuditedPropertiesReader#overriddenNotAuditedClasses} * collection, the result is also {@code null}. */ private Audited computeAuditConfiguration(XClass clazz) { Audited allClassAudited = clazz.getAnnotation( Audited.class ); // If processed class is not explicitly marked with @Audited annotation, check whether auditing is // forced by any of its child entities configuration (@AuditedOverride.forClass). if ( allClassAudited == null && overriddenAuditedClasses.contains( clazz ) ) { // Declared audited parent copies @Audited.modStore and @Audited.targetAuditMode configuration from // currently mapped entity. allClassAudited = persistentPropertiesSource.getXClass().getAnnotation( Audited.class ); if ( allClassAudited == null ) { // If parent class declares @Audited on the field/property level. allClassAudited = DEFAULT_AUDITED; } } else if ( allClassAudited != null && overriddenNotAuditedClasses.contains( clazz ) ) { return null; } return allClassAudited; }
private void processNamedEntityGraphs() { processNamedEntityGraph( annotatedClass.getAnnotation( NamedEntityGraph.class ) ); final NamedEntityGraphs graphs = annotatedClass.getAnnotation( NamedEntityGraphs.class ); if ( graphs != null ) { for ( NamedEntityGraph graph : graphs.value() ) { processNamedEntityGraph( graph ); } } }
/** * @param clazz Source class. * * @return List of @AuditOverride annotations applied at class level. */ private List<AuditOverride> computeAuditOverrides(XClass clazz) { final AuditOverrides auditOverrides = clazz.getAnnotation( AuditOverrides.class ); final AuditOverride auditOverride = clazz.getAnnotation( AuditOverride.class ); if ( auditOverrides == null && auditOverride != null ) { return Arrays.asList( auditOverride ); } else if ( auditOverrides != null && auditOverride == null ) { return Arrays.asList( auditOverrides.value() ); } else if ( auditOverrides != null && auditOverride != null ) { throw new MappingException( "@AuditOverrides annotation should encapsulate all @AuditOverride declarations. " + "Please revise Envers annotations applied to class " + clazz.getName() + "." ); } return Collections.emptyList(); }
private SecondaryTable findMatchingSecondaryTable(Join join) { final String nameToMatch = join.getTable().getQuotedName(); SecondaryTable secondaryTable = annotatedClass.getAnnotation( SecondaryTable.class ); if ( secondaryTable != null && nameToMatch.equals( secondaryTable.name() ) ) { return secondaryTable; } SecondaryTables secondaryTables = annotatedClass.getAnnotation( SecondaryTables.class ); if ( secondaryTables != null ) { for ( SecondaryTable secondaryTablesEntry : secondaryTables.value() ) { if ( secondaryTablesEntry != null && nameToMatch.equals( secondaryTablesEntry.name() ) ) { return secondaryTablesEntry; } } } return null; }
private org.hibernate.annotations.Table findMatchingComplimentTableAnnotation(Join join) { String tableName = join.getTable().getQuotedName(); org.hibernate.annotations.Table table = annotatedClass.getAnnotation( org.hibernate.annotations.Table.class ); org.hibernate.annotations.Table matchingTable = null; if ( table != null && tableName.equals( table.appliesTo() ) ) { matchingTable = table; } else { Tables tables = annotatedClass.getAnnotation( Tables.class ); if ( tables != null ) { for (org.hibernate.annotations.Table current : tables.value()) { if ( tableName.equals( current.appliesTo() ) ) { matchingTable = current; break; } } } } return matchingTable; }
private void addAuditTable(XClass clazz) { final AuditTable auditTable = clazz.getAnnotation( AuditTable.class ); if ( auditTable != null ) { auditData.setAuditTable( auditTable ); } else { auditData.setAuditTable( getDefaultAuditTable() ); } }
private void addAuditSecondaryTables(XClass clazz) { // Getting information on secondary tables final SecondaryAuditTable secondaryVersionsTable1 = clazz.getAnnotation( SecondaryAuditTable.class ); if ( secondaryVersionsTable1 != null ) { auditData.getSecondaryTableDictionary().put( secondaryVersionsTable1.secondaryTableName(), secondaryVersionsTable1.secondaryAuditTableName() ); } final SecondaryAuditTables secondaryAuditTables = clazz.getAnnotation( SecondaryAuditTables.class ); if ( secondaryAuditTables != null ) { for ( SecondaryAuditTable secondaryAuditTable2 : secondaryAuditTables.value() ) { auditData.getSecondaryTableDictionary().put( secondaryAuditTable2.secondaryTableName(), secondaryAuditTable2.secondaryAuditTableName() ); } } }
@SuppressWarnings("SimplifiableConditionalExpression") private void bindHibernateAnnotation(org.hibernate.annotations.Entity hibAnn) { final DynamicInsert dynamicInsertAnn = annotatedClass.getAnnotation( DynamicInsert.class ); this.dynamicInsert = dynamicInsertAnn == null ? ( hibAnn == null ? false : hibAnn.dynamicInsert() ) final DynamicUpdate dynamicUpdateAnn = annotatedClass.getAnnotation( DynamicUpdate.class ); this.dynamicUpdate = dynamicUpdateAnn == null ? ( hibAnn == null ? false : hibAnn.dynamicUpdate() ) final SelectBeforeUpdate selectBeforeUpdateAnn = annotatedClass.getAnnotation( SelectBeforeUpdate.class ); this.selectBeforeUpdate = selectBeforeUpdateAnn == null ? ( hibAnn == null ? false : hibAnn.selectBeforeUpdate() ) final OptimisticLocking optimisticLockingAnn = annotatedClass.getAnnotation( OptimisticLocking.class ); this.optimisticLockType = optimisticLockingAnn == null ? ( hibAnn == null ? OptimisticLockType.VERSION : hibAnn.optimisticLock() ) final Polymorphism polymorphismAnn = annotatedClass.getAnnotation( Polymorphism.class ); this.polymorphismType = polymorphismAnn == null ? ( hibAnn == null ? PolymorphismType.IMPLICIT : hibAnn.polymorphism() )
private AccessType determineLocalClassDefinedAccessStrategy() { AccessType classDefinedAccessType; AccessType hibernateDefinedAccessType = AccessType.DEFAULT; AccessType jpaDefinedAccessType = AccessType.DEFAULT; org.hibernate.annotations.AccessType accessType = xClass.getAnnotation( org.hibernate.annotations.AccessType.class ); if ( accessType != null ) { hibernateDefinedAccessType = AccessType.getAccessStrategy( accessType.value() ); } Access access = xClass.getAnnotation( Access.class ); if ( access != null ) { jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() ); } if ( hibernateDefinedAccessType != AccessType.DEFAULT && jpaDefinedAccessType != AccessType.DEFAULT && hibernateDefinedAccessType != jpaDefinedAccessType ) { throw new MappingException( "@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. " ); } if ( hibernateDefinedAccessType != AccessType.DEFAULT ) { classDefinedAccessType = hibernateDefinedAccessType; } else { classDefinedAccessType = jpaDefinedAccessType; } return classDefinedAccessType; }
private void processAttributeConversions(XClass embeddableXClass, Map<String, AttributeConversionInfo> infoMap) { { // @Convert annotation on the Embeddable class level final Convert convertAnnotation = embeddableXClass.getAnnotation( Convert.class ); if ( convertAnnotation != null ) { final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, embeddableXClass ); if ( StringHelper.isEmpty( info.getAttributeName() ) ) { throw new IllegalStateException( "@Convert placed on @Embeddable must define attributeName" ); } infoMap.put( info.getAttributeName(), info ); } } { // @Converts annotation on the Embeddable class level final Converts convertsAnnotation = embeddableXClass.getAnnotation( Converts.class ); if ( convertsAnnotation != null ) { for ( Convert convertAnnotation : convertsAnnotation.value() ) { final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, embeddableXClass ); if ( StringHelper.isEmpty( info.getAttributeName() ) ) { throw new IllegalStateException( "@Converts placed on @Embeddable must define attributeName" ); } infoMap.put( info.getAttributeName(), info ); } } } }
javax.persistence.DiscriminatorColumn discAnn = clazzToProcess.getAnnotation( javax.persistence.DiscriminatorColumn.class ); : DiscriminatorType.STRING; org.hibernate.annotations.DiscriminatorFormula discFormulaAnn = clazzToProcess.getAnnotation( org.hibernate.annotations.DiscriminatorFormula.class ); ? clazzToProcess.getAnnotation( DiscriminatorValue.class ).value() : null; entityBinder.setDiscriminatorValue( discriminatorValue ); DiscriminatorOptions discriminatorOptions = clazzToProcess.getAnnotation( DiscriminatorOptions.class ); if ( discriminatorOptions != null) { entityBinder.setForceDiscriminator( discriminatorOptions.force() );
final Convert convertAnnotation = xClass.getAnnotation( Convert.class ); if ( convertAnnotation != null ) { final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, xClass ); final Converts convertsAnnotation = xClass.getAnnotation( Converts.class ); if ( convertsAnnotation != null ) { for ( Convert convertAnnotation : convertsAnnotation.value() ) {
final Audited allClassAudited = clazz.getAnnotation( Audited.class ); if ( allClassAudited != null && allClassAudited.auditParents().length > 0 ) { for ( Class c : allClassAudited.auditParents() ) {
associatedClassWithIdClass.getAnnotation( IdClass.class ).value() ); return idClass.equals( compositeClass );
private AccessType determineDefaultAccessType() { for (XClass xclass = clazz; xclass != null; xclass = xclass.getSuperclass()) { if ( ( xclass.getSuperclass() == null || Object.class.getName().equals( xclass.getSuperclass().getName() ) ) && ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) && xclass.isAnnotationPresent( Access.class ) ) { return AccessType.getAccessStrategy( xclass.getAnnotation( Access.class ).value() ); } } // Guess from identifier. // FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations, but without an // explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type? for (XClass xclass = clazz; xclass != null && !Object.class.getName().equals(xclass.getName()); xclass = xclass.getSuperclass()) { if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) { for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.PROPERTY; } } for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.FIELD; } } } } throw new AnnotationException( "No identifier specified for entity: " + clazz ); }
final DiscriminatorValue discriminatorValueAnnotation = clazzToProcess.getAnnotation( DiscriminatorValue.class ); final String discriminatorValue = discriminatorValueAnnotation != null ? clazzToProcess.getAnnotation( DiscriminatorValue.class ).value() : null; entityBinder.setDiscriminatorValue( discriminatorValue ); final DiscriminatorColumn discriminatorColumnAnnotation = clazzToProcess.getAnnotation( DiscriminatorColumn.class ); if ( !inheritanceState.hasParents() ) {
if ( hasJoinedColumns ) { PrimaryKeyJoinColumns jcsAnn = clazzToProcess.getAnnotation( PrimaryKeyJoinColumns.class ); boolean explicitInheritanceJoinedColumns = jcsAnn != null && jcsAnn.value().length != 0; if ( explicitInheritanceJoinedColumns ) { PrimaryKeyJoinColumn jcAnn = clazzToProcess.getAnnotation( PrimaryKeyJoinColumn.class ); inheritanceJoinedColumns = new Ejb3JoinColumn[1]; inheritanceJoinedColumns[0] = Ejb3JoinColumn.buildJoinColumn(
denormalizedSuperTableXref ); final RowId rowId = annotatedClass.getAnnotation( RowId.class ); if ( rowId != null ) { table.setRowId( rowId.value() );