OSDN Git Service

20170319
authorkuboryu <kuboryu@yahoo.co.jp>
Sat, 18 Mar 2017 22:47:51 +0000 (07:47 +0900)
committerkuboryu <kuboryu@yahoo.co.jp>
Sat, 18 Mar 2017 22:47:51 +0000 (07:47 +0900)
com/rapide_act/CmnProperty.java
com/rapide_act/CmnUtils.java
com/rapide_act/DataAccessObjects.java
com/rapide_act/RapideLoader.java
com/rapide_act/RapideUnloader.java

index e8d96ce..5782436 100644 (file)
@@ -33,10 +33,10 @@ public class CmnProperty{
        protected static final int DB_TYPE_SQLSERVER = 1;
        protected static final int DB_TYPE_MYSQL = 2;
        protected static final int DB_TYPE_DB2 = 3;
-//     protected static final int DB_TYPE_POSTGRESQL = 4;
+       protected static final int DB_TYPE_POSTGRESQL = 4;
        protected static final int DB_TYPE_UNKNOWN = -1;
-       protected static final String [] DB_TYPE_NAME = {"ORACLE", "SQLSERVER", "MYSQL", "DB2"};
-       protected static final String [] DB_SQL_QUOTED = {"\"", "\"", "`", "\""};
+       protected static final String [] DB_TYPE_NAME = {"ORACLE", "SQLSERVER", "MYSQL", "DB2", "POSTGRESQL"};
+       protected static final String [] DB_SQL_QUOTED = {"\"", "\"", "`", "\"", "\""};
        protected static final int MASK_PTN_ALL = 0;
        protected static final int MASK_PTN_ALT = 1;
        protected static final int MASK_PTN_EDGE = 2;
@@ -97,7 +97,12 @@ public class CmnProperty{
                + " tabname "
                + " from syscat.tables "
                + " where tabschema = CURRENT_SCHEMA and ownertype = 'U' and type = 'T' "
-               + " order by tabname"
+               + " order by tabname",
+               "select "
+               + " table_name "
+               + " from information_schema.TABLES "
+               + " where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = current_schema() "
+               + " order by table_name"
        };
        protected static final String [] TK_SQL_ARRAY = {
                "select "
@@ -180,7 +185,42 @@ public class CmnProperty{
                + "  group by c.tabschema,c.tabname,c.colname,c.colseq"
                + "  ) b "
                + " on a.tabschema = b.tabschema and a.tabname = b.tabname"
-               + " order by a.tabname,b.colseq"
+               + " order by a.tabname,b.colseq",
+               "select "
+               + " a.table_name, "
+               + " b.column_name "
+               + " from "
+               + " ( "
+               + " select "
+               + " table_schema, "
+               + " table_name "
+               + " from "
+               + " information_schema.tables a"
+               + " where table_type = 'BASE TABLE' and table_schema = current_schema()"
+               + " ) a "
+               + " left outer join "
+               + " ("
+               + "     select"
+               + "             b1.table_schema,"
+               + "             b1.table_name,"
+               + "             b2.column_name,"
+               + "             b2.ordinal_position"
+               + "     from"
+               + "             information_schema.table_constraints b1,"
+               + "             information_schema.key_column_usage b2"
+               + "     where"
+               + "         b1.table_schema = current_schema() and"
+               + "             b1.table_catalog = current_database() and"
+               + "             b1.constraint_type = 'PRIMARY KEY' and"
+               + "             b1.table_catalog = b2.table_catalog and"
+               + "             b1.table_schema = b2.table_schema and"
+               + "             b1.table_name = b2.table_name and"
+               + "             b1.constraint_name = b2.constraint_name"
+               + " ) b"
+               + " on a.TABLE_SCHEMA = b.TABLE_SCHEMA "
+               + "  and a.TABLE_NAME = b.TABLE_NAME "
+               + " order by "
+               + "  a.table_name,b.ordinal_position"
        };
        
        protected String user                                   = null;
index fdb8711..6617b2d 100644 (file)
@@ -298,6 +298,7 @@ public class CmnUtils{
                        _str.toUpperCase().equals("NTEXT") ||
                        _str.toUpperCase().equals("CHARACTER") ||
                        _str.toUpperCase().equals("CHAR") ||
+                       _str.toUpperCase().equals("BPCHAR") ||
                        _str.toUpperCase().equals("NCHAR") ||
                        _str.toUpperCase().equals("VARCHAR") ||
                        _str.toUpperCase().equals("VARCHAR2") ||
@@ -314,6 +315,17 @@ public class CmnUtils{
                }
        }
 
+       protected static boolean isColBoolean(String _str) throws Exception{
+               if(
+                       _str.toUpperCase().equals("BIT") ||
+                       _str.toUpperCase().equals("BOOL") ||
+                       _str.toUpperCase().equals("BOOLEAN")){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
        protected static boolean isColDate(String _str) throws Exception{
                if(
                        _str.toUpperCase().equals("DATE")){
@@ -383,6 +395,9 @@ public class CmnUtils{
                        _str.toUpperCase().equals("INTEGER") ||
                        _str.toUpperCase().equals("SMALLINT UNSIGNED") ||
                        _str.toUpperCase().equals("MEDIUMINT") ||
+                       _str.toUpperCase().equals("SERIAL") ||
+                       _str.toUpperCase().equals("INT2") ||
+                       _str.toUpperCase().equals("INT4") ||
                        _str.toUpperCase().equals("INT")){
                        return true;
                } else {
@@ -396,6 +411,9 @@ public class CmnUtils{
                        _str.toUpperCase().equals("MEDIUMINT UNSIGNED") ||
                        _str.toUpperCase().equals("BIGINT UNSIGNED") ||
                        _str.toUpperCase().equals("BIGINT") ||
+                       _str.toUpperCase().equals("BIGSERIAL") ||
+                       _str.toUpperCase().equals("SERIAL8") ||
+                       _str.toUpperCase().equals("INT8") ||
                        _str.toUpperCase().equals("LONG")){
                        return true;
                } else {
@@ -437,6 +455,7 @@ public class CmnUtils{
 
        protected static boolean isColBlob(String _str) throws Exception{
                if(
+                       _str.toUpperCase().equals("BYTEA") ||
                        _str.toUpperCase().equals("BLOB") ||
                        _str.toUpperCase().equals("VARBINARY") ||
                        _str.toUpperCase().equals("UDT") ||
index 37c29e4..5d6f71e 100644 (file)
@@ -60,6 +60,7 @@ public class DataAccessObjects{
        private Short colShort = null;
        private Float colFloat = null;
        private Double colDouble = null;
+       private Boolean colBoolean = null;
        private java.sql.Timestamp colTimestamp = null;
        private java.sql.Time colTime = null;
        private java.sql.Date colDate = null;
@@ -403,6 +404,7 @@ public class DataAccessObjects{
                colBytes = null;
                colBlob = null;
                colClob = null;
+               colBoolean = null;
                ByteArrayOutputStream baos = null;
                InputStream is = null;
 
@@ -464,6 +466,11 @@ public class DataAccessObjects{
                        if (colBigDecimal != null) {
                                colString = colBigDecimal.toString();
                        }
+               } else if (CmnUtils.isColBoolean(_colTypeName)) {
+                       colBoolean = _rst.getBoolean(_rec_cnt);
+                       if (colBoolean != null) {
+                               colString = colBoolean.toString();
+                       }
                } else if (CmnUtils.isColShort(_colTypeName)) {
                        colShort = _rst.getShort(_rec_cnt);
                        if (colShort != null) {
@@ -608,6 +615,12 @@ public class DataAccessObjects{
                        } else {
                                stmt_ins.setNull(ins_col_count+1,java.sql.Types.SMALLINT);
                        }
+               } else if (CmnUtils.isColBoolean(colTypeName[tb_col_seq[ins_col_count]])){
+                       if (!colData[fl_col_seq[ins_col_count]].equals("")){
+                               stmt_ins.setBoolean(ins_col_count+1,Boolean.valueOf(colData[fl_col_seq[ins_col_count]]));
+                       } else {
+                               stmt_ins.setNull(ins_col_count+1,java.sql.Types.BOOLEAN);
+                       }
                } else if (CmnUtils.isColInt(colTypeName[tb_col_seq[ins_col_count]])){
                        if (!colData[fl_col_seq[ins_col_count]].equals("")){
                                stmt_ins.setInt(ins_col_count+1,Integer.parseInt(colData[fl_col_seq[ins_col_count]]));
index e25c582..67df5ad 100644 (file)
@@ -122,7 +122,7 @@ public class RapideLoader{
                        if(inFiles != null) {
                                for(int k=0;k<inFiles.length;k++){
                                        flName = CmnUtils.splitDot(inFiles[k].getName());
-                                       tbName = flName[0].toUpperCase();
+                                       tbName = flName[0];
                                        StringBuffer sbColumnName = null;
                                        TABLE_LOOP:
                                        for(int i=0;i<alData.size();i++){
@@ -409,10 +409,12 @@ public class RapideLoader{
                } catch(SQLException se) {
                        try{
                                CmnUtils.errorPrint(se.toString());
-                               while (se != null) {
-                                 System.out.println("Error Message: " + se.getMessage());
-                                 se = se.getNextException();
-                               }
+                               se.printStackTrace();
+                               //while (se != null) {
+                               //  System.out.println(se.getMessage());
+                               //  se = se.getNextException();
+                               //}
+                               dao.rollback();
                        } catch (Exception see) {}
                } catch (Exception e) {
                        try{
index 29e3f29..914980c 100644 (file)
@@ -283,6 +283,16 @@ public class RapideUnloader{
 
                        CmnUtils.infoPrint("\83f\81[\83^\83A\83\93\83\8d\81[\83h\82ð\8fI\97¹\82µ\82Ü\82µ\82½\81B");
 
+               } catch(SQLException se) {
+                       try{
+                               CmnUtils.errorPrint(se.toString());
+                               se.printStackTrace();
+                               //while (se != null) {
+                               //  System.out.println(se.getMessage());
+                               //  se = se.getNextException();
+                               //}
+                               dao.rollback();
+                       } catch (Exception see) {}
                } catch (Exception e) {                 
                        try{
                                CmnUtils.errorPrint(e.toString());