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


Java Table.name方法代碼示例

本文整理匯總了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;
}
 
開發者ID:fast-sql,項目名稱:FastSQL,代碼行數:25,代碼來源:EntityRefelectUtils.java

示例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;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:21,代碼來源:EntityHelper.java

示例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);
}
 
開發者ID:wz2cool,項目名稱:mybatis-dynamic-query,代碼行數:17,代碼來源:EntityHelper.java

示例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);
}
 
開發者ID:StallionCMS,項目名稱:stallion-core,代碼行數:27,代碼來源:DataAccessRegistry.java

示例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;
}
 
開發者ID:Pardus-LiderAhenk,項目名稱:lider,代碼行數:23,代碼來源:PluginDbServiceImpl.java

示例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;
}
 
開發者ID:sigmah-dev,項目名稱:sigmah,代碼行數:17,代碼來源:ModelUtil.java

示例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();
			}
		}
	}
}
 
開發者ID:makeandbuild,項目名稱:vessl,代碼行數:18,代碼來源:BaseDomainMapper.java

示例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;
}
 
開發者ID:GreenDelta,項目名稱:olca-modules,代碼行數:19,代碼來源:Seq.java

示例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();

}
 
開發者ID:rlsutton1,項目名稱:VaadinUtils,代碼行數:24,代碼來源:JpaBaseDao.java

示例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();
    }
}
 
開發者ID:wspeirs,項目名稱:sop4j-dbutils,代碼行數:22,代碼來源:EntityUtils.java

示例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();
    }
}
 
開發者ID:Martion2017,項目名稱:ApplicationDetection,代碼行數:10,代碼來源:ModelSQLBuilder.java

示例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;
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:24,代碼來源:GeneralMapperReflectUtil.java

示例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)");
}
 
開發者ID:jambo-framework,項目名稱:jambo2,代碼行數:13,代碼來源:BaseVO.java

示例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();
}
 
開發者ID:cybozu,項目名稱:spring-data-jdbc-template,代碼行數:8,代碼來源:EntityUtils.java

示例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();
}
 
開發者ID:michaelliao,項目名稱:crypto-exchange,代碼行數:8,代碼來源:EntityInfo.java


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