本文整理汇总了Java中org.hibernate.metadata.ClassMetadata.getIdentifierPropertyName方法的典型用法代码示例。如果您正苦于以下问题:Java ClassMetadata.getIdentifierPropertyName方法的具体用法?Java ClassMetadata.getIdentifierPropertyName怎么用?Java ClassMetadata.getIdentifierPropertyName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.metadata.ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata.getIdentifierPropertyName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIdName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 取得对象的主键名,辅助函数.
*
* @param entityClass
* 实体类型
* @return 主键名称
*/
public String getIdName(Class entityClass) {
Assert.notNull(entityClass);
entityClass = ReflectUtils.getOriginalClass(entityClass);
ClassMetadata meta = this.getSessionFactory().getClassMetadata(
entityClass);
Assert.notNull(meta, "Class " + entityClass
+ " not define in hibernate session factory.");
String idName = meta.getIdentifierPropertyName();
Assert.hasText(idName, entityClass.getSimpleName()
+ " has no identifier property define.");
return idName;
}
示例2: _countRows
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
private TreeMap<String, Object> _countRows(Object value) {
ClassMetadata meta = getSessionFactory().getClassMetadata(value.getClass());
String idName = meta.getIdentifierPropertyName();
Serializable idValue = meta.getIdentifier(value, (SessionImplementor)getTmpSession());
ArrayList<String[]> fieldSets;
if(this._fields.length > 0){
fieldSets = _prepareFields();
}else{
fieldSets = _getFieldsFromUniqueConstraint(value);
fieldSets.addAll(_extractFieldsFromObject(value));
}
for(String[] fieldSet : fieldSets){
TreeMap<String, Object> fieldMap = new TreeMap<>();
for(String fieldName: fieldSet){
fieldMap.put(fieldName, meta.getPropertyValue(value, fieldName));
}
if(_hasRecord(value, fieldMap, idName, idValue, meta)){
return fieldMap;
}
}
return null;
}
示例3: extractIdPropertyNames
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@Override
public String[] extractIdPropertyNames(Object entity)
{
final IdClass idClassAnn = entity.getClass().getAnnotation(IdClass.class);
if (idClassAnn != null)
{
final Class<?> entityClass = idClassAnn.value();
final List<String> retVal = new ArrayList<>(3);
ReflectionUtils.doWithFields(entityClass, (f)->
{
if (! Modifier.isStatic(f.getModifiers()))
{
retVal.add(f.getName());
}
});
return retVal.toArray(new String[retVal.size()]);
}
else
{
final ClassMetadata classMetadata = factory.getClassMetadata(entity.getClass());
final String propertyName = classMetadata.getIdentifierPropertyName();
return propertyName != null ? new String[]{propertyName} : null;
}
}
示例4: getIdMetadata
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
Map<String, Object> response = new HashMap<String, Object>();
SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
if (metadata == null) {
return null;
}
String idProperty = metadata.getIdentifierPropertyName();
response.put("name", idProperty);
Type idType = metadata.getIdentifierType();
response.put("type", idType);
return response;
}
示例5: updaterCopyToPersistentObject
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 将更新对象拷贝至实体对象,并处理many-to-one的更新。
*
* @param updater
* @param po
*/
private void updaterCopyToPersistentObject(Updater<T> updater, T po,
ClassMetadata cm) {
String[] propNames = cm.getPropertyNames();
String identifierName = cm.getIdentifierPropertyName();
T bean = updater.getBean();
Object value;
for (String propName : propNames) {
if (propName.equals(identifierName)) {
continue;
}
try {
value = MyBeanUtils.getSimpleProperty(bean, propName);
if (!updater.isUpdate(propName, value)) {
continue;
}
cm.setPropertyValue(po, propName, value, POJO);
} catch (Exception e) {
throw new RuntimeException(
"copy property to persistent object failed: '"
+ propName + "'", e);
}
}
}
示例6: getIdMetadata
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
Map<String, Object> response = new HashMap<String, Object>();
SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
if (metadata == null) {
return null;
}
String idProperty = metadata.getIdentifierPropertyName();
response.put("name", idProperty);
Type idType = metadata.getIdentifierType();
response.put("type", idType);
return response;
}
示例7: get
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends Serializable, I extends Serializable> T get(Class<T> type, I id) {
Object idv = id;
String name = type.getName();
ClassMetadata classMetadata = (ClassMetadata) new MetadataResolver().getAllClassMetadata(sessionFactory).get(name);
String oid = classMetadata.getIdentifierPropertyName();
if (id instanceof String) {
IdentifierType<?> identifierType = (IdentifierType<?>) classMetadata.getIdentifierType();
if (!(identifierType instanceof StringType)) {
try {
idv = identifierType.stringToObject((String) id);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
QueryParameters hql = new QueryParameters("from " + name + " where " + oid + "=:" + oid,
new QueryParameter().setName(oid).setValueTypeText(idv));
logger.debug("hql={}", hql);
List<Serializable> value = execute(hql).getResults().getValue();
return (T) (value.isEmpty() ? null : value.get(0));
}
示例8: getPrimaryKeyPropertyName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@Override
public String getPrimaryKeyPropertyName() {
ClassMetadata classMetadata = getClassMetadata();
if (classMetadata == null) {
return null;
}
if (classMetadata.hasIdentifierProperty() == true) {
return classMetadata.getIdentifierPropertyName();
} else {
return null;
}
}
示例9: getIdName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 取得对象的主键名.
*/
public String getIdName() {
ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
return meta.getIdentifierPropertyName();
}
示例10: getIdName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@Override
public String getIdName() {
ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
return meta.getIdentifierPropertyName();
}
示例11: getIdName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 取得对象的主键名.
*/
public String getIdName() {
ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
return meta.getIdentifierPropertyName();
}
示例12: loadByExample
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
private Object loadByExample(PageContext pc, Object obj, boolean unique) throws PageException {
Component cfc=HibernateCaster.toComponent(obj);
Key dsn = KeyImpl.init(ORMUtil.getDataSourceName(pc, cfc));
ComponentScope scope = cfc.getComponentScope();
String name=HibernateCaster.getEntityName(cfc);
Session sess = getSession(dsn);
Object rtn=null;
try{
//trans.begin();
ClassMetadata metaData = sess.getSessionFactory().getClassMetadata(name);
String idName = metaData.getIdentifierPropertyName();
Type idType = metaData.getIdentifierType();
Criteria criteria=sess.createCriteria(name);
if(!Util.isEmpty(idName)){
Object idValue = scope.get(CommonUtil.createKey(idName),null);
if(idValue!=null){
criteria.add(Restrictions.eq(idName, HibernateCaster.toSQL(idType, idValue,null)));
}
}
criteria.add(Example.create(cfc));
// execute
if(!unique){
rtn = criteria.list();
}
else {
//Map map=(Map) criteria.uniqueResult();
rtn= criteria.uniqueResult();
}
}
catch(Throwable t){
lucee.commons.lang.ExceptionUtil.rethrowIfNecessary(t);
// trans.rollback();
throw CommonUtil.toPageException(t);
}
//trans.commit();
return rtn;
}
示例13: GrailsHibernateDomainClass
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* Contructor to be used by all child classes to create a new instance
* and get the name right.
*
* @param clazz the Grails class
* @param sessionFactory The Hibernate SessionFactory instance
* @param metaData The ClassMetaData for this class retrieved from the SF
* @param defaultConstraints The default global constraints definition
*/
public GrailsHibernateDomainClass(Class<?> clazz, SessionFactory sessionFactory, GrailsApplication application, ClassMetadata metaData, Map<String, Object> defaultConstraints) {
super(clazz, "");
this.application = application;
new StandardAnnotationMetadata(clazz);
String ident = metaData.getIdentifierPropertyName();
this.defaultConstraints = defaultConstraints;
if (ident != null) {
Class<?> identType = getPropertyType(ident);
this.identifier = new GrailsHibernateDomainClassProperty(this, ident);
this.identifier.setIdentity(true);
this.identifier.setType(identType);
this.propertyMap.put(ident, this.identifier);
}
// configure the version property
final int versionIndex = metaData.getVersionProperty();
String versionPropertyName = null;
if (versionIndex > -1) {
versionPropertyName = metaData.getPropertyNames()[versionIndex];
this.version = new GrailsHibernateDomainClassProperty(this, versionPropertyName);
this.version.setType(getPropertyType(versionPropertyName));
}
// configure remaining properties
String[] propertyNames = metaData.getPropertyNames();
boolean[] propertyNullablility = metaData.getPropertyNullability();
for (int i = 0; i < propertyNames.length; i++) {
String propertyName = propertyNames[i];
if (!propertyName.equals(ident) && !(versionPropertyName != null && propertyName.equals(versionPropertyName))) {
GrailsHibernateDomainClassProperty prop = new GrailsHibernateDomainClassProperty(this, propertyName);
prop.setType(getPropertyType(propertyName));
Type hibernateType = metaData.getPropertyType(propertyName);
// if its an association type
if (hibernateType.isAssociationType()) {
prop.setAssociation(true);
// get the associated type from the session factory and set it on the property
AssociationType assType = (AssociationType) hibernateType;
if (assType instanceof AnyType) {
continue;
}
try {
String associatedEntity = assType.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory);
ClassMetadata associatedMetaData = sessionFactory.getClassMetadata(associatedEntity);
prop.setRelatedClassType(associatedMetaData.getMappedClass(EntityMode.POJO));
} catch (MappingException me) {
// other side must be a value object
if (hibernateType.isCollectionType()) {
prop.setRelatedClassType(Collection.class);
}
}
// configure type of relationship
if (hibernateType.isCollectionType()) {
prop.setOneToMany(true);
} else if (hibernateType.isEntityType()) {
prop.setManyToOne(true);
// might not really be true, but for our purposes this is ok
prop.setOneToOne(true);
}
prop.setOptional(propertyNullablility[i]);
}
this.propertyMap.put(propertyName, prop);
}
}
this.properties = this.propertyMap.values().toArray(new GrailsDomainClassProperty[this.propertyMap.size()]);
// process the constraints
evaluateConstraints();
}
示例14: getIdPropertyName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
protected String getIdPropertyName() {
ClassMetadata meta = getSessionFactory().getClassMetadata(entityType);
return meta.getIdentifierPropertyName();
}
示例15: getIdName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
public String getIdName() {
ClassMetadata meta = getSessionFactory().getClassMetadata(entityClass);
return meta.getIdentifierPropertyName();
}