📄 cmsdescriptorsstore.java
字号:
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);
statement = null;
Enumeration children = object.enumerateChildren();
while (children.hasMoreElements()) {
if (statement == null) {
statement =
connection.prepareStatement(
"insert into children values(?, ?)");
}
statement.setString(1, object.getUri());
statement.setString(2, (String) children.nextElement());
statement.execute();
}
closeStatement(statement);
// Updating inbound links
/*
s = "delete from links where linkto='" + object.getUri() + "'";
statement.execute(s);
Enumeration links = object.enumerateLinks();
while (children.hasMoreElements()) {
s = "insert into links values('"
+ (String) links.nextElement() + "', '"
+ object.getUri() + "')";
statement.execute(s);
}
*/
// Updating links
statement =
connection.prepareStatement("delete from links where link= ?");
statement.setString(1, object.getUri());
statement.execute();
closeStatement(statement);
if (object instanceof LinkNode) {
statement =
connection.prepareStatement(
"insert into links values(?,?)");
statement.setString(1, object.getUri());
statement.setString(2, ((LinkNode) object).getLinkedUri());
statement.execute();
closeStatement(statement);
}
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Create a new object.
*
* @param object ObjectNode
* @param uri Uri of the object we want to create
* @exception ServiceAccessException Error accessing the Service
* @exception ObjectAlreadyExistsException An object already exists
* at this Uri
*/
public void createObject(Uri uri, ObjectNode object)
throws ServiceAccessException, ObjectAlreadyExistsException {
PreparedStatement statement = null;
try {
String className = object.getClass().getName();
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 ObjectAlreadyExistsException(uri.toString());
}
closeStatement(statement);
statement =
connection.prepareStatement("insert into objects values(?,?)");
statement.setString(1, uri.toString());
statement.setString(2, className);
statement.execute();
closeStatement(statement);
statement = null;
// Inserting children
Enumeration children = object.enumerateChildren();
while (children.hasMoreElements()) {
if (statement == null) {
statement =
connection.prepareStatement(
"insert into children values(?,?)");
}
statement.setString(1, uri.toString());
statement.setString(2, (String) children.nextElement());
statement.execute();
}
closeStatement(statement);
// Updating inbound links
/*
Enumeration links = object.enumerateLinks();
while (children.hasMoreElements()) {
s = "insert into links values('"
+ (String) links.nextElement() + "', '"
+ object.getUri() + "')";
statement.execute(s);
}
*/
// If the object is a link, also store the link information
if (object instanceof LinkNode) {
statement =
connection.prepareStatement(
"insert into links values(?,?)");
statement.setString(1, uri.toString());
statement.setString(2, ((LinkNode) object).getLinkedUri());
statement.execute();
closeStatement(statement);
}
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Remove an object.
*
* @param object Object to remove
* @exception ServiceAccessException Error accessing the Service
* @exception ObjectNotFoundException The object to remove was not found
*/
public void removeObject(Uri uri, ObjectNode object)
throws ServiceAccessException, ObjectNotFoundException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -