Java Code Examples for javax.persistence.Embeddable

The following examples show how to use javax.persistence.Embeddable. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Gets all the fields of an entity, including all parent classes.
 */
private static List<Field> getEntityFields(Class<?> entity) {
  List<Field> fields = new ArrayList<>();

  for (Field field : entity.getDeclaredFields()) {
    Class<?> fieldType = field.getType();
    if (fieldType.getAnnotation(Embeddable.class) != null) {
      fields.addAll(Arrays.asList(fieldType.getDeclaredFields()));
    }
  }

  while (entity != Object.class) {
    fields.addAll(Arrays.asList(entity.getDeclaredFields()));
    entity = entity.getSuperclass();
  }

  return fields;
}
 
Example 2
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 3
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 4
@Override
public AnnotatedClassType addClassType(XClass clazz) {
	AnnotatedClassType type;
	if ( clazz.isAnnotationPresent( Entity.class ) ) {
		type = AnnotatedClassType.ENTITY;
	}
	else if ( clazz.isAnnotationPresent( Embeddable.class ) ) {
		type = AnnotatedClassType.EMBEDDABLE;
	}
	else if ( clazz.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
		type = AnnotatedClassType.EMBEDDABLE_SUPERCLASS;
	}
	else {
		type = AnnotatedClassType.NONE;
	}
	annotatedClassTypeMap.put( clazz.getName(), type );
	return type;
}
 
Example 5
@Override
public void onInitialized(MetaProviderContext context, MetaElement element) {
	super.onInitialized(context, element);
	if (element.getParent() instanceof MetaJpaDataObject && element instanceof MetaAttribute) {
		MetaAttribute attr = (MetaAttribute) element;
		MetaDataObject parent = attr.getParent();
		Type implementationType = PropertyUtils.getPropertyType(parent.getImplementationClass(), attr.getName());

		Class<?> elementType = getElementType(implementationType);

		boolean jpaObject = attr.isAssociation() || elementType.getAnnotation(Embeddable.class) != null;

		Class<? extends MetaType> metaClass = jpaObject ? MetaJpaDataObject.class : MetaType.class;
		MetaType metaType = context.getLookup().getMeta(implementationType, metaClass);
		attr.setType(metaType);
	}
}
 
Example 6
Source Project: lams   Source File: AbstractPropertyHolder.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void buildHierarchyColumnOverride(XClass element) {
	XClass current = element;
	Map<String, Column[]> columnOverride = new HashMap<String, Column[]>();
	Map<String, JoinColumn[]> joinColumnOverride = new HashMap<String, JoinColumn[]>();
	Map<String, JoinTable> joinTableOverride = new HashMap<String, JoinTable>();
	Map<String, ForeignKey> foreignKeyOverride = new HashMap<String, ForeignKey>();
	while ( current != null && !context.getBootstrapContext().getReflectionManager().toXClass( Object.class ).equals( current ) ) {
		if ( current.isAnnotationPresent( Entity.class ) || current.isAnnotationPresent( MappedSuperclass.class )
				|| current.isAnnotationPresent( Embeddable.class ) ) {
			//FIXME is embeddable override?
			Map<String, Column[]> currentOverride = buildColumnOverride( current, getPath() );
			Map<String, JoinColumn[]> currentJoinOverride = buildJoinColumnOverride( current, getPath() );
			Map<String, JoinTable> currentJoinTableOverride = buildJoinTableOverride( current, getPath() );
			Map<String, ForeignKey> currentForeignKeyOverride = buildForeignKeyOverride( current, getPath() );
			currentOverride.putAll( columnOverride ); //subclasses have precedence over superclasses
			currentJoinOverride.putAll( joinColumnOverride ); //subclasses have precedence over superclasses
			currentJoinTableOverride.putAll( joinTableOverride ); //subclasses have precedence over superclasses
			currentForeignKeyOverride.putAll( foreignKeyOverride ); //subclasses have precedence over superclasses
			columnOverride = currentOverride;
			joinColumnOverride = currentJoinOverride;
			joinTableOverride = currentJoinTableOverride;
			foreignKeyOverride = currentForeignKeyOverride;
		}
		current = current.getSuperclass();
	}

	holderColumnOverride = columnOverride.size() > 0 ? columnOverride : null;
	holderJoinColumnOverride = joinColumnOverride.size() > 0 ? joinColumnOverride : null;
	holderJoinTableOverride = joinTableOverride.size() > 0 ? joinTableOverride : null;
	holderForeignKeyOverride = foreignKeyOverride.size() > 0 ? foreignKeyOverride : null;
}
 
