📄 cmsdescriptorsstore.java
字号:
}
closeStatement(statement);
statement =
connection.prepareStatement(
"select * from revision where uri= ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
while (res.next()) {
String currentRevisionNumber = res.getString(REVISION_NUMBER);
// We parse the revision list of the object
if (statement2 == null) {
statement2 =
connection.prepareStatement(
"select * from branches where uri = ? and xnumber = ?");
}
statement2.setString(1, uri.toString());
statement2.setString(2, currentRevisionNumber);
ResultSet res2 = statement2.executeQuery();
Vector childList = new Vector();
while (res2.next()) {
childList.addElement(
new NodeRevisionNumber(
res2.getString(BRANCHES_CHILDNUMBER)));
}
branches.put(
new NodeRevisionNumber(currentRevisionNumber),
childList);
res2.close();
}
closeStatement(statement2);
revisionDescriptors =
new NodeRevisionDescriptors(
uri.toString(),
initialRevision,
workingRevisions,
latestRevisionNumbers,
branches,
isVersioned);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
closeStatement(statement2);
}
return revisionDescriptors;
}
/**
* Create a new revision information object.
*
* @param uri Uri
* @param revisionDescriptors Node revision descriptors
* @exception ServiceAccessException Service access error
*/
public void createRevisionDescriptors(
Uri uri,
NodeRevisionDescriptors revisionDescriptors)
throws ServiceAccessException {
// TODO : Here, we have the option of "cleaning up" before
// creating the new records in the database.
PreparedStatement statement = null;
try {
ResultSet res = null;
// Creating record in revisions tables
int isVersioned = 0;
if (revisionDescriptors.isVersioned()) {
isVersioned = 1;
}
statement =
connection.prepareStatement(
"insert into revisions values(?,?,?)");
statement.setString(1, uri.toString());
statement.setInt(2, isVersioned);
statement.setString(
3,
revisionDescriptors.getInitialRevision().toString());
statement.execute();
closeStatement(statement);
// Creating records in working revisions table
// ... TODO (working revisions are not used for now)
// Creating records in latest revisions table
// For now, only the latest revision from the main branch is stored
if (revisionDescriptors.getLatestRevision() != null) {
statement =
connection.prepareStatement(
"insert into latestrevisions values(?,?,?)");
statement.setString(1, uri.toString());
statement.setString(
2,
NodeRevisionDescriptors.MAIN_BRANCH.toString());
statement.setString(
3,
revisionDescriptors.getLatestRevision().toString());
statement.execute();
closeStatement(statement);
}
// Creating records in the branches table
// TODO
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Update revision information.
*
* @param uri Uri
* @param revisionDescriptors Node revision descriptors
* @exception ServiceAccessException Service access error
* @exception RevisionDescriptorNotFoundException Revision descriptor
* was not found
*/
public void storeRevisionDescriptors(
Uri uri,
NodeRevisionDescriptors revisionDescriptors)
throws ServiceAccessException, RevisionDescriptorNotFoundException {
removeRevisionDescriptors(uri);
createRevisionDescriptors(uri, revisionDescriptors);
}
/**
* Remove revision information.
*
* @param uri Uri
* @exception ServiceAccessException Service access error
*/
public void removeRevisionDescriptors(Uri uri)
throws ServiceAccessException {
PreparedStatement statement = null;
try {
statement =
connection.prepareStatement(
"delete from revisions where uri= ?");
statement.setString(1, uri.toString());
statement.execute();
closeStatement(statement);
statement =
connection.prepareStatement(
"delete from workingrevision where uri= ?");
statement.setString(1, uri.toString());
statement.execute();
closeStatement(statement);
statement =
connection.prepareStatement(
"delete from latestrevisions where uri= ?");
statement.setString(1, uri.toString());
statement.execute();
closeStatement(statement);
statement =
connection.prepareStatement(
"delete from branches where uri= ?");
statement.setString(1, uri.toString());
statement.execute();
closeStatement(statement);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Retrieve an individual object's revision descriptor.
*
* @param Uri uri
* @param revisionNumber Node revision number
*/
public NodeRevisionDescriptor retrieveRevisionDescriptor(
Uri uri,
NodeRevisionNumber revisionNumber)
throws ServiceAccessException, RevisionDescriptorNotFoundException {
NodeRevisionDescriptor revisionDescriptor = null;
PreparedStatement statement = null;
if (revisionNumber == null) {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
try {
ResultSet res = null;
String branchName = null;
Vector labels = new Vector();
Hashtable properties = new Hashtable();
// Retrieving branch name (and also check that revision
// does indeed exist)
statement =
connection.prepareStatement(
"select * from revision where uri= ? and xnumber = ?");
statement.setString(1, uri.toString());
statement.setString(2, revisionNumber.toString());
res = statement.executeQuery();
if (res.next()) {
branchName = res.getString(REVISION_BRANCHNAME);
} else {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
closeStatement(statement);
// Retrieve labels
statement =
connection.prepareStatement(
"select * from label where uri= ? and xnumber = ?");
statement.setString(1, uri.toString());
statement.setString(2, revisionNumber.toString());
res = statement.executeQuery();
while (res.next()) {
labels.addElement(res.getString(LABEL_LABEL));
}
closeStatement(statement);
// Retrieve properties
statement =
connection.prepareStatement(
"select * from property where uri= ? and xnumber = ?");
statement.setString(1, uri.toString());
statement.setString(2, revisionNumber.toString());
res = statement.executeQuery();
while (res.next()) {
String propertyName = res.getString(PROPERTY_NAME);
String propertyNamespace = res.getString(PROPERTY_NAMESPACE);
NodeProperty property =
new NodeProperty(
propertyName,
res.getString(PROPERTY_VALUE),
propertyNamespace,
res.getString(PROPERTY_TYPE),
(res.getInt(PROPERTY_PROTECTED) == 1));
properties.put(propertyNamespace + propertyName, property);
}
revisionDescriptor =
new NodeRevisionDescriptor(
revisionNumber,
branchName,
labels,
properties);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
return revisionDescriptor;
}
/**
* Create a new revision descriptor.
*
* @param uri Uri
* @param revisionDescriptor Node revision descriptor
* @exception ServiceAccessException Service access error
*/
public void createRevisionDescriptor(
Uri uri,
NodeRevisionDescriptor revisionDescriptor)
throws ServiceAccessException {
PreparedStatement statement = null;
try {
ResultSet res = null;
statement =
connection.prepareStatement(
"insert into revision values(?, ?, ?)");
statement.setString(1, uri.toString());
statement.setString(
2,
revisionDescriptor.getRevisionNumber().toString());
statement.setString(3, revisionDescriptor.getBranchName());
statement.execute();
closeStatement(statement);
// Creating revision labels
statement = null;
Enumeration labels = revisionDescriptor.enumerateLabels();
while (labels.hasMoreElements()) {
if (statement == null) {
statement =
connection.prepareStatement(
"insert into label values(?,?,?)");
}
statement.setString(1, uri.toString());
statement.setString(
2,
revisionDescriptor.getRevisionNumber().toString());
statement.setString(3, (String) labels.nextElement());
statement.execute();
}
closeStatement(statement);
// Creating associated properties
statement = null;
Enumeration properties = revisionDescriptor.enumerateProperties();
while (properties.hasMoreElements()) {
NodeProperty property = (NodeProperty) properties.nextElement();
int protectedProperty = 0;
if (property.isProtected()) {
protectedProperty = 1;
}
if (statement == null) {
statement =
connection.prepareStatement(
"insert into property values(?,?,?,?,?,?,?)");
}
statement.setString(1, uri.toString());
statement.setString(
2,
revisionDescriptor.getRevisionNumber().toString());
statement.setString(3, property.getName());
statement.setString(4, property.getValue().toString());
statement.setString(5, property.getNamespace());
statement.setString(6, property.getType());
statement.setInt(7, protectedProperty);
statement.execute();
}
closeStatement(statement);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Update a revision descriptor.
*
* @param uri Uri
* @param revisionDescriptors Node revision descriptor
* @exception ServiceAccessException Service access error
* @exception RevisionDescriptorNotFoundException Revision descriptor
* was not found
*/
public void storeRevisionDescriptor(
Uri uri,
NodeRevisionDescriptor revisionDescriptor)
throws ServiceAccessException, RevisionDescriptorNotFoundException {
removeRevisionDescriptor(uri, revisionDescriptor.getRevisionNumber());
createRevisionDescriptor(uri, revisionDescriptor);
}
/**
* Remove a revision descriptor.
*
* @param uri Uri
* @param revisionNumber Revision number
* @exception ServiceAccessException Service access error
*/
public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber number)
throws ServiceAccessException {
PreparedStatement statement = null;
try {
statement =
connection.prepareStatement(
"delete from revision where uri= ? and xnumber = ?");
statement.setString(1, uri.toString());
statement.setString(2, number.toString());
statement.execute();
closeStatement(statement);
// Removing revision labels
statement =
connection.prepareStatement(
"delete from label where uri= ? and xnumber = ?");
statement.setString(1, uri.toString());
statement.setString(2, number.toString());
statement.execute();
closeStatement(statement);
// Removing associated properties
statement =
connection.prepareStatement(
"delete from property where uri= ? and xnumber = ?");
statement.setString(1, uri.toString());
statement.setString(2, number.toString());
statement.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
// ------------------------------------------------------ Protected Methods
/**
* Close specified statement.
*/
protected void closeStatement(Statement statement) {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -