1 package com.sslexplorer.jdbc.hsqldb; 2 3 import java.io.File ; 4 import java.text.SimpleDateFormat ; 5 import java.util.Calendar ; 6 import java.util.Date ; 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 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 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 (dbDir, getDatabase() + ".data").exists(); 32 } 33 34 public String formatTimestamp(Calendar c) { 35 SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS"); 36 return sdf.format(new Date (c.getTimeInMillis())); 37 } 38 39 public void setDBDir(File dbDir) { 40 this.dbDir = dbDir; 41 } 42 } 43 | Popular Tags |