本文整理汇总了Java中org.hibernate.metadata.ClassMetadata.getPropertyTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ClassMetadata.getPropertyTypes方法的具体用法?Java ClassMetadata.getPropertyTypes怎么用?Java ClassMetadata.getPropertyTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.metadata.ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata.getPropertyTypes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyProperties
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* Copies the persistent properties from the source to the destination entity
*/
public void copyProperties(final Entity source, final Entity dest) {
if (source == null || dest == null) {
return;
}
final ClassMetadata metaData = getClassMetaData(source);
final Object[] values = metaData.getPropertyValues(source, EntityMode.POJO);
// Skip the collections
final Type[] types = metaData.getPropertyTypes();
for (int i = 0; i < types.length; i++) {
final Type type = types[i];
if (type instanceof CollectionType) {
values[i] = null;
}
}
metaData.setPropertyValues(dest, values, EntityMode.POJO);
}
示例2: HibernateEntityCollection
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* Construct a entity collection.
*
* @param parentMetadata parent meta data
* @param childMetadata child meta data
* @param parent parent object
* @param objects child objects
*/
public HibernateEntityCollection(ClassMetadata parentMetadata, ClassMetadata childMetadata, Object parent,
Collection<?> objects) {
this.objects = objects;
int i = 0;
for (Type type : childMetadata.getPropertyTypes()) {
if (type instanceof ManyToOneType) {
ManyToOneType mto = (ManyToOneType) type;
if (mto.getAssociatedEntityName().equals(parentMetadata.getEntityName())) {
parentName = childMetadata.getPropertyNames()[i];
}
}
i++;
}
this.metadata = childMetadata;
this.parent = parent;
}
示例3: toString
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* @param entity an actual entity object, not a proxy!
*/
public String toString(Object entity, EntityMode entityMode) throws HibernateException {
// todo : this call will not work for anything other than pojos!
ClassMetadata cm = factory.getClassMetadata( entity.getClass() );
if ( cm==null ) return entity.getClass().getName();
Map result = new HashMap();
if ( cm.hasIdentifierProperty() ) {
result.put(
cm.getIdentifierPropertyName(),
cm.getIdentifierType().toLoggableString( cm.getIdentifier( entity, entityMode ), factory )
);
}
Type[] types = cm.getPropertyTypes();
String[] names = cm.getPropertyNames();
Object[] values = cm.getPropertyValues( entity, entityMode );
for ( int i=0; i<types.length; i++ ) {
if ( !names[i].startsWith("_") ) {
String strValue = values[i]==LazyPropertyInitializer.UNFETCHED_PROPERTY ?
values[i].toString() :
types[i].toLoggableString( values[i], factory );
result.put( names[i], strValue );
}
}
return cm.getEntityName() + result.toString();
}
示例4: processRelationships
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* Connect the related entities based on the foreign key values.
* Note that this may cause related entities to be loaded from the DB if they are not already in the session.
* @param entityInfo Entity that will be saved
* @param meta Metadata about the entity type
*/
private void processRelationships(EntityInfo entityInfo, ClassMetadata meta) {
addToGraph(entityInfo, null); // make sure every entity is in the graph
String[] propNames = meta.getPropertyNames();
Type[] propTypes = meta.getPropertyTypes();
Type propType = meta.getIdentifierType();
if (propType != null) {
processRelationship(meta.getIdentifierPropertyName(), propType, entityInfo, meta);
}
for (int i = 0; i < propNames.length; i++) {
processRelationship(propNames[i], propTypes[i], entityInfo, meta);
}
}
示例5: resolveReferences
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void resolveReferences(final Entity entity) {
final ClassMetadata meta = getClassMetaData(entity);
final String[] names = meta.getPropertyNames();
final Type[] types = meta.getPropertyTypes();
for (int i = 0; i < types.length; i++) {
final Type type = types[i];
final String name = names[i];
if (type instanceof EntityType) {
// Properties that are relationships to other entities
Entity rel = PropertyHelper.get(entity, name);
if (rel instanceof EntityReference) {
rel = getHibernateTemplate().load(EntityHelper.getRealClass(rel), rel.getId());
PropertyHelper.set(entity, name, rel);
}
} else if (type instanceof CollectionType && !(type instanceof MapType)) {
// Properties that are collections of other entities
final Collection<?> current = PropertyHelper.get(entity, name);
if (current != null && !(current instanceof PersistentCollection)) {
// We must check that the collection is made of entities, since Hibernate supports collections os values
boolean isEntityCollection = true;
final Collection<Entity> resolved = ClassHelper.instantiate(current.getClass());
for (final Object object : current) {
if (object != null && !(object instanceof Entity)) {
isEntityCollection = false;
break;
}
Entity e = (Entity) object;
if (object instanceof EntityReference) {
e = getHibernateTemplate().load(EntityHelper.getRealClass(e), e.getId());
}
resolved.add(e);
}
if (isEntityCollection) {
PropertyHelper.set(entity, name, resolved);
}
}
}
}
}