OSDN Git Service

20170304
authorkuboryu <kuboryu@yahoo.co.jp>
Fri, 3 Mar 2017 21:53:34 +0000 (06:53 +0900)
committerkuboryu <kuboryu@yahoo.co.jp>
Fri, 3 Mar 2017 21:53:34 +0000 (06:53 +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 14517b0..5a38c52 100644 (file)
@@ -36,6 +36,7 @@ public class CmnProperty{
 //     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"};
+       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;
@@ -65,17 +66,20 @@ public class CmnProperty{
        protected static final int D_DBYTEMASKCHR = 23;
        protected static final int D_MASKPTN = 24;
        protected static final int D_PROPFILE = 25;
-       protected static final int KEYS = 26;
+       protected static final int D_SPCPADDING = 26;
+       protected static final int D_FILEEXT = 27;
+       protected static final int D_SQLQUOTED = 28;
+       protected static final int KEYS = 29;
        protected static final String [] PROP_KEY = { "us","pw","url","dr","out","in","ls","ils","fe","nm",
-                                                                                               "dm","ts","tks","od","qt","bc","it","et","ic","ec",
-                                                                                               "icm","ecm","smc","dmc","mp","pf"};
+                                                                                                 "dm","ts","tks","od","qt","bc","it","et","ic","ec",
+                                                                                                 "icm","ecm","smc","dmc","mp","pf","sp","ext","sq"};
 
        protected String [] prop_val = new String[KEYS];
        protected static final String [] MASK_PTN = {"ALL", "ALT", "EDGE"};
        protected static final String DEFAULT_IN_FOLDER = "input";
        protected static final String DEFAULT_OUT_FOLDER = "output";
        protected static final String DEFAULT_PROP_FILE = "RapideAct.properties";
-       protected static String [] tSqlArray = {
+       protected static final String [] T_SQL_ARRAY = {
                "select "
                + " table_name "
                + " from user_tables "
@@ -90,7 +94,7 @@ public class CmnProperty{
                + " where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = database() "
                + " order by table_name"
        };
-       protected static String [] tkSqlArray = {
+       protected static final String [] TK_SQL_ARRAY = {
                "select "
                + "a.table_name,"
                + "d.column_name "
@@ -140,46 +144,49 @@ public class CmnProperty{
                + "  a.table_name,b.ORDINAL_POSITION"
        };
        
-       protected String user = null;
-       protected String pass = null;
-       protected String url = null;
-       protected String driver = null;
+       protected String user                                   = null;
+       protected String pass                                   = null;
+       protected String url                                    = null;
+       protected String driver                                 = null;
        protected String outFolder                              = null;
        protected String inFolder                               = null;
        protected String lineSeparator                  = System.getProperty("line.separator");
-       protected String inColLineSeparator             = System.getProperty("line.separator");
+       protected String inColLineSeparator     = System.getProperty("line.separator");
        protected String fileEncoding                   = System.getProperty("file.encoding");
        protected String nullMark                               = "";
        protected String delimiter                              = "\t";
-       protected String tSql = null;
-       protected String tkSql = null;
+       protected String fileExtension                  = "tsv";
+       protected boolean isSpcPadding                  = false;
+       protected String sqlQuoted                              = null;
+       protected String tSql                                   = null;
+       protected String tkSql                                  = null;
        protected boolean isOrder                               = false;
        protected boolean isQuotation                   = true;
-       protected int batchCount                                        = 1000;
-       protected String inclTables                             = null;
-       protected String exclTables                             = null;
+       protected int batchCount                                = 1000;
+       protected String inclTables                     = null;
+       protected String exclTables                     = null;
        protected String inclCols                               = null;
        protected String exclCols                               = null;
        protected String inclColsMask                   = null;
        protected String exclColsMask                   = null;
-       protected char singleByteMaskChar                       = '*';
+       protected char singleByteMaskChar               = '*';
        protected char doubleByteMaskChar               = '\u25A0';
-       protected String maskPattern                            = "ALT";
+       protected String maskPattern                    = "ALT";
 
-       protected String [] inclTablesArray             = null;
-       protected String [] exclTablesArray             = null;
-       protected String [] inclColsArray                       = null;
-       protected String [] exclColsArray                       = null;
-       protected String [] inclColsMaskArray           = null;
-       protected String [] exclColsMaskArray           = null;
+       protected String [] inclTablesArray     = null;
+       protected String [] exclTablesArray     = null;
+       protected String [] inclColsArray               = null;
+       protected String [] exclColsArray               = null;
+       protected String [] inclColsMaskArray   = null;
+       protected String [] exclColsMaskArray   = null;
        protected boolean isInclTables                  = false;
        protected boolean isExclTables                  = false;
-       protected boolean isInclCols                            = false;
-       protected boolean isExclCols                            = false;
-       protected boolean isMask                                        = false;
-       protected boolean isInclColsMask                        = false;
-       protected boolean isExclColsMask                        = false;
-       protected int dbType                                            = DB_TYPE_UNKNOWN;
+       protected boolean isInclCols                    = false;
+       protected boolean isExclCols                    = false;
+       protected boolean isMask                                = false;
+       protected boolean isInclColsMask                = false;
+       protected boolean isExclColsMask                = false;
+       protected int dbType                                    = DB_TYPE_UNKNOWN;
 
        protected void getProperties(String _propFile) throws Exception{
                BufferedReader br = null;
@@ -269,6 +276,8 @@ public class CmnProperty{
                if(!CmnUtils.isEmpty(prop_val[D_SBYTEMASKCHR]))singleByteMaskChar = prop_val[D_SBYTEMASKCHR].charAt(0);
                if(!CmnUtils.isEmpty(prop_val[D_DBYTEMASKCHR]))doubleByteMaskChar = prop_val[D_DBYTEMASKCHR].charAt(0);
                if(!CmnUtils.isEmpty(prop_val[D_MASKPTN]))maskPattern = prop_val[D_MASKPTN];
+               if(!CmnUtils.isEmpty(prop_val[D_SPCPADDING]) && prop_val[D_SPCPADDING].toUpperCase().equals("Y"))isSpcPadding = true;
+               if(!CmnUtils.isEmpty(prop_val[D_FILEEXT]))fileExtension = prop_val[D_FILEEXT];
 
                if(CmnUtils.isEmpty(user)){
                        throw new Exception("us(\83\86\81[\83UID)\82ª\96¢\8ew\92è\82Å\82·\81B");
@@ -290,23 +299,34 @@ public class CmnProperty{
                if (dbType != DB_TYPE_UNKNOWN){
                        if(!CmnUtils.isEmpty(prop_val[D_TBLSQL])){
                                tSql = prop_val[D_TBLSQL];
+                       } else {
+                               tSql = T_SQL_ARRAY[dbType];
+                       }
+                       if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL])){
                                tkSql = prop_val[D_TBLKEYSQL];
                        } else {
-                               tSql = tSqlArray[dbType];
-                               tkSql = tkSqlArray[dbType];
+                               tkSql = TK_SQL_ARRAY[dbType];
+                       }
+                       if(!CmnUtils.isEmpty(prop_val[D_SQLQUOTED])){
+                               sqlQuoted = prop_val[D_SQLQUOTED];
+                       } else {
+                               sqlQuoted = DB_SQL_QUOTED[dbType];
                        }
                } else {
                        throw new Exception("\83f\81[\83^\83x\81[\83X\90»\95i\82ª\8e¯\95Ê\82Å\82«\82Ü\82¹\82ñ\81B[" + url + "]");
                }
 
                if(database!=null)CmnUtils.infoPrint("-->\91Î\8fÛ\83f\81[\83^\83x\81[\83X='" + database.toUpperCase() + "'");
+               if(!CmnUtils.isEmpty(prop_val[D_FILEEXT]))CmnUtils.infoPrint("-->\83t\83@\83C\83\8b\8ag\92£\8eq='" + prop_val[D_FILEEXT] + "'");
                if(!CmnUtils.isEmpty(prop_val[D_DELIMITER]))CmnUtils.infoPrint("-->\8bæ\90Ø\82è\95\8e\9a='" + prop_val[D_DELIMITER] + "'");
                if(!CmnUtils.isEmpty(prop_val[D_LINESEP]))CmnUtils.infoPrint("-->\89ü\8ds\83R\81[\83h='" + prop_val[D_LINESEP] + "'");
                if(!CmnUtils.isEmpty(prop_val[D_INLINESEP]))CmnUtils.infoPrint("-->\83J\83\89\83\80\93à\89ü\8ds\83R\81[\83h='" + prop_val[D_INLINESEP] + "'");
                if(!CmnUtils.isEmpty(prop_val[D_FILENCODE]))CmnUtils.infoPrint("-->\95\8e\9a\83R\81[\83h='" + prop_val[D_FILENCODE] + "'");
                if(!CmnUtils.isEmpty(prop_val[D_QUOTATION]))CmnUtils.infoPrint("-->\88ø\97p\8bå=" + CmnUtils.getYesNo(isQuotation));
+               if(!CmnUtils.isEmpty(prop_val[D_SQLQUOTED]))CmnUtils.infoPrint("-->SQL\88ø\97p\95\84=" + "'" + sqlQuoted + "'");
                if(!CmnUtils.isEmpty(prop_val[D_ORDER]))CmnUtils.infoPrint("-->\83\\81[\83g=" + CmnUtils.getYesNo(isOrder));
                if(!CmnUtils.isEmpty(prop_val[D_BATCOUNT]))CmnUtils.infoPrint("-->\83o\83b\83`\8f\88\97\9d\90\94=" + batchCount);
+               if(isSpcPadding)CmnUtils.infoPrint("-->\8bó\94\92\96\84\82ß=" + CmnUtils.getYesNo(isSpcPadding));
                if(isInclTables)CmnUtils.infoPrint("-->\91Î\8fÛ\83e\81[\83u\83\8b='" + inclTables.toUpperCase() + "'");
                if(isExclTables)CmnUtils.infoPrint("-->\8f\9c\8aO\83e\81[\83u\83\8b='" + exclTables.toUpperCase() + "'");
                if(isInclCols)CmnUtils.infoPrint("-->\91Î\8fÛ\83J\83\89\83\80='" + inclCols.toUpperCase() + "'");
index 76249d6..b4109cb 100644 (file)
@@ -31,6 +31,7 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.regex.Pattern;
 import org.apache.commons.codec.binary.Base64;
+import java.nio.charset.Charset;
 
 public class CmnUtils{
        
@@ -654,4 +655,29 @@ public class CmnUtils{
                return retValue;
        }
 
+       protected static boolean isFixString(String _str) throws Exception{
+               if(
+                       _str.toUpperCase().equals("CHARACTER") ||
+                       _str.toUpperCase().equals("CHAR") ||
+                       _str.toUpperCase().equals("NCHAR")){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       protected static int getByteLength(String string, Charset charset) {
+               return string.getBytes(charset).length;
+       }
+
+       protected static String padSpace(String str, int len, Charset charset){
+               int bytelen = getByteLength(str, charset);
+               if(len > bytelen){
+                       for(int i=0; i<(len - bytelen);i++){
+                           str = str + " ";
+                       }
+               }
+               return str;
+       }
+
 }
index ec458c3..74fcd27 100644 (file)
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.math.BigInteger;
 import java.math.BigDecimal;
+import java.nio.charset.Charset;
 
 public class DataAccessObjects{
 
@@ -39,6 +40,7 @@ public class DataAccessObjects{
        private int ColumnCount = 0;
        private ArrayList<String> alColName = null;
        private ArrayList<String> alColTypeName = null;
+       private ArrayList<Integer> alColPrecision = null;
        private ArrayList<Integer> alIsNullable = null;
        private ArrayList<Boolean> alColMask = null;
        private ArrayList<Boolean> alColIncl = null;
@@ -46,6 +48,7 @@ public class DataAccessObjects{
        private static String sql="select sysdate from dual";
        private String[] colTypeName = null;
        private String[] colName = null;
+       private Integer[] colPrecision = null;
        private Integer[] isNullable = null;
        private Boolean [] colMask = null;
        private Boolean [] colIncl = null;
@@ -173,15 +176,18 @@ public class DataAccessObjects{
                        CmnUtils.debugPrint("End get ColumnCount," + ColumnCount);
                        alColTypeName = new ArrayList<String>();
                        alColName = new ArrayList<String>();
+                       alColPrecision = new ArrayList<Integer>();
                        alIsNullable = new ArrayList<Integer>();
                        alData = new ArrayList<String>();
                        for(int i=0;i<ColumnCount;i++){
                                alColTypeName.add(rsmd.getColumnTypeName(i + 1));
                                alColName.add(rsmd.getColumnName(i + 1));
+                               alColPrecision.add(rsmd.getPrecision(i + 1));
                                alIsNullable.add(rsmd.isNullable(i + 1));
                        }
                        colTypeName = (String[])alColTypeName.toArray(new String[0]);
                        colName = (String[])alColName.toArray(new String[0]);
+                       colPrecision = (Integer[])alColPrecision.toArray(new Integer[0]);
                        isNullable = (Integer[])alIsNullable.toArray(new Integer[0]);
                        
                }
@@ -248,6 +254,10 @@ public class DataAccessObjects{
                return alIsNullable;
        }
 
+       public ArrayList<Integer> getArrayPrecisionList() throws Exception{
+               return alColPrecision;
+       }
+
        public void setArrayColumnMaskList(ArrayList<Boolean> _alColMask) throws Exception{
                alColMask = _alColMask;
                colMask = (Boolean[])alColMask.toArray(new Boolean[0]);
@@ -303,6 +313,7 @@ public class DataAccessObjects{
                                                colString = getColString(rst, i + 1, colTypeName[i], isNullable[i], colMask[i]);
 
                                                if (colString != null) {
+                                                       if(CmnUtils.isFixString(colTypeName[i]) && cp.isSpcPadding)colString = colString + CmnUtils.padSpace(colString, colPrecision[i], Charset.forName(cp.fileEncoding));
                                                        if (i == _firstCol){
                                                                if(cp.isQuotation){
                                                                        if (_firstCol == _lastCol){
index 5f013ea..704f40e 100644 (file)
@@ -209,9 +209,9 @@ public class RapideLoader{
                                                                                        if(colName[l].equals(colData[j].replaceAll("\"",""))){
                                                                                                if (colIncl[tb_fl_match_count]) {
                                                                                                        if (ins_rec_count == 0){
-                                                                                                               sql_insert += colName[l];
+                                                                                                               sql_insert += cp.sqlQuoted + colName[l] + cp.sqlQuoted;
                                                                                                        } else {
-                                                                                                               sql_insert += "," + colName[l];
+                                                                                                               sql_insert += "," + cp.sqlQuoted + colName[l] + cp.sqlQuoted;
                                                                                                        }
                                                                                                        tb_col_seq[ins_rec_count]=l;
                                                                                                        fl_col_seq[ins_rec_count]=j;
index 7530302..29e3f29 100644 (file)
@@ -219,7 +219,7 @@ public class RapideUnloader{
                                                dao.setArrayColumnMaskList(alColMask);
                                                
                                                if (lastCol >= 0){
-                                                       pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(folder + "/" + alData.get(i) + ".csv"), cp.fileEncoding)));
+                                                       pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(folder + "/" + alData.get(i) + "." + cp.fileExtension), cp.fileEncoding)));
                                                        CmnUtils.infoPrinting(String.format("%1$-30s",alData.get(i)));
 
                                                        for(int j=0;j<alColName.size();j++){