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


Java Table類代碼示例

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


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

示例1: queryByPrimaryKey

import javax.persistence.Table; //導入依賴的package包/類
/**
 * queryByPrimaryKey
 *
 * @param obj 實體bean
 * @return sql
 */
public String queryByPrimaryKey(Object obj) {
    Table table = getTable(obj);
    String key = "queryByPrimaryKey_" + table.getClass();
    String sql = sqlMap.get(key);
    if (sql == null) {
        StringBuilder stringBuilder = new StringBuilder("select ");
        StringBuilder columnStr = new StringBuilder();
        Map<String, String> columnMap = columnMap(obj.getClass());
        for (Map.Entry<String, String> entry : columnMap.entrySet()) {
            columnStr.append(entry.getKey());
            columnStr.append(" as ");
            columnStr.append(entry.getValue());
            columnStr.append(" ,");
        }
        columnStr.deleteCharAt(columnStr.lastIndexOf(","));
        stringBuilder.append(columnStr.toString());
        stringBuilder.append(" from ");
        stringBuilder.append(table.name());
        stringBuilder.append(buildWhereByPrimaryKey(obj.getClass()));
        sql = stringBuilder.toString();
        sqlMap.put(key, sql);

    }
    return sql;
}
 
開發者ID:ChenXun1989,項目名稱:ace,代碼行數:32,代碼來源:BaseProvider.java

示例2: 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

示例3: EntityInfo

