本文整理汇总了Java中javax.persistence.Table.name方法的典型用法代码示例。如果您正苦于以下问题:Java Table.name方法的具体用法?Java Table.name怎么用?Java Table.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.Table
的用法示例。
在下文中一共展示了Table.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTableNameFromEntityClass
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* 获取指定实体类对应的表名
*
* @param entityClass 实体类的类型令牌
* @return 若指定的类中含有{@code javax.persistence.Table}注解,则返回注解的name字段的值
*/
public static String getTableNameFromEntityClass(Class<?> entityClass) {
//获取类名
final String className = entityClass.getSimpleName();
//通过将类名由驼峰转为蛇形获取表名
String tableName = StringExtUtils.camelToUnderline(className);
//获取实体类中的Table注解实例
final Table table = entityClass.getAnnotation(Table.class);
//判断实例是否非空
if (table != null) {
//若非空,判断元数据name是否不为空字符串
if (!StringUtils.isEmpty(table.name())) {
//若是,则使用name的值覆盖表名
tableName = table.name();
}
}
//返回表名
return tableName;
}
示例2: getTableMapper
import javax.persistence.Table; //导入方法依赖的package包/类
private static TableMapper getTableMapper(Class<?> entityClass) {
// 表名
TableMapper tableMapper = new TableMapper();
String tableName = null;
if (entityClass.isAnnotationPresent(Table.class)) {
Table table = entityClass.getAnnotation(Table.class);
if (!table.name().equals("")) {
tableName = table.name();
} else {
tableName = camelhumpToUnderline(entityClass.getSimpleName());
}
}
if (tableName == null || tableName.equals("")) {
throw new RuntimeException("实体" + entityClass.getName() + "不存在'Table'注解");
}
tableMapper.setName(tableName);
return tableMapper;
}
示例3: getTableName
import javax.persistence.Table; //导入方法依赖的package包/类
static String getTableName(final Class<?> tableClass) {
if (tableClass == null) {
throw new NullPointerException("tableClass");
}
if (tableClass.isAnnotationPresent(Table.class)) {
Table table = tableClass.getAnnotation(Table.class);
String dbTableName = table.name();
if (StringUtils.isNotBlank(dbTableName)) {
return dbTableName;
}
}
String useTableName = tableClass.getSimpleName();
return camelCaseToUnderscore(useTableName);
}
示例4: registerDbModel
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* Registers the given model and controller with a database persister, getting the bucket name
* from the @Table annotation on the model.
*
* @param model
* @param controller
* @param stash
* @return
*/
public ModelController registerDbModel(Class<? extends Model> model, Class<? extends ModelController> controller, Class<? extends Stash> stash, String bucket) {
Table anno = model.getAnnotation(Table.class);
if (anno == null) {
throw new UsageException("A @Table annotation is required on the model " + model.getCanonicalName() + " in order to register it.");
}
bucket = or(bucket, anno.name());
String table = anno.name();
DataAccessRegistration registration = new DataAccessRegistration()
.setDatabaseBacked(true)
.setPersisterClass(DbPersister.class)
.setBucket(bucket)
.setTableName(table)
.setControllerClass(controller)
.setStashClass(stash)
.setModelClass(model);
return register(registration);
}
示例5: getTableName
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* Returns the table name for a given entity type in the
* {@link EntityManager}.
*
* @param entityClass
* @return
*/
public <T> String getTableName(Class<T> entityClass) {
/*
* Check if the specified class is present in the metamodel. Throws
* IllegalArgumentException if not.
*/
Metamodel meta = entityManager.getMetamodel();
EntityType<T> entityType = meta.entity(entityClass);
// Check whether @Table annotation is present on the class.
Table t = entityClass.getAnnotation(Table.class);
String tableName = (t == null) ? entityType.getName().toUpperCase() : t.name();
logger.debug("Table name found: {}", tableName);
return tableName;
}
示例6: retrieveTable
import javax.persistence.Table; //导入方法依赖的package包/类
private String retrieveTable(final String className) {
final int bI = className.lastIndexOf(".") + 1;
String table = className.substring(bI);
try {
final Class<?> c = Class.forName(className);
final Table tableAnnotation = c.getAnnotation(Table.class);
table = tableAnnotation.name();
} catch (final Exception e) {
LOG.error("Exception while retrieving 'table' annotation from the flexible element of type '" + className + "'.", e);
}
return table;
}
示例7: buildMap
import javax.persistence.Table; //导入方法依赖的package包/类
protected void buildMap(Class<T> c) {
if (c.isAnnotationPresent(Table.class)){
Table table = c.getAnnotation(Table.class);
tablename = table.name();
}
for (Field f : c.getDeclaredFields()) {
if (f.isAnnotationPresent(Column.class)) {
Column column = f.getAnnotation(Column.class);
columnMap.put(f.getName(), column.name());
if (f.isAnnotationPresent(Id.class)) {
primaryKeyField = f;
f.setAccessible(true);
primaryKeyName = column.name();
}
}
}
}
示例8: initType
import javax.persistence.Table; //导入方法依赖的package包/类
private void initType(ModelType type) {
Table table = type.getModelClass().getAnnotation(Table.class);
String query = "select id, ref_id from " + table.name();
HashMap<String, Long> seq = new HashMap<>();
HashSet<String> inDb = new HashSet<>();
try {
NativeSql.on(db).query(query, result -> {
String refId = result.getString(2);
seq.put(refId, result.getLong(1));
inDb.add(refId);
return true;
});
} catch (Exception e) {
log.error("failed to initialize sequence map for " + type, e);
}
sequences[type.ordinal()] = seq;
inDatabase[type.ordinal()] = inDb;
}
示例9: getCount
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* @return the number of entities in the table.
*/
public long getCount()
{
String entityName = entityClass.getSimpleName();
Table annotation = entityClass.getAnnotation(Table.class);
String tableName;
if (annotation != null)
{
tableName = annotation.name();
}
else
{
tableName = entityName;
}
String qry = "select count(" + entityName + ") from " + tableName + " " + entityName;
Query query = getEntityManager().createQuery(qry);
Number countResult = (Number) query.getSingleResult();
return countResult.longValue();
}
示例10: getTableName
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* Given an entity, returns the table name for the entity.
* @param entity the entity to lookup.
* @return the name of the table for the entity.
*/
public static String getTableName(final Class<?> entity) {
final Entity annotation = entity.getAnnotation(Entity.class);
if(annotation == null) {
throw new IllegalArgumentException(entity.getName() + " does not have the Entity annotation");
}
final Table table = entity.getAnnotation(Table.class);
// get the table's name from the annotation
if(table != null && !table.name().isEmpty()) {
return table.name();
} else {
return entity.getSimpleName();
}
}
示例11: init
import javax.persistence.Table; //导入方法依赖的package包/类
private void init() {
Table table = model.getClass().getAnnotation(Table.class);
if(table != null) {
tableName = table.name();
}
if(tableName == null || "".equals(tableName.trim())) {
tableName = model.getClass().getSimpleName();
}
}
示例12: getTableName
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* 获取pojo表名
* <p>
* 下划线风格
* </p>
*
* @param clazz pojo类class对象
* @return tableName
*/
public static String getTableName(Class<?> clazz) {
// 驼峰转下划线
String tableName = StringUtil.camelToUnderline(clazz.getName());
// 判断是否有Table注解
if (clazz.isAnnotationPresent(Table.class)) {
// 获取注解对象
Table table = clazz.getAnnotation(Table.class);
// 设置了name属性
if (!table.name().trim().equals("")) {
return table.name();
}
}
return tableName;
}
示例13: tablename
import javax.persistence.Table; //导入方法依赖的package包/类
/**
* 获取POJO对应的表名
* 需要POJO中的属性定义@Table(name)
* @return
*/
public String tablename() {
Table table = this.getClass().getAnnotation(Table.class);
if(table != null)
return table.name();
else
throw new JOPException("undefine POJO @Table, need Tablename(@Table)");
}
示例14: tableName
import javax.persistence.Table; //导入方法依赖的package包/类
public static String tableName(Class<?> klass) {
Table t = klass.getAnnotation(Table.class);
if (t != null) {
return t.name();
}
return klass.getSimpleName();
}
示例15: getTableName
import javax.persistence.Table; //导入方法依赖的package包/类
static String getTableName(Class<?> clazz) {
Table table = clazz.getAnnotation(Table.class);
if (table == null) {
return clazz.getSimpleName();
}
return table.name().isEmpty() ? clazz.getSimpleName() : table.name();
}