From: <one...@us...> - 2002-12-14 09:27:58
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools In directory sc8-pr-cvs1:/tmp/cvs-serv888/tools Modified Files: SchemaUpdater.java Removed Files: JdbcColumnInfo.java Log Message: Benoit Menendez patches to SchemaUpdater and blob support Index: SchemaUpdater.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/SchemaUpdater.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SchemaUpdater.java 11 Nov 2002 10:09:56 -0000 1.2 --- SchemaUpdater.java 14 Dec 2002 09:27:56 -0000 1.3 *************** *** 6,9 **** --- 6,10 ---- import cirrus.hibernate.HibernateException; import cirrus.hibernate.sql.Dialect; + import cirrus.hibernate.tools.updater.*; import cirrus.hibernate.connection.ConnectionProvider; import cirrus.hibernate.connection.ConnectionProviderFactory; *************** *** 78,83 **** public void execute(boolean script) throws SQLException, HibernateException { Connection connection = cp.getConnection(); ! Map columnInfo = getColumnInfo(connection); Statement stmt; stmt = connection.createStatement(); --- 79,85 ---- public void execute(boolean script) throws SQLException, HibernateException { + Dialect dialect = Dialect.getDialect(); Connection connection = cp.getConnection(); ! JdbcDatabaseInfo info = new JdbcDatabaseInfo(connection, dialect); Statement stmt; stmt = connection.createStatement(); *************** *** 86,90 **** String[] createSQL; ! createSQL = store.generateSchemaUpdateScript(Dialect.getDialect(), columnInfo); for (int j = 0; j < createSQL.length; j++) { --- 88,92 ---- String[] createSQL; ! createSQL = store.generateSchemaUpdateScript(dialect, info); for (int j = 0; j < createSQL.length; j++) { *************** *** 110,239 **** connection.close(); } - - - // the next 2 functions are highly inspired by the ofbiz entity engine - - private Map getColumnInfo(Connection connection) { - - - DatabaseMetaData dbData = null; - - try { - dbData = connection.getMetaData(); - } catch (SQLException sqle) { - String message = "Unable to get database meta data... Error was:" + sqle.toString(); - - log.error(message); - - } - - - log.info("Getting Column Info From Database"); - - Map colInfo = new HashMap(); - - try { - String userName = dbData.supportsSchemasInTableDefinitions() ? dbData.getUserName() : null; - if (userName!=null) log.info("Schema: " + userName); - //ResultSet rsCols = dbData.getColumns(null, userName, "%", "%"); - ResultSet rsCols = dbData.getColumns(null, "%", "%", "%"); - - while (rsCols.next()) { - try { - JdbcColumnInfo info = new JdbcColumnInfo(); - - info.table = rsCols.getString("TABLE_NAME"); - info.table = (info.table == null) ? null : info.table.toUpperCase(); - - info.columnName = rsCols.getString("COLUMN_NAME"); - - info.typeName = rsCols.getString("TYPE_NAME"); - info.columnSize = rsCols.getInt("COLUMN_SIZE"); - info.decimalDigits = rsCols.getInt("DECIMAL_DIGITS"); - - info.isNullable = rsCols.getString("IS_NULLABLE"); - - log.info("Existing column: " + info); - - Map tableColInfo = (Map)colInfo.get(info.table.toLowerCase()); - - if (tableColInfo == null) { - tableColInfo = new HashMap(); - colInfo.put(info.table.toLowerCase(), tableColInfo); - } - tableColInfo.put( info.columnName.toLowerCase(), info ); - } catch (SQLException sqlex) { - String messagex = "Error getting column info for column. Error was:" + sqlex.toString(); - - log.debug(messagex); - continue; - } - } - - try { - rsCols.close(); - } catch (SQLException sqle) { - String message = "Unable to close ResultSet for column list, continuing anyway... Error was:" + sqle.toString(); - - log.error(message); - } - } catch (SQLException sqle) { - String message = "Error getting column meta data for Error was:" + sqle.toString() + ". Not checking columns."; - - log.error(message); - } - return colInfo; - } - - private Set getTableNames(Connection connection) throws SQLException { - - DatabaseMetaData dbData = connection.getMetaData(); - - log.info("Getting Table Info From Database"); - - Set tableNames = new TreeSet(); - ResultSet tableSet; - try { - String[] types = {"TABLE"}; - String userName = dbData.supportsSchemasInTableDefinitions() ? dbData.getUserName() : null; - - tableSet = dbData.getTables(null, userName, null, types); - } catch (SQLException sqle) { - - log.error("Unable to get list of table information, trying to create all tables.", sqle); - - // we are returning an empty set here because databases like SapDB throw an exception when there are no tables in the database - return tableNames; - } - - try { - while (tableSet.next()) { - try { - String tableName = tableSet.getString("TABLE_NAME"); - log.debug("Found Table:" + tableName); - tableNames.add(tableName); - - log.info("Existing table: " + tableName); - - } catch (SQLException sqle) { - - log.error("Error getting table information... Error was:", sqle); - continue; - } - } - } catch (SQLException sqle) { - log.error("Error in tableSet.next(). Error was:" , sqle); - } finally { - try { - tableSet.close(); - } catch (SQLException sqle) { - String message = "Unable to close ResultSet for table list, continuing anyway... Error was:" + sqle.toString(); - - log.error(message); - } - } - return tableNames; - } - - } --- 112,114 ---- --- JdbcColumnInfo.java DELETED --- |