KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > jdbc > hsqldb > HSQLDBDatabaseEngine


1 package com.sslexplorer.jdbc.hsqldb;
2
3 import java.io.File JavaDoc;
4 import java.text.SimpleDateFormat JavaDoc;
5 import java.util.Calendar JavaDoc;
6 import java.util.Date JavaDoc;
7
8 import com.sslexplorer.boot.ContextHolder;
9 import com.sslexplorer.jdbc.JDBCDatabaseEngine;
10
11 public class HSQLDBDatabaseEngine extends JDBCDatabaseEngine {
12
13     private boolean serverMode;
14     private File JavaDoc dbDir;
15
16     public HSQLDBDatabaseEngine() {
17         super("HSQLDB", "org.hsqldb.jdbcDriver");
18         serverMode = "true".equalsIgnoreCase(System.getProperty("sslexplorer.hsqldb.tcpipServer"));
19         dbDir = ContextHolder.getContext().getDBDirectory();
20     }
21
22     public String JavaDoc getURL() {
23         if (serverMode) {
24             return "jdbc:hsqldb:hsql://127.0.0.1:9001/" + getDatabase();
25         } else {
26             return "jdbc:hsqldb:file:" + ContextHolder.getContext().getDBDirectory() + "/" + getDatabase();
27         }
28     }
29
30     public boolean isDatabaseExists() {
31         return new File JavaDoc(dbDir, getDatabase() + ".data").exists();
32     }
33
34     public String JavaDoc formatTimestamp(Calendar JavaDoc c) {
35         SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ss.SSS");
36         return sdf.format(new Date JavaDoc(c.getTimeInMillis()));
37     }
38     
39     public void setDBDir(File JavaDoc dbDir) {
40         this.dbDir = dbDir;
41     }
42 }
43
Popular Tags