List of usage examples for org.hibernate.mapping Table getName
public String getName()
From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape.java
License:Open Source License
@Override public Object getPropertyValue(Object propertyId) { Object res = null;//from w ww .java 2s . c om RootClass rootClass = null; Table table = null; Object ormElement = getOrmElement(); if (ormElement instanceof RootClass) { rootClass = (RootClass) ormElement; } else if (ormElement instanceof Subclass) { //rootClass = ((Subclass)ormElement).getRootClass(); } else if (ormElement instanceof Table) { table = (Table) getOrmElement(); } if (rootClass != null) { if (ENTITY_isAbstract.equals(propertyId)) { if (rootClass.isAbstract() != null) { res = rootClass.isAbstract().toString(); } } else if (ENTITY_isCustomDeleteCallable.equals(propertyId)) { res = Boolean.valueOf(rootClass.isCustomDeleteCallable()).toString(); } else if (ENTITY_isCustomInsertCallable.equals(propertyId)) { res = Boolean.valueOf(rootClass.isCustomInsertCallable()).toString(); } else if (ENTITY_isCustomUpdateCallable.equals(propertyId)) { res = Boolean.valueOf(rootClass.isCustomUpdateCallable()).toString(); } else if (ENTITY_isDiscriminatorInsertable.equals(propertyId)) { res = Boolean.valueOf(rootClass.isDiscriminatorInsertable()).toString(); } else if (ENTITY_isDiscriminatorValueNotNull.equals(propertyId)) { res = Boolean.valueOf(rootClass.isDiscriminatorValueNotNull()).toString(); } else if (ENTITY_isDiscriminatorValueNull.equals(propertyId)) { res = Boolean.valueOf(rootClass.isDiscriminatorValueNull()).toString(); } else if (ENTITY_isExplicitPolymorphism.equals(propertyId)) { res = Boolean.valueOf(rootClass.isExplicitPolymorphism()).toString(); } else if (ENTITY_isForceDiscriminator.equals(propertyId)) { res = Boolean.valueOf(rootClass.isForceDiscriminator()).toString(); } else if (ENTITY_isInherited.equals(propertyId)) { res = Boolean.valueOf(rootClass.isInherited()).toString(); } else if (ENTITY_isJoinedSubclass.equals(propertyId)) { res = Boolean.valueOf(rootClass.isJoinedSubclass()).toString(); } else if (ENTITY_isLazy.equals(propertyId)) { res = Boolean.valueOf(rootClass.isLazy()).toString(); } else if (ENTITY_isLazyPropertiesCacheable.equals(propertyId)) { res = Boolean.valueOf(rootClass.isLazyPropertiesCacheable()).toString(); } else if (ENTITY_isMutable.equals(propertyId)) { res = Boolean.valueOf(rootClass.isMutable()).toString(); } else if (ENTITY_isPolymorphic.equals(propertyId)) { res = Boolean.valueOf(rootClass.isPolymorphic()).toString(); } else if (ENTITY_isVersioned.equals(propertyId)) { res = Boolean.valueOf(rootClass.isVersioned()).toString(); } else if (ENTITY_batchSize.equals(propertyId)) { res = Integer.valueOf(rootClass.getBatchSize()).toString(); } else if (ENTITY_cacheConcurrencyStrategy.equals(propertyId)) { res = rootClass.getCacheConcurrencyStrategy(); } else if (ENTITY_className.equals(propertyId)) { res = rootClass.getClassName(); } else if (ENTITY_customSQLDelete.equals(propertyId)) { res = rootClass.getCustomSQLDelete(); } else if (ENTITY_customSQLInsert.equals(propertyId)) { res = rootClass.getCustomSQLInsert(); } else if (ENTITY_customSQLUpdate.equals(propertyId)) { res = rootClass.getCustomSQLUpdate(); } else if (ENTITY_discriminatorValue.equals(propertyId)) { res = rootClass.getDiscriminatorValue(); } else if (ENTITY_entityName.equals(propertyId)) { res = rootClass.getEntityName(); } else if (ENTITY_loaderName.equals(propertyId)) { res = rootClass.getLoaderName(); } else if (ENTITY_nodeName.equals(propertyId)) { res = rootClass.getNodeName(); } else if (ENTITY_optimisticLockMode.equals(propertyId)) { res = Integer.valueOf(rootClass.getOptimisticLockMode()).toString(); } else if (ENTITY_table.equals(propertyId)) { if (rootClass.getTable() != null) { res = rootClass.getTable().getName(); } } else if (ENTITY_temporaryIdTableDDL.equals(propertyId)) { res = rootClass.getTemporaryIdTableDDL(); } else if (ENTITY_temporaryIdTableName.equals(propertyId)) { res = rootClass.getTemporaryIdTableName(); } else if (ENTITY_where.equals(propertyId)) { res = rootClass.getWhere(); } } if (table != null) { if (TABLE_catalog.equals(propertyId)) { res = table.getCatalog(); } else if (TABLE_comment.equals(propertyId)) { res = table.getComment(); } else if (TABLE_name.equals(propertyId)) { res = table.getName(); } else if (TABLE_primaryKey.equals(propertyId)) { if (table.getPrimaryKey() != null) { res = table.getPrimaryKey().getName(); } } else if (TABLE_rowId.equals(propertyId)) { res = table.getRowId(); } else if (TABLE_schema.equals(propertyId)) { res = table.getSchema(); } else if (TABLE_subselect.equals(propertyId)) { res = table.getSubselect(); } else if (TABLE_hasDenormalizedTables.equals(propertyId)) { res = Boolean.valueOf(table.hasDenormalizedTables()).toString(); } else if (TABLE_isAbstract.equals(propertyId)) { res = Boolean.valueOf(table.isAbstract()).toString(); } else if (TABLE_isAbstractUnionTable.equals(propertyId)) { res = Boolean.valueOf(table.isAbstractUnionTable()).toString(); } else if (TABLE_isPhysicalTable.equals(propertyId)) { res = Boolean.valueOf(table.isPhysicalTable()).toString(); } } if (res == null) { res = super.getPropertyValue(propertyId); } return toEmptyStr(res); }
From source file:org.jboss.tools.hibernate.ui.diagram.editors.model.Utils.java
License:Open Source License
public static String getTableName(Table table) { return getTableName(table.getCatalog(), table.getSchema(), table.getName()); }
From source file:org.jboss.tools.seam.ui.views.DBTableFilterView.java
License:Open Source License
@Override protected void toggle(boolean exclude) { ISelection selection = viewer.getSelection(); if (!selection.isEmpty()) { StructuredSelection ss = (StructuredSelection) selection; Iterator iterator = ss.iterator(); while (iterator.hasNext()) { Object sel = iterator.next(); ITableFilter filter = null;// w w w . ja v a 2 s . c om if (sel instanceof Table) { Table table = (Table) sel; filter = revEngDef.createTableFilter(); if (StringHelper.isNotEmpty(table.getName())) { filter.setMatchName(table.getName()); } if (StringHelper.isNotEmpty(table.getCatalog())) { filter.setMatchCatalog(table.getCatalog()); } if (StringHelper.isNotEmpty(table.getSchema())) { filter.setMatchSchema(table.getSchema()); } filter.setExclude(Boolean.valueOf(exclude)); } else if (sel instanceof Schema) { // assume its a schema! Schema tc = (Schema) sel; filter = revEngDef.createTableFilter(); String schema = tc.getName(); String catalog = tc.getParent().getName(); if (StringHelper.isNotEmpty(schema)) { filter.setMatchSchema(schema); } if (StringHelper.isNotEmpty(catalog)) { filter.setMatchCatalog(catalog); } filter.setExclude(Boolean.valueOf(exclude)); } else if (sel instanceof Catalog) { // assume its a catalog! Catalog tc = (Catalog) sel; filter = revEngDef.createTableFilter(); if (StringHelper.isNotEmpty(tc.getName())) { filter.setMatchCatalog(tc.getName()); } filter.setExclude(Boolean.valueOf(exclude)); } if (filter != null) revEngDef.addTableFilter(filter); } } else { ITableFilter filter = revEngDef.createTableFilter(); filter.setExclude(Boolean.valueOf(exclude)); revEngDef.addTableFilter(filter); } }
From source file:org.jbpm.db.JbpmSchema.java
License:Open Source License
public String[] getCleanSql() { if (cleanSql == null) { // loop over all foreign key constraints List dropForeignKeysSql = new ArrayList(); List createForeignKeysSql = new ArrayList(); Iterator iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { Iterator subIter = table.getForeignKeyIterator(); while (subIter.hasNext()) { ForeignKey fk = (ForeignKey) subIter.next(); if (fk.isPhysicalConstraint()) { // collect the drop foreign key constraint sql dropForeignKeysSql.add( fk.sqlDropString(dialect, properties.getProperty(Environment.DEFAULT_CATALOG), properties.getProperty(Environment.DEFAULT_SCHEMA))); // and collect the create foreign key constraint sql createForeignKeysSql.add(fk.sqlCreateString(dialect, mapping, properties.getProperty(Environment.DEFAULT_CATALOG), properties.getProperty(Environment.DEFAULT_SCHEMA))); }/* w w w . j a v a 2 s . c o m*/ } } } List deleteSql = new ArrayList(); iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); deleteSql.add("delete from " + table.getName()); } // glue // - drop foreign key constraints // - delete contents of all tables // - create foreign key constraints // together to form the clean script List cleanSqlList = new ArrayList(); cleanSqlList.addAll(dropForeignKeysSql); cleanSqlList.addAll(deleteSql); cleanSqlList.addAll(createForeignKeysSql); cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]); } return cleanSql; }
From source file:org.jbpm.identity.hibernate.IdentitySchema.java
License:Open Source License
public String[] getCleanSql() { if (cleanSql == null) { // loop over all foreign key constraints List dropForeignKeysSql = new ArrayList(); List createForeignKeysSql = new ArrayList(); Iterator iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { Iterator subIter = table.getForeignKeyIterator(); while (subIter.hasNext()) { ForeignKey fk = (ForeignKey) subIter.next(); if (fk.isPhysicalConstraint()) { // collect the drop key constraint dropForeignKeysSql.add( fk.sqlDropString(dialect, properties.getProperty(Environment.DEFAULT_CATALOG), properties.getProperty(Environment.DEFAULT_SCHEMA))); createForeignKeysSql.add(fk.sqlCreateString(dialect, mapping, properties.getProperty(Environment.DEFAULT_CATALOG), properties.getProperty(Environment.DEFAULT_SCHEMA))); }//w ww. j a va 2s.c o m } } } List deleteSql = new ArrayList(); iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); deleteSql.add("delete from " + table.getName()); } List cleanSqlList = new ArrayList(); cleanSqlList.addAll(dropForeignKeysSql); cleanSqlList.addAll(deleteSql); cleanSqlList.addAll(createForeignKeysSql); cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]); } return cleanSql; }
From source file:org.jbpm.test.Db.java
License:Open Source License
public static void clean(ProcessEngine processEngine) { SessionFactory sessionFactory = processEngine.get(SessionFactory.class); // when running this with a remote ejb invocation configuration, there is no // session factory and no cleanup needs to be done if (sessionFactory == null) { return;/* w w w.j a v a 2 s . c o m*/ } String[] cleanSql = cleanSqlCache.get(processEngine); if (cleanSql == null) { Configuration configuration = processEngine.get(Configuration.class); SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) sessionFactory; Dialect dialect = sessionFactoryImplementor.getDialect(); // loop over all foreign key constraints List<String> dropForeignKeysSql = new ArrayList<String>(); List<String> createForeignKeysSql = new ArrayList<String>(); Iterator<Table> iter = configuration.getTableMappings(); //if no session-factory is build, the configuration is not fully initialized. //Hence, the ForeignKey's won't have a referenced table. This is calculated on //second pass. configuration.buildMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { String catalog = table.getCatalog(); String schema = table.getSchema(); Iterator<ForeignKey> subIter = table.getForeignKeyIterator(); while (subIter.hasNext()) { ForeignKey fk = (ForeignKey) subIter.next(); if (fk.isPhysicalConstraint()) { // collect the drop foreign key constraint sql dropForeignKeysSql.add(fk.sqlDropString(dialect, catalog, schema)); // MySQLDialect creates an index for each foreign key. // see // http://opensource.atlassian.com/projects/hibernate/browse/HHH-2155 // This index should be dropped or an error will be thrown during // the creation phase if (dialect instanceof MySQLDialect) { dropForeignKeysSql .add("alter table " + table.getName() + " drop key " + fk.getName()); } // and collect the create foreign key constraint sql createForeignKeysSql .add(fk.sqlCreateString(dialect, sessionFactoryImplementor, catalog, schema)); } } } } List<String> deleteSql = new ArrayList<String>(); iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { deleteSql.add("delete from " + table.getName()); } } // glue // - drop foreign key constraints // - delete contents of all tables // - create foreign key constraints // together to form the clean script List<String> cleanSqlList = new ArrayList<String>(); cleanSqlList.addAll(dropForeignKeysSql); cleanSqlList.addAll(deleteSql); cleanSqlList.addAll(createForeignKeysSql); cleanSql = (String[]) cleanSqlList.toArray(new String[cleanSqlList.size()]); cleanSqlCache.put(processEngine, cleanSql); } Session session = sessionFactory.openSession(); try { for (String query : cleanSql) { // log.trace(query); session.createSQLQuery(query).executeUpdate(); } } finally { session.close(); } }
From source file:org.jbpm.test.Db.java
License:Open Source License
public static String verifyClean(ProcessEngine processEngine) { SessionFactory sessionFactory = processEngine.get(SessionFactory.class); // when running this with a remote ejb invocation configuration, there is no // session factory and no cleanup needs to be done if (sessionFactory == null) { return null; }//from w w w . jav a2s . c om String[] tableNames = tableNamesCache.get(processEngine); if (tableNames == null) { Configuration configuration = processEngine.get(Configuration.class); // loop over all foreign key constraints List<String> tableNamesList = new ArrayList<String>(); Iterator iter = configuration.getTableMappings(); while (iter.hasNext()) { Table table = (Table) iter.next(); if (table.isPhysicalTable()) { tableNamesList.add(table.getName()); } } tableNames = tableNamesList.toArray(new String[tableNamesList.size()]); tableNamesCache.put(processEngine, tableNames); } String recordsLeftMsg = ""; Session session = sessionFactory.openSession(); try { for (String tableName : tableNames) { String countSql = "select count(*) as RECORD_COUNT_ from " + tableName; SQLQuery sqlQuery = session.createSQLQuery(countSql); sqlQuery.addScalar("RECORD_COUNT_", Hibernate.LONG); Long recordCount = (Long) sqlQuery.uniqueResult(); if (recordCount > 0L) { recordsLeftMsg += tableName + ":" + recordCount + ", "; } } } finally { session.close(); } if (recordsLeftMsg.length() > 0) { clean(processEngine); } return recordsLeftMsg; }
From source file:org.jooq.meta.extensions.jpa.AttributeConverterExtractor.java
License:Apache License
@SuppressWarnings("unchecked") final Map<Name, AttributeConverter<?, ?>> extract() { Map<Name, AttributeConverter<?, ?>> result = new LinkedHashMap<>(); initEntityManagerFactory();// www . ja v a 2s . co m for (PersistentClass persistentClass : meta.getEntityBindings()) { Table table = persistentClass.getTable(); Iterator<Property> propertyIterator = persistentClass.getPropertyIterator(); propertyLoop: while (propertyIterator.hasNext()) { Property property = propertyIterator.next(); Type type = property.getValue().getType(); if (type instanceof AttributeConverterTypeAdapter) { AttributeConverter<?, ?> converter = ((AttributeConverterTypeAdapter<?>) type) .getAttributeConverter().getConverterBean().getBeanInstance(); Iterator<Column> columnIterator = property.getColumnIterator(); if (columnIterator.hasNext()) { Column column = columnIterator.next(); if (columnIterator.hasNext()) { log.info("AttributeConverter", "Cannot apply AttributeConverter of property " + property + " on several columns."); continue propertyLoop; } result.put(name(table.getCatalog(), table.getSchema(), table.getName(), column.getName()), converter); } } } } return result; }
From source file:org.n52.sos.ds.datasource.AbstractH2Datasource.java
License:Open Source License
@Override public void clear(Properties properties) { Map<String, Object> settings = parseDatasourceProperties(properties); CustomConfiguration config = getConfig(settings); Iterator<Table> tables = config.getTableMappings(); Connection conn = null;//www. j a v a 2 s . co m Statement stmt = null; try { conn = openConnection(settings); stmt = conn.createStatement(); stmt.execute("set referential_integrity false"); while (tables.hasNext()) { Table table = tables.next(); if (table.isPhysicalTable()) { stmt.execute("truncate table " + table.getName()); } } stmt.execute("set referential_integrity true"); GeoDB.InitGeoDB(conn); } catch (SQLException ex) { throw new ConfigurationException(ex); } finally { close(stmt); close(conn); } }
From source file:org.n52.sos.ds.datasource.AbstractHibernateDatasource.java
License:Open Source License
@Override public boolean checkIfSchemaExists(Map<String, Object> settings) { Connection conn = null;/* ww w. j a v a2 s . c o m*/ try { /* check if any of the needed tables is existing */ conn = openConnection(settings); DatabaseMetadata metadata = getDatabaseMetadata(conn, getConfig(settings)); Iterator<Table> iter = getConfig(settings).getTableMappings(); String catalog = checkCatalog(conn); String schema = checkSchema((String) settings.get(SCHEMA_KEY), catalog, conn); while (iter.hasNext()) { Table table = iter.next(); if (table.isPhysicalTable() && metadata.isTable(table.getQuotedName()) && metadata.getTableMetadata(table.getName(), schema, catalog, table.isQuoted()) != null) { return true; } } return false; } catch (SQLException ex) { throw new ConfigurationException(ex); } finally { close(conn); } }