读书人

hsqldb 源码剖解

发布时间: 2012-09-01 09:33:03 作者: rapoo

hsqldb 源码剖析
hsqldb,一个只有700多k的小型数据库.

内嵌支持JDBC驱动与数据库引擎.

Server模式启动流程:


org.hsqldb.Server.java

public static void main(String[] paramArrayOfString)  {    //获取并读取 server.properties 文件,若没有取默认    String str = FileUtil.getDefaultInstance().canonicalOrAbsolutePath("server");    HsqlProperties localHsqlProperties1 = ServerConfiguration.getPropertiesFromFile(str);    HsqlProperties localHsqlProperties2 = (localHsqlProperties1 == null) ? new HsqlProperties() : localHsqlProperties1;    HsqlProperties localHsqlProperties3 = null;    //获取main参数数组,加入 server.properties.保存到HsqlProperties对象.    try    {      localHsqlProperties3 = HsqlProperties.argArrayToProps(paramArrayOfString, "server");    }    catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)    {      printHelp("server.help");      return;    }    if (localHsqlProperties3 != null)    {      if (localHsqlProperties3.getErrorKeys().length != 0)      {        printHelp("server.help");        return;      }      localHsqlProperties2.addProperties(localHsqlProperties3);    }        //可略过    ServerConfiguration.translateDefaultDatabaseProperty(localHsqlProperties2);    ServerConfiguration.translateDefaultNoSystemExitProperty(localHsqlProperties2);        //创建Server,并设置属性文件.主要分配serverid.取默认协议.    Server localServer = new Server();    try    {      localServer.setProperties(localHsqlProperties2);    }    catch (Exception localException)    {      localServer.printError("Failed to set properties");      localServer.printStackTrace(localException);      return;    }    //输出初始化信息    localServer.print("Startup sequence initiated from main() method");    if (localHsqlProperties1 != null)    {      localServer.print("Loaded properties from [" + str + ".properties]");    }    else    {      localServer.print("Could not load properties from file");      localServer.print("Using cli/default properties only");    }    //启动Server.    localServer.start();  }


配置文件内容server.properties
server.remote_open=false
server.database.0=file:\\d:\\hsqldb\\data/dbfile
server.dbname.0=dbname
server.no_system_exit=false
server.restart_on_shutdown=false
server.address=127.0.0.1
server.port=12345
server.silent=true
server.trace=false


启动Server命令
java -cp d:\hsqldb\lib\hsqldb.jar org.hsqldb.Server


//启动服务器线程this.serverThread = new ServerThread(this, "HSQLDB Server ");this.serverThread.start();





读书人网 >其他数据库

热点推荐