📄 localdatabase.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: LocalDatabase.java,v 1.8 2002/09/18 06:54:13 per_nyfelt Exp $package org.ozoneDB;import org.ozoneDB.core.DbRemote.DbClient;import org.ozoneDB.core.DbRemote.DbLocalClient;import org.ozoneDB.core.Env;import org.ozoneDB.tools.Install;import org.ozoneDB.util.OzoneDebugLevel;import java.io.PrintWriter;import java.io.StringWriter;import java.util.Hashtable;/** * This class represents a local database server that runs inside the same * JVM as the client. For a detailed method description see OzoneInterface. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @author <a href="http://www.medium.net/">SMB</a> * @version $Revision: 1.8 $Date: 2002/09/18 06:54:13 $ * @see OzoneInterface */public final class LocalDatabase extends ExternalDatabase { public Env env; public String userName; public LocalDatabase() { } /** * Create a new database in the given directory using default values * for all Setup entries. * * * @param dirName The directory to create the database in * @return a StringWriter that holds the status messages * @exception java.lang.Exception * @see Setup */ public synchronized String create( String dirName ) throws Exception { //use default values Setup setup = new Setup( env ); return create( dirName, setup ); } /** * Create a new database in the given directory using the values * of the given Setup. * * @param dirName * @return a StringWriter that holds the status messages * @exception java.lang.Exception * @see Setup */ public synchronized String create( String dirName, Setup setup ) throws Exception { StringWriter writer = new StringWriter(); PrintWriter logFile = new PrintWriter( writer, true ); Install.createDB( dirName, setup, logFile ); return writer.toString(); } /** opens the database. * @param dirName is the path name of the database directory root */ public void open( String dirName) throws Exception { String username = System.getProperty( "user.name" ); open( dirName, null, username, username ); } /** * For backwards compatibility * * @deprecated but still needed by legacy software. * use open(String _dirName, String _debugLevel ) instead. * @param dirName is the path name of the database directory root * @param debugLevel should match one of the constants in OzoneDebugLevel. * Overrrides the property ozoneDB.logLevel in config.properties. */ public void open(String dirName, int debugLevel) throws Exception { String level = OzoneDebugLevel.toLevel(debugLevel, OzoneDebugLevel.INFO).toString(); open(dirName, level); } /** * Opens the database. * @param dirName is the path name of the database directory root * @param debugLevel derived from OzoneDebugLevel. * Overrrides the property ozoneDB.logLevel in config.properties. If set to null, the config.properties * setting will be used. */ public void open( String dirName, String debugLevel ) throws Exception { String username = System.getProperty( "user.name" ); open( dirName, debugLevel, username, username ); } /** * Opens the database. * @param dirName * @param debugLevel one of the String constants in OzoneDebugLevel (e.g. INFO_STR). * Overrrides the property ozoneDB.logLevel in config.properties. If set to null, the config.properties * setting will be used. * @param userName * @param password */ public void open( String dirName, String debugLevel, String userName, String password ) throws Exception { Hashtable props = new Hashtable(); props.put( PROP_DIR, dirName ); props.put( PROP_USER, userName ); props.put( PROP_PASSWD, password ); if (debugLevel != null) { props.put( PROP_DEBUG, debugLevel ); } open( props ); } protected synchronized void open( Hashtable props ) throws Exception { try { super.open( props ); String dirName = (String)props.get( PROP_DIR ); userName = (String)props.get( PROP_USER ); //String passwd = (String)props.get( PROP_PASSWD ); String debugLevel = ((String)props.get( PROP_DEBUG )); env = new Env( dirName, debugLevel); // create the user if it doesn't exist yet; in local mode we cannot use // the admin tool to do so if (env.userManager.userForName( userName ) == null) { env.userManager.newUser( userName, userName.hashCode() ); } env.startDeadlockRecognition(); } catch (Exception e) { close(); throw e; } } public boolean isOpen() throws Exception { return env != null; } public synchronized void close() throws Exception { super.close(); if (env != null) { try { env.shutdown(); } finally { env = null; } } } protected DbClient newConnection() throws org.ozoneDB.core.UserManagerException,org.ozoneDB.PermissionDeniedException { return new DbLocalClient(this,env,userName); } public String toString() { return "LocalDatabase"; } protected void finalize() throws Exception { close(); } /* Tells whether a database has been installed in the dbDir directory or not * useful for erver when starting up the ExternalDatabase and makes it possible to * determine whether to create or open a LocalDatabase */ public boolean exists(String dbDir) { return Install.dbExists(dbDir); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -