diff --git a/drivers/.gitignore b/drivers/.gitignore index b3b3865..5a17421 100644 --- a/drivers/.gitignore +++ b/drivers/.gitignore @@ -1 +1 @@ -mysql-connector-java-3.0.7-stable-bin.jar +mysql-connector-*.jar diff --git a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexDirectoryImpl.java b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexDirectoryImpl.java index 7417d4e..33f8b11 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexDirectoryImpl.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexDirectoryImpl.java @@ -86,6 +86,22 @@ class IndexDirectoryImpl extends Directory } // end release + public boolean isLocked() + { + try + { // call through to the database + return m_ops.queryLock(m_ndx,m_name); + + } // end try + catch (DatabaseException e) + { // turn it into an I/O exception + logger.warn("IndexDirectoryImpl.MyLock.isLocked(): failed operation",e); + return false; + + } // end catch + + } // end isLocked + } // end class MyLock /*-------------------------------------------------------------------------------- diff --git a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps.java b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps.java index 3901722..f625426 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps.java @@ -64,6 +64,8 @@ abstract class IndexOps extends OpsBase abstract void releaseLock(int ndx, String lock) throws DatabaseException; + abstract boolean queryLock(int ndx, String lock) throws DatabaseException; + abstract void releaseAllLocks(int ndx) throws DatabaseException; } // end class IndexOps diff --git a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps_mysql.java b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps_mysql.java index feb8ce0..1acb239 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps_mysql.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/index/IndexOps_mysql.java @@ -538,6 +538,45 @@ class IndexOps_mysql extends IndexOps } // end releaseLock + boolean queryLock(int ndx, String lock) throws DatabaseException + { + Connection conn = null; + PreparedStatement stmt = null; + Statement stmt2 = null; + ResultSet rs = null; + try + { // get a connection + conn = getConnection(); + + // lock the table + stmt2 = conn.createStatement(); + stmt2.executeUpdate("LOCK TABLES ndx_locks READ;"); + + // see if the lock is present + stmt = conn.prepareStatement("SELECT ndxid FROM ndx_locks WHERE ndxid = ? AND name = ?;"); + stmt.setInt(1,ndx); + stmt.setString(2,lock); + rs = stmt.executeQuery(); + return rs.next(); // present if true + + } // end try + catch (SQLException e) + { // translate to a general DatabaseException + throw generalException(e); + + } // end catch + finally + { // shut everything down + MySQLUtils.unlockTables(conn); + SQLUtils.shutdown(rs); + SQLUtils.shutdown(stmt); + SQLUtils.shutdown(stmt2); + SQLUtils.shutdown(conn); + + } // end finally + + } // end queryLock + void releaseAllLocks(int ndx) throws DatabaseException { Connection conn = null;