com.ymonnier.sql.help.service.utilities.ClassUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ym-sql-helper Show documentation
Show all versions of ym-sql-helper Show documentation
A little abstraction of CRUD operations and
generator find function for model's attributs.
The newest version!
package com.ymonnier.sql.help.service.utilities;
import javax.persistence.EntityManager;
import javax.persistence.Table;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.Metamodel;
/**
* Project SqlHelper.
* Package com.ymonnier.sql.help.service.utilities.
* File ClassUtil.java.
* Created by Ysee on 15/03/2017 - 21:39.
* www.yseemonnier.com
* https://github.com/YMonnier
*/
public class ClassUtil {
/**
* Return the table name for a giben entity type.
* @param em Entity manager.
* @param entityClass Entity type.
* @param Generic value
* @return Table name.
*/
public static String getTableName(EntityManager em, Class entityClass) {
Metamodel meta = em.getMetamodel();
EntityType 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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy