1 11 package com.nilostep.xlsql.jdbc; 12 13 import com.nilostep.xlsql.sql.*; 14 15 import java.io.*; 16 import java.sql.*; 17 import java.util.*; 18 19 import kiwi.io.*; 20 26 public class xlConnectionMcKoi extends xlConnection implements FileAcceptor { 27 29 private String context; 30 private File dbconf; 31 private File data; 32 33 35 43 public xlConnectionMcKoi(String url, 44 Properties info) throws SQLException { 45 try { 46 createMcKoiFiles(); 47 context = "APP"; 48 URL = url; 49 w = xlSqlWriterFactory.create("mckoi"); 50 51 String sql_url = "jdbc:mckoi:local://./xlsqldb.conf?create=true"; 52 dbCon = DriverManager.getConnection(sql_url, "xlsql", "xlsql"); 53 query = xlSqlSelectFactory.create("mckoi", dbCon); 54 startup(); 55 xlsql = xlSqlFactory.create("mckoi", datastore, context); 56 } catch (Exception e) { 57 throw new SQLException("xlSQL: connect to McKoi " + 58 e.getMessage()); 59 } 60 } 61 62 64 71 public void shutdown() throws Exception { 72 if (!closed) { 73 logger.info("Executing McKoi clean-up..."); 74 75 dbCon.close(); 76 rmDir(data); 77 dbconf.delete(); 78 79 closed = true; 80 logger.info("McKoi clean-up done"); 81 } 82 } 83 84 91 protected void finalize() throws Throwable { 92 shutdown(); 93 } 94 95 private void createMcKoiFiles() throws Exception { 96 97 String sDbconf = System.getProperty("user.dir") + File.separator + "xlsqldb.conf"; 98 dbconf = new File(sDbconf); 99 if (dbconf.exists()) { dbconf.delete(); } 100 FileOutputStream fs = new FileOutputStream(dbconf); 101 PrintStream pw = new PrintStream(fs); 102 103 pw.print("database_path=./xlsqldb\n"); 104 pw.print("log_path=./xlsqldb\n"); 105 pw.print("root_path=jvm\n"); 106 pw.print("ignore_case_for_identifiers=disabled\n"); 107 pw.print("regex_library=gnu.regexp\n"); 108 pw.print("data_cache_size=16777216\n"); 109 pw.print("max_cache_entry_size=8192\n"); 110 pw.print("maximum_worker_threads=4\n"); 111 pw.print("debug_log_file=debug.log\n"); 112 pw.print("debug_level=20\n"); 113 pw.close(); 114 115 String sData = System.getProperty("user.dir") + File.separator + "xlsqldb"; 116 data = new File(sData); 117 rmDir(data); 118 119 } 120 121 private void rmDir(File f) { 122 if (f.exists()) { 123 FilesystemTraverser dt = new FilesystemTraverser(f, this); 124 dt.traverse(); 125 f.delete(); 126 } 127 } 128 129 public boolean accept(java.io.File file) { 130 file.delete(); 131 return true; 132 } 133 134 public boolean accessError(java.io.File file) { 135 return false; 136 } 137 138 } 139 | Popular Tags |