Example usage for org.hibernate.mapping Index getColumnIterator

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

Introduction

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

Prototype

public Iterator<Column> getColumnIterator() 

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  ww  w  . j  a v a2  s  . c o  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.vecna.dbDiff.hibernate.HibernateMappingsConverter.java

License:Apache License

/**
 * Convert a Hibernate index representation to a {@link RelationalIndex}.
 * @param mappedIndex hibernate index.//from  w  w w .j a  va 2  s. com
 * @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 add index command for the given index.
 *
 * @param sb append the result into this string builder
 * @param index the index//ww  w .  ja  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 String gegenerateIndexName(Table table, Index index) {
    List<String> columnNames = new ArrayList<String>();
    @SuppressWarnings("unchecked")
    Iterator<Column> columns = index.getColumnIterator();
    while (columns.hasNext()) {
        columnNames.add(columns.next().getName());
    }/*from   w  ww .  j  ava2 s . c o m*/
    return "IX" + table.uniqueColumnString(columnNames.iterator());
}

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();// ww w  . j  a va 2s  . c o 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);
    }
}