Example usage for org.hibernate.mapping PersistentClass getClassName

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

Introduction

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

Prototype

public String getClassName() 

Source Link

Usage

From source file:com.clueride.rest.MemberWebService.java

License:Apache License

private void dumpEntities() {
    Metadata metadata = MetadataExtractorIntegrator.INSTANCE.getMetadata();

    for (PersistentClass persistentClass : metadata.getEntityBindings()) {

        Table table = persistentClass.getTable();

        LOGGER.info(String.format("Entity: {} is mapped to table: {}", persistentClass.getClassName(),
                table.getName()));//from   w w w.j a  va2 s  . co  m

        for (Iterator propertyIterator = persistentClass.getPropertyIterator(); propertyIterator.hasNext();) {
            Property property = (Property) propertyIterator.next();

            for (Iterator columnIterator = property.getColumnIterator(); columnIterator.hasNext();) {
                Column column = (Column) columnIterator.next();

                LOGGER.info(String.format("Property: {} is mapped on table column: {} of type: {}",
                        property.getName(), column.getName(), column.getSqlType()));
            }
        }
    }
}

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   w w  w  .  j a va2  s.  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:com.oy.shared.lm.ext.HBMCtoGRAPH.java

License:Open Source License

private void processClasses(PersistentClass[] nodes) {
    for (int i = 0; i < nodes.length; i++) {

        PersistentClass node = nodes[i];

        String clazz = node.getClassName();
        GraphNode current = getOrCreateNode(clazz);

        // process attributes
        processProperties(node.getPropertyIterator(), current);

        // process subclasses
        processSubclasses(current,//from w  w w  .  j  ava  2 s  .c o  m
                (PersistentClass[]) iterToList(node.getDirectSubclasses()).toArray(new PersistentClass[] {}));
    }
}

From source file:com.oy.shared.lm.ext.HBMCtoGRAPH.java

License:Open Source License

private void processSubclasses(GraphNode parent, PersistentClass[] nodes) {
    for (int i = 0; i < nodes.length; i++) {
        PersistentClass node = nodes[i];

        String clazz = node.getClassName();
        GraphNode current = getOrCreateNode(clazz);

        // relation
        GraphEdge edge = graph.addEdge(current, parent);
        edge.getInfo().setLineColor(colors[1]);
        edge.getInfo().setArrowHeadOnormal();

        // rename child node with its class
        current.getInfo().setHeader(node.getClassName());
    }//from  w ww.  java2 s .  c om
}

From source file:com.rouletteapi.model.enums.EnumTuplizer.java

@Override
protected Instantiator buildInstantiator(final PersistentClass persistentClass) {

    return new Instantiator() {
        @Override/*ww w.  jav a2 s .c  o m*/
        public Object instantiate(Serializable id) {
            try {
                return Enum.valueOf((Class) persistentClass.getClass().getClassLoader()
                        .loadClass(persistentClass.getClassName()), (String) id);
            } catch (ClassNotFoundException e) {
                throw new AssertionError(e);
            }
        }

        @Override
        public Object instantiate() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInstance(Object object) {

            if (object == null)
                return false;

            Class clazz = persistentClass.getMappedClass();
            if (!clazz.isEnum())
                return false;
            try {
                clazz.cast(object);
                if (object.getClass().getName().equalsIgnoreCase(clazz.getName()))
                    return true;
            } catch (ClassCastException e) {
                return false;
            }

            return false;
        }
    };
}

From source file:com.siemens.scr.avt.ad.query.common.DicomMappingDictionaryLoadingStrategy.java

License:Open Source License

private void loadPersistentClass(DicomMappingDictionary dict, PersistentClass pc) {
    Table table = pc.getTable();/*from   w  w  w .jav  a 2s.c  o  m*/
    Iterator<Property> it = pc.getPropertyIterator();
    while (it.hasNext()) {
        Property prop = it.next();
        loadProperty(dict, prop, table, pc.getClassName());
    }
    String tableName = table.getSchema() + "." + table.getName();
    String key = pc.getClassName();
    dict.put(key, new WildcardEntry(tableName));
}

From source file:com.vecna.maven.hibernate.HibernateDocMojo.java

License:Apache License

/**
 * Populate table/column comments in a Hibernate model from javadocs
 *//*from www . j  av a  2 s .  c  o m*/
private void populateCommentsFromJavadocs(Configuration configuration, JavaDocBuilder javaDocs) {
    Iterator<PersistentClass> mappedClasses = configuration.getClassMappings();
    while (mappedClasses.hasNext()) {
        PersistentClass mappedClass = mappedClasses.next();

        Table table = mappedClass.getTable();
        JavaClass javaClass = javaDocs.getClassByName(mappedClass.getClassName());

        if (javaClass != null) {
            if (table != null) {
                String comment = javaClass.getComment();

                if (mappedClass.getDiscriminator() != null) {
                    String newComment = "Discriminator '" + mappedClass.getDiscriminatorValue() + "': "
                            + comment;
                    if (table.getComment() != null) {
                        newComment = table.getComment() + "<br><br>" + newComment;
                    }
                    table.setComment(newComment);
                    @SuppressWarnings("unchecked")
                    Iterator<Column> discriminatorColumns = mappedClass.getDiscriminator().getColumnIterator();
                    setComment("discriminator - see table comment", discriminatorColumns);
                } else {
                    table.setComment(comment);
                }
            }

            @SuppressWarnings("unchecked")
            Iterator<Property> propertyIterator = mappedClass.getPropertyIterator();
            processProperties(propertyIterator, mappedClass.getMappedClass(), javaDocs, null);
        }

        if (mappedClass.getIdentifierProperty() != null) {
            setComment("Primary key", mappedClass.getIdentifierProperty());
        }
    }
}

From source file:com.wavemaker.tools.data.WMHibernateConfigurationExporter.java

License:Open Source License

@SuppressWarnings("unchecked")
private void dump(PrintWriter pw, boolean useClass, PersistentClass element) {
    if (useClass) {
        pw.println("<mapping class=\"" + element.getClassName() + "\"/>");
    } else {/*from  ww  w. jav a  2s.  c  o  m*/
        pw.println("<mapping resource=\"" + getMappingFileResource(element) + "\"/>");

    }

    Iterator directSubclasses = element.getDirectSubclasses();
    while (directSubclasses.hasNext()) {
        PersistentClass subclass = (PersistentClass) directSubclasses.next();
        dump(pw, useClass, subclass);
    }

}

From source file:com.wavemaker.tools.data.WMHibernateConfigurationExporter.java

License:Open Source License

private String getMappingFileResource(PersistentClass element) {
    return element.getClassName().replace('.', '/') + ".hbm.xml";
}

From source file:com.wavemaker.tools.data.WMHibernateConfigurationExporter.java

License:Open Source License

private String getQueryFileResource(PersistentClass element) {
    return element.getClassName().replace('.', '/') + DataServiceConstants.QUERY_EXT;
}