📄 jdbcdescriptorsstore.java
字号:
/**
* 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)));
}
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -