當前位置: 首頁>>代碼示例>>Java>>正文


Java Embeddable類代碼示例

本文整理匯總了Java中javax.persistence.Embeddable的典型用法代碼示例。如果您正苦於以下問題:Java Embeddable類的具體用法?Java Embeddable怎麽用?Java Embeddable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Embeddable類屬於javax.persistence包,在下文中一共展示了Embeddable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addClassType

import javax.persistence.Embeddable; //導入依賴的package包/類
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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:Configuration.java

示例2: buildHierarchyColumnOverride

import javax.persistence.Embeddable; //導入依賴的package包/類
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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:AbstractPropertyHolder.java

示例3: onInitialized

import javax.persistence.Embeddable; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:katharsis-project,項目名稱:katharsis-framework,代碼行數:18,代碼來源:AbstractJpaDataObjectProvider.java

示例4: jpaResultListQuery

import javax.persistence.Embeddable; //導入依賴的package包/類
@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);
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:20,代碼來源:DefaultExecutor.java

示例5: testStaticWeaving

import javax.persistence.Embeddable; //導入依賴的package包/類
@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);
}
 
開發者ID:kuali,項目名稱:rice,代碼行數:16,代碼來源:StaticWeavingTest.java

示例6: testModelTestCoverage

import javax.persistence.Embeddable; //導入依賴的package包/類
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);
    }
  }
}
 
開發者ID:hmsiccbl,項目名稱:screensaver,代碼行數:21,代碼來源:ModelTestCoverageTest.java

示例7: processId

import javax.persistence.Embeddable; //導入依賴的package包/類
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() );
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:AnnotationBinder.java

示例8: getEmbeddable

import javax.persistence.Embeddable; //導入依賴的package包/類
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
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:JPAOverriddenAnnotationReader.java

示例9: getManagedJpaClasses

import javax.persistence.Embeddable; //導入依賴的package包/類
@Nonnull
@SuppressWarnings("unchecked")
public static Set<Class<?>> getManagedJpaClasses() {
    return getMainClasses(Predicates.or(
            withAnnotation(Entity.class),
            withAnnotation(Embeddable.class),
            withAnnotation(MappedSuperclass.class)));
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:9,代碼來源:ClassInventory.java

示例10: accept

import javax.persistence.Embeddable; //導入依賴的package包/類
@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;
}
 
開發者ID:katharsis-project,項目名稱:katharsis-framework,代碼行數:8,代碼來源:EmbeddableMetaProvider.java

示例11: scanShouldFilterOnAnnotation

import javax.persistence.Embeddable; //導入依賴的package包/類
@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();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:15,代碼來源:EntityScannerTests.java

示例12: isEntity

import javax.persistence.Embeddable; //導入依賴的package包/類
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;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:8,代碼來源:ClassDefinitionParser.java

示例13: testGetNamesOfIdPropertiesFromASingleClassHavingAFieldAnnotatedWithEmbeddedId

import javax.persistence.Embeddable; //導入依賴的package包/類
@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));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:33,代碼來源:EntityUtilsTest.java

示例14: testGetNamesOfIdPropertiesFromASingleClassHavingAMethodAnnotatedWithEmbeddedId

import javax.persistence.Embeddable; //導入依賴的package包/類
@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));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:35,代碼來源:EntityUtilsTest.java

示例15: testGetNamesOfIdPropertiesFromAClassHierarchyHavingAFieldAnnotatedWithEmbeddedId

import javax.persistence.Embeddable; //導入依賴的package包/類
@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));
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:39,代碼來源:EntityUtilsTest.java


注:本文中的javax.persistence.Embeddable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。