Fix two JdbcStorage bugs which were causing JMITCK failures.
1.1 --- a/mdr/extras/jdbcstorage/src/org/netbeans/mdr/persistence/jdbcimpl/JdbcMultivaluedIndex.java Mon Feb 09 20:46:56 2004 +0000
1.2 +++ b/mdr/extras/jdbcstorage/src/org/netbeans/mdr/persistence/jdbcimpl/JdbcMultivaluedIndex.java Thu Feb 12 03:32:42 2004 +0000
1.3 @@ -30,7 +30,7 @@
1.4 {
1.5 protected LazyPreparedStatement sqlDeleteWithValue;
1.6 protected LazyPreparedStatement sqlFindCount;
1.7 - protected LazyPreparedStatement sqlFindWithValue;
1.8 + protected LazyPreparedStatement sqlFindCountWithValue;
1.9
1.10 protected void defineSql()
1.11 {
1.12 @@ -45,7 +45,7 @@
1.13 "select count(*) from " + tableName
1.14 + " where " + keyColName + " = ?");
1.15
1.16 - sqlFindWithValue = new LazyPreparedStatement(
1.17 + sqlFindCountWithValue = new LazyPreparedStatement(
1.18 "select count(*) from " + tableName
1.19 + " where " + keyColName + " = ?"
1.20 + " and " + valColName + " = ?");
1.21 @@ -87,9 +87,14 @@
1.22 // checking first. What I don't understand is why this isn't an
1.23 // issue with BtreeStorage, which also enforces constraints.
1.24 int n = storage.getSingletonInt(
1.25 - sqlFindWithValue,
1.26 + sqlFindCountWithValue,
1.27 new Object[]{key,value});
1.28 if (n == 1) {
1.29 + /*
1.30 + System.out.println(
1.31 + "duplicate detected for index " + getName()
1.32 + + ": key = " + key + ", value = " + value);
1.33 + */
1.34 return;
1.35 }
1.36 // TODO: assert n == 0
1.37 @@ -188,7 +193,7 @@
1.38 value = iter.next();
1.39 if (repos != null) {
1.40 try {
1.41 - value = repos.get(value);
1.42 + return repos.get(value);
1.43 } catch (StorageException ex) {
1.44 throw new RuntimeStorageException(ex);
1.45 }
2.1 --- a/mdr/extras/jdbcstorage/src/org/netbeans/mdr/persistence/jdbcimpl/JdbcMultivaluedOrderedIndex.java Mon Feb 09 20:46:56 2004 +0000
2.2 +++ b/mdr/extras/jdbcstorage/src/org/netbeans/mdr/persistence/jdbcimpl/JdbcMultivaluedOrderedIndex.java Thu Feb 12 03:32:42 2004 +0000
2.3 @@ -34,6 +34,7 @@
2.4 protected LazyPreparedStatement sqlDeleteWithOrdinal;
2.5 protected LazyPreparedStatement sqlShiftOrdinals;
2.6 protected LazyPreparedStatement sqlFindOrdered;
2.7 + protected LazyPreparedStatement sqlFindValueOrdinal;
2.8
2.9 protected void defineSql()
2.10 {
2.11 @@ -82,6 +83,11 @@
2.12 selectOrdered + " from " + tableName
2.13 + " where " + keyColName + " = ? order by "
2.14 + keyColName + ", " + storage.ORDINAL_COL_NAME);
2.15 +
2.16 + sqlFindValueOrdinal = new LazyPreparedStatement(
2.17 + "select " + storage.ORDINAL_COL_NAME + " from " + tableName
2.18 + + " where " + keyColName + " = ?"
2.19 + + " and " + valColName + " = ?");
2.20 }
2.21
2.22 // implement MultivaluedOrderedIndex
2.23 @@ -133,7 +139,7 @@
2.24 new Long(storage.getSerialNumber())};
2.25 storage.executeUpdate(sqlInsertWithOrdinal,args);
2.26 }
2.27 -
2.28 +
2.29 // implement MultivaluedOrderedIndex
2.30 public boolean remove(Object key, int index)
2.31 throws StorageException
2.32 @@ -141,6 +147,19 @@
2.33 return removeImpl(key,index,true);
2.34 }
2.35
2.36 + // override JdbcMultivaluedIndex
2.37 + public boolean remove(Object key, Object value) throws StorageException
2.38 + {
2.39 + int index = storage.getSingletonInt(
2.40 + sqlFindValueOrdinal,
2.41 + new Object[]{key,value});
2.42 + if (index == -1) {
2.43 + return false;
2.44 + }
2.45 + remove(key,index);
2.46 + return true;
2.47 + }
2.48 +
2.49 private boolean removeImpl(Object key, int index,boolean shiftOrdinals)
2.50 throws StorageException
2.51 {
3.1 --- a/mdr/extras/jdbcstorage/src/org/netbeans/mdr/persistence/jdbcimpl/JdbcStorage.java Mon Feb 09 20:46:56 2004 +0000
3.2 +++ b/mdr/extras/jdbcstorage/src/org/netbeans/mdr/persistence/jdbcimpl/JdbcStorage.java Thu Feb 12 03:32:42 2004 +0000
3.3 @@ -905,8 +905,10 @@
3.4 bindArgs(ps,args);
3.5 jdbcResultSet = ps.executeQuery();
3.6 try {
3.7 - // TODO: assert exactly one row, one column
3.8 - jdbcResultSet.next();
3.9 + // TODO: assert exactly one column
3.10 + if (!jdbcResultSet.next()) {
3.11 + return -1;
3.12 + }
3.13 return jdbcResultSet.getInt(1);
3.14 } finally {
3.15 closeResultSet();