Skip to content

Commit

Permalink
Fix class cast in remove
Browse files Browse the repository at this point in the history
KeyValue cast to DBKey issue fixed for relation deletion.
  • Loading branch information
neocoretechs committed Aug 13, 2022
1 parent b259e75 commit 0f28400
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
30 changes: 18 additions & 12 deletions src/com/neocoretechs/relatrix/Relatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,38 +329,44 @@ public static synchronized void remove(Comparable<?> d, Comparable<?> m, Compara
System.out.println("Relatrix.remove could not find relationship dmr:"+dmr);
return;
}
KeyValue kv = (KeyValue)o;
DBKey dbKey = (DBKey) kv.getmValue();
//KeyValue kv = (KeyValue)o;
//DBKey dbKey = (DBKey) kv.getmValue();
DBKey dbKey = (DBKey)o;
IndexResolver.getIndexInstanceTable().delete(dbKey);
o = RelatrixKV.get(drm);
if(o == null)
throw new IOException(drm+" not found for delete");
kv = (KeyValue)o;
dbKey = (DBKey) kv.getmValue();
//kv = (KeyValue)o;
//dbKey = (DBKey) kv.getmValue();
dbKey = (DBKey)o;
IndexResolver.getIndexInstanceTable().delete(dbKey);
o = RelatrixKV.get(mdr);
if(o == null)
throw new IOException(mdr+" not found for delete");
kv = (KeyValue)o;
dbKey = (DBKey) kv.getmValue();
//kv = (KeyValue)o;
//dbKey = (DBKey) kv.getmValue();
dbKey = (DBKey)o;
IndexResolver.getIndexInstanceTable().delete(dbKey);
o = RelatrixKV.get(mrd);
if(o == null)
throw new IOException(mrd+" not found for delete");
kv = (KeyValue)o;
dbKey = (DBKey) kv.getmValue();
//kv = (KeyValue)o;
//dbKey = (DBKey) kv.getmValue();
dbKey = (DBKey)o;
IndexResolver.getIndexInstanceTable().delete(dbKey);
o = RelatrixKV.get(rdm);
if(o == null)
throw new IOException(rdm+" not found for delete");
kv = (KeyValue)o;
dbKey = (DBKey) kv.getmValue();
//kv = (KeyValue)o;
//dbKey = (DBKey) kv.getmValue();
dbKey = (DBKey)o;
IndexResolver.getIndexInstanceTable().delete(dbKey);
o = RelatrixKV.get(rmd);
if(o == null)
throw new IOException(rmd+" not found for delete");
kv = (KeyValue)o;
dbKey = (DBKey) kv.getmValue();
//kv = (KeyValue)o;
//dbKey = (DBKey) kv.getmValue();
dbKey = (DBKey)o;
IndexResolver.getIndexInstanceTable().delete(dbKey);
} catch (ClassNotFoundException | DuplicateKeyException e) {
throw new IOException(e);
Expand Down
32 changes: 26 additions & 6 deletions src/com/neocoretechs/relatrix/client/RelatrixKVStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public synchronized String getSession() {
if( session == null ) {
session = UUID.randomUUID().toString();
if( DEBUG )
System.out.printf("%s Generated ID for %s%n",this.getClass().getName(),session);
System.out.printf("%s%n",this.toString());
}
return session;
}
Expand Down Expand Up @@ -84,9 +84,27 @@ public synchronized Class<?>[] getParams() {
return c;
}
@Override
public synchronized String toString() { return String.format("%s for Session:%s Class:%s Method:%s Arg:%s%n",
this.getClass().getName(),session,className,methodName,
(paramArray == null || paramArray.length == 0 ? "nil" : (paramArray[0] == null ? "NULL PARAM!" : paramArray[0]))); }
public synchronized String toString() {
StringBuilder sb = new StringBuilder(String.format("%s for Session:%s Class/method:%s.%s",this.getClass().getName(),session,className,methodName));
if(paramArray == null || paramArray.length == 0) {
sb.append("(void)");
} else {
sb.append("(");
for(Object param: paramArray) {
if(param == null) {
sb.append(" null,");
} else {
sb.append(" ");
sb.append(param.getClass());
sb.append(" ");
sb.append(param.toString());
sb.append(",");
}
}
sb.append(")\r\n");
}
return sb.toString();
}

@Override
public synchronized CountDownLatch getCountDownLatch() {
Expand Down Expand Up @@ -134,6 +152,8 @@ public synchronized Object getObjectReturn() {
*/
@Override
public synchronized void process() throws Exception {
if(DEBUG)
System.out.println(this);
Object result = RelatrixKVServer.relatrixMethods.invokeMethod(this);
// See if we are dealing with an object that must be remotely maintained, e.g. iterator
// which does not serialize so we front it
Expand Down Expand Up @@ -190,7 +210,7 @@ public synchronized void process() throws Exception {
} else {
setObjectReturn(result);
}
getCountDownLatch().countDown();
}
getCountDownLatch().countDown();
}

}
4 changes: 2 additions & 2 deletions src/com/neocoretechs/relatrix/key/IndexInstanceTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public void put(DBKey index, Comparable instance) throws IllegalAccessException,
try {
RelatrixKV.transactionalStore(index, instance);
} catch(DuplicateKeyException dke) {
throw new IOException(String.format("DBKey to Instance table duplicate key:%s encountered for instance:%s. Existing entry=%s/%s%n",index,instance,((KeyValue)RelatrixKV.get(index)).getmKey(),((KeyValue)RelatrixKV.get(index)).getmValue()));
throw new IOException(String.format("DBKey to Instance table duplicate key:%s encountered for instance:%s. Index class=%s Instance class=%s%n",index,instance,index.getClass().getName(),instance.getClass().getName()));
}
try {
RelatrixKV.transactionalStore(instance, index);
} catch(DuplicateKeyException dke) {
throw new IOException(String.format("Instance to DBKey duplicate instance:%s encountered for key:%s Existing entry=%s/%s%n",instance,index,((KeyValue)RelatrixKV.get(instance)).getmKey(),((KeyValue)RelatrixKV.get(instance)).getmValue()));
throw new IOException(String.format("Instance to DBKey duplicate instance:%s encountered for key:%s Instance class=%s Index class=%s%n",instance,index,instance.getClass().getName(),index.getClass().getName()));
}
classCommits.add(index.getClass());
classCommits.add(instance.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public Object lastKey(Class<DBKey> class1) throws IllegalAccessException, IOExce
try {
return rc.lastKey(DBKey.class);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
Expand Down
19 changes: 18 additions & 1 deletion src/com/neocoretechs/relatrix/server/HandlerClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,24 @@ public static void main(String[] args) throws IOException, IllegalAccessExceptio
//Path p = FileSystems.getDefault().getPath("C:/users/jg/workspace/volvex/bin/com/neocoretechs/volvex");
//setBytesInRepository("com.neocoretechs.volvex",p);
size = 0;
connectToRemoteRepository();
switch(args.length) {
case 0:
connectToRemoteRepository();
break;
case 1:
connectToRemoteRepository(args[0]);
break;
case 2:
connectToRemoteRepository(args[0], Integer.parseInt(args[1]));
break;
case 3:
connectToRemoteRepository(args[0], args[1], Integer.parseInt(args[2]));
break;
default:
System.out.println("Number of arguments is "+args.length+", using first 3 for local host, remote host, remote port...");
connectToRemoteRepository(args[0], args[1], Integer.parseInt(args[2]));
break;
}
remoteRepository.entrySetStream(String.class).of().forEach(e-> {
System.out.printf("Class: %s size:%d%n",((ClassNameAndBytes)((Map.Entry)e).getValue()).getName(),
((ClassNameAndBytes)((Map.Entry)e).getValue()).getBytes().length);
Expand Down

0 comments on commit 0f28400

Please sign in to comment.