Example usage for org.hibernate.mapping Table getComment

List of usage examples for org.hibernate.mapping Table getComment

Introduction

In this page you can find the example usage for org.hibernate.mapping Table getComment.

Prototype

public String getComment() 

Source Link

Usage

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

License:Apache License

/**
 * Populate Hibernate properties with comments from javadocs (including nested properties).
 * @param propertyIterator iterator over top-level properties
 * @param accumulatedJavadoc comments accumulated so far (for nested properties)
 */// w  ww .j a  va  2s. c o  m
private void processProperties(Iterator<Property> propertyIterator, Class<?> cls, JavaDocBuilder javaDocs,
        String accumulatedJavadoc) {
    JavaClass javaClass = javaDocs.getClassByName(cls.getName());

    if (javaClass != null) {
        while (propertyIterator.hasNext()) {
            Property prop = propertyIterator.next();

            Value value = prop.getValue();

            if (value instanceof Collection) {
                Collection collection = (Collection) value;

                Value elementValue = collection.getElement();

                if (elementValue instanceof Component) {
                    processComponent((Component) elementValue, javaDocs, accumulatedJavadoc);
                }

                Table collectionTable = collection.getCollectionTable();

                if (collectionTable.getComment() == null) {
                    collectionTable.setComment(getSimpleValueJavadoc(prop, cls, javaClass));
                }
            } else if (value instanceof Component) {
                String comment = getSimpleValueJavadoc(prop, cls, javaClass);
                comment = accumulateJavadoc(comment, accumulatedJavadoc);
                processComponent((Component) value, javaDocs, comment);
            } else if (value instanceof SimpleValue) {
                String comment = getSimpleValueJavadoc(prop, cls, javaClass);
                comment = accumulateJavadoc(comment, accumulatedJavadoc);
                setComment(comment, prop);
            }
        }

    }
}

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

License:Apache License

