当前位置: 首页>>代码示例>>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;未经允许,请勿转载。