javax.persistence.MappedSuperclass Java Examples
The following examples show how to use
javax.persistence.MappedSuperclass.
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: CubaClientTestCase.java From cuba with Apache License 2.0 | 6 votes |
protected List<String> getClasses(Resource[] resources) { List<String> classNames = new ArrayList<>(); for (Resource resource : resources) { if (resource.isReadable()) { MetadataReader metadataReader; try { metadataReader = metadataReaderFactory.getMetadataReader(resource); } catch (IOException e) { throw new RuntimeException("Unable to read metadata resource", e); } AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata(); if (annotationMetadata.isAnnotated(com.haulmont.chile.core.annotations.MetaClass.class.getName()) || annotationMetadata.isAnnotated(MappedSuperclass.class.getName()) || annotationMetadata.isAnnotated(Entity.class.getName())) { ClassMetadata classMetadata = metadataReader.getClassMetadata(); classNames.add(classMetadata.getClassName()); } } } return classNames; }
Example #2
Source File: EntityCallbacksListener.java From nomulus with Apache License 2.0 | 6 votes |
/** * Executes eligible callbacks in {@link Embedded} properties recursively. * * @param entity the Java object of the entity class * @param entityType either the type of the entity or an ancestor type */ private void execute(Object entity, Class<?> entityType) { Class<?> parentType = entityType.getSuperclass(); if (parentType != null && parentType.isAnnotationPresent(MappedSuperclass.class)) { execute(entity, parentType); } findEmbeddedProperties(entity, entityType) .forEach( normalEmbedded -> { // For each normal embedded property, we don't execute its callback method because // it is handled by Hibernate. However, for the embedded property defined in the // entity's parent class, we need to treat it as a nested embedded property and // invoke its callback function. if (entity.getClass().equals(entityType)) { executeCallbackForNormalEmbeddedProperty( normalEmbedded, normalEmbedded.getClass()); } else { executeCallbackForNestedEmbeddedProperty( normalEmbedded, normalEmbedded.getClass()); } }); }
Example #3
Source File: EntityCallbacksListener.java From nomulus with Apache License 2.0 | 6 votes |
private void executeCallbackForNestedEmbeddedProperty( Object nestedEmbeddedObject, Class<?> nestedEmbeddedType) { Class<?> parentType = nestedEmbeddedType.getSuperclass(); if (parentType != null && parentType.isAnnotationPresent(MappedSuperclass.class)) { executeCallbackForNestedEmbeddedProperty(nestedEmbeddedObject, parentType); } findEmbeddedProperties(nestedEmbeddedObject, nestedEmbeddedType) .forEach( embeddedProperty -> executeCallbackForNestedEmbeddedProperty( embeddedProperty, embeddedProperty.getClass())); for (Method method : nestedEmbeddedType.getDeclaredMethods()) { if (method.isAnnotationPresent(callbackType)) { invokeMethod(method, nestedEmbeddedObject); } } }
Example #4
Source File: AnnotationMetadataSourceProcessorImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private void categorizeAnnotatedClass(Class annotatedClass, AttributeConverterManager attributeConverterManager) { final XClass xClass = reflectionManager.toXClass( annotatedClass ); // categorize it, based on assumption it does not fall into multiple categories if ( xClass.isAnnotationPresent( Converter.class ) ) { //noinspection unchecked attributeConverterManager.addAttributeConverter( annotatedClass ); } else if ( xClass.isAnnotationPresent( Entity.class ) || xClass.isAnnotationPresent( MappedSuperclass.class ) ) { xClasses.add( xClass ); } else if ( xClass.isAnnotationPresent( Embeddable.class ) ) { xClasses.add( xClass ); } else { log.debugf( "Encountered a non-categorized annotated class [%s]; ignoring", annotatedClass.getName() ); } }
Example #5
Source File: ClassFileArchiveEntryHandler.java From lams with GNU General Public License v2.0 | 6 votes |
private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) { ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;; final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag ); if ( visibleAnnotations != null ) { if ( visibleAnnotations.getAnnotation( Entity.class.getName() ) != null || visibleAnnotations.getAnnotation( MappedSuperclass.class.getName() ) != null || visibleAnnotations.getAnnotation( Embeddable.class.getName() ) != null ) { categorization = ClassDescriptor.Categorization.MODEL; } else if ( visibleAnnotations.getAnnotation( Converter.class.getName() ) != null ) { categorization = ClassDescriptor.Categorization.CONVERTER; } } return new ClassDescriptorImpl( classFile.getName(), categorization, entry.getStreamAccess() ); }
Example #6
Source File: JpaResourceInformationProvider.java From crnk-framework with Apache License 2.0 | 6 votes |
@Override public String getResourceType(Class<?> entityClass) { JsonApiResource annotation1 = entityClass.getAnnotation(JsonApiResource.class); if (annotation1 != null) { return annotation1.type(); } if (entityClass.getAnnotation(MappedSuperclass.class) != null) { return null; // super classes do not have a document type } String name = entityClass.getSimpleName(); if (name.endsWith(ENTITY_NAME_SUFFIX)) { name = name.substring(0, name.length() - ENTITY_NAME_SUFFIX.length()); } return Character.toLowerCase(name.charAt(0)) + name.substring(1); }
Example #7
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections( DocumentAttachment.class.getPackage().getName(), DocumentBase.class.getPackage().getName(), MaintenanceLock.class.getPackage().getName(), Message.class.getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #8
Source File: MetaClassRepresentation.java From cuba with Apache License 2.0 | 5 votes |
public String getParent() { MetaClass ancestor = meta.getAncestor(); if (ancestor == null || !ancestor.getName().contains("$") && !ancestor.getName().contains("_") || ancestor.getJavaClass().isAnnotationPresent(MappedSuperclass.class)) return ""; if (!readPermitted(ancestor)) { return null; } return "Parent is " + asHref(ancestor.getName()); }
Example #9
Source File: QueryCacheManager.java From cuba with Apache License 2.0 | 5 votes |
protected Set<String> getDescendants(Set<String> relatedTypes) { if (relatedTypes == null) return null; Set<String> newRelatedTypes = new HashSet<>(); relatedTypes.forEach(type -> { newRelatedTypes.add(type); MetaClass metaClass = metadata.getClassNN(type); if (metaClass.getDescendants() != null) { Set<String> descendants = metaClass.getDescendants().stream() .filter(it -> it.getJavaClass() != null && !it.getJavaClass().isAnnotationPresent(MappedSuperclass.class)) .map(MetadataObject::getName).collect(Collectors.toSet()); newRelatedTypes.addAll(descendants); } }); return newRelatedTypes; }
Example #10
Source File: EntityCallbacksListener.java From nomulus with Apache License 2.0 | 5 votes |
private void executeCallbackForNormalEmbeddedProperty( Object normalEmbeddedObject, Class<?> normalEmbeddedType) { Class<?> parentType = normalEmbeddedType.getSuperclass(); if (parentType != null && parentType.isAnnotationPresent(MappedSuperclass.class)) { executeCallbackForNormalEmbeddedProperty(normalEmbeddedObject, parentType); } findEmbeddedProperties(normalEmbeddedObject, normalEmbeddedType) .forEach( embeddedProperty -> executeCallbackForNestedEmbeddedProperty( embeddedProperty, embeddedProperty.getClass())); }
Example #11
Source File: EntityCallbacksListenerTest.java From nomulus with Apache License 2.0 | 5 votes |
private static boolean hasMethodAnnotatedWithEmbedded(Class<?> entityType) { boolean result = false; Class<?> parentType = entityType.getSuperclass(); if (parentType != null && parentType.isAnnotationPresent(MappedSuperclass.class)) { result = hasMethodAnnotatedWithEmbedded(parentType); } for (Method method : entityType.getDeclaredMethods()) { if (method.isAnnotationPresent(Embedded.class)) { result = true; break; } } return result; }
Example #12
Source File: DefaultProcessPropertyInfos.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 5 votes |
public boolean isRootClass(Class<?> theClass) { final boolean notMappedSuperclassAndNotEmbeddable = theClass .getAnnotation(MappedSuperclass.class) == null && theClass.getAnnotation(Embeddable.class) == null; if (theClass.getSuperclass() != null) { return notMappedSuperclassAndNotEmbeddable && !isSelfOrAncestorRootClass(theClass.getSuperclass()); } else { return notMappedSuperclassAndNotEmbeddable; } }
Example #13
Source File: DefaultProcessPropertyInfos.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 5 votes |
public boolean isSelfOrAncestorRootClass(Class<?> theClass) { if (isRootClass(theClass)) { return true; } else if (theClass.getSuperclass() != null) { return isSelfOrAncestorRootClass(theClass.getSuperclass()); } else { return theClass.getAnnotation(MappedSuperclass.class) == null && theClass.getAnnotation(Embeddable.class) == null; } }
Example #14
Source File: JPAPersistenceUnitPostProcessor.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Scans for *.orm.xml and adds Entites from classpath. * * @param pui * the pui */ @Override public void postProcessPersistenceUnitInfo( MutablePersistenceUnitInfo pui ) { _Log.info( "Scanning for JPA orm.xml files" ); for ( File ormFile : getListORMFiles( ) ) { String ormAbsolutePath = ormFile.getAbsolutePath( ); _Log.info( "Found ORM file : " + ormAbsolutePath ); pui.addMappingFileName( ormAbsolutePath.substring( ormAbsolutePath.indexOf( CLASSPATH_PATH_IDENTIFIER ) ) ); } _Log.info( "Scanning for JPA entities..." ); Set<String> entityClasses = AnnotationUtil.find( Entity.class.getName( ) ); entityClasses.addAll( AnnotationUtil.find( Embeddable.class.getName( ) ) ); entityClasses.addAll( AnnotationUtil.find( MappedSuperclass.class.getName( ) ) ); for ( String strClass : entityClasses ) { _Log.info( "Found entity class : " + strClass ); if ( !pui.getManagedClassNames( ).contains( strClass ) ) { pui.addManagedClassName( strClass ); } } if ( _Log.isDebugEnabled( ) ) { dumpPersistenceUnitInfo( pui ); } }
Example #15
Source File: EclipselinkStaticWeaveMojo.java From eclipselink-maven-plugin with Apache License 2.0 | 5 votes |
private Set<String> findEntities(String[] allBasePackages, final URL[] classPath) { final Set<String> result = new TreeSet<>(); try (final ScanResult scanResult = new ClassGraph().whitelistPackages(allBasePackages).enableAnnotationInfo().overrideClasspath((Object[]) classPath).scan()) { result.addAll(extract(scanResult, Entity.class)); result.addAll(extract(scanResult, MappedSuperclass.class)); result.addAll(extract(scanResult, Embeddable.class)); result.addAll(extract(scanResult, Converter.class)); } return result; }
Example #16
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections("org.kuali.rice.krad"); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #17
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #18
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections( PersistableBusinessObjectBase.class.getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #19
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #20
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #21
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #22
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #23
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections("org.kuali.rice.kew", "org.kuali.rice.kim", "org.kuali.rice.kcb", "org.kuali.rice.ken"); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #24
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #25
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #26
Source File: StaticWeavingTest.java From rice with Educational Community License v2.0 | 5 votes |
@Test public void testStaticWeaving() { // first, scan for all files on the classpath with an @Entity or @MappedSuperClass annotation Reflections reflections = new Reflections(getClass().getPackage().getName()); Set<Class<?>> entityTypes = reflections.getTypesAnnotatedWith(Entity.class); Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class); Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class); // next, let's assert that they have been statically weaved assertStaticWeaved(entityTypes, superTypes, embeddableTypes); }
Example #27
Source File: AbstractEntityMetaProvider.java From katharsis-framework with Apache License 2.0 | 5 votes |
private Class<?> getJpaSuperclass(Class<?> resourceClass) { Class<?> superclass = resourceClass.getSuperclass(); while(superclass != Object.class){ if(superclass.getAnnotation(Entity.class) != null || superclass.getAnnotation(MappedSuperclass.class) != null){ return superclass; } superclass = superclass.getSuperclass(); } return null; }
Example #28
Source File: EnhanceBuilder.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private static Set<Class<?>> scanMappedSuperclass(Class<?> clz) throws Exception { Set<Class<?>> set = new HashSet<Class<?>>(); set.add(clz); Class<?> s = clz.getSuperclass(); while (null != s) { if (null != s.getAnnotation(MappedSuperclass.class)) { set.add(s); } s = s.getSuperclass(); } return set; }
Example #29
Source File: AnnotationMetadataSourceProcessorImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private void insertMappedSuperclasses(List<XClass> original, List<XClass> copy) { for ( XClass clazz : original ) { XClass superClass = clazz.getSuperclass(); while ( superClass != null && !reflectionManager.equals( superClass, Object.class ) && !copy.contains( superClass ) ) { if ( superClass.isAnnotationPresent( Entity.class ) || superClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) { copy.add( superClass ); } superClass = superClass.getSuperclass(); } } }
Example #30
Source File: PersistenceXmlWriter.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private static Set<Class<?>> scanMappedSuperclass(Class<?> clz) throws Exception { Set<Class<?>> set = new HashSet<Class<?>>(); set.add(clz); Class<?> s = clz.getSuperclass(); while (null != s) { if (null != s.getAnnotation(MappedSuperclass.class)) { set.add(s); } s = s.getSuperclass(); } return set; }