OSDN Git Service

modified: build/classes/parauni/CommandController.class
authorYouhei KARIKAWA <karihei@users.sourceforge.jp>
Thu, 22 Oct 2009 15:34:32 +0000 (00:34 +0900)
committerYouhei KARIKAWA <karihei@users.sourceforge.jp>
Thu, 22 Oct 2009 15:34:32 +0000 (00:34 +0900)
modified:   build/classes/parauni/UserTaskModel.class
modified:   build/classes/parauni/UserTaskView.class
modified:   puc.db
modified:   src/parauni/DataBase.java

15 files changed:
build.xml
build/classes/parauni/CommandController.class
build/classes/parauni/DataBase.class
build/classes/parauni/TextView.class
build/classes/parauni/UserTaskModel.class
build/classes/parauni/UserTaskView.class
nbproject/private/private.properties
nbproject/project.properties
puc.db
sample.db [deleted file]
src/parauni/CommandController.java
src/parauni/DataBase.java
src/parauni/TextView.java
src/parauni/UserTaskModel.java
src/parauni/UserTaskView.java

index 7162122..fad5f9d 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- You may freely edit this file. See commented blocks below for -->
+<!-- You may fteely edit this file. See commented blocks below for -->
 <!-- some examples of how to customize the build. -->
 <!-- (If you delete it and reopen the project it will be recreated.) -->
 <!-- By default, only the Clean and Build commands use this build script. -->
index aa1144e..7ad4d0b 100644 (file)
Binary files a/build/classes/parauni/CommandController.class and b/build/classes/parauni/CommandController.class differ
index 13b9132..cccebdd 100644 (file)
Binary files a/build/classes/parauni/DataBase.class and b/build/classes/parauni/DataBase.class differ
index 52edbac..f57318b 100644 (file)
Binary files a/build/classes/parauni/TextView.class and b/build/classes/parauni/TextView.class differ
index c7b6639..079f4e0 100644 (file)
Binary files a/build/classes/parauni/UserTaskModel.class and b/build/classes/parauni/UserTaskModel.class differ
index 1844c36..987fb89 100644 (file)
Binary files a/build/classes/parauni/UserTaskView.class and b/build/classes/parauni/UserTaskView.class differ
index a528210..64eb81f 100644 (file)
@@ -3,5 +3,5 @@ do.depend=false
 do.jar=true
 javac.debug=true
 javadoc.preview=true
-jaxws.endorsed.dir=/home/karihei/programs/netbeans-6.7.1/java2/modules/ext/jaxws21/api:/home/karihei/programs/netbeans-6.7.1/ide11/modules/ext/jaxb/api
-user.properties.file=/home/karihei/.netbeans/6.7/build.properties
+jaxws.endorsed.dir=/Applications/NetBeans/NetBeans 6.7.1.app/Contents/Resources/NetBeans/java2/modules/ext/jaxws21/api:/Applications/NetBeans/NetBeans 6.7.1.app/Contents/Resources/NetBeans/ide11/modules/ext/jaxb/api
+user.properties.file=/Users/yohey/.netbeans/6.7/build.properties
index 03f28ba..e305df3 100644 (file)
@@ -24,7 +24,8 @@ excludes=
 includes=**
 jar.compress=false
 javac.classpath=\
