OSDN Git Service

20170615
[rapideact/rapideact.git] / com / rapide_act / CmnUtils.java
index 76249d6..4734afc 100644 (file)
@@ -31,9 +31,21 @@ 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{
        
+       protected static void emptyFile(String _file) throws Exception{
+               PrintWriter pw = null;
+               try {
+                       pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
+                       pw.close();
+               }
+               catch (Exception e){
+                       throw e;
+               }
+       }
+
        protected static void writeCsv(String _file, int _columnCount, ArrayList<String> _alData) throws Exception{
                PrintWriter pw = null;
                try {
@@ -59,6 +71,31 @@ public class CmnUtils{
                }
        }
 
+       protected static void writeSeparator(String _file, int _columnCount, ArrayList<String> _alData, String _sprtr) throws Exception{
+               PrintWriter pw = null;
+               try {
+                       debugPrint("Start write Separator," + "columnCount=" + _columnCount);
+                       pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(_file))));
+                       for(int i=0;i<_alData.size();i++){
+                               pw.print(_alData.get(i).replaceAll("\n","\r\n"));
+                               if (_columnCount == 1){
+                                       pw.println("");
+                               } else {
+                                       if ((i+1) % _columnCount == 0 && i > 0){
+                                               pw.println("");
+                                       } else {
+                                               pw.print(_sprtr);
+                                       }
+                               }
+                       }
+                       pw.close();
+                       debugPrint("End write Separator");
+               }
+               catch (Exception e){
+                       throw e;
+               }
+       }
+
        protected static void printConsole(int _columnCount, ArrayList<String> _alData) throws Exception{
                try {
                        debugPrint("Start console print");
@@ -289,18 +326,70 @@ public class CmnUtils{
                }
        }
 
+       protected static boolean isColLength(String _colType) throws Exception{
+               if(
+                       _colType.toUpperCase().equals("RAW") ||
+                       _colType.toUpperCase().equals("BINARY") ||
+                       _colType.toUpperCase().equals("VARBINARY") ||
+                       _colType.toUpperCase().equals("CHAR") ||
+                       _colType.toUpperCase().equals("NCHAR") || 
+                       _colType.toUpperCase().equals("VARCHAR") || 
+                       _colType.toUpperCase().equals("VARCHAR2") || 
+                       _colType.toUpperCase().equals("NVARCHAR") || 
+                       _colType.toUpperCase().equals("NVARCHAR2")
+               ){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       protected static boolean isColPrec(String _colType, String _colPrec) throws Exception{
+               if(
+                       !_colPrec.equals("") && 
+                       !_colPrec.equals("0") && 
+                       (
+                               _colType.toUpperCase().equals("DECIMAL") ||
+                               _colType.toUpperCase().equals("NUMBER") || 
+                               _colType.toUpperCase().equals("NUMERIC")
+                       )
+               ){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       protected static int getColLength(String _colType, String _colLen) throws Exception{
+               if(
+                       _colType.toUpperCase().equals("NCHAR") ||
+                       _colType.toUpperCase().equals("NVARCHAR") ||
+                       _colType.toUpperCase().equals("NVARCHAR2")){
+                               return Integer.parseInt(_colLen)/2;
+               } else {
+                       return Integer.parseInt(_colLen);
+               }
+       }
+
        protected static boolean isColString(String _str) throws Exception{
                if(
+                       _str.toUpperCase().equals("LONG") ||
                        _str.toUpperCase().equals("XML") ||
                        _str.toUpperCase().equals("UNIQUEIDENTIFIER") ||
                        _str.toUpperCase().equals("TEXT") ||
                        _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") ||
                        _str.toUpperCase().equals("NVARCHAR") ||
                        _str.toUpperCase().equals("NVARCHAR2") ||
+                       _str.toUpperCase().equals("LONG VARCHAR") ||
+                       _str.toUpperCase().equals("GRAPHIC") ||
+                       _str.toUpperCase().equals("VARGRAPHIC") ||
+                       _str.toUpperCase().equals("LONG VARGRAPHIC") ||
                        _str.toUpperCase().equals("MVARCHAR")){
                        return true;
                } else {
@@ -308,6 +397,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")){
@@ -353,6 +453,7 @@ public class CmnUtils{
                        _str.toUpperCase().equals("NUMBER") ||
                        _str.toUpperCase().equals("MONEY") ||
                        _str.toUpperCase().equals("SMALLMONEY") ||
+                       _str.toUpperCase().equals("DECFLOAT") ||
                        _str.toUpperCase().equals("DECIMAL")){
                        return true;
                } else {
@@ -376,6 +477,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 {
@@ -389,7 +493,9 @@ public class CmnUtils{
                        _str.toUpperCase().equals("MEDIUMINT UNSIGNED") ||
                        _str.toUpperCase().equals("BIGINT UNSIGNED") ||
                        _str.toUpperCase().equals("BIGINT") ||
-                       _str.toUpperCase().equals("LONG")){
+                       _str.toUpperCase().equals("BIGSERIAL") ||
+                       _str.toUpperCase().equals("SERIAL8") ||
+                       _str.toUpperCase().equals("INT8")){
                        return true;
                } else {
                        return false;
@@ -409,6 +515,7 @@ public class CmnUtils{
        protected static boolean isColDouble(String _str) throws Exception{
                if(
                        _str.toUpperCase().equals("FLOAT") ||
+                       _str.toUpperCase().equals("DOUBLE") ||
                        _str.toUpperCase().equals("DOUBLE PRECISION")){
                        return true;
                } else {
@@ -429,6 +536,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") ||
@@ -476,6 +584,21 @@ public class CmnUtils{
                return retVal;
        }
 
+       protected static boolean isReserved(String _str) throws Exception{
+               if(
+                       _str.toUpperCase().equals("CURRENT_DATE") ||
+                       _str.toUpperCase().equals("CURRENT_TIME") ||
+                       _str.toUpperCase().equals("CURRENT_TIMESTAMP") ||
+                       _str.toUpperCase().equals("CURRENT_USER") ||
+                       _str.toUpperCase().equals("LOCALTIME") ||
+                       _str.toUpperCase().equals("LOCALTIMESTAMP") ||
+                       _str.toUpperCase().equals("NULL")){
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+       
        protected static String[] getSystemProperty(String _str) throws Exception{
                String [] retValue = null;
                if(System.getProperty(_str)!=null){
@@ -654,4 +777,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;
+       }
+
 }