From 1e7575c7b750f9c4eb87131e0dc9758861ecfc8c Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Sun, 18 Sep 2016 19:50:17 +0800 Subject: [PATCH] --- src/META-INF/persistence-template.xml | 2 +- src/org/redkale/source/DataDefaultSource.java | 20 ++++++++++++++++--- src/org/redkale/source/EntityInfo.java | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/META-INF/persistence-template.xml b/src/META-INF/persistence-template.xml index c674c631c..35236afa2 100644 --- a/src/META-INF/persistence-template.xml +++ b/src/META-INF/persistence-template.xml @@ -28,7 +28,7 @@ - + diff --git a/src/org/redkale/source/DataDefaultSource.java b/src/org/redkale/source/DataDefaultSource.java index 7afdb261b..bcf41c939 100644 --- a/src/org/redkale/source/DataDefaultSource.java +++ b/src/org/redkale/source/DataDefaultSource.java @@ -36,7 +36,7 @@ public final class DataDefaultSource implements DataSource, Function 0 && info.tablenotexistSqlstates.contains(';' + se.getSQLState() + ';')) { + Statement st = conn.createStatement(); + st.execute("CREATE DATABASE " + newTable.substring(0, newTable.indexOf('.'))); + st.close(); + try { + st = conn.createStatement(); + st.execute(info.tablecopySQL.replace("${newtable}", newTable).replace("${oldtable}", oldTable)); + st.close(); + info.tables.add(newTable); + } catch (SQLException sqle2) { + logger.log(Level.SEVERE, "create table(" + info.tablecopySQL.replace("${newtable}", newTable).replace("${oldtable}", oldTable) + ") error", sqle2); + } + } else { + logger.log(Level.SEVERE, "create table(" + info.tablecopySQL.replace("${newtable}", newTable).replace("${oldtable}", oldTable) + ") error", sqle); + } } } } diff --git a/src/org/redkale/source/EntityInfo.java b/src/org/redkale/source/EntityInfo.java index 0acfa2508..c9b9d4986 100644 --- a/src/org/redkale/source/EntityInfo.java +++ b/src/org/redkale/source/EntityInfo.java @@ -62,7 +62,7 @@ public final class EntityInfo { final String notcontainSQL; //用于反向LIKE使用 - final String tablenotexistSqlstate; //用于判断表不存在的使用 + final String tablenotexistSqlstates; //用于判断表不存在的使用, 多个SQLState用;隔开 final String tablecopySQL; //用于复制表结构使用 @@ -277,7 +277,7 @@ public final class EntityInfo { this.containSQL = conf.getProperty(JDBC_CONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) > 0"); this.notcontainSQL = conf.getProperty(JDBC_NOTCONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) = 0"); - this.tablenotexistSqlstate = conf.getProperty(JDBC_TABLENOTEXIST_SQLSTATE, "42S02"); + this.tablenotexistSqlstates = ";" + conf.getProperty(JDBC_TABLENOTEXIST_SQLSTATES, "42000;42S02") + ";"; this.tablecopySQL = conf.getProperty(JDBC_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} LIKE ${oldtable}"); }