hsqldb 源码剖析
程序员文章站
2022-05-24 18:52:33
...
[color=black][b]hsqldb,一个只有700多k的小型数据库.[/b]
[b]内嵌支持JDBC驱动与数据库引擎.[/b]
[u]Server模式启动流程:[/u]
[/color]
[b][color=blue]org.hsqldb.Server.java[/color][/b]
[color=black]配置文件内容server.properties
server.remote_open=false
server.database.0=[b]file:\\d:\\hsqldb\\data/dbfile[/b]
server.dbname.0=[b]dbname[/b]
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
[/color]
[color=black]启动Server命令
java -cp d:\hsqldb\lib\hsqldb.jar org.hsqldb.Server
[/color]
[b]内嵌支持JDBC驱动与数据库引擎.[/b]
[u]Server模式启动流程:[/u]
[/color]
[b][color=blue]org.hsqldb.Server.java[/color][/b]
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();
}
[color=black]配置文件内容server.properties
server.remote_open=false
server.database.0=[b]file:\\d:\\hsqldb\\data/dbfile[/b]
server.dbname.0=[b]dbname[/b]
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
[/color]
[color=black]启动Server命令
java -cp d:\hsqldb\lib\hsqldb.jar org.hsqldb.Server
[/color]
//启动服务器线程
this.serverThread = new ServerThread(this, "HSQLDB Server ");
this.serverThread.start();