List of usage examples for org.hibernate.mapping Table qualify
@Deprecated public static String qualify(String catalog, String schema, String table)
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 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:com.clican.pluto.orm.tool.DatabaseMetadata.java
License:LGPL
private Object identifier(String catalog, String schema, String name) { return Table.qualify(catalog, schema, name); }
From source file:com.literatejava.hibernate.allocator.LinearBlockAllocator.java
License:Open Source License
public void configure(Type type, Properties params, Dialect dialect) { ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER); this.tableName = ConfigurationHelper.getString(ALLOC_TABLE, params, DEFAULT_TABLE); this.sequenceColumn = ConfigurationHelper.getString(SEQUENCE_COLUMN, params, DEFAULT_SEQUENCE_COLUMN); this.allocColumn = ConfigurationHelper.getString(ALLOC_COLUMN, params, DEFAULT_ALLOC_COLUMN); // get SequenceName; default to Entities' TableName. // -/*from w w w . j ava 2 s . co m*/ this.sequenceName = ConfigurationHelper.getString(SEQUENCE_NAME, params, params.getProperty(PersistentIdentifierGenerator.TABLE)); if (sequenceName == null) { throw new IdentifierGenerationException( "LinearBlockAllocator: '" + SEQUENCE_NAME + "' must be specified"); } this.blockSize = ConfigurationHelper.getInt(BLOCK_SIZE, params, DEFAULT_BLOCK_SIZE); if (blockSize < 1) { blockSize = 1; } // qualify Table Name, if necessary; // -- if (tableName.indexOf('.') < 0) { String schemaName = normalizer.normalizeIdentifierQuoting(params.getProperty(SCHEMA)); String catalogName = normalizer.normalizeIdentifierQuoting(params.getProperty(CATALOG)); this.tableName = Table.qualify(catalogName, schemaName, tableName); } // build SQL strings; // -- use appendLockHint(LockMode) for now, as that is how Hibernate's generators do it. // this.query = "select " + allocColumn + " from " + dialect.appendLockHint(LockMode.PESSIMISTIC_WRITE, tableName) + " where " + sequenceColumn + " = ?" + dialect.getForUpdateString(); this.update = "update " + tableName + " set " + allocColumn + " = ? where " + sequenceColumn + " = ? and " + allocColumn + " = ?"; // setup Return Type & Result Holder. // -- this.returnType = type; this.returnClass = type.getReturnedClass(); this.resultFactory = IdentifierGeneratorHelper.getIntegralDataTypeHolder(returnClass); // done. }
From source file:com.zutubi.pulse.master.hibernate.MutableConfiguration.java
License:Apache License
private String getTableKey(Table table) { return table.getSubselect() == null ? Table.qualify(table.getCatalog(), table.getSchema(), table.getName()) : table.getSubselect(); }
From source file:de.innovationgate.webgate.api.mysql.GaleraClusterTableGenerator.java
License:Open Source License
/** * Determine the table name to use for the generator values. * <p/>//from w w w . j a va 2 s. c o m * Called during {@link #configure configuration}. * * @see #getTableName() * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The table name to use. */ protected String determineGeneratorTableName(Properties params, Dialect dialect) { String name = ConfigurationHelper.getString(TABLE_PARAM, params, DEF_TABLE); boolean isGivenNameUnqualified = name.indexOf('.') < 0; if (isGivenNameUnqualified) { ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER); name = normalizer.normalizeIdentifierQuoting(name); // if the given name is un-qualified we may neen to qualify it String schemaName = normalizer.normalizeIdentifierQuoting(params.getProperty(SCHEMA)); String catalogName = normalizer.normalizeIdentifierQuoting(params.getProperty(CATALOG)); name = Table.qualify(dialect.quote(catalogName), dialect.quote(schemaName), dialect.quote(name)); } else { // if already qualified there is not much we can do in a portable manner so we pass it // through and assume the user has set up the name correctly. } return name; }
From source file:org.beangle.commons.orm.hibernate.internal.SchemaValidator.java
License:Open Source License
private void validateColumns(Table table, Dialect dialect, Mapping mapping, TableMetadata tableInfo) { Iterator<?> iter = table.getColumnIterator(); Set<ColumnMetadata> processed = CollectUtils.newHashSet(); String tableName = Table.qualify(tableInfo.getCatalog(), tableInfo.getSchema(), tableInfo.getName()); while (iter.hasNext()) { Column col = (Column) iter.next(); ColumnMetadata columnInfo = tableInfo.getColumnMetadata(col.getName()); if (columnInfo == null) { reporter.append("Missing column: " + col.getName() + " in " + tableName); } else {/*from w w w .j av a2s . c o m*/ final boolean typesMatch = col.getSqlType(dialect, mapping).toLowerCase() .startsWith(columnInfo.getTypeName().toLowerCase()) || columnInfo.getTypeCode() == col.getSqlTypeCode(mapping); if (!typesMatch) { reporter.append("Wrong column type in " + tableName + " for column " + col.getName() + ". Found: " + columnInfo.getTypeName().toLowerCase() + ", expected: " + col.getSqlType(dialect, mapping)); } processed.add(columnInfo); } } // try { Field field = tableInfo.getClass().getField("columns"); @SuppressWarnings("unchecked") Set<ColumnMetadata> allColumns = CollectUtils .newHashSet(((Map<String, ColumnMetadata>) field.get(tableInfo)).values()); allColumns.removeAll(processed); if (!allColumns.isEmpty()) { for (ColumnMetadata col : allColumns) { reporter.append("Extra column " + col.getName() + " in " + tableName); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.hyperic.hibernate.id.HQMultipleHiLoPerTableGenerator.java
License:Open Source License
public void configure(Type type, Properties params, Dialect dialect) throws MappingException { tableName = PropertiesHelper.getString(ID_TABLE, params, DEFAULT_TABLE); pkColumnName = PropertiesHelper.getString(PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN); valueColumnName = PropertiesHelper.getString(VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN); initialHi = PropertiesHelper.getInt(INITIAL_HI, params, DEFAULT_INITIAL_HI); String schemaName = params.getProperty(SCHEMA); String catalogName = params.getProperty(CATALOG); keySize = PropertiesHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH); keyValue = PropertiesHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE)); if (tableName.indexOf('.') < 0) { tableName = Table.qualify(catalogName, schemaName, tableName); }/*from w ww . j av a2s.c om*/ query = "select " + valueColumnName + " from " + dialect.appendLockHint(LockMode.UPGRADE, tableName) + " where " + pkColumnName + " = '" + keyValue + "'" + dialect.getForUpdateString(); update = "update " + tableName + " set " + valueColumnName + " = ? where " + valueColumnName + " = ? and " + pkColumnName + " = '" + keyValue + "'"; insert = "insert into " + tableName + "(" + pkColumnName + ", " + valueColumnName + ") " + "values('" + keyValue + "', ?)"; // hilo config maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE); lo = maxLo + 1; // so we "clock over" on the first invocation returnClass = type.getReturnedClass(); }