📄 cmsdescriptorsstore.java
字号:
PreparedStatement statement = null;
try {
// Removing object
statement =
connection.prepareStatement("delete from objects where uri= ?");
statement.setString(1, object.getUri());
statement.execute();
closeStatement(statement);
// Removing children
statement =
connection.prepareStatement("delete from children where uri=?");
statement.setString(1, object.getUri());
statement.execute();
closeStatement(statement);
// Removing inbound links
/*
s = "delete from links where linkto='" + object.getUri() + "'";
statement.execute(s);
*/
// Removing links
statement =
connection.prepareStatement("delete from links where link= ?");
statement.setString(1, object.getUri());
statement.execute();
closeStatement(statement);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
}
}
/**
* Grant a new permission.
*
* @param permission Permission we want to create
* @exception ServiceAccessException Error accessing the Service
*/
public void grantPermission(Uri uri, NodePermission permission)
throws ServiceAccessException {
PreparedStatement statement = null;
try {
int inheritable = 0;
if (permission.isInheritable()) {
inheritable = 1;
}
int negative = 0;
if (permission.isNegative()) {
negative = 1;
}
NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
String revisionNumberStr =
(revisionNumber == null) ? null : revisionNumber.toString();
statement =
connection.prepareStatement(
"insert into permissions values(?,?,?,?,?,?)");
statement.setString(1, permission.getObjectUri());
statement.setString(2, revisionNumberStr);
statement.setString(3, permission.getSubjectUri());
statement.setString(4, permission.getActionUri());
statement.setInt(5, inheritable);
statement.setInt(6, negative);
statement.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Revoke a permission.
*
* @param permission Permission we want to create
* @exception ServiceAccessException Error accessing the Service
*/
public void revokePermission(Uri uri, NodePermission permission)
throws ServiceAccessException {
PreparedStatement statement = null;
try {
NodeRevisionNumber revisionNumber = permission.getRevisionNumber();
if (revisionNumber != null) {
statement =
connection.prepareStatement(
"delete from permissions where object= ? and subject = ? and \"ACTION\" = ? and revisionnumber = ? ");
statement.setString(4, revisionNumber.toString());
} else {
statement =
connection.prepareStatement(
"delete from permissions where object = ? and subject = ? and \"ACTION\" = ? and revisionnumber is NULL");
}
statement.setString(1, permission.getObjectUri());
statement.setString(2, permission.getSubjectUri());
statement.setString(3, permission.getActionUri());
statement.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Revoke all the permissions on an object.
*
* @param permission Permission we want to create
* @exception ServiceAccessException Error accessing the Service
*/
public void revokePermissions(Uri uri) throws ServiceAccessException {
PreparedStatement statement = null;
try {
statement =
connection.prepareStatement(
"delete from permissions where object= ?");
statement.setString(1, uri.toString());
statement.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Enumerate permissions on an object.
*
* @param permission Permission we want to create
* @exception ServiceAccessException Error accessing the Service
*/
public Enumeration enumeratePermissions(Uri uri)
throws ServiceAccessException {
Vector permissionVector = new Vector();
PreparedStatement statement = null;
try {
statement =
connection.prepareStatement(
"select * from permissions where object= ?");
statement.setString(1, uri.toString());
ResultSet res = statement.executeQuery();
while (res.next()) {
String object = res.getString(PERMISSIONS_OBJECT);
String revision = res.getString(PERMISSIONS_REVISION_NUMBER);
String subject = res.getString(PERMISSIONS_SUBJECT);
String action = res.getString(PERMISSIONS_ACTION);
boolean inheritable = false;
if (res.getInt(PERMISSIONS_INHERITABLE) == 1) {
inheritable = true;
}
boolean negative = false;
if (res.getInt(PERMISSIONS_NEGATIVE) == 1) {
negative = true;
}
NodePermission permission =
new NodePermission(
object,
revision,
subject,
action,
inheritable,
negative);
permissionVector.addElement(permission);
}
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
return permissionVector.elements();
}
/**
* Create a new lock.
*
* @param lock Lock token
* @exception ServiceAccessException Service access error
*/
public void putLock(Uri uri, NodeLock lock) throws ServiceAccessException {
PreparedStatement statement = null;
try {
int inheritable = 0;
if (lock.isInheritable()) {
inheritable = 1;
}
int exclusive = 0;
if (lock.isExclusive()) {
exclusive = 1;
}
statement =
connection.prepareStatement(
"insert into locks values(?,?,?,?,?,?,?)");
statement.setString(1, lock.getLockId());
statement.setString(2, lock.getObjectUri());
statement.setString(3, lock.getSubjectUri());
statement.setString(4, lock.getTypeUri());
statement.setString(
5,
String.valueOf(lock.getExpirationDate().getTime()));
statement.setInt(6, inheritable);
statement.setInt(7, exclusive);
statement.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Renew a lock.
*
* @param lock Token to renew
* @exception ServiceAccessException Service access error
* @exception LockTokenNotFoundException Lock token was not found
*/
public void renewLock(Uri uri, NodeLock lock)
throws ServiceAccessException, LockTokenNotFoundException {
PreparedStatement statement = null;
try {
int inheritable = 0;
if (lock.isInheritable()) {
inheritable = 1;
}
int exclusive = 0;
if (lock.isExclusive()) {
exclusive = 1;
}
statement =
connection.prepareStatement("delete from locks where id=?");
statement.setString(1, lock.getLockId());
statement.execute();
closeStatement(statement);
statement =
connection.prepareStatement(
"insert into locks values(?,?,?,?,?,?,?)");
statement.setString(1, lock.getLockId());
statement.setString(2, lock.getObjectUri());
statement.setString(3, lock.getSubjectUri());
statement.setString(4, lock.getTypeUri());
statement.setString(
5,
String.valueOf(lock.getExpirationDate().getTime()));
statement.setInt(6, inheritable);
statement.setInt(7, exclusive);
statement.execute();
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Unlock.
*
* @param lock Token to remove
* @exception ServiceAccessException Service access error
* @exception LockTokenNotFoundException Lock token was not found
*/
public void removeLock(Uri uri, NodeLock lock)
throws ServiceAccessException, LockTokenNotFoundException {
Statement statement = null;
try {
statement = connection.createStatement();
int inheritable = 0;
if (lock.isInheritable()) {
inheritable = 1;
}
String s = null;
s = "delete from locks where id='" + lock.getLockId() + "'";
statement.execute(s);
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
}
/**
* Kill a lock.
*
* @param lock Token to remove
* @exception ServiceAccessException Service access error
* @exception LockTokenNotFoundException Lock token was not found
*/
public void killLock(Uri uri, NodeLock lock)
throws ServiceAccessException, LockTokenNotFoundException {
removeLock(uri, lock);
}
/**
* Enumerate locks on an object.
*
* @param subject Subject
* @return Enumeration List of locks which have been put on the subject
* @exception ServiceAccessException Service access error
*/
public Enumeration enumerateLocks(Uri uri) throws ServiceAccessException {
Vector lockVector = new Vector();
PreparedStatement statement = null;
try {
statement =
connection.prepareStatement(
"select * from locks where object= ?");
statement.setString(1, uri.toString());
statement.execute();
ResultSet res = statement.getResultSet();
while (res.next()) {
Date expirationDate = null;
try {
Long timeValue =
new Long(res.getString(LOCKS_EXPIRATIONDATE));
expirationDate = new Date(timeValue.longValue());
} catch (NumberFormatException e) {
expirationDate = new Date();
}
NodeLock lock =
new NodeLock(
res.getString(LOCKS_ID),
res.getString(LOCKS_OBJECT),
res.getString(LOCKS_SUBJECT),
res.getString(LOCKS_TYPE),
expirationDate,
(res.getInt(LOCKS_INHERITABLE) == 1),
(res.getInt(LOCKS_EXCLUSIVE) == 1));
lockVector.addElement(lock);
}
} catch (SQLException e) {
getLogger().log(e, LOG_CHANNEL, Logger.ERROR);
throw new ServiceAccessException(this, e);
} finally {
closeStatement(statement);
}
return lockVector.elements();
}
/**
* Retrieve the revisions informations of an object.
*
* @param uri Uri
* @exception ServiceAccessException Service access error
* @exception RevisionDescriptorNotFoundException Revision descriptor
* was not found
*/
public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
throws ServiceAccessException, RevisionDescriptorNotFoundException {
NodeRevisionDescriptors revisionDescriptors = null;
PreparedStatement statement = null;
PreparedStatement statement2 = null;
try {
ResultSet res = null;
NodeRevisionNumber initialRevision = new NodeRevisionNumber();
Hashtable workingRevisions = new Hashtable();
Hashtable latestRevisionNumbers = new Hashtable();
Hashtable branches = new Hashtable();
boolean isVersioned = false;
statement =
connection.prepareStatement(
"select * from revisions where uri= ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
if (res.next()) {
int isVersionedInt = res.getInt(REVISIONS_ISVERSIONED);
if (isVersionedInt == 1) {
isVersioned = true;
}
} else {
throw new RevisionDescriptorNotFoundException(uri.toString());
}
closeStatement(statement);
statement =
connection.prepareStatement(
"select * from workingrevision where uri= ?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
while (res.next()) {
// TODO : Parse each working revision definition
}
closeStatement(statement);
statement =
connection.prepareStatement(
"select * from latestrevisions where uri=?");
statement.setString(1, uri.toString());
res = statement.executeQuery();
while (res.next()) {
latestRevisionNumbers.put(
res.getString(LATESTREVISIONS_BRANCHNAME),
new NodeRevisionNumber(
res.getString(LATESTREVISIONS_NUMBER)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -