📄 jdbcdescriptorsstore.java
字号:
*
* @exception ServiceInitializationFailedException Throws an exception
* if the data source has already been initialized before
*/
public synchronized void initialize(NamespaceAccessToken token)
throws ServiceInitializationFailedException
{
try
{
// Loading and registering driver
token.getLogger().log("Loading and registering driver: " + driver,LOG_CHANNEL,Logger.INFO);
Class driverClass = Class.forName(driver);
Driver databaseDriver = (Driver) driverClass.newInstance();
DriverManager.registerDriver(databaseDriver);
}
catch (ClassNotFoundException e)
{
token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
throw new ServiceInitializationFailedException(this, e.getMessage());
}
catch (InstantiationException e)
{
token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
throw new ServiceInitializationFailedException(this, e.getMessage());
}
catch (IllegalAccessException e)
{
token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
throw new ServiceInitializationFailedException(this, e.getMessage());
}
catch (SQLException e)
{
token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
throw new ServiceInitializationFailedException(this, e.getMessage());
}
catch (ClassCastException e)
{
token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
throw new ServiceInitializationFailedException(this, e.getMessage());
}
catch (Exception e)
{
token.getLogger().log("Loading and registering driver " + driver + " failed",LOG_CHANNEL,Logger.ERROR);
token.getLogger().log(e.toString(),LOG_CHANNEL,Logger.ERROR);
throw new ServiceInitializationFailedException(this, e.getMessage());
}
}
/**
* Deletes data source. Should remove stored data if possible.
*
* @exception ServiceResetFailedException Reset failed
*/
public synchronized void reset()
throws ServiceResetFailedException
{
Statement statement = null;
/*
try {
connectIfNeeded();
statement = connection.createStatement();
String s = null;
s = "drop table objects";
statement.execute(s);
s = "drop table children";
statement.execute(s);
s = "drop table links";
statement.execute(s);
s = "drop table permissions";
statement.execute(s);
s = "drop table locks";
statement.execute(s);
s = "drop table revisions";
statement.execute(s);
s = "drop table workingrevision";
statement.execute(s);
s = "drop table latestrevisions";
statement.execute(s);
s = "drop table branches";
statement.execute(s);
s = "drop table revision";
statement.execute(s);
s = "drop table label";
statement.execute(s);
s = "drop table property";
statement.execute(s);
statement.close();
disconnect();
} catch (SQLException e) {
throw new ServiceResetFailedException(this, e.getMessage());
} catch (ServiceAccessException e) {
throw new ServiceResetFailedException(this, e.getMessage());
} catch (ServiceConnectionFailedException e) {
throw new ServiceResetFailedException(this, e.getMessage());
} catch (ServiceDisconnectionFailedException e) {
throw new ServiceResetFailedException(this, e.getMessage());
} finally {
closeStatement(statement);
}
*/
}
/**
* This function tells whether or not the data source is connected.
*
* @return boolean true if we are connected
* @exception ServiceAccessException Error accessing DataSource
*/
public boolean isConnected()
throws ServiceAccessException
{
try
{
return ((connection != null) && (!connection.isClosed()));
}
catch (SQLException e)
{
throw new ServiceAccessException(this, e);
}
}
// ----------------------------------------------------- XAResource Methods
/**
* Commit the global transaction specified by xid.
*/
public void commit(Xid xid, boolean onePhase)
throws XAException
{
super.commit(xid, onePhase);
try
{
// getLogger().log("commit",LOG_CHANNEL,Logger.DEBUG);
connection.commit();
}
catch (SQLException e)
{
throw new XAException(XAException.XA_RBCOMMFAIL);
}
alreadyEnlisted=false;
}
/**
* Inform the resource manager to roll back work done on behalf of a
* transaction branch.
*/
public void rollback(Xid xid)
throws XAException
{
super.rollback(xid);
try
{
// getLogger().log("rollback",LOG_CHANNEL,Logger.DEBUG);
connection.rollback();
}
catch (SQLException e)
{
throw new XAException(XAException.XA_HEURCOM);
}
alreadyEnlisted=false;
}
/**
* Start work on behalf of a transaction branch specified in xid.
*/
public void start(Xid xid, int flags)
throws XAException
{
super.start(xid, flags);
if (!alreadyEnlisted)
{
try
{
// getLogger().log("start",LOG_CHANNEL,Logger.DEBUG);
// discard changes made outside a tranaction
connection.rollback();
}
catch (SQLException e)
{
throw new XAException(XAException.XAER_RMERR);
}
alreadyEnlisted=true;
}
}
// ----------------------------------------------- DescriptorsStore Methods
/**
* Retrive an object.
*
* @param uri Uri of the object we want to retrieve
* @exception ServiceAccessException Error accessing the Service
* @exception ObjectNotFoundException The object to retrieve was not found
*/
public ObjectNode retrieveObject(Uri uri)
throws ServiceAccessException, ObjectNotFoundException
{
ObjectNode result = null;
PreparedStatement statement = null;
try
{
statement = connection.prepareStatement
("select * from objects where uri= ?");
statement.setString(1, uri.toString());
ResultSet res = statement.executeQuery();
// Parsing result set
String className;
if (res.next())
{
// Retrieving and loading the object
className = res.getString(OBJECTS_CLASS);
}
else
{
// Object was not found ...
throw new ObjectNotFoundException(uri);
}
closeStatement(statement);
// Then, retrieve the children
statement = connection.prepareStatement
("select * from children where uri= ?");
statement.setString(1,uri.toString());
res = statement.executeQuery();
Vector childrenVector = new Vector();
// Parse result set
while (res.next())
{
// Load each permission
childrenVector.addElement(res.getString(CHILDREN_CHILDURI));
}
closeStatement(statement);
statement = connection.prepareStatement
("select * from links where linkto= ?");
statement.setString(1,uri.toString());
res = statement.executeQuery();
Vector linksVector = new Vector();
// Parse result set
while (res.next())
{
// Load each permission
linksVector.addElement(res.getString(LINKS_LINKTO));
}
closeStatement(statement);
if (className.equals("org.apache.slide.structure.LinkNode"))
{
String linkTo = new String();
statement = connection.prepareStatement
("select * from links where link= ?");
statement.setString(1,uri.toString());
res = statement.executeQuery();
if(res.next())
{
linkTo = res.getString(LINKS_LINKTO);
}
closeStatement(statement);
result = new LinkNode(uri.toString(), childrenVector,
linksVector, linkTo);
}
else
{
try
{
Class objclass = Class.forName(className);
Class[] argClasses =
{
Class.forName("java.lang.String"),
Class.forName("java.util.Vector"),
Class.forName("java.util.Vector")
};
Object[] arguments =
{
uri.toString(),
childrenVector,
linksVector
};
Constructor constructor =
objclass.getConstructor(argClasses);
result = (ObjectNode)constructor.newInstance(arguments);
}
catch(Exception e)
{
// ClassNotFoundException, NoSuchMethodException, etc.
throw new ServiceAccessException(this, e);
}
}
}
catch (SQLException e)
{
getLogger().log(e,LOG_CHANNEL,Logger.ERROR);
throw new ServiceAccessException(this, e);
}
finally
{
closeStatement(statement);
}
return result;
}
/**
* Update an object.
*
* @param object Object to update
* @exception ServiceAccessException Error accessing the Service
* @exception ObjectNotFoundException The object to update was not found
*/
public void storeObject(Uri uri, ObjectNode object)
throws ServiceAccessException, ObjectNotFoundException
{
PreparedStatement statement = null;
try
{
statement = connection.prepareStatement
("select * from objects where uri= ?");
statement.setString(1, uri.toString());
ResultSet res = statement.executeQuery();
// Parsing result set
if (!res.next())
{
throw new ObjectNotFoundException(uri);
}
closeStatement(statement);
// Updating children
statement = connection.prepareStatement
("delete from children where uri= ?");
statement.setString(1, object.getUri());
statement.execute();
closeStatement(statement);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -