Example usage for org.hibernate.mapping PersistentClass getRootClass

List of usage examples for org.hibernate.mapping PersistentClass getRootClass

Introduction

In this page you can find the example usage for org.hibernate.mapping PersistentClass getRootClass.

Prototype

public abstract RootClass getRootClass();

Source Link

Usage

From source file:com.db4o.drs.hibernate.impl.HibernateReplicationProvider.java

License:Open Source License

private Collection getChangedObjectsSinceLastReplication(PersistentClass persistentClass) {
    Criteria criteria = getSession().createCriteria(ObjectReference.class);
    long lastReplicationVersion = getLastReplicationVersion();
    criteria.add(Restrictions.gt(ObjectReference.Fields.VERSION, lastReplicationVersion));
    criteria.add(Restrictions.lt(ObjectReference.Fields.VERSION, _commitTimestamp));
    Disjunction disjunction = Restrictions.disjunction();

    List<String> names = new ArrayList<String>();
    names.add(persistentClass.getClassName());
    if (persistentClass.hasSubclasses()) {
        final Iterator it = persistentClass.getSubclassClosureIterator();
        while (it.hasNext()) {
            PersistentClass subC = (PersistentClass) it.next();
            names.add(subC.getClassName());
        }//from   ww w .ja  va 2s  . c o  m
    }

    for (String s : names)
        disjunction.add(Restrictions.eq(ObjectReference.Fields.CLASS_NAME, s));

    criteria.add(disjunction);

    Set out = new HashSet();
    for (Object o : criteria.list()) {
        ObjectReference ref = (ObjectReference) o;
        out.add(getSession().load(persistentClass.getRootClass().getClassName(), ref.getTypedId()));
    }
    return out;
}

From source file:org.infinispan.test.hibernate.cache.commons.functional.AbstractFunctionalTest.java

License:LGPL

@Override
protected void afterMetadataBuilt(Metadata metadata) {
    if (addVersions) {
        for (PersistentClass clazz : metadata.getEntityBindings()) {
            if (clazz.getVersion() != null) {
                continue;
            }// ww w.  j a va  2  s.  co  m
            try {
                clazz.getMappedClass().getMethod("getVersion");
                clazz.getMappedClass().getMethod("setVersion", long.class);
            } catch (NoSuchMethodException e) {
                continue;
            }
            RootClass rootClazz = clazz.getRootClass();
            Property versionProperty = new Property();
            versionProperty.setName("version");
            SimpleValue value = new SimpleValue((MetadataImplementor) metadata, rootClazz.getTable());
            value.setTypeName("long");
            Column column = new Column();
            column.setValue(value);
            column.setName("version");
            value.addColumn(column);
            rootClazz.getTable().addColumn(column);
            versionProperty.setValue(value);
            rootClazz.setVersion(versionProperty);
            rootClazz.addProperty(versionProperty);
        }
    }
}