Example usage for org.hibernate DuplicateMappingException DuplicateMappingException

List of usage examples for org.hibernate DuplicateMappingException DuplicateMappingException

Introduction

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

Prototype

@Deprecated
public DuplicateMappingException(String customMessage, String type, String name) 

Source Link

Document

Creates a DuplicateMappingException using the given customMessage, type and name.

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  .ja v  a 2  s .c om*/
    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);
}