Example usage for org.hibernate.mapping PersistentClass getDiscriminator

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

Introduction

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

Prototype

public abstract Value getDiscriminator();

Source Link

Usage

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

License:Apache License

/**
 * Populate table/column comments in a Hibernate model from javadocs
 *//*  w w  w .j  a v a  2 s  .c  om*/
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());
        }
    }
}