当前位置: 首页>>代码示例>>Java>>正文


Java Entity类代码示例

本文整理汇总了Java中javax.persistence.Entity的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Entity类属于javax.persistence包,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupRelationshipRepositories

import javax.persistence.Entity; //导入依赖的package包/类
/**
 * Sets up relationship repositories for the given document class. In case
 * of a mapper the resource class might not correspond to the entity class.
 */
private void setupRelationshipRepositories(Class<?> resourceClass, boolean mapped) {
	if (context.getResourceInformationBuilder().accept(resourceClass)) {
		ResourceInformation information = context.getResourceInformationBuilder().build(resourceClass);


		for (ResourceField field : information.getFields()) {
			if (field.getResourceFieldType() != ResourceFieldType.RELATIONSHIP) {
				continue;
			}

			Class<?> attrType = field.getElementType();
			boolean isEntity = attrType.getAnnotation(Entity.class) != null;
			if (isEntity) {
				setupRelationshipRepositoryForEntity(resourceClass, field);
			}
			else {
				setupRelationshipRepositoryForResource(resourceClass, field);
			}
		}
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:26,代码来源:JpaModule.java

示例2: deleteEntities

import javax.persistence.Entity; //导入依赖的package包/类
public void deleteEntities(Class<?> entity){

        if(entity == null || entity.getAnnotation(Entity.class) == null){
            throw new IllegalArgumentException("Invalid non-entity class");
        }

        String name = entity.getSimpleName();

        /*
            Note: we passed as input a Class<?> instead of a String to
            avoid SQL injection. However, being here just test code, it should
            not be a problem. But, as a good habit, always be paranoiac about
            security, above all when you have code that can delete the whole
            database...
         */

        Query query = em.createQuery("delete from " + name);
        query.executeUpdate();
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:20,代码来源:DeleterEJB.java

示例3: configureRepositoryRestConfiguration

import javax.persistence.Entity; //导入依赖的package包/类
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
    //config.setBasePath("api");

    try {
        config.exposeIdsFor(UserEntity.class);
        ClassPathUtils.streamClassesAnnotatedWith(UserEntity.class, Entity.class)
                .peek(clazz -> log.debug("enable @Id json mapping for entity {}", clazz.getSimpleName()))
                .forEach(config::exposeIdsFor);
    } catch (IOException e) {
        throw new IllegalStateException("Could not exposeIds for @Entity classes");
    }
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:14,代码来源:RepositoryConfig.java

示例4: getClasses

import javax.persistence.Entity; //导入依赖的package包/类
/**
 * Retourne les classes d'une package
 *
 * @param packageName
 * @return
 * @throws Exception
 */
public static List<Class> getClasses(String packageName) {
    final List<Class> list = new ArrayList<>();

    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(Object.class));
    final Set<BeanDefinition> bds = scanner.findCandidateComponents(packageName);
    try {
        for (BeanDefinition bd : bds) {
            final Class<?> tc = Class.forName(bd.getBeanClassName());
            if (tc.getAnnotation(Entity.class) != null) {
                list.add(tc);
            }
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return list;
}
 
开发者ID:shared-vd,项目名称:tipi-engine,代码行数:26,代码来源:HibernateMetaDataHelper.java

示例5: weave

import javax.persistence.Entity; //导入依赖的package包/类
@Override
public void weave(WovenClass wovenClass) {
    BundleWiring wiring = wovenClass.getBundleWiring();
    Bundle bundle = wiring.getBundle();
    ClassLoader cl = wiring.getClassLoader();
    Collection<ClassTransformer> transformersToTry = getTransformers(bundle);
    for (ClassTransformer transformer : transformersToTry) {
        if (transformClass(wovenClass, cl, transformer)) {
            LOGGER.info("Weaving " + wovenClass.getClassName() + " using " + transformer.getClass().getName());
            break;
        }
    }
    Class<?> dClass = wovenClass.getDefinedClass();
    if (transformersToTry.isEmpty() && dClass != null && dClass.getAnnotation(Entity.class) != null) {
        LOGGER.warn("Loading " + wovenClass.getClassName() + " before transformer is present");
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:18,代码来源:JPAWeavingHook.java

示例6: deleteEntities

import javax.persistence.Entity; //导入依赖的package包/类
private void deleteEntities(Class<?> entity){

        if(entity == null || entity.getAnnotation(Entity.class) == null){
            throw new IllegalArgumentException("Invalid non-entity class");
        }

        String name = entity.getSimpleName();

        /*
            Note: we passed as input a Class<?> instead of a String to
            avoid SQL injection. However, being here just test code, it should
            not be a problem. But, as a good habit, always be paranoiac about
            security, above all when you have code that can delete the whole
            database...
         */

        Query query = em.createQuery("delete from " + name);
        query.executeUpdate();
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:20,代码来源:ResetEjb.java

示例7: addClassType

import javax.persistence.Entity; //导入依赖的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

示例8: isEntityClassType

import javax.persistence.Entity; //导入依赖的package包/类
private static boolean isEntityClassType(XClass clazzToProcess, AnnotatedClassType classType) {
	if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) //will be processed by their subentities
			|| AnnotatedClassType.NONE.equals( classType ) //to be ignored
			|| AnnotatedClassType.EMBEDDABLE.equals( classType ) //allow embeddable element declaration
			) {
		if ( AnnotatedClassType.NONE.equals( classType )
				&& clazzToProcess.isAnnotationPresent( org.hibernate.annotations.Entity.class ) ) {
			LOG.missingEntityAnnotation( clazzToProcess.getName() );
		}
		return false;
	}

	if ( !classType.equals( AnnotatedClassType.ENTITY ) ) {
		throw new AnnotationException(
				"Annotated class should have a @javax.persistence.Entity, @javax.persistence.Embeddable or @javax.persistence.EmbeddedSuperclass annotation: " + clazzToProcess
						.getName()
		);
	}

	return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AnnotationBinder.java

示例9: buildHierarchyColumnOverride

import javax.persistence.Entity; //导入依赖的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

示例10: getEntity

import javax.persistence.Entity; //导入依赖的package包/类
private Entity getEntity(Element tree, XMLContext.Default defaults) {
	if ( tree == null ) {
		return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation( Entity.class ) : null;
	}
	else {
		if ( "entity".equals( tree.getName() ) ) {
			AnnotationDescriptor entity = new AnnotationDescriptor( Entity.class );
			copyStringAttribute( entity, tree, "name", false );
			if ( defaults.canUseJavaAnnotations()
					&& StringHelper.isEmpty( (String) entity.valueOf( "name" ) ) ) {
				Entity javaAnn = getPhysicalAnnotation( Entity.class );
				if ( javaAnn != null ) {
					entity.setValue( "name", javaAnn.name() );
				}
			}
			return AnnotationFactory.create( entity );
		}
		else {
			return null; //this is not an entity
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:JPAOverriddenAnnotationReader.java

示例11: build

import javax.persistence.Entity; //导入依赖的package包/类
public EntityManagerFactory build() {

		Properties properties = createProperties();

		DefaultPersistenceUnitInfoImpl persistenceUnitInfo = new DefaultPersistenceUnitInfoImpl(JSPARE_GATEWAY_DATASOURCE);
		persistenceUnitInfo.setProperties(properties);

		// Using RESOURCE_LOCAL for manage transactions on DAO side.
		persistenceUnitInfo.setTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL);

		// Add all entities to configuration
		ClassAnnotationMatchProcessor processor = (c) -> persistenceUnitInfo.addAnnotatedClassName(c);
		ClasspathScannerUtils.scanner(ALL_SCAN_QUOTE).matchClassesWithAnnotation(Entity.class, processor)
				.scan(NUMBER_CLASSPATH_SCANNER_THREADS);

		Map<String, Object> configuration = new HashMap<>();
		properties.forEach((k, v) -> configuration.put((String) k, v));

		EntityManagerFactory entityManagerFactory = persistenceProvider.createContainerEntityManagerFactory(persistenceUnitInfo,
				configuration);
		return entityManagerFactory;
	}
 
开发者ID:pflima92,项目名称:jspare-vertx-ms-blueprint,代码行数:23,代码来源:JDBCProvider.java

示例12: start

import javax.persistence.Entity; //导入依赖的package包/类
@Override
public void start() {
    StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
            .applySetting("hibernate.connection.username", config.persistence.user)
            .applySetting("hibernate.connection.password", config.persistence.pass)
            .applySetting("hibernate.connection.driver_class", config.persistence.driver)
            .applySetting("hibernate.connection.url", config.persistence.url)
            .applySetting("hibernate.dialect", config.persistence.dialect)
            .applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
            .applySetting("hibernate.hbm2ddl.auto", "update")
            .applySetting("hibernate.show_sql", config.persistence.showSQL + "")
            .build();

    MetadataSources sources = new MetadataSources(registry);

    Timings.time("RegisterDBEntities", () ->
            new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));

    try {
        Metadata metadata = sources.buildMetadata();
        sessionFactory = metadata.buildSessionFactory();
    } catch (Exception e) {
        StandardServiceRegistryBuilder.destroy(registry);
        e.printStackTrace();
    }
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLib,代码行数:27,代码来源:HibernatePersistenceProvider.java

示例13: list

import javax.persistence.Entity; //导入依赖的package包/类
/**
 * 
 * @param manager {@link EntityManager} to create the query
 * @param klass klass to guess the list query and count query
 * @param currentPage 
 * @param max max number of elements
 * @return
 */
public <T> PaginatedList list(EntityManager manager, Class<T> klass,
      int currentPage, int max)
{

   if (!klass.isAnnotationPresent(Entity.class))
   {
      throw new IllegalArgumentException("Your entity is not annotated with @Entity");
   }

   TypedQuery<T> listQuery = manager.createQuery(
         "select o from " + klass.getSimpleName() + " o", klass);

   TypedQuery<Number> countQuery = manager.createQuery(
         "select count(1) from " + klass.getSimpleName() + " o",
         Number.class);

   return list(listQuery, countQuery, currentPage, max);
}
 
开发者ID:ismartonline,项目名称:ismartonline,代码行数:27,代码来源:PaginatorQueryHelper.java

示例14: getAllField

import javax.persistence.Entity; //导入依赖的package包/类
/**
 *
 * @param entityClass
 * @param fieldList
 * @return
 */
private static List<Field> getAllField(Class<?> entityClass, List<Field> fieldList) {
    if (fieldList == null) {
        fieldList = new LinkedList<Field>();
    }
    if (entityClass.equals(Object.class)) {
        return fieldList;
    }
    Field[] fields = entityClass.getDeclaredFields();
    for (Field field : fields) {
        if (!Modifier.isStatic(field.getModifiers())) {
            fieldList.add(field);
        }
    }
    Class<?> superClass = entityClass.getSuperclass();
    if (superClass != null
            && !superClass.equals(Object.class)
            && (superClass.isAnnotationPresent(Entity.class)
            || (!Map.class.isAssignableFrom(superClass)
            && !Collection.class.isAssignableFrom(superClass)))) {
        return getAllField(entityClass.getSuperclass(), fieldList);
    }
    return fieldList;
}
 
开发者ID:mazhaoyong,项目名称:api-server-seed,代码行数:30,代码来源:TableSearchColumnHelper.java

示例15: testGetEntityClassFromNodeLabelsHavingTheLabelDeclaredByTheTableAnnotationWithoutInheritance

import javax.persistence.Entity; //导入依赖的package包/类
@Test
public void testGetEntityClassFromNodeLabelsHavingTheLabelDeclaredByTheTableAnnotationWithoutInheritance() throws Exception {
    final String simpleClassName = "EntityClass";
    final String nodeLabel = "ENTITY_CLASS";

    final JPackage jp = jCodeModel.rootPackage();
    final JDefinedClass jClass = jp._class(JMod.PUBLIC, simpleClassName);
    jClass.annotate(Entity.class);
    jClass.annotate(Table.class).param("name", nodeLabel);

    buildModel(testFolder.getRoot(), jCodeModel);

    compileModel(testFolder.getRoot());

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

    final Class<?> clazz = EntityUtils.getEntityClassFromNodeLabels(Arrays.asList(nodeLabel), Arrays.asList(entityClass));

    assertThat(clazz, equalTo(entityClass));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:21,代码来源:EntityUtilsTest.java


注:本文中的javax.persistence.Entity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。