Example usage for org.hibernate.mapping Table setAbstract

List of usage examples for org.hibernate.mapping Table setAbstract

Introduction

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

Prototype

public void setAbstract(boolean isAbstract) 

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  ww. ja  va2s  .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.zutubi.pulse.master.hibernate.SchemaRefactor.java

License:Apache License

protected Table clone(Table table) {
    Table clone = new Table(table.getName());
    clone.setAbstract(table.isAbstract());
    clone.setCatalog(table.getCatalog());
    clone.setComment(table.getComment());
    clone.setName(table.getName());/*from w w  w. j  ava 2s  . c  o m*/
    clone.setPrimaryKey(table.getPrimaryKey());
    clone.setQuoted(table.isQuoted());
    clone.setRowId(table.getRowId());
    clone.setSchema(table.getSchema());
    clone.setSubselect(table.getSubselect());

    Iterator columns = table.getColumnIterator();
    while (columns.hasNext()) {
        Column column = (Column) columns.next();
        clone.addColumn(column);
    }

    Iterator foreignKeys = table.getForeignKeyIterator();
    while (foreignKeys.hasNext()) {
        ForeignKey key = (ForeignKey) foreignKeys.next();
        clone.createForeignKey(key.getName(), key.getColumns(), key.getReferencedEntityName(),
                key.getReferencedColumns());
    }

    return clone;
}