perfsonar-dev - r1773 - branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml
Subject: perfsonar development work
List archive
r1773 - branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml
Chronological Thread
- From:
- To:
- Subject: r1773 - branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml
- Date: Wed, 22 Nov 2006 14:59:07 -0500
Author: yi
Date: 2006-11-22 14:59:06 -0500 (Wed, 22 Nov 2006)
New Revision: 1773
Modified:
branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml/BerkeleyDbXmlStorageManager.java
Log:
improve the performance by making the manager static
Modified:
branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml/BerkeleyDbXmlStorageManager.java
===================================================================
---
branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml/BerkeleyDbXmlStorageManager.java
2006-11-22 17:10:22 UTC (rev 1772)
+++
branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml/BerkeleyDbXmlStorageManager.java
2006-11-22 19:59:06 UTC (rev 1773)
@@ -69,57 +69,50 @@
//------------------------------------------------------------------------
private static Environment myEnv = null;
- private XmlManager myManager = null;
- private XmlContainer myContainer = null;
+ private static XmlManager myManager = null;
+ private XmlContainer myContainer;
- public BerkeleyDbXmlStorageManager ()
+ public BerkeleyDbXmlStorageManager () throws SystemException
{
- myEnv = null;
- myManager = null;
- myContainer = null;
- }
-
- private void openManager () throws DatabaseException,
FileNotFoundException
- {
- // Environment
- if (myEnv == null)
+ try
{
- File envHome = new File (XML_DB_HOME);
- EnvironmentConfig envConf = new EnvironmentConfig();
-
- envConf.setCacheSize(50 * 1024 * 1024);
- envConf.setAllowCreate(true);
- envConf.setInitializeCache(true);
- envConf.setTransactional(true);
- envConf.setInitializeLocking(true);
- envConf.setInitializeLogging(true);
- if (DEBUG) { envConf.setErrorStream (System.err); }
-
- myEnv = new Environment(envHome, envConf);
+ // Environment
+ if (myEnv == null)
+ {
+ File envHome = new File (XML_DB_HOME);
+ EnvironmentConfig envConf = new
EnvironmentConfig();
+
+ envConf.setCacheSize(50 * 1024 * 1024);
+ envConf.setAllowCreate(true);
+ envConf.setInitializeCache(true);
+ if (DEBUG) { envConf.setErrorStream
(System.err); }
+
+ myEnv = new Environment(envHome, envConf);
+ }
+
+ // XmlManager
+ if (myManager == null)
+ {
+ XmlManagerConfig managerConf = new
XmlManagerConfig ();
+ // set this to be true,
+ // so we don't worry to open the
corresponding container when doing the query
+ managerConf.setAllowAutoOpen(true);
+ myManager = new XmlManager (myEnv,
managerConf);
+ if (DEBUG)
+ {
+
XmlManager.setLogLevel(XmlManager.LEVEL_ALL, true);
+
XmlManager.setLogCategory(XmlManager.CATEGORY_ALL, true);
+ }
+ }
}
-
- // XmlManager
- XmlManagerConfig managerConf = new XmlManagerConfig ();
- //avoid using setAdoptEnvironment when you set
setAllowAutoOpen to be true
- //managerConf.setAdoptEnvironment(true);
- managerConf.setAllowAutoOpen(true);
- myManager = new XmlManager (myEnv, managerConf);
-
- if (DEBUG)
- {
- XmlManager.setLogLevel(XmlManager.LEVEL_ALL, true);
- XmlManager.setLogCategory(XmlManager.CATEGORY_ALL,
true);
- }
- }
-
- public void open() throws SystemException
- {
- try {
- openManager ();
- }
- catch (DatabaseException e)
+ catch (XmlException e)
{
throw new SystemException("error.common.storage.xmldb.query",
+ "Can't initiate Berkeley XML DB Manager:
"+e.getMessage());
+ }
+ catch (DatabaseException e)
+ {
+ throw new SystemException("error.common.storage.xmldb.query",
"Can't find Berkeley DB: "+e.getMessage());
}
catch (FileNotFoundException e)
@@ -127,55 +120,52 @@
throw new SystemException("error.common.storage.xmldb.query",
"Can't find Berkeley DB evironment:
"+e.getMessage());
}
+
+ myContainer = null;
}
- public void open(String container) throws SystemException
+ public void openContainer(String container) throws SystemException
{
- try {
- openManager ();
-
+ // initially I open the Enviroment and XMLManager here,
+ // but I think now it is more reasonable to make them static,
+ // because once initialize, they are going to be used forever
+ try {
// XmlContainer
XmlContainerConfig containerConf = new XmlContainerConfig();
myContainer = myManager.openContainer(container,
containerConf);
}
- catch (DatabaseException e)
+ catch (XmlException e)
{
throw new SystemException("error.common.storage.xmldb.query",
- "Can't find Berkeley DB: "+e.getMessage());
+ "Can't Open Berkeley DB container: "+e.getMessage());
}
- catch (FileNotFoundException e)
- {
- throw new SystemException("error.common.storage.xmldb.query",
- "Can't find Berkeley DB evironment:
"+e.getMessage());
- }
}
- public void close() throws SystemException
+ public void closeContainer() throws SystemException
{
try
{
if (myContainer != null)
myContainer.close();
- if (myManager != null)
- myManager.close();
-
myContainer = null;
- myManager = null;
}
catch (XmlException e)
{
throw new SystemException("error.common.storage.xmldb.query",
- "Can't disconnect Berkeley DB:
"+e.getMessage());
+ "Can't Disconnect Berkeley DB
container: "+e.getMessage());
}
}
public Object fetch(Object dataQuery) throws SystemException,
RequestException, DataFormatException
{
String queryString = null;
- try {
+ try
+ {
queryString = (String)dataQuery;
- } catch (ClassCastException ex) {
+ }
+ catch (ClassCastException e)
+ {
throw new
DataFormatException("error.common.storage.xmldb.wrong_query",
"BerkelyDbXmlStorageManager: This method accepts " +
"StringData data format only");
@@ -184,7 +174,7 @@
return fetch (queryString);
}
- public Object fetch(String queryString) throws SystemException,
RequestException, DataFormatException
+ public Object fetch(String queryString) throws SystemException,
DataFormatException
{
if (queryString == null)
{
@@ -195,8 +185,6 @@
try
{
- this.open();
-
// XmlQueryContext
XmlQueryContext qc = myManager.createQueryContext();
@@ -211,8 +199,6 @@
value = results.next();
xmlResults[i] = value.asString();
}
-
- this.close();
// determine return type
if (getResultType() == XmlDbConstants.RETURN_STRING_ARRAY)
@@ -229,7 +215,7 @@
}
}
- public void insertDocument (String container, String insertData) throws
SystemException, RequestException, DataFormatException
+ public void insertDocument (String container, String insertData) throws
SystemException, DataFormatException
{
if (insertData == null)
{
@@ -240,7 +226,7 @@
try
{
- this.open(container);
+ this.openContainer(container);
// XmlUpdateContext
XmlUpdateContext uc = myManager.createUpdateContext();
@@ -253,7 +239,7 @@
myContainer.putDocument(theDoc, uc, documentConf);
- this.close();
+ this.closeContainer();
}
catch (XmlException e)
{
@@ -262,7 +248,7 @@
}
}
- public void insert (String container, String namespaceDecl, String
xPath, String insertData) throws SystemException, RequestException,
DataFormatException
+ public void insert (String container, String namespaceDecl, String
xPath, String insertData) throws SystemException, DataFormatException
{
if (insertData == null)
{
@@ -273,7 +259,7 @@
try
{
- this.open(container);
+ this.openContainer(container);
// Find the result set to be inserted
XmlQueryContext qc = myManager.createQueryContext();
@@ -294,7 +280,7 @@
mod.execute(docValue, qc, uc);
}
- this.close();
+ this.closeContainer();
}
catch (XmlException e)
{
@@ -303,7 +289,7 @@
}
}
- public void deleteDocument (String container, String namespaceDecl,
String xPath) throws SystemException, RequestException, DataFormatException
+ public void deleteDocument (String container, String namespaceDecl,
String xPath) throws SystemException, DataFormatException
{
if (xPath == null)
{
@@ -314,7 +300,7 @@
try
{
- this.open(container);
+ this.openContainer(container);
// Perform the query
XmlQueryContext qc = myManager.createQueryContext();
@@ -329,7 +315,7 @@
myContainer.deleteDocument(theDoc, uc);
}
- this.close();
+ this.closeContainer();
}
catch (XmlException e)
{
@@ -338,7 +324,7 @@
}
}
- public void delete (String container, String namespaceDecl, String
xPath) throws SystemException, RequestException, DataFormatException
+ public void delete (String container, String namespaceDecl, String
xPath) throws SystemException, DataFormatException
{
if (xPath == null)
{
@@ -349,7 +335,7 @@
try
{
- this.open(container);
+ this.openContainer(container);
// Perform the query
XmlQueryContext qc = myManager.createQueryContext();
@@ -370,7 +356,7 @@
mod.execute(docValue, qc, uc);
}
- this.close();
+ this.closeContainer();
}
catch (XmlException e)
{
@@ -379,7 +365,7 @@
}
}
- public void update (String container, String namespaceDecl, String
xPath, String updateData) throws SystemException, RequestException,
DataFormatException
+ public void update (String container, String namespaceDecl, String
xPath, String updateData) throws SystemException, DataFormatException
{
if (updateData == null)
{
@@ -390,7 +376,7 @@
try
{
- this.open(container);
+ this.openContainer(container);
// Find the result set to be updated
XmlQueryContext qc = myManager.createQueryContext();
@@ -411,7 +397,7 @@
mod.execute(docValue, qc, uc);
}
- this.close();
+ this.closeContainer();
}
catch (XmlException e)
{
- r1773 - branches/yi-udel/perfsonar/src/org/perfsonar/service/commons/storage/xmldb/bdbxml, svnlog, 11/22/2006
Archive powered by MHonArc 2.6.16.