Example usage for org.hibernate.mapping Index Index

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

Introduction

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

Prototype

Index

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  av  a 2 s  .  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:org.apereo.portal.tools.dbloader.TableXmlHandler.java

License:Apache License

@Override
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
    if ("table".equals(name)) {
        this.currentColumns = new LinkedHashMap<String, Column>();
        this.currentColumnTypes = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
    } else if ("index".equals(name)) {
        this.currentIndex = new Index();
        this.currentIndex.setTable(this.currentTable);
    } else if ("unique".equals(name)) {
        this.currentUnique = new UniqueKey();
        this.currentUnique.setTable(this.currentTable);
    }/*from  ww w .  java2 s  .c  o  m*/

    this.chars = new StringBuilder();
}