-    ${libs.SQLite3JDBC3.6.17.3.classpath}
+    ${libs.SQLite3JDBC3.6.17.3.classpath}:\
+    ${libs.SQLite-puc.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=
 javac.deprecation=false
@@ -46,6 +47,12 @@ javadoc.splitindex=true
 javadoc.use=true
 javadoc.version=false
 javadoc.windowtitle=
+jnlp.codebase.type=local
+jnlp.codebase.url=file:/Users/yohey/git/para-repos/dist/
+jnlp.descriptor=application
+jnlp.enabled=false
+jnlp.offline-allowed=false
+jnlp.signed=false
 main.class=parauni.Main
 manifest.file=manifest.mf
 meta.inf.dir=${src.dir}/META-INF
diff --git a/puc.db b/puc.db
index 6279c7d..5fb4bb7 100644 (file)
Binary files a/puc.db and b/puc.db differ
diff --git a/sample.db b/sample.db
deleted file mode 100644 (file)
index d0bd27e..0000000
Binary files a/sample.db and /dev/null differ
index 8debc22..09eec1e 100644 (file)
@@ -31,7 +31,7 @@ public class CommandController {
 
         } else if(head.equals("lstask")){
             utaskview.showTaskList();
-        } else if(head.equals("")){
+        } else if(head.equals("vmrun")){
 
         } else if(head.equals("exit")){
             return false;
index 4f2e644..8585bb7 100644 (file)
@@ -14,10 +14,18 @@ import java.util.regex.Pattern;
  * @author karihei
  */
 public class DataBase {
+    String TASK_TBL = "task_tbl";
+    Connection con;
+    Statement st;
 
-    public DataBase(){
+    public DataBase() throws SQLException{
         try {
             Class.forName("org.sqlite.JDBC");
+            con = DriverManager.getConnection("jdbc:sqlite:puc.db");
+            st = con.createStatement();
+            st.setQueryTimeout(1);
+            con.setAutoCommit(false);
+            
         } catch (ClassNotFoundException ex) {
             Logger.getLogger(DataBase.class.getName()).log(Level.SEVERE, null, ex);
         }
@@ -25,8 +33,8 @@ public class DataBase {
     
     // データベースを初期化
     public void initDB() throws SQLException{
-        Connection con = DriverManager.getConnection("jdbc:sqlite:puc.db");
-        Statement st = con.createStatement();
+        con = DriverManager.getConnection("jdbc:sqlite:puc.db");
+        st = con.createStatement();
         st.executeUpdate("create table task_tbl (" +
                 "TASKID int," +
                 "TASKNAME string," +
@@ -37,12 +45,15 @@ public class DataBase {
 
     
     }
+    public void commit() throws SQLException{
+        con.commit();
+    }
 
     public ResultSet executeQuery(String sql) throws SQLException{
-        Connection con = DriverManager.getConnection("jdbc:sqlite:puc.db");
-        Statement st = con.createStatement();
-        return st.executeQuery(sql);
+        ResultSet rs = st.executeQuery(sql);
+        return rs;
     }
+            
 
     public int executeUpdate(String sql) throws SQLException{
         Connection con = DriverManager.getConnection("jdbc:sqlite:puc.db");
@@ -50,6 +61,12 @@ public class DataBase {
         return st.executeUpdate(sql);
     }
 
+    public void close() throws SQLException{
+        Connection con = DriverManager.getConnection("jdbc:sqlite:puc.db");
+        Statement st = con.createStatement();
+        st.close();
+    }
+
     public boolean isDate(String date){
         if(Pattern.matches("\\d{4}-\\d{2}-\\d{2}", date)){
             return true;
@@ -58,4 +75,12 @@ public class DataBase {
         }
 
     }
+
+    public Connection getConnection(){
+        return con;
+    }
+
+    public Statement getStatment(){
+        return st;
+    }
 }
index e752e1b..f58cd2d 100644 (file)
@@ -3,6 +3,7 @@ package parauni;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.sql.SQLException;
 
 /**
  *
@@ -11,11 +12,11 @@ import java.io.InputStreamReader;
 public class TextView {
     String com = new String();
     CommandController cntl = new CommandController();
-    public TextView() throws IOException{
+    public TextView() throws IOException, SQLException, ClassNotFoundException{
         run();
     }
 
-    private void run() throws IOException{
+    private void run() throws IOException, SQLException, ClassNotFoundException{
         BufferedReader buf = new BufferedReader(new InputStreamReader(System.in),1);
         System.out.println("Welcome to Parallel Universe Computer System!");
 
index 7fb4f18..034017e 100644 (file)
@@ -106,5 +106,17 @@ public class UserTaskModel {
                 "'"+outline+"')");
 
     }
+
+    // 配列の要素中で最大の文字数を返す
+    public int getMaxStrLength(String[] str){
+        int count = -1;
+
+        for(int i = 0;i < str.length;i++){
+            if(str[i].length() > count){
+                count = str[i].length();
+            }
+        }
+        return count;
+    }
 }
 
index cc270fc..f9054d6 100644 (file)
@@ -3,7 +3,11 @@ package parauni;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Hashtable;
 
 /**
  *
@@ -72,5 +76,113 @@ public class UserTaskView {
     // タスクリストを表示
     public void showTaskList() throws SQLException{
         DataBase db = new DataBase();
+        Connection con = db.getConnection();
+        Statement st = db.getStatment();
+
+        ResultSet rs0 = db.executeQuery("select count(*) from "+db.TASK_TBL);
+        rs0.next();
+        int tasknum = rs0.getInt(1);
+        
+        
+        // 各要素の文字列の最大値を得るため、をいったん配列にストア
+        String taskid[]  = new String[tasknum];
+        String tname[]   = new String[tasknum];
+        String vmid[]    = new String[tasknum];
+        String sdate[]   = new String[tasknum];
+        String edate[]   = new String[tasknum];
+        String outline[] = new String[tasknum];
+        System.out.println(tasknum);
+        
+      
+        ResultSet rs = db.executeQuery("select * from "+db.TASK_TBL);
+        for(int i = 0;rs.next();i++){
+            taskid[i] = rs.getString("TASKID");
+            tname[i] = rs.getString("TASKNAME");
+            vmid[i] = rs.getString("VMID");
+            sdate[i] = rs.getString("SDATE");
+            edate[i] = rs.getString("EDATE");
+            outline[i] = rs.getString("OUTLINE");
+        }
+
+
+        UserTaskModel utaskmodel = new UserTaskModel();
+
+               String[] field = {"TaskID","TaskName","OutLine","StartDate","DeadLine"};
+
+
+               // 各要素の文字列の最大値。並順は下記と対応させること。
+               int[] max = {utaskmodel.getMaxStrLength(taskid),
+                       utaskmodel.getMaxStrLength(tname),
+                       utaskmodel.getMaxStrLength(outline),
+                       utaskmodel.getMaxStrLength(sdate),
+                       utaskmodel.getMaxStrLength(edate)};
+
+               // 枠の描写
+               printBorder(field,max);
+
+               // 属性の列挙
+               // 各要素の文字列の最大値が属性値の文字数より多い場合、整形のため空白文字を追加する。
+           System.out.print("|");
+               for(int i = 0;i < field.length;i++){
+                   // 属性名 > 要素の最長文字列
+                       if(field[i].length() > max[i]){
+                               System.out.print(field[i]+"|");
+                               max[i] = field[i].length();
+                   }else {
+                               int d = max[i] - field[i].length();
+                               System.out.print(field[i]);
+                               for(int j = 0;j < d;j++){
+                                       System.out.print(" ");
+                               }
+                               System.out.print("|");
+                       }
+               }
+               System.out.println("");
+
+               // 枠の描写
+               printBorder(field,max);
+
+               // 要素の列挙
+               String[][] elem = {taskid,tname,outline,sdate,edate};
+               for(int i = 0;i < taskid.length;i++){
+                       for(int j = 0;j < elem.length;j++){
+                               int d = 0;
+                               System.out.print("|" + elem[j][i]);
+                               if(max[j] > elem[j][i].length()){
+                                       d = max[j] - elem[j][i].length();
+                               }
+                               for(int k = 0;k < d;k++){
+                                       System.out.print(" ");
+                               }
+                       }
+                       System.out.println("|");
+               }
+
+               // 枠の描写
+               printBorder(field,max);
+
+               db.close();
     }
+
+
+
+       private void printBorder(String[] field, int[] max){
+           System.out.print("+");
+               for(int i = 0;i < field.length;i++){
+                   // 属性名 > 要素の最長文字列
+                       if(field[i].length() > max[i]){
+                               for(int k = 0;k < field[i].length();k++){
+                                               System.out.print("-");
+                               }
+                               System.out.print("+");
+                               max[i] = field[i].length();
+                   }else {
+                               for(int j = 0;j < max[i];j++){
+                                       System.out.print("-");
+                               }
+                               System.out.print("+");
+                       }
+               }
+               System.out.println("");
+       }
 }