Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#714 Fixed error during data transfer #716

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public static void main(String[] args) throws Exception {
try {
initLogName("DataTransferBat.log");
configInit(ClassUtils.getShortClassName(DataTransferBat.class));

DataTransferLogic.get().requestTransfer();
DataTransferBat bat = new DataTransferBat();
bat.dbInit();
bat.start();

} catch (Exception e) {
LOG.error("any error", e);
throw e;
Expand All @@ -38,10 +39,10 @@ public void run() {
try {
AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
String[] parms = { "-tcp", "-baseDir", appConfig.getDatabasePath() };


LOG.info("start h2 database");
Server server = Server.createTcpServer(parms);
server.start();

// System.out.println("Database start...");
serverStarted = true;
while (runing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ public MailLocaleTemplatesEntity selectOnKey(String key, String templateId) {
String sql = SQLManager.getInstance().getSql("/org/support/project/knowledge/dao/sql/MailLocaleTemplatesDao/MailLocaleTemplatesDao_select_on_key.sql");
return executeQuerySingle(sql, MailLocaleTemplatesEntity.class, key, templateId);
}
/**
* Select data that not deleted on KEY column.
* @param key key
* @return list
*/
public List<MailLocaleTemplatesEntity> selectOnKey(String key) {
String sql = SQLManager.getInstance().getSql("/org/support/project/knowledge/dao/sql/MailLocaleTemplatesDao/MailLocaleTemplatesDao_select_on_col_key.sql");
return executeQueryList(sql, MailLocaleTemplatesEntity.class, key);
}
/**
* Select data that not deleted on TEMPLATE_ID column.
* @param templateId templateId
Expand All @@ -118,7 +127,7 @@ public List<MailLocaleTemplatesEntity> selectOnTemplateId(String templateId) {
* @return list
*/
public List<MailLocaleTemplatesEntity> physicalSelectOnKey(String key) {
String sql = SQLManager.getInstance().getSql("/org/support/project/knowledge/dao/sql/MailLocaleTemplatesDao/MailLocaleTemplatesDao_physical_select_on_key.sql");
String sql = SQLManager.getInstance().getSql("/org/support/project/knowledge/dao/sql/MailLocaleTemplatesDao/MailLocaleTemplatesDao_physical_select_on_col_key.sql");
return executeQueryList(sql, MailLocaleTemplatesEntity.class, key);
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,27 @@ public void transferData(ConnectionConfig from, ConnectionConfig to) throws Exce
initDB.start();

// コピー先のDBの初期化
LOG.info("migrate to db");
LOG.info("init and migrate to db : " + to.getName());
ConnectionManager.getInstance().setDefaultConnectionName(to.getName());
DatabaseControlDao dao1 = new DatabaseControlDao();
org.support.project.web.dao.gen.DatabaseControlDao dao2 = new org.support.project.web.dao.gen.DatabaseControlDao();
dao1.setConnectionName(to.getName());
dao2.setConnectionName(to.getName());
dao1.dropAllTable();
dao2.dropAllTable();
DatabaseControlDao knowledgeControlDao = new DatabaseControlDao();
org.support.project.web.dao.gen.DatabaseControlDao webControlDao = new org.support.project.web.dao.gen.DatabaseControlDao();
knowledgeControlDao.setConnectionName(to.getName());
webControlDao.setConnectionName(to.getName());
knowledgeControlDao.dropAllTable();
webControlDao.dropAllTable();
initDB.start();

// データコピー先のDBに入っている、初期データを削除
LOG.info("clear init data from to db.");
ConnectionManager.getInstance().setDefaultConnectionName(to.getName());
List<AbstractDao> truncateTargets = new ArrayList<AbstractDao>();
truncateTargets.add(GroupsDao.get());
// truncateTargets.add(GroupsDao.get());
truncateTargets.add(RolesDao.get());
truncateTargets.add(UserRolesDao.get());
truncateTargets.add(UsersDao.get());
truncateTargets.add(SystemsDao.get());
truncateTargets.add(TemplateItemsDao.get());
truncateTargets.add(TemplateMastersDao.get());
// truncateTargets.add(SystemsDao.get());
// truncateTargets.add(TemplateItemsDao.get());
// truncateTargets.add(TemplateMastersDao.get());
for (AbstractDao targetDao : truncateTargets) {
targetDao.setConnectionName(to.getName());
Method truncateMethods = targetDao.getClass().getMethod("truncate");
Expand Down Expand Up @@ -149,7 +149,7 @@ public void transferData(ConnectionConfig from, ConnectionConfig to) throws Exce
List<?> list = (List<?>) selectAllMethods.invoke(dao, args);

// Toへデータ登録
LOG.info(" -> insert data to " + to.getName());
LOG.info(" -> insert data(100) to " + to.getName());
ConnectionManager.getInstance().setDefaultConnectionName(to.getName());
setConnectionNameMethods.invoke(dao, to.getName());
TransactionManager transactionManager = Container.getComp(TransactionManager.class);
Expand All @@ -158,8 +158,26 @@ public void transferData(ConnectionConfig from, ConnectionConfig to) throws Exce
if (LOG.isTraceEnabled()) {
LOG.trace(entity);
}
Method insertMethods = class1.getMethod("rawPhysicalInsert", entity.getClass());
insertMethods.invoke(dao, entity);
Method getKeyValuesMethods = entity.getClass().getMethod("getKeyValues");
Object[] keys = (Object[]) getKeyValuesMethods.invoke(entity);
Class<?>[] params = new Class[keys.length];
StringBuilder builder = new StringBuilder();
for (int j = 0; j < keys.length; j++) {
params[j] = keys[j].getClass();
if (j > 0) {
builder.append(",");
}
builder.append(keys[j]);
}
LOG.trace(class1.getName() + " : " + builder.toString());
Method physicalSelectOnKeyMethods = class1.getMethod("physicalSelectOnKey", params);
Object obj = physicalSelectOnKeyMethods.invoke(dao, keys);
if (obj == null) {
Method insertMethods = class1.getMethod("rawPhysicalInsert", entity.getClass());
insertMethods.invoke(dao, entity);
} else {
LOG.warn("skip (already exists): " + class1.getName() + " : " + builder.toString());
}
}
transactionManager.commit(to.getName());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<!-- FileAppender -->
<appender name="APP_FILEOUT" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${user.dir}/app.log" />
<param name="File" value="${user.home}/app.log" />
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT * FROM MAIL_LOCALE_TEMPLATES
WHERE
KEY = ?
;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SELECT * FROM MAIL_LOCALE_TEMPLATES
WHERE
KEY = ?
AND TEMPLATE_ID = ?
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT * FROM MAIL_LOCALE_TEMPLATES
WHERE
TEMPLATE_ID = ?
AND DELETE_FLAG = 0;