List of usage examples for org.hibernate.mapping Table setName
public void setName(String name)
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 www .j av a2s .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 copyTable(Connection connection, Table fromTable, String toTableName) throws SQLException { Table toTable = clone(fromTable); toTable.setName(toTableName); String sql = toTable.sqlCreateString(dialect, config.getMapping(), defaultCatalog, defaultSchema); LOG.info(sql);/*www. j a v a2s . c om*/ JDBCUtils.execute(connection, sql); // if there is data to transfer.. if (JDBCUtils.executeCount(connection, "select * from " + fromTable.getName()) > 0) { String columnSql = ""; String sep = ""; Iterator columns = toTable.getColumnIterator(); while (columns.hasNext()) { Column column = (Column) columns.next(); columnSql = columnSql + sep + column.getName(); sep = ","; } sql = "insert into " + toTableName + "(" + columnSql + ") select " + columnSql + " from " + fromTable.getName(); LOG.info(sql); JDBCUtils.execute(connection, sql); } config.addTable(toTable); return toTable; }
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()); clone.setPrimaryKey(table.getPrimaryKey()); clone.setQuoted(table.isQuoted());/* w ww. j a v a2s.co m*/ 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:it.eng.qbe.datasource.hibernate.HibernateDataSource.java
License:Mozilla Public License
protected void addDbLink(String modelName, Configuration srcCfg, Configuration dstCfg) { String dbLink = null;/* w ww. j ava 2 s . c om*/ PersistentClass srcPersistentClass = null; PersistentClass dstPersistentClass = null; String targetEntityName = null; Table targetTable = null; dbLink = (String) getDbLinkMap().get(modelName); if (dbLink != null) { Iterator it = srcCfg.getClassMappings(); while (it.hasNext()) { srcPersistentClass = (PersistentClass) it.next(); targetEntityName = srcPersistentClass.getEntityName(); dstPersistentClass = dstCfg.getClassMapping(targetEntityName); targetTable = dstPersistentClass.getTable(); targetTable.setName(targetTable.getName() + "@" + dbLink); } } }
From source file:org.openflexo.technologyadapter.jdbc.model.DynamicModelBuilder.java
License:Open Source License
public Metadata buildDynamicModel() { Metadata metadata = metadataCollector.buildMetadataInstance(metadataBuildingContext); Database database = metadata.getDatabase(); // ********** // Creation / Dfinition de la table T_Dynamic_Table Table table = metadataCollector.addTable("", "", "T_Dynamic_Table", null, false); table.setName("T_Dynamic_Table"); Column col = new Column(); col.setName("pouet"); col.setLength(256);//from w w w.jav a 2 s.com col.setSqlType("CHAR(256)"); col.setNullable(false); table.addColumn(col); PrimaryKey pk = new PrimaryKey(table); pk.addColumn(col); UniqueKey uk1 = new UniqueKey(); uk1.setName("Nom_Unique"); uk1.setTable(table); uk1.addColumn(col); table.addUniqueKey(uk1); Column col2 = new Column(); col2.setName("padam"); col2.setLength(256); col2.setSqlType("CHAR(256)"); col2.setNullable(true); table.addColumn(col2); // pour rire les couples "Nom + Prenom" doivent tre uniques UniqueKey uk = new UniqueKey(); uk.setName("Couple_Nom_Prenom_Unique"); uk.setTable(table); uk.addColumn(col); uk.addColumn(col2); table.addUniqueKey(uk); // une colonne de clef etrangre vers T_Adresse Column col3 = new Column(); col3.setName("id_addr"); col3.setLength(16); col3.setSqlType("INTEGER"); col3.setNullable(true); table.addColumn(col3); // ********** // Creation / Dfinition de la table T_Adresse Table table2 = metadataCollector.addTable("", "", "T_Adresse", null, false); table2.setName("T_Adresse"); Column col4 = new Column(); col4.setName("Id"); col4.setLength(16); col4.setSqlType("INTEGER"); col4.setNullable(false); table2.addColumn(col4); pk = new PrimaryKey(table2); pk.addColumn(col); uk1 = new UniqueKey(); uk1.setName("Id_Unique"); uk1.setTable(table2); uk1.addColumn(col4); table.addUniqueKey(uk1); Column col5 = new Column(); col5.setName("Adresse"); col5.setLength(512); col5.setSqlType("CHAR(512)"); col5.setNullable(true); table2.addColumn(col5); // ************************ // Creation de l'entit persiste "Dynamic_Class" RootClass pClass = new RootClass(metadataBuildingContext); pClass.setEntityName("Dynamic_Class"); pClass.setJpaEntityName("Dynamic_Class"); pClass.setTable(table); metadataCollector.addEntityBinding(pClass); // Creation d'une proprit (clef) et son mapping Property prop = new Property(); prop.setName("Nom"); SimpleValue value = new SimpleValue((MetadataImplementor) metadata, table); value.setTypeName("java.lang.String"); value.setIdentifierGeneratorStrategy("assigned"); value.addColumn(col); value.setTable(table); prop.setValue(value); pClass.setDeclaredIdentifierProperty(prop); pClass.setIdentifierProperty(prop); pClass.setIdentifier(value); // Creation d'une proprit et son mapping prop = new Property(); prop.setName("Prenom"); value = new SimpleValue((MetadataImplementor) metadata, table); value.setTypeName(String.class.getCanonicalName()); value.addColumn(col2); value.setTable(table); prop.setValue(value); pClass.addProperty(prop); // ************************ // Creation de l'entit persiste "Adresse" RootClass pClass2 = new RootClass(metadataBuildingContext); pClass2.setEntityName("Adresse"); pClass2.setJpaEntityName("Adresse"); pClass2.setTable(table2); metadataCollector.addEntityBinding(pClass2); // Creation d'une proprit (clef) et son mapping prop = new Property(); prop.setName("Identifiant"); value = new SimpleValue((MetadataImplementor) metadata, table2); value.setTypeName("java.lang.Integer"); value.setIdentifierGeneratorStrategy("native"); value.addColumn(col4); value.setTable(table2); prop.setValue(value); pClass2.setDeclaredIdentifierProperty(prop); pClass2.setIdentifierProperty(prop); pClass2.setIdentifier(value); // Creation d'une proprit et son mapping prop = new Property(); prop.setName("Prenom"); value = new SimpleValue((MetadataImplementor) metadata, table2); value.setTypeName(String.class.getCanonicalName()); value.addColumn(col5); value.setTable(table2); prop.setValue(value); pClass2.addProperty(prop); try { ((MetadataImplementor) metadata).validate(); } catch (MappingException e) { System.out.println("Validation Error: " + e.getMessage()); } return metadata; }
From source file:org.teiid.spring.autoconfigure.RedirectionSchemaInitializer.java
License:Apache License
List<Resource> generatedScripts() { List<Resource> resources = Collections.emptyList(); for (PersistentClass clazz : metadata.getEntityBindings()) { org.hibernate.mapping.Table ormTable = clazz.getTable(); String tableName = ormTable.getQuotedName(); if (this.schema.getTable(tableName) != null) { org.hibernate.mapping.Column c = new org.hibernate.mapping.Column( RedirectionSchemaBuilder.ROW_STATUS_COLUMN); c.setSqlTypeCode(TypeFacility.getSQLTypeFromRuntimeType(Integer.class)); c.setSqlType(JDBCSQLTypeInfo.getTypeName(TypeFacility.getSQLTypeFromRuntimeType(Integer.class))); ormTable.addColumn(c);/*from w w w .j a va 2s.com*/ ormTable.setName(tableName + TeiidConstants.REDIRECTED_TABLE_POSTFIX); } } List<String> statements = createScript(metadata, dialect, true); StringBuilder sb = new StringBuilder(); for (String s : statements) { // we have no need for sequences in the redirected scenario, they are fed from // other side. if (s.startsWith("drop sequence") || s.startsWith("create sequence")) { continue; } sb.append(s).append(";\n"); } logger.debug("Redirected Schema:\n" + sb.toString()); resources = Arrays.asList(new ByteArrayResource(sb.toString().getBytes())); return resources; }