Example 7
private Embeddable getEmbeddable(Element tree, XMLContext.Default defaults) {
	if ( tree == null ) {
		return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation( Embeddable.class ) : null;
	}
	else {
		if ( "embeddable".equals( tree.getName() ) ) {
			AnnotationDescriptor entity = new AnnotationDescriptor( Embeddable.class );
			return AnnotationFactory.create( entity );
		}
		else {
			return null; //this is not an entity
		}
	}
}
 
Example 8
@Override
public boolean accept(Type type, Class<? extends MetaElement> metaClass) {
	boolean hasAnnotation = ClassUtils.getRawType(type).getAnnotation(Embeddable.class) != null;
	boolean hasType = metaClass == MetaElement.class || metaClass == MetaEmbeddable.class
			|| metaClass == MetaJpaDataObject.class;
	return hasAnnotation && hasType;
}
 
Example 9
Source Project: jpa-unit   Source File: EntityUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNamesOfIdPropertiesFromASingleClassHavingAFieldAnnotatedWithEmbeddedId() throws Exception {
    // GIVEN
    final String simpleClassName = "EntityClass";
    final String compositeIdPropertyName = "compositeKey";
    final String id1PropertyName = "key1";
    final String id2PropertyName = "key2";

    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
    jIdTypeClass.annotate(Embeddable.class);
    jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
    jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);

    final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName);
    jClass.annotate(Entity.class);
    jClass.field(JMod.PRIVATE, jIdTypeClass, compositeIdPropertyName).annotate(EmbeddedId.class);

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

    final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name());

    // WHEN
    final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);

    // THEN
    assertThat(namesOfIdProperties.size(), equalTo(2));
    assertThat(namesOfIdProperties,
            hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
 
Example 10
Source Project: jpa-unit   Source File: EntityUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNamesOfIdPropertiesFromASingleClassHavingAMethodAnnotatedWithEmbeddedId() throws Exception {
    // GIVEN
    final String simpleClassName = "EntityClass";
    final String compositeIdPropertyName = "compositeKey";
    final String id1PropertyName = "key1";
    final String id2PropertyName = "key2";

    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
    jIdTypeClass.annotate(Embeddable.class);
    jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
    jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);

    final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName);
    jClass.annotate(Entity.class);
    final JMethod method = jClass.method(JMod.PUBLIC, jIdTypeClass, "getCompositeKey");
    method.annotate(EmbeddedId.class);
    method.body()._return(JExpr._null());

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

    final Class<?> entityClass = loadClass(testFolder.getRoot(), jClass.name());

    // WHEN
    final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);

    // THEN
    assertThat(namesOfIdProperties.size(), equalTo(2));
    assertThat(namesOfIdProperties,
            hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
 
Example 11
Source Project: jpa-unit   Source File: EntityUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNamesOfIdPropertiesFromAClassHierarchyHavingAFieldAnnotatedWithEmbeddedId() throws Exception {
    // GIVEN
    final String simpleClassNameBase = "EntityClass";
    final String simpleClassNameB = "SubEntityClass";
    final String compositeIdPropertyName = "compositeKey";
    final String id1PropertyName = "key1";
    final String id2PropertyName = "key2";

    final JPackage jp = jCodeModel.rootPackage();

    final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
    jIdTypeClass.annotate(Embeddable.class);
    jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
    jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);

    final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase);
    jBaseClass.annotate(Entity.class);
    jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.TABLE_PER_CLASS);
    jBaseClass.field(JMod.PRIVATE, jIdTypeClass, compositeIdPropertyName).annotate(EmbeddedId.class);

    final JDefinedClass jSubclass = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass);
    jSubclass.annotate(Entity.class);

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

    final Class<?> entityClass = loadClass(testFolder.getRoot(), jSubclass.name());

    // WHEN
    final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);

    // THEN
    assertThat(namesOfIdProperties.size(), equalTo(2));
    assertThat(namesOfIdProperties,
            hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
 
Example 12
Source Project: jpa-unit   Source File: EntityUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNamesOfIdPropertiesFromAClassHierarchyHavingAMethodAnnotatedWithEmbeddedId() throws Exception {
    // GIVEN
    final String simpleClassNameBase = "EntityClass";
    final String simpleClassNameB = "SubEntityClass";
    final String compositeIdPropertyName = "compositeKey";
    final String id1PropertyName = "key1";
    final String id2PropertyName = "key2";

    final JPackage jp = jCodeModel.rootPackage();

    final JDefinedClass jIdTypeClass = jp._class(JMod.PUBLIC, "IdType");
    jIdTypeClass.annotate(Embeddable.class);
    jIdTypeClass.field(JMod.PRIVATE, Integer.class, id1PropertyName);
    jIdTypeClass.field(JMod.PRIVATE, String.class, id2PropertyName);

    final JDefinedClass jBaseClass = jp._class(JMod.PUBLIC, simpleClassNameBase);
    jBaseClass.annotate(Entity.class);
    jBaseClass.annotate(Inheritance.class).param("strategy", InheritanceType.TABLE_PER_CLASS);
    final JMethod method = jBaseClass.method(JMod.PUBLIC, jIdTypeClass, "getCompositeKey");
    method.annotate(EmbeddedId.class);
    method.body()._return(JExpr._null());

    final JDefinedClass jSubclass = jp._class(JMod.PUBLIC, simpleClassNameB)._extends(jBaseClass);
    jSubclass.annotate(Entity.class);

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

    final Class<?> entityClass = loadClass(testFolder.getRoot(), jSubclass.name());

    // WHEN
    final List<String> namesOfIdProperties = EntityUtils.getNamesOfIdProperties(entityClass);

    // THEN
    assertThat(namesOfIdProperties.size(), equalTo(2));
    assertThat(namesOfIdProperties,
            hasItems(compositeIdPropertyName + "." + id1PropertyName, compositeIdPropertyName + "." + id2PropertyName));
}
 
Example 13
Source Project: cuba   Source File: MetaClassRepresentation.java    License: Apache License 2.0 5 votes vote down vote up
public String getTableName() {
    boolean isEmbeddable = meta.getJavaClass().isAnnotationPresent(Embeddable.class);
    if (isEmbeddable)
        return "not defined for embeddable entities";

    MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);

    String databaseTable = metadataTools.getDatabaseTable(meta);
    return databaseTable != null ? databaseTable : "not defined";
}
 
