Java Code Examples for javax.persistence.Embeddable

The following are top voted examples for showing how to use javax.persistence.Embeddable. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lams   File: Configuration.java   View source code 6 votes vote down vote up
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;
	}
	classTypes.put( clazz.getName(), type );
	return type;
}
 
Example 2
Project: lams   File: AbstractPropertyHolder.java   View source code 6 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>();
	while ( current != null && !mappings.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() );
			currentOverride.putAll( columnOverride ); //subclasses have precedence over superclasses
			currentJoinOverride.putAll( joinColumnOverride ); //subclasses have precedence over superclasses
			currentJoinTableOverride.putAll( joinTableOverride ); //subclasses have precedence over superclasses
			columnOverride = currentOverride;
			joinColumnOverride = currentJoinOverride;
			joinTableOverride = currentJoinTableOverride;
		}
		current = current.getSuperclass();
	}

	holderColumnOverride = columnOverride.size() > 0 ? columnOverride : null;
	holderJoinColumnOverride = joinColumnOverride.size() > 0 ? joinColumnOverride : null;
	holderJoinTableOverride = joinTableOverride.size() > 0 ? joinTableOverride : null;
}
 
Example 3
Project: katharsis-framework   File: AbstractJpaDataObjectProvider.java   View source code 6 votes vote down vote up
@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 4
Project: cibet   File: DefaultExecutor.java   View source code 6 votes vote down vote up
@Override
public void jpaResultListQuery(EventMetadata metadata, Query query, CEntityManager entityManager) {
   List<?> result = new ArrayList<Object>();

   if (!Context.requestScope().isPlaying()) {
      result = query.getResultList();
      for (Object object : result) {
         if (object != null && entityManager.isLoadEager()
               && (object.getClass().getAnnotation(Embeddable.class) != null
                     || object.getClass().getAnnotation(Entity.class) != null)) {
            CibetUtil.loadLazyEntities(object, object.getClass());
            List<Object> references = new ArrayList<Object>();
            references.add(object);
            CibetUtil.deepDetach(object, references);
         }
      }
   }
   metadata.getResource().setResultObject(result);
}
 
Example 5
Project: rice   File: StaticWeavingTest.java   View source code 6 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 6
Project: screensaver   File: ModelTestCoverageTest.java   View source code 6 votes vote down vote up
public void testModelTestCoverage()
{
  assertNotNull(entityManagerFactory);
  for (ManagedType<?> managedType : entityManagerFactory.getMetamodel().getManagedTypes()) {
    Class<?> entityClass = managedType.getJavaType();
    String entityClassName = entityClass.getSimpleName();
    if (Modifier.isAbstract(entityClass.getModifiers())) {
      continue;
    }
    if (entityClass.getAnnotation(Embeddable.class) != null) {
      continue;
    }
    try {
      Class.forName(entityClass.getName() + "Test");
    }
    catch (ClassNotFoundException e) {
      fail("missing test class for " + entityClassName);
    }
  }
}
 
Example 7
Project: lams   File: AnnotationBinder.java   View source code 5 votes vote down vote up
private static void processId(
		PropertyHolder propertyHolder,
		PropertyData inferredData,
		SimpleValue idValue,
		HashMap<String, IdGenerator> classGenerators,
		boolean isIdentifierMapper,
		Mappings mappings) {
	if ( isIdentifierMapper ) {
		throw new AnnotationException(
				"@IdClass class should not have @Id nor @EmbeddedId properties: "
						+ BinderHelper.getPath( propertyHolder, inferredData )
		);
	}
	XClass returnedClass = inferredData.getClassOrElement();
	XProperty property = inferredData.getProperty();
	//clone classGenerator and override with local values
	HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
	localGenerators.putAll( buildLocalGenerators( property, mappings ) );

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

	GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
	String generatorType = generatedValue != null ?
			generatorType( generatedValue.strategy(), mappings ) :
			"assigned";
	String generatorName = generatedValue != null ?
			generatedValue.generator() :
			BinderHelper.ANNOTATION_STRING_DEFAULT;
	if ( isComponent ) {
		generatorType = "assigned";
	} //a component must not have any generator
	BinderHelper.makeIdGenerator( idValue, generatorType, generatorName, mappings, localGenerators );

	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
	}
}
 