import javax.persistence.Table; //導入依賴的package包/類
public EntityInfo(String mapperClassName, String entityClassName, String tableName) {
    this.tableName = tableName;
    try {
        if (StringUtils.isNotBlank(entityClassName)) { entityClass = Class.forName(entityClassName); }
        if (StringUtils.isBlank(this.tableName)) { this.tableName = entityClass.getAnnotation(Table.class).name(); }
        mapperClass = Class.forName(mapperClassName);
    } catch (Exception e) {
        try {
            //根據mapper接口解析entity Class
            Type[] types = mapperClass.getGenericInterfaces();
            Type[] tempTypes = ((ParameterizedType) types[0]).getActualTypeArguments();
            Class<?> clazz = (Class<?>) tempTypes[0];
            if (clazz != null) {
                entityClass = clazz;
            }
        } catch (Exception e1) {}
    }
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:19,代碼來源:EntityInfo.java

示例4: 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

示例5: 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

示例6: 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

示例7: testDeleteUploadTable

import javax.persistence.Table; //導入依賴的package包/類
@Test
public void testDeleteUploadTable() throws Exception {
  TableData tableData = new TableData();
  tableData.setTableName(RtEvent.class.getAnnotation(Table.class).name());
  RowData value = new RowData();
  ObjectList list = new ObjectList();
  list.getObjects().add(0L);
  list.getObjects().add(0L);
  list.getObjects().add("gif");
  value.getRows().add(list);
  tableData.setData(value);
  tableData.setForceCleanup(true);
  StringList stringList = new StringList();
  stringList.getStrings().add("EVENT_NR");
  stringList.getStrings().add("CLIENT_NR");
  stringList.getStrings().add("FORMAT");
  tableData.setColumns(stringList);
  UploadUtility.deleteTable(tableData, Long.MAX_VALUE, 0L);
}
 
開發者ID:innovad,項目名稱:4mila-1.0,代碼行數:20,代碼來源:UploadUtilityTest.java

示例8: EntityInfo

import javax.persistence.Table; //導入依賴的package包/類
public EntityInfo(String mapperClassName, String entityClassName, String tableName) {
	this.tableName = tableName;
	try {
		if(StringUtils.isNotBlank(entityClassName))entityClass = Class.forName(entityClassName);
		if(StringUtils.isBlank(this.tableName))this.tableName = entityClass.getAnnotation(Table.class).name();
		mapperClass = Class.forName(mapperClassName);
	} catch (Exception e) {
		try {					
			//根據mapper接口解析entity Class
			Type[] types = mapperClass.getGenericInterfaces();  
			Type[] tempTypes = ((ParameterizedType) types[0]).getActualTypeArguments();  
			Class<?> clazz = (Class<?>) tempTypes[0];
			if(clazz != null){
				entityClass = clazz;
			}
		} catch (Exception e1) {}
	}
}
 
開發者ID:vakinge,項目名稱:jeesuite-libs,代碼行數:19,代碼來源:EntityInfo.java

示例9: 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

示例10: getEntityClassFromNodeLabels

import javax.persistence.Table; //導入依賴的package包/類
public static Class<?> getEntityClassFromNodeLabels(final List<String> labels, final List<Class<?>> classes)
        throws NoSuchClassException {
    for (final String label : labels) {
        final Optional<Class<?>> classHit = classes.stream().filter(c -> {
            // try to find the class based on its name
            if (c.getName().endsWith(label)) {
                return true;
            } else {
                // try to find the class based on the @Table(name) settings
                final Table annotation = c.getAnnotation(Table.class);
                return annotation != null && annotation.name().equals(label);
            }
        }).findFirst();

        if (classHit.isPresent()) {
            return classHit.get();
        }
    }

    throw new NoSuchClassException("could not find class for a node with " + labels + " labels.");
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:22,代碼來源:EntityUtils.java

示例11: testGetEntityClassFromNodeLabelsHavingTheLabelDeclaredByTheTableAnnotationWithoutInheritance

import javax.persistence.Table; //導入依賴的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

示例12: getPkValues

import javax.persistence.Table; //導入依賴的package包/類
/**
 * 獲取主鍵的值
 * @param target	Entity的class類型
 * @return	如果該Entity沒有@Id注解,則return null,如果有一個則返回{val},兩個則返回{val1, val2}
 * 			其中的val值可能為null,所以需要實時判斷下
 */
public static Object[] getPkValues(Object target) {
	Assert.notNull(target, "target param must not be null.");
	Assert.isInstanceOf(Entity.class, target);
	com.easycodebox.jdbc.Table table = Configuration.getTable(target.getClass());
	if(table != null) {
		List<com.easycodebox.jdbc.PkColumn> pks = table.getPrimaryKeys();
		if(pks != null && pks.size() > 0) {
			Object[] vals = new Object[pks.size()];
			for(int i = 0; i < pks.size(); i++) {
				Object val;
				try {
					val = PropertyUtils.getSimpleProperty(target, pks.get(i).getName());
				} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
					throw new BaseException("Obtain object({0}) property({1}) error.", e, target, pks.get(i).getName());
				}
				vals[i] = val;
			}
			return vals;
		}
	}
	return null;
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:29,代碼來源:Entitys.java

示例13: register

import javax.persistence.Table; //導入依賴的package包/類
protected <T> void register(OObjectDatabaseTx db, OSchema schema, Class<T> aClass) {
    if (schema.getClass(aClass.getSimpleName()) == null) {
        db.getEntityManager().registerEntityClasses(aClass, true);
        OClass cls = db.getMetadata().getSchema().getClass(aClass);
        String indexName = aClass.getName() + ".unq";
        Table t = aClass.getAnnotation(Table.class);
        if (t != null) {
            Set<String> fields = new HashSet<>();
            for (UniqueConstraint uc : t.uniqueConstraints()) {
                fields.addAll(Lists.newArrayList(uc.columnNames()));
            }
            if (fields.size() > 0) {
                LOG.info("Registering unique constraint for fields: " + fields);
                for (String field : fields)
                    cls.createIndex(indexName + "." + field, OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, field);
            }
        }
    } else {
        db.getEntityManager().registerEntityClasses(aClass, true);
    }
}
 
開發者ID:dmart28,項目名稱:gcplot,代碼行數:22,代碼來源:AbstractOrientDbRepository.java

示例14: map

import javax.persistence.Table; //導入依賴的package包/類
public static List<Ddl2Rest.Klass> map(final Table table) {
  Column[] _columns = table.getColumns();
  final Function1<Column, Ddl2Rest.Klass> _function = (Column column) -> {
    Ddl2Rest.Klass _xblockexpression = null;
    {
      String _type = column.getType();
      String type = Ddl2Rest.fieldType(_type);
      String columnName = column.getName();
      String _name = column.getName();
      String[] _split = _name.split("_");
      final Function1<String, String> _function_1 = (String it) -> {
        return StringExtensions.toFirstUpper(it);
      };
      List<String> _map = ListExtensions.<String, String>map(((List<String>)Conversions.doWrapArray(_split)), _function_1);
      String _join = IterableExtensions.join(_map);
      String name = StringExtensions.toFirstLower(_join);
      String comment = column.getDescription();
      _xblockexpression = new Ddl2Rest.Klass(type, name, columnName, comment);
    }
    return _xblockexpression;
  };
  return ListExtensions.<Column, Ddl2Rest.Klass>map(((List<Column>)Conversions.doWrapArray(_columns)), _function);
}
 
開發者ID:East196,項目名稱:maker,代碼行數:24,代碼來源:Ddl2Rest.java

示例15: test

import javax.persistence.Table; //導入依賴的package包/類
@Test
public void test() {
    doInJPA(entityManager -> {
        Table table = new Table();
        table.id = 1L;
        table.from = "from";
        table.number = 123;
        table.select = "*";

        entityManager.persist(table);
    });

    doInJPA(entityManager -> {
        List<Table> tables = entityManager.createQuery(
            "select t " +
            "from Table t " +
            "where t.from like 'from'", Table.class)
        .getResultList();
        assertEquals(1, tables.size());
    });
}
 
開發者ID:vladmihalcea,項目名稱:high-performance-java-persistence,代碼行數:22,代碼來源:EscapeKeywordTest.java


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