+ String query =
+ "update content set to_locking_user=" + JDBCStringRoutines.escapeStringLiteral(aUserId) +
+ " where id = " + JDBCStringRoutines.escapeStringLiteral(anId);
+
+ if (!aForce)
+ query = query + " and to_locking_user is null";
+
+ return database.executeUpdate(query) > 0;
+ }
+ catch (Throwable t) {
+ return false;
+ }
+ }
+
+ /**
+ * Unlocks an article. Forced (that is, without checking wether it's locked by
+ * the person that unlocks it) if necessary.
+ *
+ * @param anId The article number
+ * @param aUserId The user that unlocks
+ * @param aForce Should it e forced?
+ * @return <code>true</code> if successfull, <code>false</code> if not
+ */
+ public boolean unlockArticle(String anId, String aUserId, boolean aForce) {
+ try {
+ String query =
+ "update content set to_locking_user=null" +
+ " where id = " + JDBCStringRoutines.escapeStringLiteral(anId);
+
+ if (!aForce)
+ query = query + " and to_locking_user = "+JDBCStringRoutines.escapeStringLiteral(aUserId);
+
+ return database.executeUpdate(query) > 0;
+ }
+ catch (Throwable t) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the id of the locking user of an article. <code>null</code> otherwise.
+ *
+ * @param anId
+ * @return
+ */
+ public String queryArticleLock(String anId) {
+ try {
+ String result = database.executeFreeSingleValueSql("select to_locking_user from content where id = " + JDBCStringRoutines.escapeStringLiteral(anId));
+
+ if (result!=null && !MirGlobal.isUserLoggedIn(result)) {
+ expireArticleLock(anId, result);
+ result = null;
+ }
+
+ return result;