Example 8
Project: lams   File: JPAOverriddenAnnotationReader.java   View source code 5 votes vote down vote up
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 9
Project: oma-riista-web   File: ClassInventory.java   View source code 5 votes vote down vote up
@Nonnull
@SuppressWarnings("unchecked")
public static Set<Class<?>> getManagedJpaClasses() {
    return getMainClasses(Predicates.or(
            withAnnotation(Entity.class),
            withAnnotation(Embeddable.class),
            withAnnotation(MappedSuperclass.class)));
}
 
Example 10
Project: katharsis-framework   File: EmbeddableMetaProvider.java   View source code 5 votes vote down vote up
@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 11
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: EntityScannerTests.java   View source code 5 votes vote down vote up
@Test
public void scanShouldFilterOnAnnotation() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			ScanConfig.class);
	EntityScanner scanner = new EntityScanner(context);
	assertThat(scanner.scan(Entity.class)).containsOnly(EntityA.class, EntityB.class,
			EntityC.class);
	assertThat(scanner.scan(Embeddable.class)).containsOnly(EmbeddableA.class,
			EmbeddableB.class, EmbeddableC.class);
	assertThat(scanner.scan(Entity.class, Embeddable.class)).containsOnly(
			EntityA.class, EntityB.class, EntityC.class, EmbeddableA.class,
			EmbeddableB.class, EmbeddableC.class);
	context.close();
}
 
Example 12
Project: engerek   File: ClassDefinitionParser.java   View source code 5 votes vote down vote up
private boolean isEntity(Class type) {
    if (RPolyString.class.isAssignableFrom(type)) {
        //it's hibernate entity but from prism point of view it's property
        return false;
    }
    return type.getAnnotation(Entity.class) != null || type.getAnnotation(Embeddable.class) != null;
}
 
Example 13
Project: jpa-unit   File: EntityUtilsTest.java   View source code 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 14
Project: jpa-unit   File: EntityUtilsTest.java   View source code 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 15
Project: jpa-unit   File: EntityUtilsTest.java   View source code 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 16
Project: jpa-unit   File: EntityUtilsTest.java   View source code 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 17
Project: cibet   File: DefaultExecutor.java   View source code 5 votes vote down vote up
@Override
public void jpaSingleResultQuery(EventMetadata metadata, Query query, CEntityManager entityManager) {
   if (!Context.requestScope().isPlaying()) {
      Object result = query.getSingleResult();
      if (result != null && entityManager.isLoadEager() && (result.getClass().getAnnotation(Embeddable.class) != null
            || result.getClass().getAnnotation(Entity.class) != null)) {
         CibetUtil.loadLazyEntities(result, result.getClass());
         List<Object> references = new ArrayList<Object>();
         references.add(result);
         CibetUtil.deepDetach(result, references);
      }
      metadata.getResource().setResultObject(result);
   }
}
 
Example 18
Project: cuba   File: MetaClassRepresentation.java   View source code 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 19
Project: metaworks_framework   File: EntityMarkerClassTransformer.java   View source code 5 votes vote down vote up
/**
 * Determines if a given annotation set contains annotations that correspond to ones that someone would expect to appear
 * in a persistence.xml
 * 
 * @param annotations
 * @return
 */
protected boolean containsTypeLevelPersistenceAnnotation(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.getTypeName().equals(Entity.class.getName())
                || annotation.getTypeName().equals(Embeddable.class.getName())
                || annotation.getTypeName().equals(MappedSuperclass.class.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 20
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 21
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 22
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 23
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 24
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 25
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 26
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 27
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 28
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 29
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 30
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 31
Project: kc-rice   File: StaticWeavingTest.java   View source code 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, true);
    Set<Class<?>> superTypes = reflections.getTypesAnnotatedWith(MappedSuperclass.class, true);
    Set<Class<?>> embeddableTypes = reflections.getTypesAnnotatedWith(Embeddable.class, true);

    // next, let's assert that they have been statically weaved
    assertStaticWeaved(entityTypes, superTypes, embeddableTypes);
}
 
Example 32
Project: SparkCommerce   File: EntityMarkerClassTransformer.java   View source code 5 votes vote down vote up
/**
 * Determines if a given annotation set contains annotations that correspond to ones that someone would expect to appear
 * in a persistence.xml
 * 
 * @param annotations
 * @return
 */
