Java Code Examples for javax.persistence.Table#name()
The following examples show how to use
javax.persistence.Table#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: EntityHelper.java From azeroth with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: EntityHelper.java From mybatis-dynamic-query with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: EntityHelper.java From jeesuite-libs with Apache License 2.0 | 6 votes |
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; }
Example 4
Source File: EntityRefelectUtils.java From FastSQL with Apache License 2.0 | 6 votes |
/** * 获取指定实体类对应的表名 * * @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) { if (!StringUtils.isEmpty(table.name())) { tableName = table.name(); } } //返回表名 return tableName; }
Example 5
Source File: EntityManager.java From dal with Apache License 2.0 | 5 votes |
private void processTableAnnotation(Class<?> clazz) { Table table = clazz.getAnnotation(Table.class); if (table == null) return; String name = table.name(); if (name == null) return; if (tableName == null) { tableName = name; } }
Example 6
Source File: JavaxPersistenceImpl.java From ormlite-core with ISC License | 5 votes |
@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; }
Example 7
Source File: BaseDaoMysqlImpl.java From Crawer with MIT License | 5 votes |
protected BaseDaoMysqlImpl(Class<T> persistentClass) { this.persistentClass = persistentClass; Table table = AnnotationUtils.findAnnotation(persistentClass, Table.class); if (table == null) { throw new RuntimeException(persistentClass + "没有定义@table"); } this.tableName = table.name(); BeanInfo beanInfo = null; try { beanInfo = Introspector.getBeanInfo(persistentClass); } catch (IntrospectionException e) { log.error(e.getMessage(), e); } PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { Id id = AnnotationUtils .findAnnotation(pd.getReadMethod(), Id.class); if (pk.equals("") && id != null) { pk = pd.getName(); GeneratedValue gv = AnnotationUtils.findAnnotation( pd.getReadMethod(), GeneratedValue.class); if (gv == null) { strategy = GenerationType.IDENTITY; } else { strategy = gv.strategy(); } } Transient transient_ = AnnotationUtils.findAnnotation( pd.getReadMethod(), Transient.class); if (transient_ != null) { transientPropertys.add(pd.getName()); } } if ("".equals(this.getPk())) { throw new RuntimeException(persistentClass + "类型中没有在get方法上定义@Id"); } }
Example 8
Source File: AbstractModelService.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
private <T> String getTableName(EntityManager em, Class<T> entityClass){ /* * Check if the specified class is present in the metamodel. * Throws IllegalArgumentException if not. */ Metamodel meta = em.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(); return tableName; }
Example 9
Source File: ModelSqlUtils.java From jdbctemplatetool with Apache License 2.0 | 5 votes |
/** * 从po类获取表名 * @return */ private static <T> String getTableName(Class<T> clazz) { Table tableAnno = clazz.getAnnotation(Table.class); if(tableAnno != null){ if(tableAnno.catalog() != null){ return tableAnno.catalog() + "." + tableAnno.name(); } return tableAnno.name(); } //if Table annotation is null String className = clazz.getName(); return IdUtils.toUnderscore(className.substring(className.lastIndexOf(".")+1)); }
Example 10
Source File: BaseDao.java From ranger with Apache License 2.0 | 5 votes |
public void updateUserIDReference(String paramName,long oldID) { Table table = tClass.getAnnotation(Table.class); if(table != null) { String tableName = table.name(); String query = "update " + tableName + " set " + paramName+"=null" + " where " +paramName+"=" + oldID; int count=getEntityManager().createNativeQuery(query).executeUpdate(); if(count>0){ logger.warn(count + " records updated in table '" + tableName + "' with: set " + paramName + "=null where " + paramName + "=" + oldID); } }else{ logger.warn("Required annotation `Table` not found"); } }
Example 11
Source File: BaseDao.java From ranger with Apache License 2.0 | 5 votes |
public void setIdentityInsert(boolean identityInsert) { if (RangerBizUtil.getDBFlavor() != AppConstants.DB_FLAVOR_SQLSERVER) { logger.debug("Ignoring BaseDao.setIdentityInsert(). This should be executed if DB flavor is sqlserver."); return; } EntityManager entityMgr = getEntityManager(); String identityInsertStr; if (identityInsert) { identityInsertStr = "ON"; } else { identityInsertStr = "OFF"; } Table table = tClass.getAnnotation(Table.class); if(table == null) { throw new NullPointerException("Required annotation `Table` not found"); } String tableName = table.name(); try { entityMgr.unwrap(Connection.class).createStatement().execute("SET IDENTITY_INSERT " + tableName + " " + identityInsertStr); } catch (SQLException e) { logger.error("Error while settion identity_insert " + identityInsertStr, e); } }
Example 12
Source File: SqlGenerateUtil.java From jeecg with Apache License 2.0 | 5 votes |
/** * 获取OBJ对应的table名 * @param searchObj * @return */ public static String generateTable(Object searchObj){ Table table = searchObj.getClass().getAnnotation(Table.class); if(StringUtil.isEmpty(table.name())){ return searchObj.getClass().getSimpleName(); }else{ return table.name(); } }
Example 13
Source File: ClassHelper.java From gd-generator with MIT License | 5 votes |
public static String resolveTableName(Class<?> entityClass) { Table table = entityClass.getDeclaredAnnotation(Table.class); if (table == null) { throw new IllegalArgumentException("@Table注解缺失"); } if (StringUtils.isNotBlank(table.name())) { return table.name(); } else { return StringUtils.camelToUnderline(entityClass.getSimpleName()); } }
Example 14
Source File: SqlDAO.java From wangmarket with Apache License 2.0 | 5 votes |
/** * 从JPA的实体类中,获取数据库表的名字 * @param c 实体类,如 User.class * @return 此实体类的数据表的原名 */ public static String getDatabaseTableName(Class c){ Table table = (Table) c.getAnnotation(javax.persistence.Table.class); String tableName = null; if(table != null && table.name() != null && table.name().length() > 0){ tableName = table.name(); }else{ tableName = StringUtil.firstCharToLowerCase(c.getSimpleName()); } return tableName; }
Example 15
Source File: PersistentUtil.java From mybatis-jpa with Apache License 2.0 | 5 votes |
public static String getTableName(Class<?> clazz, NamingStrategy namingStrategy) { if (clazz.isAnnotationPresent(Table.class)) { Table table = clazz.getAnnotation(Table.class); if (!"".equals(table.name().trim())) { return table.name(); } } String tableName = clazz.getSimpleName(); return namingStrategy.translate(tableName); }
Example 16
Source File: DbUtil.java From cosmic with Apache License 2.0 | 4 votes |
public static final String getTableName(final Class<?> clazz) { final Table table = clazz.getAnnotation(Table.class); return table != null ? table.name() : clazz.getSimpleName(); }
Example 17
Source File: EntityTable.java From Mapper with MIT License | 4 votes |
public void setTable(Table table) { this.name = table.name(); this.catalog = table.catalog(); this.schema = table.schema(); }
Example 18
Source File: DbUtil.java From cloudstack with Apache License 2.0 | 4 votes |
public static final String getTableName(Class<?> clazz) { Table table = clazz.getAnnotation(Table.class); return table != null ? table.name() : clazz.getSimpleName(); }
Example 19
Source File: EntityTable.java From tk-mybatis with MIT License | 4 votes |
public void setTable(Table table) { this.name = table.name(); this.catalog = table.catalog(); this.schema = table.schema(); }
Example 20
Source File: BusinessLogInterceptor.java From boubei-tss with Apache License 2.0 | 4 votes |
public Object invoke(MethodInvocation invocation) throws Throwable { Method targetMethod = invocation.getMethod(); /* 获取目标方法 */ Object[] args = invocation.getArguments(); /* 获取目标方法的参数 */ Long preTime = System.currentTimeMillis(); Object returnVal = invocation.proceed(); /* 调用目标方法的返回值 */ int methodExcuteTime = (int) (System.currentTimeMillis() - preTime); Logable annotation = targetMethod.getAnnotation(Logable.class); // 取得注释对象 if (annotation != null) { String operateTable = annotation.operateObject(); String operateInfo = annotation.operateInfo(); String operateMethod = targetMethod.getName(); returnVal = EasyUtils.checkNull(returnVal, "_null_"); Map<String, Object> data = new HashMap<String, Object>(); data.put("returnVal", returnVal); Class<? extends Object> rvClazz = returnVal.getClass(); Table table = rvClazz.getAnnotation(Table.class); if( table != null ) { // 检测数据表是否配置了忽略日志,eg:取号器等 LogDisable logDisable = rvClazz.getAnnotation(LogDisable.class); if( logDisable != null ) { return returnVal; } if( "${table}".equals(operateTable) ) { operateTable = table.name(); } data.put("tableName", operateTable); } if( returnVal instanceof IEntity ) { operateMethod += ", " + ((IEntity)returnVal).getPK(); } Log log = new Log(operateMethod, parseMacro(operateInfo, args, data)); log.setOperateTable(operateTable); log.setMethodExcuteTime(methodExcuteTime); businessLogger.output(log); } return returnVal; }