Example 14
Source Project: nomulus   Source File: EntityCallbacksListener.java    License: Apache License 2.0 5 votes vote down vote up
private Stream<Object> findEmbeddedProperties(Object object, Class<?> clazz) {
  return Arrays.stream(clazz.getDeclaredFields())
      .filter(field -> !field.isAnnotationPresent(Transient.class))
      .filter(
          field ->
              field.isAnnotationPresent(Embedded.class)
                  || field.getType().isAnnotationPresent(Embeddable.class))
      .filter(field -> !Modifier.isStatic(field.getModifiers()))
      .map(field -> getFieldObject(field, object))
      .filter(Objects::nonNull);
}
 
Example 15
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 16
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 17
/**
 * 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 18
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 19
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 20
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 22
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 24
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 27
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 28
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 29
Source Project: rice   Source File: StaticWeavingTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@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 30
Source Project: dropwizard-experiment   Source File: EbeanEntities.java    License: MIT License 5 votes vote down vote up
public static Set<Class> getEntities() {
    Reflections reflections = new Reflections("bo.gotthardt.model");
    Set<Class<?>> entities = reflections.getTypesAnnotatedWith(Entity.class);
    Set<Class<?>> embeddables = reflections.getTypesAnnotatedWith(Embeddable.class);

    return Sets.union(embeddables, entities);
}
 
Example 31
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 32
@Test
public void persistenceEmbeddable() {
	testSingleComponent(SampleEmbeddable.class, Embeddable.class);
}
 
Example 33
@Test
public void persistenceEmbeddable() {
	testSingleComponent(SampleEmbeddable.class, Embeddable.class);
}
 
Example 34
Source Project: crnk-framework   Source File: EmbeddableMetaFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public boolean accept(Type type) {
	return ClassUtils.getRawType(type).getAnnotation(Embeddable.class) != null;
}
 
Example 35
@Override
public boolean accept(Type type) {
	Class<?> rawType = ClassUtils.getRawType(type);
	return rawType.getAnnotation(MappedSuperclass.class) != null && rawType.getAnnotation(Embeddable.class) == null;
}
 
Example 36
Source Project: crnk-framework   Source File: JpaMetaUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isJpaType(Class<?> type) {
	return type.getAnnotation(Embeddable.class) != null
			|| type.getAnnotation(Entity.class) != null
			|| type.getAnnotation(MappedSuperclass.class) != null;
}
 
Example 37
@Override
public boolean isEmbeddedType(BeanAttributeInformation attributeDesc) {
    Class elementType = ClassUtils.getRawType(ClassUtils.getElementType(attributeDesc.getImplementationType()));
    return elementType.getAnnotation(Embeddable.class) != null;
}
 
Example 38
Source Project: lams   Source File: AnnotationBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static void processId(
		PropertyHolder propertyHolder,
		PropertyData inferredData,
		SimpleValue idValue,
		HashMap<String, IdentifierGeneratorDefinition> classGenerators,
		boolean isIdentifierMapper,
		MetadataBuildingContext buildingContext) {
	if ( isIdentifierMapper ) {
		throw new AnnotationException(
				"@IdClass class should not have @Id nor @EmbeddedId properties: "
						+ BinderHelper.getPath( propertyHolder, inferredData )
		);
	}
	XClass entityXClass = inferredData.getClassOrElement();
	XProperty idXProperty = inferredData.getProperty();

	//manage composite related metadata
	//guess if its a component and find id data access (property, field etc)
	final boolean isComponent = entityXClass.isAnnotationPresent( Embeddable.class )
			|| idXProperty.isAnnotationPresent( EmbeddedId.class );

	GeneratedValue generatedValue = idXProperty.getAnnotation( GeneratedValue.class );
	String generatorType = generatedValue != null
			? generatorType( generatedValue, buildingContext, entityXClass )
			: "assigned";
	String generatorName = generatedValue != null
			? generatedValue.generator()
			: BinderHelper.ANNOTATION_STRING_DEFAULT;
	if ( isComponent ) {
		//a component must not have any generator
		generatorType = "assigned";
	}

	if ( isGlobalGeneratorNameGlobal( buildingContext ) ) {
		buildGenerators( idXProperty, buildingContext );
		SecondPass secondPass = new IdGeneratorResolverSecondPass(
				idValue,
				idXProperty,
				generatorType,
				generatorName,
				buildingContext
		);
		buildingContext.getMetadataCollector().addSecondPass( secondPass );
	}
	else {
		//clone classGenerator and override with local values
		HashMap<String, IdentifierGeneratorDefinition> localGenerators = (HashMap<String, IdentifierGeneratorDefinition>) classGenerators
				.clone();
		localGenerators.putAll( buildGenerators( idXProperty, buildingContext ) );
		BinderHelper.makeIdGenerator(
				idValue,
				idXProperty,
				generatorType,
				generatorName,
				buildingContext,
				localGenerators
		);
	}

	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
	}
}
 
Example 39
/**
 * look for @Embeddable annotation
 */
@Override
public boolean isCompositeClass(UnloadedClass classDescriptor) {
	return classDescriptor.hasAnnotation( Embeddable.class );
}
 
Example 40
@Override
public boolean isEmbeddable() {
	return isAnnotationPresent(Embedded.class)
			|| hasActualTypeAnnotation(Embeddable.class);
}