Marked plutodb as deprecated until made stable

This commit is contained in:
Tefek 2020-09-03 02:53:09 +02:00
parent 744baf102a
commit 8763691e77
7 changed files with 34 additions and 17 deletions

View File

@ -6,18 +6,18 @@ import java.nio.ByteBuffer;
public interface ILMDBValueRecipe public interface ILMDBValueRecipe
{ {
public int sizeOf(); int sizeOf();
public void serialize(ByteBuffer output); void serialize(ByteBuffer output);
public void deserialize(ByteBuffer input); void deserialize(ByteBuffer input);
public static int sizeOfUTF8(CharSequence string) static int sizeOfUTF8(CharSequence string)
{ {
return Integer.BYTES + MemoryUtil.memLengthUTF8(string, false); return Integer.BYTES + MemoryUtil.memLengthUTF8(string, false);
} }
public static void putUTF8(CharSequence string, ByteBuffer output) static void putUTF8(CharSequence string, ByteBuffer output)
{ {
int strLen = MemoryUtil.memUTF8(string, false, output, output.position() + Integer.BYTES); int strLen = MemoryUtil.memUTF8(string, false, output, output.position() + Integer.BYTES);
output.putInt(strLen); output.putInt(strLen);
@ -25,7 +25,7 @@ public interface ILMDBValueRecipe
output.position(output.position() + strLen); output.position(output.position() + strLen);
} }
public static String getUTF8(ByteBuffer input) static String getUTF8(ByteBuffer input)
{ {
var strLen = input.getInt(); var strLen = input.getInt();
var string = MemoryUtil.memUTF8(input, strLen); var string = MemoryUtil.memUTF8(input, strLen);

View File

@ -42,7 +42,12 @@ public class LMDBDatabase<K extends LMDBKey, V extends ILMDBValueRecipe>
var valueStruct = MDBVal.mallocStack(stack).mv_data(data).mv_size(size); var valueStruct = MDBVal.mallocStack(stack).mv_data(data).mv_size(size);
assert LMDB.mdb_put(this.transaction.getAddress(), this.handle, keyStruct, valueStruct, 0) == LMDB.MDB_SUCCESS; int retval = LMDB.mdb_put(this.transaction.getAddress(), this.handle, keyStruct, valueStruct, 0);
if (retval != LMDB.MDB_SUCCESS)
{
throw new RuntimeException(String.format("Error: mdb_put failed with the following error code: %d", retval));
}
} }
} }
@ -68,7 +73,12 @@ public class LMDBDatabase<K extends LMDBKey, V extends ILMDBValueRecipe>
var valueStruct = MDBVal.mallocStack(stack); var valueStruct = MDBVal.mallocStack(stack);
assert LMDB.mdb_get(this.transaction.getAddress(), this.handle, keyStruct, valueStruct) == LMDB.MDB_SUCCESS; int retval = LMDB.mdb_get(this.transaction.getAddress(), this.handle, keyStruct, valueStruct);
if (retval != LMDB.MDB_SUCCESS)
{
throw new RuntimeException(String.format("Error: mdb_get failed with the following error code: %d", retval));
}
valueToUpdate.deserialize(valueStruct.mv_data()); valueToUpdate.deserialize(valueStruct.mv_data());

View File

@ -5,7 +5,7 @@ import org.lwjgl.util.lmdb.MDBVal;
public class LMDBIntegerKey extends LMDBKey public class LMDBIntegerKey extends LMDBKey
{ {
private int key; private final int key;
private LMDBIntegerKey(int key) private LMDBIntegerKey(int key)
{ {

View File

@ -5,7 +5,7 @@ import org.lwjgl.util.lmdb.MDBVal;
public class LMDBLongKey extends LMDBKey public class LMDBLongKey extends LMDBKey
{ {
private long key; private final long key;
private LMDBLongKey(long key) private LMDBLongKey(long key)
{ {

View File

@ -5,7 +5,7 @@ import org.lwjgl.util.lmdb.MDBVal;
public class LMDBStringKey extends LMDBKey public class LMDBStringKey extends LMDBKey
{ {
private String key; private final String key;
private LMDBStringKey(String key) private LMDBStringKey(String key)
{ {

View File

@ -73,11 +73,7 @@ public class LMDBTransaction implements AutoCloseable
{ {
return new LMDBDatabase<K, V>(this, dbHandle, recipeClazz); return new LMDBDatabase<K, V>(this, dbHandle, recipeClazz);
} }
catch (NoSuchMethodException e) catch (NoSuchMethodException | IllegalAccessException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
@ -87,7 +83,13 @@ public class LMDBTransaction implements AutoCloseable
public void commit() public void commit()
{ {
LMDB.mdb_txn_commit(this.ptr); int returnCode = LMDB.mdb_txn_commit(this.ptr);
if (returnCode != LMDB.MDB_SUCCESS)
{
throw new RuntimeException(String.format("Error: mdb_txn_commit failed with the following error code: %d", returnCode));
}
this.uncommited = false; this.uncommited = false;
} }

View File

@ -0,0 +1,5 @@
/**
* @deprecated Usage discouraged until tested well enough.
* */
@Deprecated
package cz.tefek.pluto.lmdb;