Example usage for org.hibernate.mapping Index containsColumn

List of usage examples for org.hibernate.mapping Index containsColumn

Introduction

In this page you can find the example usage for org.hibernate.mapping Index containsColumn.

Prototype

public boolean containsColumn(Column column) 

Source Link

Usage

From source file:com.tomitribe.reveng.codegen.FreemarkerObject.java

License:Apache License

public String annotate(final BasicPOJOClass pojo, final Object pObj, final Object rootObj,
        final Object toolObj) {
    // public String annotate(final Object pojo, final Property p, final
    // RootClass root, final Cfg2HbmTool tool) {

    if (BasicPOJOClass.class.isInstance(pojo)) {

    } else {/*from  w  w w  . j  a v a  2s .  c o  m*/
        // System.out.println(ob.class.getName());
    }

    RootClass root = null;
    try {
        root = (RootClass) rootObj;
    } catch (final Exception e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        return "";
    }

    final Property p = (Property) pObj;
    final Cfg2HbmTool tool = (Cfg2HbmTool) toolObj;

    final Table table = root.getTable();

    Iterator it = table.getColumnIterator();

    Column column = null;
    Column c;
    String name;
    while (it.hasNext()) {
        c = (Column) it.next();

        name = c.getName().replace("_", "").toLowerCase();

        if (name.equals(p.getName().toLowerCase())) {
            column = c;
            break;
        }
    }

    if (null != column) {

        System.out.print("FreemarkerObject.annotate: " + table.getName() + " - " + p.getName() + " - ");

        it = table.getIndexIterator();

        org.hibernate.mapping.Index index;
        while (it.hasNext()) {

            final Object next = it.next();

            if (org.hibernate.mapping.Index.class.isInstance(next)) {

                index = org.hibernate.mapping.Index.class.cast(next);

                if (index.containsColumn(column)) {
                    System.out.print(index.getName());

                    return String.format("\n@Index(name = \"%1$s\", columnNames = {\"%2$s\"})",
                            index.getName().toLowerCase(), column.getName());
                }
            }
        }

        System.out.println();
    } else {
        System.out.println("FreemarkerObject.annotate: " + table.getName() + " - " + p.getName() + " - "
                + p.getNodeName() + " - " + p.getPropertyAccessorName());
    }

    return "";
}