Updated
This commit is contained in:
parent
e68d29e64e
commit
1abc761fe6
@ -1,8 +1,6 @@
|
|||||||
package org.warp.cowdb;
|
package org.warp.cowdb;
|
||||||
|
|
||||||
import com.esotericsoftware.kryo.Kryo;
|
import com.esotericsoftware.kryo.Kryo;
|
||||||
import com.esotericsoftware.kryo.io.ByteBufferInput;
|
|
||||||
import com.esotericsoftware.kryo.io.ByteBufferInputStream;
|
|
||||||
import com.esotericsoftware.kryo.io.Input;
|
import com.esotericsoftware.kryo.io.Input;
|
||||||
import com.esotericsoftware.kryo.io.Output;
|
import com.esotericsoftware.kryo.io.Output;
|
||||||
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
|
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
|
||||||
@ -15,7 +13,6 @@ import org.apache.commons.lang3.reflect.FieldUtils;
|
|||||||
import org.warp.jcwdb.ann.*;
|
import org.warp.jcwdb.ann.*;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOError;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -29,7 +26,6 @@ import java.util.*;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static org.warp.cowdb.IBlocksMetadata.EMPTY_BLOCK_ID;
|
import static org.warp.cowdb.IBlocksMetadata.EMPTY_BLOCK_ID;
|
||||||
import static org.warp.cowdb.IBlocksMetadata.EMPTY_BLOCK_INFO;
|
|
||||||
|
|
||||||
public class Database implements IDatabase {
|
public class Database implements IDatabase {
|
||||||
|
|
||||||
@ -206,6 +202,8 @@ public class Database implements IDatabase {
|
|||||||
private final IDatabase database;
|
private final IDatabase database;
|
||||||
private final DatabaseReferencesIO referencesIO;
|
private final DatabaseReferencesIO referencesIO;
|
||||||
|
|
||||||
|
private final Object accessLock = new Object();
|
||||||
|
|
||||||
private Kryo kryo = new Kryo();
|
private Kryo kryo = new Kryo();
|
||||||
|
|
||||||
private DatabaseObjectsIO(IDatabase database, DatabaseReferencesIO referencesIO) {
|
private DatabaseObjectsIO(IDatabase database, DatabaseReferencesIO referencesIO) {
|
||||||
@ -268,6 +266,7 @@ public class Database implements IDatabase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends EnhancedObject> T loadEnhancedObject(long reference, Class<T> objectType) throws IOException {
|
public <T extends EnhancedObject> T loadEnhancedObject(long reference, Class<T> objectType) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -284,12 +283,13 @@ public class Database implements IDatabase {
|
|||||||
}
|
}
|
||||||
return preloadEnhancedObject(objectType, fieldRefs, methodRefs);
|
return preloadEnhancedObject(objectType, fieldRefs, methodRefs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Object loadData(DBDataType propertyType, long dataReference, Supplier<Class<?>> returnType) throws IOException {
|
private Object loadData(DBDataType propertyType, long dataReference, Supplier<Class<?>> returnType) throws IOException {
|
||||||
switch (propertyType) {
|
switch (propertyType) {
|
||||||
case DATABASE_OBJECT:
|
case ENHANCED_OBJECT:
|
||||||
return loadEnhancedObject(dataReference, (Class<? extends EnhancedObject>) returnType.get());
|
return loadEnhancedObject(dataReference, (Class<? extends EnhancedObject>) returnType.get());
|
||||||
case OBJECT:
|
case OBJECT:
|
||||||
return loadObject(dataReference);
|
return loadObject(dataReference);
|
||||||
@ -338,7 +338,7 @@ public class Database implements IDatabase {
|
|||||||
case REFERENCES_LIST:
|
case REFERENCES_LIST:
|
||||||
setReferencesList(reference, (LongArrayList) loadedPropertyValue);
|
setReferencesList(reference, (LongArrayList) loadedPropertyValue);
|
||||||
break;
|
break;
|
||||||
case DATABASE_OBJECT:
|
case ENHANCED_OBJECT:
|
||||||
setEnhancedObject(reference, (EnhancedObject) loadedPropertyValue);
|
setEnhancedObject(reference, (EnhancedObject) loadedPropertyValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -346,6 +346,7 @@ public class Database implements IDatabase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends EnhancedObject> void setEnhancedObject(long reference, T value) throws IOException {
|
public <T extends EnhancedObject> void setEnhancedObject(long reference, T value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
EnhancedObjectFullInfo objectFullInfo = value.getAllInfo();
|
EnhancedObjectFullInfo objectFullInfo = value.getAllInfo();
|
||||||
int totalSize = Integer.BYTES * 2 + objectFullInfo.getFieldReferences().length * Long.BYTES + objectFullInfo.getPropertyReferences().length * Long.BYTES;
|
int totalSize = Integer.BYTES * 2 + objectFullInfo.getFieldReferences().length * Long.BYTES + objectFullInfo.getPropertyReferences().length * Long.BYTES;
|
||||||
@ -374,10 +375,12 @@ public class Database implements IDatabase {
|
|||||||
referencesIO.writeToReference(reference, 0, null);
|
referencesIO.writeToReference(reference, 0, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> T loadObject(long reference) throws IOException {
|
public <T> T loadObject(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -386,9 +389,11 @@ public class Database implements IDatabase {
|
|||||||
byte[] data = buffer.array();
|
byte[] data = buffer.array();
|
||||||
return (T) kryo.readClassAndObject(new Input(data));
|
return (T) kryo.readClassAndObject(new Input(data));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LongArrayList loadReferencesList(long reference) throws IOException {
|
public LongArrayList loadReferencesList(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return null;
|
return null;
|
||||||
@ -400,63 +405,77 @@ public class Database implements IDatabase {
|
|||||||
}
|
}
|
||||||
return arrayList;
|
return arrayList;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean loadBoolean(long reference) throws IOException {
|
public boolean loadBoolean(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return buffer.get() == 1;
|
return buffer.get() == 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte loadByte(long reference) throws IOException {
|
public byte loadByte(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return buffer.get();
|
return buffer.get();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short loadShort(long reference) throws IOException {
|
public short loadShort(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return buffer.getShort();
|
return buffer.getShort();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char loadChar(long reference) throws IOException {
|
public char loadChar(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return buffer.getChar();
|
return buffer.getChar();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int loadInt(long reference) throws IOException {
|
public int loadInt(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return buffer.getInt();
|
return buffer.getInt();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long loadLong(long reference) throws IOException {
|
public long loadLong(long reference) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
ByteBuffer buffer = referencesIO.readFromReference(reference);
|
||||||
if (buffer.limit() == 0) {
|
if (buffer.limit() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return buffer.getLong();
|
return buffer.getLong();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void setObject(long reference, T value) throws IOException {
|
public <T> void setObject(long reference, T value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
Output output = new Output(outputStream);
|
Output output = new Output(outputStream);
|
||||||
@ -469,9 +488,11 @@ public class Database implements IDatabase {
|
|||||||
referencesIO.writeToReference(reference, 0, null);
|
referencesIO.writeToReference(reference, 0, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReferencesList(long reference, LongArrayList value) throws IOException {
|
public void setReferencesList(long reference, LongArrayList value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
int items = value.size();
|
int items = value.size();
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * items + Integer.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * items + Integer.BYTES);
|
||||||
@ -485,64 +506,81 @@ public class Database implements IDatabase {
|
|||||||
referencesIO.writeToReference(reference, 0, null);
|
referencesIO.writeToReference(reference, 0, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBoolean(long reference, boolean value) throws IOException {
|
public void setBoolean(long reference, boolean value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES);
|
||||||
buffer.put(value ? (byte) 1 : (byte) 0);
|
buffer.put(value ? (byte) 1 : (byte) 0);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
referencesIO.writeToReference(reference, Byte.BYTES, buffer);
|
referencesIO.writeToReference(reference, Byte.BYTES, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setByte(long reference, byte value) throws IOException {
|
public void setByte(long reference, byte value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Byte.BYTES);
|
||||||
buffer.put(value);
|
buffer.put(value);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
referencesIO.writeToReference(reference, Byte.BYTES, buffer);
|
referencesIO.writeToReference(reference, Byte.BYTES, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShort(long reference, short value) throws IOException {
|
public void setShort(long reference, short value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Short.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Short.BYTES);
|
||||||
buffer.putShort(value);
|
buffer.putShort(value);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
referencesIO.writeToReference(reference, Short.BYTES, buffer);
|
referencesIO.writeToReference(reference, Short.BYTES, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChar(long reference, char value) throws IOException {
|
public void setChar(long reference, char value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Character.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Character.BYTES);
|
||||||
buffer.putChar(value);
|
buffer.putChar(value);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
referencesIO.writeToReference(reference, Character.BYTES, buffer);
|
referencesIO.writeToReference(reference, Character.BYTES, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInt(long reference, int value) throws IOException {
|
public void setInt(long reference, int value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
|
||||||
buffer.putInt(value);
|
buffer.putInt(value);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
referencesIO.writeToReference(reference, Integer.BYTES, buffer);
|
referencesIO.writeToReference(reference, Integer.BYTES, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLong(long reference, long value) throws IOException {
|
public void setLong(long reference, long value) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
|
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
|
||||||
buffer.putLong(value);
|
buffer.putLong(value);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
referencesIO.writeToReference(reference, Long.BYTES, buffer);
|
referencesIO.writeToReference(reference, Long.BYTES, buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long newNullObject() throws IOException {
|
public long newNullObject() throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
return referencesIO.allocateReference();
|
return referencesIO.allocateReference();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadProperty(EnhancedObject obj, int propertyId, Method property, DBDataType propertyType, long propertyUID) throws IOException {
|
public void loadProperty(EnhancedObject obj, int propertyId, Method property, DBDataType propertyType, long propertyUID) throws IOException {
|
||||||
|
synchronized (accessLock) {
|
||||||
obj.setProperty(propertyId, loadData(propertyType, propertyUID, property::getReturnType));
|
obj.setProperty(propertyId, loadData(propertyType, propertyUID, property::getReturnType));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerClass(Class<?> type, int id) {
|
public void registerClass(Class<?> type, int id) {
|
||||||
@ -756,7 +794,11 @@ public class Database implements IDatabase {
|
|||||||
SeekableByteChannel currentFileChannel = metaFileChannel.position(reference * REF_META_BYTES_COUNT);
|
SeekableByteChannel currentFileChannel = metaFileChannel.position(reference * REF_META_BYTES_COUNT);
|
||||||
currentFileChannel.read(buffer);
|
currentFileChannel.read(buffer);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
return buffer.getLong();
|
long block = buffer.getLong();
|
||||||
|
if (buffer.limit() == 0 || block == 0xFFFFFFFFFFFFFFFFL) {
|
||||||
|
return EMPTY_BLOCK_ID;
|
||||||
|
}
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,8 +13,7 @@ public abstract class CowList<T> extends EnhancedObject {
|
|||||||
|
|
||||||
private final Object indicesAccessLock = new Object();
|
private final Object indicesAccessLock = new Object();
|
||||||
|
|
||||||
@DBField(id = 0, type = DBDataType.REFERENCES_LIST)
|
protected abstract LongArrayList getIndices();
|
||||||
private LongArrayList indices;
|
|
||||||
|
|
||||||
public CowList() {
|
public CowList() {
|
||||||
|
|
||||||
@ -24,14 +23,9 @@ public abstract class CowList<T> extends EnhancedObject {
|
|||||||
super(database);
|
super(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize() throws IOException {
|
|
||||||
indices = new LongArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T get(int index) throws IOException {
|
public T get(int index) throws IOException {
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
long uid = indices.getLong(index);
|
long uid = getIndices().getLong(index);
|
||||||
return loadItem(uid);
|
return loadItem(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,21 +33,22 @@ public abstract class CowList<T> extends EnhancedObject {
|
|||||||
public void add(T value) throws IOException {
|
public void add(T value) throws IOException {
|
||||||
long uid = database.getObjectsIO().newNullObject();
|
long uid = database.getObjectsIO().newNullObject();
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
indices.add(uid);
|
getIndices().add(uid);
|
||||||
writeItemToDisk(uid, value);
|
writeItemToDisk(uid, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(int index, T value) throws IOException {
|
public void update(int index, T value) throws IOException {
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
set(index, value);
|
long uid = getIndices().getLong(index);
|
||||||
|
writeItemToDisk(uid, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int index, T value) throws IOException {
|
public void set(int index, T value) throws IOException {
|
||||||
long uid = database.getObjectsIO().newNullObject();
|
long uid = database.getObjectsIO().newNullObject();
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
indices.set(index, uid);
|
getIndices().set(index, uid);
|
||||||
writeItemToDisk(uid, value);
|
writeItemToDisk(uid, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,15 +56,15 @@ public abstract class CowList<T> extends EnhancedObject {
|
|||||||
public void add(int index, T value) throws IOException {
|
public void add(int index, T value) throws IOException {
|
||||||
long uid = database.getObjectsIO().newNullObject();
|
long uid = database.getObjectsIO().newNullObject();
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
indices.add(index, uid);
|
getIndices().add(index, uid);
|
||||||
writeItemToDisk(uid, value);
|
writeItemToDisk(uid, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getLast() throws IOException {
|
public T getLast() throws IOException {
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
if (indices.size() > 0) {
|
if (getIndices().size() > 0) {
|
||||||
return get(indices.size() - 1);
|
return get(getIndices().size() - 1);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -78,13 +73,13 @@ public abstract class CowList<T> extends EnhancedObject {
|
|||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
return indices.size() <= 0;
|
return getIndices().size() <= 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
synchronized (indicesAccessLock) {
|
synchronized (indicesAccessLock) {
|
||||||
return indices.size();
|
return getIndices().size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +90,7 @@ public abstract class CowList<T> extends EnhancedObject {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringJoiner(", ", CowList.class.getSimpleName() + "[", "]")
|
return new StringJoiner(", ", CowList.class.getSimpleName() + "[", "]")
|
||||||
.add(indices.size() + " items")
|
.add(getIndices().size() + " items")
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.warp.cowdb.lists;
|
package org.warp.cowdb.lists;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
import org.warp.cowdb.EnhancedObject;
|
import org.warp.cowdb.EnhancedObject;
|
||||||
import org.warp.cowdb.IDatabase;
|
import org.warp.cowdb.IDatabase;
|
||||||
import org.warp.jcwdb.ann.DBDataType;
|
import org.warp.jcwdb.ann.DBDataType;
|
||||||
@ -9,16 +10,30 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class EnhancedObjectCowList<T extends EnhancedObject> extends CowList<T> {
|
public class EnhancedObjectCowList<T extends EnhancedObject> extends CowList<T> {
|
||||||
|
|
||||||
|
@DBField(id = 0, type = DBDataType.REFERENCES_LIST)
|
||||||
|
private LongArrayList indices;
|
||||||
|
|
||||||
@DBField(id = 1, type = DBDataType.OBJECT)
|
@DBField(id = 1, type = DBDataType.OBJECT)
|
||||||
private Class<T> type;
|
private Class<T> type;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LongArrayList getIndices() {
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
public EnhancedObjectCowList() {
|
public EnhancedObjectCowList() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public EnhancedObjectCowList(IDatabase database, Class<T> type) throws IOException {
|
public EnhancedObjectCowList(IDatabase database, Class<T> type) throws IOException {
|
||||||
super(database);
|
super(database);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
indices = new LongArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.warp.cowdb.lists;
|
package org.warp.cowdb.lists;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
import org.warp.cowdb.EnhancedObject;
|
import org.warp.cowdb.EnhancedObject;
|
||||||
import org.warp.cowdb.IDatabase;
|
import org.warp.cowdb.IDatabase;
|
||||||
import org.warp.jcwdb.ann.DBDataType;
|
import org.warp.jcwdb.ann.DBDataType;
|
||||||
@ -9,12 +10,26 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class ObjectCowList<T> extends CowList<T> {
|
public class ObjectCowList<T> extends CowList<T> {
|
||||||
|
|
||||||
|
@DBField(id = 0, type = DBDataType.REFERENCES_LIST)
|
||||||
|
private LongArrayList indices;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LongArrayList getIndices() {
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
public ObjectCowList() {
|
public ObjectCowList() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectCowList(IDatabase database) throws IOException {
|
public ObjectCowList(IDatabase database) throws IOException {
|
||||||
super(database);
|
super(database);
|
||||||
|
indices = new LongArrayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() throws IOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.warp.jcwdb.ann;
|
package org.warp.jcwdb.ann;
|
||||||
|
|
||||||
public enum DBDataType {
|
public enum DBDataType {
|
||||||
DATABASE_OBJECT,
|
ENHANCED_OBJECT,
|
||||||
OBJECT,
|
OBJECT,
|
||||||
BOOLEAN,
|
BOOLEAN,
|
||||||
BYTE,
|
BYTE,
|
||||||
|
@ -48,10 +48,10 @@ public class NDBMultipleEnhancedObjects {
|
|||||||
|
|
||||||
public static class RootTwoClasses extends EnhancedObject {
|
public static class RootTwoClasses extends EnhancedObject {
|
||||||
|
|
||||||
@DBField(id = 0, type = DBDataType.DATABASE_OBJECT)
|
@DBField(id = 0, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public NTestUtils.RootClass class1;
|
public NTestUtils.RootClass class1;
|
||||||
|
|
||||||
@DBField(id = 1, type = DBDataType.DATABASE_OBJECT)
|
@DBField(id = 1, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public NTestUtils.RootClass class2;
|
public NTestUtils.RootClass class2;
|
||||||
|
|
||||||
public RootTwoClasses() {
|
public RootTwoClasses() {
|
||||||
@ -62,22 +62,22 @@ public class NDBMultipleEnhancedObjects {
|
|||||||
super(database);
|
super(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DBPropertyGetter(id = 0, type = DBDataType.DATABASE_OBJECT)
|
@DBPropertyGetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public NTestUtils.RootClass getClass3() {
|
public NTestUtils.RootClass getClass3() {
|
||||||
return getProperty();
|
return getProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DBPropertySetter(id = 0, type = DBDataType.DATABASE_OBJECT)
|
@DBPropertySetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public void setClass3(NTestUtils.RootClass value) {
|
public void setClass3(NTestUtils.RootClass value) {
|
||||||
setProperty(value);
|
setProperty(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DBPropertyGetter(id = 1, type = DBDataType.DATABASE_OBJECT)
|
@DBPropertyGetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public NTestUtils.RootClass getClass4() {
|
public NTestUtils.RootClass getClass4() {
|
||||||
return getProperty();
|
return getProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DBPropertySetter(id = 1, type = DBDataType.DATABASE_OBJECT)
|
@DBPropertySetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public void setClass4(NTestUtils.RootClass value) {
|
public void setClass4(NTestUtils.RootClass value) {
|
||||||
setProperty(value);
|
setProperty(value);
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ public class NTestUtils {
|
|||||||
@DBField(id = 7, type = DBDataType.REFERENCES_LIST)
|
@DBField(id = 7, type = DBDataType.REFERENCES_LIST)
|
||||||
public LongArrayList field8;
|
public LongArrayList field8;
|
||||||
|
|
||||||
@DBField(id = 8, type = DBDataType.DATABASE_OBJECT)
|
@DBField(id = 8, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public NSimplestClass field9;
|
public NSimplestClass field9;
|
||||||
|
|
||||||
public RootClass() {
|
public RootClass() {
|
||||||
@ -321,7 +321,7 @@ public class NTestUtils {
|
|||||||
return getProperty();
|
return getProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DBPropertyGetter(id = 8, type = DBDataType.DATABASE_OBJECT)
|
@DBPropertyGetter(id = 8, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public NSimplestClass get9() {
|
public NSimplestClass get9() {
|
||||||
return getProperty();
|
return getProperty();
|
||||||
}
|
}
|
||||||
@ -366,7 +366,7 @@ public class NTestUtils {
|
|||||||
setProperty(val);
|
setProperty(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DBPropertySetter(id = 8, type = DBDataType.DATABASE_OBJECT)
|
@DBPropertySetter(id = 8, type = DBDataType.ENHANCED_OBJECT)
|
||||||
public void set9(NSimplestClass val) {
|
public void set9(NSimplestClass val) {
|
||||||
setProperty(val);
|
setProperty(val);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user