protected boolean containsTypeLevelPersistenceAnnotation(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.getTypeName().equals(Entity.class.getName())
                || annotation.getTypeName().equals(Embeddable.class.getName())
                || annotation.getTypeName().equals(MappedSuperclass.class.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 33
Project: pedal-dialect   File: EmbeddedColumnEvaluator.java   View source code 5 votes vote down vote up
@Override
public void evaluate(Method method, EvaluatorChain chain) {
    if (method.getReturnType().isAnnotationPresent(Embeddable.class) &&
            !method.isAnnotationPresent(Transient.class)) {
        Map<String, AttributeOverride> overrides = getAttributeOverrides(method);

        Class<?> embeddedClz = method.getReturnType();
        for (Method embeddedMethod : Arrays.stream(embeddedClz.getMethods()) //
                .filter(it -> it.isAnnotationPresent(Column.class)) //
                .collect(toList())) {
            String name = getPropertyName(embeddedMethod);
            String columnName = null;
            if (overrides.containsKey(name)) {
                columnName = overrides.get(name).column().name();
            } else {
                columnName = embeddedMethod.getAnnotation(Column.class).name();
            }
            CopyAttribute attribute = new CopyAttribute();
            attribute.getMethods().add(method);
            attribute.getMethods().add(embeddedMethod);
            attribute.setColumnName(columnName);
            chain.add(attribute);
        }
    } else {
        chain.doNext();
    }
}
 
Example 34
Project: blcdemo   File: EntityMarkerClassTransformer.java   View source code 5 votes vote down vote up
/**
 * Determines if a given annotation set contains annotations that correspond to ones that someone would expect to appear
 * in a persistence.xml
 * 
 * @param annotations
 * @return
 */
protected boolean containsTypeLevelPersistenceAnnotation(Annotation[] annotations) {
    for (Annotation annotation : annotations) {
        if (annotation.getTypeName().equals(Entity.class.getName())
                || annotation.getTypeName().equals(Embeddable.class.getName())
                || annotation.getTypeName().equals(MappedSuperclass.class.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 35
Project: querybean-generator   File: Processor.java   View source code 5 votes vote down vote up
@Override
public Set<String> getSupportedAnnotationTypes() {

  Set<String> annotations = new LinkedHashSet<>();
  annotations.add(Entity.class.getCanonicalName());
  annotations.add(Embeddable.class.getCanonicalName());
  return annotations;
}
 
Example 36
Project: hyperjaxb3   File: DefaultProcessPropertyInfos.java   View source code 5 votes vote down vote up
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 37
Project: hyperjaxb3   File: DefaultProcessPropertyInfos.java   View source code 5 votes vote down vote up
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 38
Project: midpoint   File: ClassDefinitionParser.java   View source code 5 votes vote down vote up
private boolean isEntity(Class type) {
    if (RPolyString.class.isAssignableFrom(type)) {
        //it's hibernate entity but from prism point of view it's property
        return false;
    }
    return type.getAnnotation(Entity.class) != null || type.getAnnotation(Embeddable.class) != null;
}
 
Example 39
Project: pedal-dialect   File: EmbeddedColumnEvaluator.java   View source code 5 votes vote down vote up
@Override
public void evaluate(Method method, EvaluatorChain chain) {
    if (method.getReturnType().isAnnotationPresent(Embeddable.class) &&
            !method.isAnnotationPresent(Transient.class)) {
        Map<String, AttributeOverride> overrides = getAttributeOverrides(method);

        Class<?> embeddedClz = method.getReturnType();
        for (Method embeddedMethod : Arrays.stream(embeddedClz.getMethods()) //
                .filter(it -> it.isAnnotationPresent(Column.class)) //
                .collect(toList())) {
            String name = getPropertyName(embeddedMethod);
            String columnName = null;
            if (overrides.containsKey(name)) {
                columnName = overrides.get(name).column().name();
            } else {
                columnName = embeddedMethod.getAnnotation(Column.class).name();
            }
            CopyAttribute attribute = new CopyAttribute();
            attribute.getMethods().add(method);
            attribute.getMethods().add(embeddedMethod);
            attribute.setColumnName(columnName);
            chain.add(attribute);
        }
    } else {
        chain.doNext();
    }
}
 
Example 40
Project: lutece-core   File: JPAPersistenceUnitPostProcessor.java   View source code 5 votes vote down vote up
/**
 * 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 );
    }
}