Example usage for org.hibernate.mapping PersistentClass getPropertyIterator

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

Introduction

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

Prototype

public Iterator getPropertyIterator() 

Source Link

Document

Build an iterator over the properties defined on this class.

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  av  a2  s . com

        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.github.shyiko.rook.target.hibernate4.fulltextindex.SynchronizationContext.java

License:Apache License

@SuppressWarnings("unchecked")
private Collection<Property> extractAnnotatedProperties(PersistentClass persistentClass,
        Class<? extends Annotation> annotation) {
    Class mappedClass = persistentClass.getMappedClass();
    Collection<Property> properties = new ArrayList<Property>();
    for (Iterator<Property> propertyIterator = persistentClass.getPropertyIterator(); propertyIterator
            .hasNext();) {//from   www.j  a  v a  2 s  . co m
        Property property = propertyIterator.next();
        Getter getter = property.getGetter(mappedClass);
        if (getter == null) {
            continue;
        }
        Member mappedClassMember = getter.getMember();
        boolean isRequestedAnnotationPresent = mappedClassMember instanceof AccessibleObject
                && ((AccessibleObject) mappedClassMember).isAnnotationPresent(annotation);
        if (isRequestedAnnotationPresent) {
            properties.add(property);
        }
    }
    return properties;
}

From source file:com.klistret.cmdb.utility.spring.LocalSessionFactoryBean.java

License:Open Source License

protected void postProcessMappings(Configuration config) throws HibernateException {
    logger.debug("Overriding the postProcessMappings method in the Spring LocalSessionFactoryBean");

    /**//from w ww .ja v  a2s. c  om
     * http://stackoverflow.com/questions/672063/creating-a-custom-hibernate-usertype-find-out-the-current-entity-table-name
     */
    for (Iterator<PersistentClass> classMappingIterator = config.getClassMappings(); classMappingIterator
            .hasNext();) {
        PersistentClass persistentClass = (PersistentClass) classMappingIterator.next();

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

            if (property.getType().getName().equals(JAXBUserType.class.getName())) {
                logger.debug("Setting ci context properties for Hibernate user type [{}]",
                        JAXBUserType.class.getName());

                SimpleValue simpleValue = (SimpleValue) property.getValue();
                Properties parameterMap = new Properties();

                parameterMap.setProperty("baseTypes", baseTypes);
                logger.debug("Base types [{}]", baseTypes);

                parameterMap.setProperty("assignablePackages", assignablePackages);
                logger.debug("Assignable packages [{}]", assignablePackages);

                simpleValue.setTypeParameters(parameterMap);
            }
        }
    }
}

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 ww  . j  av  a 2 s  . c  om*/
                (PersistentClass[]) iterToList(node.getDirectSubclasses()).toArray(new PersistentClass[] {}));
    }
}

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();/* w w  w  .j a  v a  2 s  .  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   w  w w  . j a  v  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.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java

License:Open Source License

/**
 * Retrieve the list of collection properties of the provided persisted class.
 * @param pClass the persisted class to analyse
 * @return a list of hibernate collections
 *///  w  w  w  .  j  a va  2s.  c  o  m
private List<org.hibernate.mapping.Collection> getCollection(PersistentClass pClass) {
    List<org.hibernate.mapping.Collection> list = new ArrayList<org.hibernate.mapping.Collection>();

    if (pClass != null) {
        @SuppressWarnings("unchecked")
        Iterator<Property> it = pClass.getPropertyIterator();
        while (it.hasNext()) {
            Property property = it.next();
            if (property.getType().isCollectionType()) {
                list.add((org.hibernate.mapping.Collection) property.getValue());
            }
        }
    }

    return list;
}

From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java

License:Open Source License

/**
 * Retrieve a list of tables used to store the given persistent class, that need to be processed for FK constraints.
 * The list include the main table use to persist the class, if this table has FK, as well as, all the collection
 * table used for storing this persisted class properties.
 *
 * @param pClass the persistent class to analyze
 * @return a list of table/*from   ww w  . ja v  a  2s .c om*/
 */
private List<Table> getForeignKeyTables(PersistentClass pClass) {
    List<Table> list = new ArrayList<Table>();

    if (pClass != null) {
        Table table = pClass.getTable();
        if (checkFKtoPKinTable(table)) {
            list.add(table);
        }

        @SuppressWarnings("unchecked")
        Iterator<Property> it = pClass.getPropertyIterator();
        while (it.hasNext()) {
            Property property = it.next();
            if (property.getType().isCollectionType()) {
                org.hibernate.mapping.Collection coll = (org.hibernate.mapping.Collection) property.getValue();
                Table collTable = coll.getCollectionTable();
                if (checkFKtoPKinTable(collTable)) {
                    list.add(collTable);
                }
            }
        }
    }

    return list;
}

From source file:com.xpn.xwiki.store.XWikiHibernateStore.java

License:Open Source License

private boolean isValidCustomMapping(String className, Configuration hibconfig, BaseClass bclass) {
    PersistentClass mapping = hibconfig.getClassMapping(className);
    if (mapping == null) {
        return true;
    }//from   w w w .  j  a v a2 s  .  c o  m

    Iterator it = mapping.getPropertyIterator();
    while (it.hasNext()) {
        Property hibprop = (Property) it.next();
        String propname = hibprop.getName();
        PropertyClass propclass = (PropertyClass) bclass.getField(propname);
        if (propclass == null) {
            log.warn("Mapping contains invalid field name " + propname);
            return false;
        }

        boolean result = isValidColumnType(hibprop.getValue().getType().getName(), propclass.getClassName());
        if (result == false) {
            log.warn("Mapping contains invalid type in field " + propname);
            return false;
        }
    }

    return true;
}

From source file:com.xpn.xwiki.store.XWikiHibernateStore.java

License:Open Source License

public List<String> getCustomMappingPropertyList(BaseClass bclass) {
    List<String> list = new ArrayList<String>();
    Configuration hibconfig;/*from   w  ww.  j av a  2s  .c o  m*/
    if (bclass.hasExternalCustomMapping()) {
        hibconfig = makeMapping(bclass.getName(), bclass.getCustomMapping());
    } else {
        hibconfig = getConfiguration();
    }
    PersistentClass mapping = hibconfig.getClassMapping(bclass.getName());
    if (mapping == null) {
        return null;
    }

    Iterator it = mapping.getPropertyIterator();
    while (it.hasNext()) {
        Property hibprop = (Property) it.next();
        String propname = hibprop.getName();
        list.add(propname);
    }
    return list;
}