Java Code Examples for javax.persistence.Entity#name()

The following examples show how to use javax.persistence.Entity#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DaoSupport.java    From bbs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 获取实体名称,由上面的方法调用
 * @param <T>
 * @param entityClass 实体类
 * @return
 */
protected <T> String getEntityName(Class<T> entityClass){
	//默认情况下实体名称为这个类的简单名称,即实体类上的这个标志@Entity
	String entityname = entityClass.getSimpleName();
	//获取实体类Entity注解上的属性,如Entity(name="xxx")这种情况
	Entity entity = entityClass.getAnnotation(Entity.class);
	//判断实体类Entity注解上是否设置了name属性
	if(entity.name() != null && !"".equals(entity.name())){
		//把实体名称修改为它的属性值
		entityname = entity.name();
	}
	return entityname;
}
 
Example 2
Source File: DefaultJpaEntityMetadata.java    From ueboot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String getEntityName() {

    Entity entity = domainType.getAnnotation(Entity.class);
    boolean hasName = null != entity && StringUtils.hasText(entity.name());

    return hasName ? entity.name() : domainType.getSimpleName();
}
 
Example 3
Source File: EntityBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void bindEjb3Annotation(Entity ejb3Ann) {
	if ( ejb3Ann == null ) throw new AssertionFailure( "@Entity should always be not null" );
	if ( BinderHelper.isEmptyAnnotationValue( ejb3Ann.name() ) ) {
		name = StringHelper.unqualify( annotatedClass.getName() );
	}
	else {
		name = ejb3Ann.name();
	}
}
 
Example 4
Source File: BaseDaoImpl.java    From niubi-job with Apache License 2.0 5 votes vote down vote up
public String getEntityAnnotationName(Class<?> clazz) {
    try {
        Entity entityAnnotation = clazz.getAnnotation(Entity.class);
        return StringHelper.isEmpty(entityAnnotation.name()) ? clazz.getSimpleName() : entityAnnotation.name();
    } catch (Exception e) {
        return clazz.getSimpleName();
    }
}
 
Example 5
Source File: EntityManager.java    From dal with Apache License 2.0 5 votes vote down vote up
public <T> String getTableName() {
	if (tableName != null)
		return tableName;

	Entity entity = clazz.getAnnotation(Entity.class);
	if (entity != null && (!entity.name().isEmpty()))
		return entity.name();
	return clazz.getSimpleName();
}
 
Example 6
Source File: DefaultMybatisEntityMetadata.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
@Override
public String getEntityName() {
	Entity entity = AnnotatedElementUtils.findMergedAnnotation(domainType,
			Entity.class);
	return null != entity && StringUtils.hasText(entity.name()) ? entity.name()
			: domainType.getSimpleName();
}
 
Example 7
Source File: JpaEntityCoverage.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private static String getJpaEntityName(Class entityType) {
  Entity entityAnnotation = (Entity) entityType.getAnnotation(Entity.class);
  checkState(
      entityAnnotation != null, "Unexpected non-entity type %s", entityType.getSimpleName());
  return Strings.isNullOrEmpty(entityAnnotation.name())
      ? entityType.getSimpleName()
      : entityAnnotation.name();
}
 
Example 8
Source File: JpaTckRepository.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private String getEntityName(Class<?> clazz) {
  if (!clazz.isAnnotationPresent(Entity.class)) {
    return clazz.getSimpleName();
  }
  final Entity entity = clazz.getAnnotation(Entity.class);
  if (entity.name().isEmpty()) {
    return clazz.getSimpleName();
  }
  return entity.name();
}
 
Example 9
Source File: AnnotationUtil.java    From zxl with Apache License 2.0 5 votes vote down vote up
public static String getEntityAnnotationName(Class<?> clazz) {
	try {
		Entity entityAnnotation = clazz.getAnnotation(Entity.class);
		return StringUtil.isEmpty(entityAnnotation.name()) ? clazz.getSimpleName() : entityAnnotation.name();
	} catch (Exception e) {
		return clazz.getSimpleName();
	}
}
 
Example 10
Source File: JavaxPersistenceImpl.java    From ormlite-core with ISC License 5 votes vote down vote up
@Override
public String getEntityName(Class<?> clazz) {
	Entity entityAnnotation = clazz.getAnnotation(Entity.class);
	Table tableAnnotation = clazz.getAnnotation(Table.class);

	if (entityAnnotation != null && stringNotEmpty(entityAnnotation.name())) {
		return entityAnnotation.name();
	}
	if (tableAnnotation != null && stringNotEmpty(tableAnnotation.name())) {
		return tableAnnotation.name();
	}
	return null;
}