OSDN Git Service

20170615
[rapideact/rapideact.git] / com / rapide_act / CmnUtils.java
index fdb8711..4734afc 100644 (file)
@@ -35,6 +35,17 @@ 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 {
@@ -60,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");
@@ -290,14 +326,61 @@ 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") ||
@@ -314,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")){
@@ -383,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 {
@@ -396,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;
@@ -437,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") ||
@@ -484,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){