public void init(Config config) { Connection connection = null; try { this.platform = PlatformFactory.createNewPlatformInstance("mysql"); connection = MetadataUtils.getJdbcConnection(config); String dbName = config.getString(MetadataUtils.JDBC_DATABASE_PATH); this.database = platform.readModelFromDatabase(connection, dbName); LOG.info("Loaded " + database); Database _database = identifyNewTables(); if (_database.getTableCount() > 0) { LOG.info("Creating {} new tables (totally {} tables)", _database.getTableCount(), database.getTableCount()); this.platform.createTables(connection, _database, false, true); LOG.info("Created {} new tables: ", _database.getTableCount(), _database.getTables()); } else { LOG.debug("All the {} tables have already been created, no new tables", database.getTableCount()); } } catch (Exception e) { LOG.error(e.getMessage(), e); throw new IllegalStateException(e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOG.warn(e.getMessage(), e); } } } }
@Override public void init() { Connection connection = null; try { Database _database = identifyNewTables(); if(_database.getTableCount() >0 ) { LOG.info("Creating {} new tables (totally {} tables)", _database.getTableCount(),database.getTableCount()); connection = ConnectionManagerFactory.getInstance().getConnection(); this.platform.createTables(connection,_database, false, true); LOG.info("Created {} new tables: ",_database.getTableCount(),_database.getTables()); } else { LOG.debug("All the {} tables have already been created, no new tables", database.getTableCount()); } } catch (Exception e) { LOG.error(e.getMessage(),e); throw new IllegalStateException(e); } finally { if(connection != null){ try { connection.close(); } catch (SQLException e) { LOG.warn(e.getMessage(),e); } } } }
@Override public void init() { Connection connection = null; try { Database _database = identifyNewTables(); if(_database.getTableCount() >0 ) { LOG.info("Creating {} new tables (totally {} tables)", _database.getTableCount(),database.getTableCount()); connection = ConnectionManagerFactory.getInstance().getConnection(); this.platform.createTables(connection,_database, false, true); LOG.info("Created {} new tables: ",_database.getTableCount(),_database.getTables()); } else { LOG.debug("All the {} tables have already been created, no new tables", database.getTableCount()); } } catch (Exception e) { LOG.error(e.getMessage(),e); throw new IllegalStateException(e); } finally { if(connection != null){ try { connection.close(); } catch (SQLException e) { LOG.warn(e.getMessage(),e); } } } }
Table[] intermediateTables = intermediateModel.getTables();
/** * Writes the data contained in the database to which the given platform is connected, as XML * to the given data writer. * * @param platform The platform; needs to be connected to a live database * @param model The model for which to retrieve and write the data * @param writer The data writer */ public void writeDataToXML(Platform platform, Database model, DataWriter writer) { registerConverters(writer.getConverterConfiguration()); // TODO: An advanced algorithm could be employed here that writes individual // objects related by foreign keys, in the correct order List tables = sortTables(model.getTables()); writer.writeDocumentStart(); for (Iterator it = tables.iterator(); it.hasNext();) { writeDataForTableToXML(platform, model, (Table)it.next(), writer); } writer.writeDocumentEnd(); }