Example usage for org.hibernate.mapping Table setSchema

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

Introduction

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

Prototype

public void setSchema(String schema) 

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  .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);
}

From source file:com.clican.pluto.common.support.spring.AnnotationSessionFactoryBean.java

License:LGPL

@SuppressWarnings("unchecked")
@Override//from  w  w w  .  j  a va  2s.  c o m
protected void postProcessAnnotationConfiguration(AnnotationConfiguration config) throws HibernateException {
    if (customizedSchema == null) {
        return;
    }
    Map<String, String> schemaMapping = new HashMap<String, String>();
    Iterator<Table> it = (Iterator<Table>) config.getTableMappings();
    while (it.hasNext()) {
        Table table = it.next();
        String name = table.getName();
        if (customizedSchema.containsKey(name.toUpperCase())) {
            table.setSchema(customizedSchema.get(name.toUpperCase()));
            schemaMapping.put(name.toUpperCase(), customizedSchema.get(name.toUpperCase()));
        } else {
            if (StringUtils.isNotEmpty(defaultSchema)) {
                table.setSchema(defaultSchema);
                schemaMapping.put(name.toUpperCase(), defaultSchema);
            }
        }
    }
}

From source file:com.clican.pluto.orm.tool.DatabaseMetadata.java

License:LGPL

public boolean isTable(Object key) throws HibernateException {
    if (key instanceof String) {
        Table tbl = new Table((String) key);
        if (getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(), tbl.isQuoted()) != null) {
            return true;
        } else {/* w w  w.j  a v  a  2s .  c o m*/
            String[] strings = StringHelper.split(".", (String) key);
            if (strings.length == 3) {
                tbl = new Table(strings[2]);
                tbl.setCatalog(strings[0]);
                tbl.setSchema(strings[1]);
                return getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(),
                        tbl.isQuoted()) != null;
            } else if (strings.length == 2) {
                tbl = new Table(strings[1]);
                tbl.setSchema(strings[0]);
                return getTableMetadata(tbl.getName(), tbl.getSchema(), tbl.getCatalog(),
                        tbl.isQuoted()) != null;
            }
        }
    }
    return false;
}

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());// w ww. j  a  va2 s .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;
}

From source file:org.beangle.commons.orm.hibernate.internal.OverrideConfiguration.java

License:Open Source License

private void configSchema() {
    TableNamingStrategy namingStrategy = null;
    if (getNamingStrategy() instanceof RailsNamingStrategy) {
        namingStrategy = ((RailsNamingStrategy) getNamingStrategy()).getTableNamingStrategy();
    }//from   ww w . j av  a  2 s  .co  m

    if (null == namingStrategy)
        return;
    else {
        // Update SeqGenerator's static variable.
        // Because generator is init by hibernate,cannot inject namingStrategy.
        TableSeqGenerator.namingStrategy = namingStrategy;
    }

    if (namingStrategy.isMultiSchema()) {
        for (PersistentClass clazz : classes.values()) {
            String schema = namingStrategy.getSchema(clazz.getEntityName());
            if (null != schema)
                clazz.getTable().setSchema(schema);
        }

        for (Collection collection : collections.values()) {
            final Table table = collection.getCollectionTable();
            if (null == table)
                continue;
            String schema = namingStrategy.getSchema(collection.getRole());
            if (null != schema)
                table.setSchema(schema);
        }
    }
}

From source file:org.beangle.orm.hibernate.internal.OverrideConfiguration.java

License:Open Source License

/**
 * Config table's schema by TableNamingStrategy
 *///from   ww  w .  ja v  a  2  s .  c  o m
private void configSchema() {
    TableNamingStrategy namingStrategy = null;
    if (getNamingStrategy() instanceof RailsNamingStrategy) {
        namingStrategy = ((RailsNamingStrategy) getNamingStrategy()).getTableNamingStrategy();
    }

    if (null == namingStrategy)
        return;
    else {
        // Update SeqGenerator's static variable.
        // Because generator is init by hibernate,cannot inject namingStrategy.
        TableSeqGenerator.namingStrategy = namingStrategy;
    }

    if (namingStrategy.isMultiSchema()) {
        for (PersistentClass clazz : classes.values()) {
            String schema = namingStrategy.getSchema(clazz.getEntityName());
            if (null != schema)
                clazz.getTable().setSchema(schema);
        }

        for (Collection collection : collections.values()) {
            final Table table = collection.getCollectionTable();
            if (null == table)
                continue;
            String schema = namingStrategy.getSchema(collection.getRole());
            if (null != schema)
                table.setSchema(schema);
        }
    }
}