}
//System.out.println("Objects moved to the server!");
} catch (HibernateException e) {
e.printStackTrace();
throw new ServerDataUnloadException("Возникла ошибка при при переброске объектов обследования с клиента на сервер!");
}
// removing all objects from base
deleteLocalObjects(request,response);
//System.out.println("Local objects deleted");
//getting new data from server to the client
Properties props = new Properties();
props.setProperty("driver.class",basicDataSource.getDriverClassName());
props.setProperty("user",basicDataSource.getUsername());
props.setProperty("password",basicDataSource.getPassword());
String driverClassName = props.getProperty("driver.class");
//driverURL = "jdbc:mysql://" + address + "/vstbase";
driverURL = basicDataSource.getUrl().replaceFirst("localhost",address);
// Default to not having a quote character
String columnNameQuote = props.getProperty("columnName.quoteChar", "");
DatabaseMetaData dbMetaData = null;
Connection dbConn = null;
try {
Class.forName(driverClassName);
//System.out.println("driverURL=" + driverURL);
dbConn = DriverManager.getConnection(driverURL, props);
dbMetaData = dbConn.getMetaData();
}
catch (Exception e) {
e.printStackTrace();
throw new ServerDataUnloadException("Возникла ошибка при установлении соединения с базой данных сервера!");
}
StringBuffer result = new StringBuffer();
try {
String catalog = props.getProperty("catalog");
String schema = props.getProperty("schemaPattern");
String tables = props.getProperty("tableName");
ResultSet rs = dbMetaData.getTables(catalog, schema, tables, null);
if (!rs.next()) {
System.err.println("Unable to find any tables matching: catalog=" + catalog + " schema=" + schema + " tables=" + tables);
rs.close();
} else {
do {
String tableName = rs.getString("TABLE_NAME");
String tableType = rs.getString("TABLE_TYPE");
//System.out.println("tableName=====" + tableName);
/*TODO this is a dump of the tables structure/ It's not needed in this application
*/
//dump the data to the local db if it's the table we need
if (isSpravochnikTable(tableName)) {
//creating local connection
// BasicDataSource basicDataSource= (BasicDataSource) BeanUtils.getBean("dataSource");
// String driverLocalURL = props.getProperty("driver.url");
String driverLocalURL = basicDataSource.getUrl();
Connection dbLocalConn = null;
try {
Class.forName(driverClassName);
dbLocalConn = DriverManager.getConnection(driverLocalURL, props);
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
throw new ServerDataUnloadException("Не удалось найти файл настройки для базы данных на клиенте!");
}
try {
dumpTable(dbConn, result, tableName, true);
} catch (SQLException e) {
throw new ServerDataUnloadException("Ошибка при получении данных с серврера от таблицы - "+tableName);
}
}
} while (rs.next());
rs.close();
}
dbConn.close();
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
throw new ServerDataUnloadException("Произошла ошибка при получении справочников из базы сервера!");
}
//System.out.println("Spravochniks received from server");
//System.out.println(result.toString());
//executing the dump on the localhost db
if (!db2sql.execDump(result.toString(), null,request,response)) {
throw new ServerDataUnloadException("Произошла ошибка при передачи справочников в базу клиента");
}
// fileName = "sql.properties";
// props = new Properties();
// try {