/**
 * Populate table/column comments in a Hibernate model from javadocs
 *//* w ww  .  j av 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());
        }
    }
}

From source file:com.zutubi.pulse.master.hibernate.SchemaRefactor.java

License:Apache License

protected Table clone(Table table) {
    Table clone = new Table(table.getName());
    clone.setAbstract(table.isAbstract());
    clone.setCatalog(table.getCatalog());
    clone.setComment(table.getComment());
    clone.setName(table.getName());//from  w  ww.j a va 2  s . c  o  m
    clone.setPrimaryKey(table.getPrimaryKey());
    clone.setQuoted(table.isQuoted());
    clone.setRowId(table.getRowId());
    clone.setSchema(table.getSchema());
    clone.setSubselect(table.getSubselect());

    Iterator columns = table.getColumnIterator();
    while (columns.hasNext()) {
        Column column = (Column) columns.next();
        clone.addColumn(column);
    }

    Iterator foreignKeys = table.getForeignKeyIterator();
    while (foreignKeys.hasNext()) {
        ForeignKey key = (ForeignKey) foreignKeys.next();
        clone.createForeignKey(key.getName(), key.getColumns(), key.getReferencedEntityName(),
                key.getReferencedColumns());
    }

    return clone;
}

From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape.java

License:Open Source License

@Override
public Object getPropertyValue(Object propertyId) {
    Object res = null;/*from  w ww  . j  av a 2s .  co m*/
    RootClass rootClass = null;
    Table table = null;
    Object ormElement = getOrmElement();
    if (ormElement instanceof RootClass) {
        rootClass = (RootClass) ormElement;
    } else if (ormElement instanceof Subclass) {
        //rootClass = ((Subclass)ormElement).getRootClass();
    } else if (ormElement instanceof Table) {
        table = (Table) getOrmElement();
    }
    if (rootClass != null) {
        if (ENTITY_isAbstract.equals(propertyId)) {
            if (rootClass.isAbstract() != null) {
                res = rootClass.isAbstract().toString();
            }
        } else if (ENTITY_isCustomDeleteCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomDeleteCallable()).toString();
        } else if (ENTITY_isCustomInsertCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomInsertCallable()).toString();
        } else if (ENTITY_isCustomUpdateCallable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isCustomUpdateCallable()).toString();
        } else if (ENTITY_isDiscriminatorInsertable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorInsertable()).toString();
        } else if (ENTITY_isDiscriminatorValueNotNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNotNull()).toString();
        } else if (ENTITY_isDiscriminatorValueNull.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isDiscriminatorValueNull()).toString();
        } else if (ENTITY_isExplicitPolymorphism.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isExplicitPolymorphism()).toString();
        } else if (ENTITY_isForceDiscriminator.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isForceDiscriminator()).toString();
        } else if (ENTITY_isInherited.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isInherited()).toString();
        } else if (ENTITY_isJoinedSubclass.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isJoinedSubclass()).toString();
        } else if (ENTITY_isLazy.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazy()).toString();
        } else if (ENTITY_isLazyPropertiesCacheable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isLazyPropertiesCacheable()).toString();
        } else if (ENTITY_isMutable.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isMutable()).toString();
        } else if (ENTITY_isPolymorphic.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isPolymorphic()).toString();
        } else if (ENTITY_isVersioned.equals(propertyId)) {
            res = Boolean.valueOf(rootClass.isVersioned()).toString();
        } else if (ENTITY_batchSize.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getBatchSize()).toString();
        } else if (ENTITY_cacheConcurrencyStrategy.equals(propertyId)) {
            res = rootClass.getCacheConcurrencyStrategy();
        } else if (ENTITY_className.equals(propertyId)) {
            res = rootClass.getClassName();
        } else if (ENTITY_customSQLDelete.equals(propertyId)) {
            res = rootClass.getCustomSQLDelete();
        } else if (ENTITY_customSQLInsert.equals(propertyId)) {
            res = rootClass.getCustomSQLInsert();
        } else if (ENTITY_customSQLUpdate.equals(propertyId)) {
            res = rootClass.getCustomSQLUpdate();
        } else if (ENTITY_discriminatorValue.equals(propertyId)) {
            res = rootClass.getDiscriminatorValue();
        } else if (ENTITY_entityName.equals(propertyId)) {
            res = rootClass.getEntityName();
        } else if (ENTITY_loaderName.equals(propertyId)) {
            res = rootClass.getLoaderName();
        } else if (ENTITY_nodeName.equals(propertyId)) {
            res = rootClass.getNodeName();
        } else if (ENTITY_optimisticLockMode.equals(propertyId)) {
            res = Integer.valueOf(rootClass.getOptimisticLockMode()).toString();
        } else if (ENTITY_table.equals(propertyId)) {
            if (rootClass.getTable() != null) {
                res = rootClass.getTable().getName();
            }
        } else if (ENTITY_temporaryIdTableDDL.equals(propertyId)) {
            res = rootClass.getTemporaryIdTableDDL();
        } else if (ENTITY_temporaryIdTableName.equals(propertyId)) {
            res = rootClass.getTemporaryIdTableName();
        } else if (ENTITY_where.equals(propertyId)) {
            res = rootClass.getWhere();
        }
    }
    if (table != null) {
        if (TABLE_catalog.equals(propertyId)) {
            res = table.getCatalog();
        } else if (TABLE_comment.equals(propertyId)) {
            res = table.getComment();
        } else if (TABLE_name.equals(propertyId)) {
            res = table.getName();
        } else if (TABLE_primaryKey.equals(propertyId)) {
            if (table.getPrimaryKey() != null) {
                res = table.getPrimaryKey().getName();
            }
        } else if (TABLE_rowId.equals(propertyId)) {
            res = table.getRowId();
        } else if (TABLE_schema.equals(propertyId)) {
            res = table.getSchema();
        } else if (TABLE_subselect.equals(propertyId)) {
            res = table.getSubselect();
        } else if (TABLE_hasDenormalizedTables.equals(propertyId)) {
            res = Boolean.valueOf(table.hasDenormalizedTables()).toString();
        } else if (TABLE_isAbstract.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstract()).toString();
        } else if (TABLE_isAbstractUnionTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isAbstractUnionTable()).toString();
        } else if (TABLE_isPhysicalTable.equals(propertyId)) {
            res = Boolean.valueOf(table.isPhysicalTable()).toString();
        }
    }
    if (res == null) {
        res = super.getPropertyValue(propertyId);
    }
    return toEmptyStr(res);
}