Example usage for org.hibernate.mapping Index getName

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

Introduction

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

Prototype

public String getName() 

Source Link

Usage

From source file:com.amalto.core.storage.hibernate.HibernateStorage.java

License:Open Source License

@SuppressWarnings("serial")
protected void internalInit() {
    if (!dataSource.supportFullText()) {
        LOGGER.warn("Storage '" + storageName + "' (" + storageType //$NON-NLS-1$//$NON-NLS-2$
                + ") is not configured to support full text queries."); //$NON-NLS-1$
    }//from  w  w  w  .  j a va 2s.co m
    configuration = new Configuration() {

        protected transient Mapping mapping = buildMapping();

        @Override
        public Mappings createMappings() {
            return new MDMMappingsImpl();
        }

        class MDMMappingsImpl extends MappingsImpl {

            @Override
            public Table addTable(String schema, String catalog, String name, String subselect,
                    boolean isAbstract) {
                name = getObjectNameNormalizer().normalizeIdentifierQuoting(name);
                schema = getObjectNameNormalizer().normalizeIdentifierQuoting(schema);
                catalog = getObjectNameNormalizer().normalizeIdentifierQuoting(catalog);

                String key = subselect == null ? Table.qualify(catalog, schema, name) : subselect;
                Table table = tables.get(key);

                if (table == null) {
                    table = new MDMTable();
                    table.setAbstract(isAbstract);
                    table.setName(name);
                    table.setSchema(schema);
                    table.setCatalog(catalog);
                    table.setSubselect(subselect);
                    tables.put(key, table);
                } else {
                    if (!isAbstract) {
                        table.setAbstract(false);
                    }
                }

                return table;
            }

            @Override
            public Table addDenormalizedTable(String schema, String catalog, String name, boolean isAbstract,
                    String subSelect, final Table includedTable) throws DuplicateMappingException {
                name = getObjectNameNormalizer().normalizeIdentifierQuoting(name);
                schema = getObjectNameNormalizer().normalizeIdentifierQuoting(schema);
                catalog = getObjectNameNormalizer().normalizeIdentifierQuoting(catalog);
                String key = subSelect == null ? Table.qualify(catalog, schema, name) : subSelect;
                if (tables.containsKey(key)) {
                    throw new DuplicateMappingException("Table " + key + " is duplicated.", //$NON-NLS-1$//$NON-NLS-2$
                            DuplicateMappingException.Type.TABLE, name);
                }
                Table table = new MDMDenormalizedTable(includedTable) {

                    @SuppressWarnings({ "unchecked" })
                    @Override
                    public Iterator<Index> getIndexIterator() {
                        List<Index> indexes = new ArrayList<Index>();
                        Iterator<Index> IndexIterator = super.getIndexIterator();
                        while (IndexIterator.hasNext()) {
                            Index parentIndex = IndexIterator.next();
                            Index index = new Index();
                            index.setName(tableResolver.get(parentIndex.getName()));
                            index.setTable(this);
                            index.addColumns(parentIndex.getColumnIterator());
                            indexes.add(index);
                        }
                        return indexes.iterator();
                    }
                };
                table.setAbstract(isAbstract);
                table.setName(name);
                table.setSchema(schema);
                table.setCatalog(catalog);
                table.setSubselect(subSelect);
                tables.put(key, table);
                return table;
            }
        }
    };
    // Setting our own entity resolver allows to ensure the DTD found/used are what we expect (and not potentially
    // one provided by the application server).
    configuration.setEntityResolver(ENTITY_RESOLVER);
}

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 {/* w w w  .j ava2s.  c  om*/
        // 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 "";
}

From source file:com.vecna.dbDiff.hibernate.HibernateMappingsConverter.java

License:Apache License

/**
 * Convert a Hibernate index representation to a {@link RelationalIndex}.
 * @param mappedIndex hibernate index.//w  w w.  j  a  v  a 2s .c  o  m
 * @param table the table the index applies to.
 * @return a {@link RelationalIndex} representation of the index.
 */
private RelationalIndex convertIndex(Index mappedIndex, RelationalTable table) {
    @SuppressWarnings("unchecked")
    Iterator<org.hibernate.mapping.Column> mappedColumns = mappedIndex.getColumnIterator();
    return convertIndex(StringUtils.lowerCase(mappedIndex.getName()), mappedColumns, table);
}

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

License:Open Source License

/**
 * Append a drop index command for the given index.
 *
 * @param sb append the result into this string builder
 * @param index the index/*from w  w w  .java 2 s .  c o m*/
 */
private void appendDropIndex(StringBuilder sb, Index index) {
    sb.append("    <dropIndex indexName=\"").append(index.getName()).append("\"  tableName=\"")
            .append(index.getTable().getName()).append("\"/>\n");
}

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

License:Open Source License

/**
 * Append a add index command for the given index.
 *
 * @param sb append the result into this string builder
 * @param index the index//w w w.  j  a va 2  s .  c om
 */
private void appendAddIndex(StringBuilder sb, Index index) {
    sb.append("    <createIndex tableName=\"").append(index.getTable().getName()).append("\"  indexName=\"")
            .append(index.getName()).append("\">\n");

    @SuppressWarnings("unchecked")
    Iterator<Column> columns = index.getColumnIterator();
    while (columns.hasNext()) {
        Column column = columns.next();
        sb.append("      <column name=\"").append(column.getName()).append("\"/>\n");
    }

    sb.append("</createIndex>\n");
}

From source file:org.codehaus.mojo.hibernate3.exporter.CustomHbm2DDLExporterMojo.java

License:Open Source License

private void processTableIndexNames(Table table) {
    if (table.isPhysicalTable()) {
        @SuppressWarnings("unchecked")
        Iterator<Index> subIter = table.getIndexIterator();
        while (subIter.hasNext()) {
            // for each index that has no name, generate a unique name
            Index index = subIter.next();
            if (index.getName().startsWith(GENERATE_INDEX_NAME_PREFIX)) {
                index.setName(gegenerateIndexName(table, index));
            }/* ww  w. j a v  a  2  s . c  o m*/
        }
    }
}

From source file:org.teiid.spring.views.ViewBuilder.java

License:Apache License

private void addIndexKeys(org.hibernate.mapping.Table ormTable, Table view, MetadataFactory mf) {
    Iterator<UniqueKey> keys = ormTable.getUniqueKeyIterator();
    while (keys.hasNext()) {
        UniqueKey uk = keys.next();//from   ww w.  j  a  v  a  2 s .  co m
        List<String> columns = new ArrayList<>();
        for (org.hibernate.mapping.Column c : uk.getColumns()) {
            columns.add(c.getName());
        }
        mf.addIndex(uk.getName(), false, columns, view);
    }

    Iterator<Index> iit = ormTable.getIndexIterator();
    while (iit.hasNext()) {
        Index idx = iit.next();
        List<String> columns = new ArrayList<>();
        Iterator<org.hibernate.mapping.Column> it = idx.getColumnIterator();
        while (it.hasNext()) {
            org.hibernate.mapping.Column c = it.next();
            columns.add(c.getName());
        }
        mf.addIndex(idx.getName(), true, columns, view);
    }
}