Rebranded to strangedb

This commit is contained in:
Andrea Cavalli 2019-03-07 11:41:45 +01:00
parent 4d5075c9d1
commit 40e794d79e
60 changed files with 459 additions and 465 deletions

View File

@ -1,3 +1,3 @@
# JCWDB
# StrangeDb
Experimental database.
Strange database.

10
pom.xml
View File

@ -4,12 +4,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.warp</groupId>
<artifactId>jcwdb</artifactId>
<version>1.5.3</version>
<groupId>it.cavallium</groupId>
<artifactId>strangedb</artifactId>
<version>1.5.4</version>
<name>jcwdb</name>
<url>https://git.ignuranza.net/andreacavalli/JCWDB</url>
<name>strangedb</name>
<url>https://git.ignuranza.net/andreacavalli/strangedb</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb;
package it.cavallium.strangedb;
import java.util.Objects;
import java.util.StringJoiner;

View File

@ -1,14 +1,14 @@
package org.warp.jcwdb;
package it.cavallium.strangedb;
import it.cavallium.strangedb.database.EnhancedObjectFullInfo;
import it.cavallium.strangedb.database.IDatabaseTools;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.warp.jcwdb.database.EnhancedObjectFullInfo;
import org.warp.jcwdb.annotations.DBClass;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import org.warp.jcwdb.annotations.DBPropertyGetter;
import org.warp.jcwdb.annotations.DBPropertySetter;
import org.warp.jcwdb.database.IDatabaseTools;
import it.cavallium.strangedb.annotations.DbClass;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import it.cavallium.strangedb.annotations.DbPropertyGetter;
import it.cavallium.strangedb.annotations.DbPropertySetter;
import java.io.IOException;
import java.lang.reflect.Field;
@ -19,19 +19,19 @@ public abstract class EnhancedObject {
protected final int version;
protected IDatabaseTools databaseTools;
private Field[] fields;
private DBDataType[] fieldTypes;
private DbDataType[] fieldTypes;
private long[] fieldReferences;
private Field[] primitiveFields;
private DBPrimitiveType[] primitiveFieldTypes;
private DbPrimitiveType[] primitiveFieldTypes;
private long primitiveFieldsDataReference;
private Method[] propertyGetters;
private Method[] propertySetters;
private DBDataType[] propertyTypes;
private DbDataType[] propertyTypes;
private long[] propertyReferences;
private boolean[] loadedProperties;
private Object[] loadedPropertyValues;
private Map<String, DBPropertySetter> setterMethods;
private Map<String, DBPropertyGetter> getterMethods;
private Map<String, DbPropertySetter> setterMethods;
private Map<String, DbPropertyGetter> getterMethods;
public EnhancedObject() {
version = getClassVersion();
@ -43,27 +43,27 @@ public abstract class EnhancedObject {
databaseTools.initializeEnhancedObject(this);
}
public void setFields(Field[] fields, DBDataType[] fieldTypes, long[] fieldReferences) {
public void setFields(Field[] fields, DbDataType[] fieldTypes, long[] fieldReferences) {
this.fields = fields;
this.fieldTypes = fieldTypes;
this.fieldReferences = fieldReferences;
}
public void setPrimitiveFields(Field[] fields, DBPrimitiveType[] fieldTypes, long primitiveFieldsDataReference) {
public void setPrimitiveFields(Field[] fields, DbPrimitiveType[] fieldTypes, long primitiveFieldsDataReference) {
this.primitiveFields = fields;
this.primitiveFieldTypes = fieldTypes;
this.primitiveFieldsDataReference = primitiveFieldsDataReference;
}
public Method[] getPropertyGetters() {
return MethodUtils.getMethodsWithAnnotation(this.getClass(), DBPropertyGetter.class);
return MethodUtils.getMethodsWithAnnotation(this.getClass(), DbPropertyGetter.class);
}
public Method[] getPropertySetters() {
return MethodUtils.getMethodsWithAnnotation(this.getClass(), DBPropertySetter.class);
return MethodUtils.getMethodsWithAnnotation(this.getClass(), DbPropertySetter.class);
}
public void setProperties(Method[] propertyGetters, Method[] propertySetters, DBDataType[] propertyTypes, long[] propertyReferences, Map<String, DBPropertySetter> setterMethods, Map<String, DBPropertyGetter> getterMethods) {
public void setProperties(Method[] propertyGetters, Method[] propertySetters, DbDataType[] propertyTypes, long[] propertyReferences, Map<String, DbPropertySetter> setterMethods, Map<String, DbPropertyGetter> getterMethods) {
this.propertyGetters = propertyGetters;
this.propertySetters = propertySetters;
this.propertyTypes = propertyTypes;
@ -83,7 +83,7 @@ public abstract class EnhancedObject {
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
StackWalker.StackFrame stackFrame = walker.walk(f -> f.skip(1).findFirst().orElse(null));
try {
int propertyId = stackFrame.getDeclaringClass().getDeclaredMethod(stackFrame.getMethodName()).getAnnotation(DBPropertyGetter.class).id();
int propertyId = stackFrame.getDeclaringClass().getDeclaredMethod(stackFrame.getMethodName()).getAnnotation(DbPropertyGetter.class).id();
return getProperty(propertyId);
} catch (IOException | NoSuchMethodException e) {
throw new RuntimeException(e);
@ -102,7 +102,7 @@ public abstract class EnhancedObject {
public <T> void setProperty(T value) {
StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
StackWalker.StackFrame stackFrame = walker.walk(f -> f.skip(1).findFirst().orElse(null));
DBPropertySetter propertyAnnotation = setterMethods.get(stackFrame.getMethodName());
DbPropertySetter propertyAnnotation = setterMethods.get(stackFrame.getMethodName());
setProperty(propertyAnnotation.id(), value);
}
@ -112,7 +112,7 @@ public abstract class EnhancedObject {
}
private int getClassVersion() {
DBClass classAnnotation = this.getClass().getAnnotation(DBClass.class);
DbClass classAnnotation = this.getClass().getAnnotation(DbClass.class);
return classAnnotation == null ? 0 : classAnnotation.version();
}

View File

@ -0,0 +1,55 @@
package it.cavallium.strangedb;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import java.io.IOException;
import java.util.function.Supplier;
public interface EnhancedObjectUpgrader {
<T> T getPrimitiveField(int id, DbPrimitiveType integer) throws IOException;
default int getPrimitiveBoolean(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.BOOLEAN);
}
default int getPrimitiveByte(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.BYTE);
}
default int getPrimitiveShort(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.SHORT);
}
default int getPrimitiveChar(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.CHAR);
}
default int getPrimitiveInt(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.INTEGER);
}
default long getPrimitiveLong(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.LONG);
}
default float getPrimitiveFloat(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.FLOAT);
}
default double getPrimitiveDouble(int id) throws IOException {
return getPrimitiveField(id, DbPrimitiveType.DOUBLE);
}
Object getField(int id, DbDataType type, Supplier<Class<?>> enhancedClassType) throws IOException;
default Object getField(int id, DbDataType type) throws IOException {
return getField(id, type, null);
}
Object getMethod(int id, DbDataType type, Supplier<Class<?>> enhancedClassType) throws IOException;
default Object getMethod(int id, DbDataType type) throws IOException {
return getField(id, type, null);
}
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb;
package it.cavallium.strangedb;
public class VariableWrapper<T> {

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.annotations;
package it.cavallium.strangedb.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -7,6 +7,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface DBClass {
public @interface DbClass {
int version() default 0;
}

View File

@ -0,0 +1,7 @@
package it.cavallium.strangedb.annotations;
public enum DbDataType {
ENHANCED_OBJECT,
OBJECT,
REFERENCES_LIST
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.annotations;
package it.cavallium.strangedb.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -7,7 +7,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface DBField {
public @interface DbField {
int id();
DBDataType type() default DBDataType.OBJECT;
DbDataType type() default DbDataType.OBJECT;
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.annotations;
package it.cavallium.strangedb.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -7,7 +7,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface DBPrimitiveField {
public @interface DbPrimitiveField {
int id();
DBPrimitiveType type();
DbPrimitiveType type();
}

View File

@ -0,0 +1,12 @@
package it.cavallium.strangedb.annotations;
public enum DbPrimitiveType {
BOOLEAN,
BYTE,
SHORT,
CHAR,
INTEGER,
LONG,
FLOAT,
DOUBLE
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.annotations;
package it.cavallium.strangedb.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -7,7 +7,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DBPropertySetter {
public @interface DbPropertyGetter {
int id();
DBDataType type() default DBDataType.OBJECT;
DbDataType type() default DbDataType.OBJECT;
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.annotations;
package it.cavallium.strangedb.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -7,7 +7,7 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DBPropertyGetter {
public @interface DbPropertySetter {
int id();
DBDataType type() default DBDataType.OBJECT;
DbDataType type() default DbDataType.OBJECT;
}

View File

@ -1,7 +1,7 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.functionalinterfaces.FunctionWithIO;
import it.cavallium.strangedb.functionalinterfaces.FunctionWithIO;
import it.cavallium.strangedb.EnhancedObject;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -129,7 +129,7 @@ public class Database implements IDatabase, IDatabaseTools {
@Override
public void initializeEnhancedObject(EnhancedObject enhancedObject) throws IOException {
this.objectsIO.getDataInitializer().initializeDBObject(enhancedObject);
this.objectsIO.getDataInitializer().initializeDbObject(enhancedObject);
}
@Override

View File

@ -1,11 +1,11 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import org.warp.jcwdb.BlockInfo;
import it.cavallium.strangedb.BlockInfo;
import java.io.IOException;
import java.nio.ByteBuffer;
import static org.warp.jcwdb.database.IBlocksMetadata.EMPTY_BLOCK_ID;
import static it.cavallium.strangedb.database.IBlocksMetadata.EMPTY_BLOCK_ID;
public class DatabaseBlocksIO implements IBlocksIO {

View File

@ -1,7 +1,7 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import org.warp.jcwdb.BlockInfo;
import it.cavallium.strangedb.BlockInfo;
import java.io.IOException;
import java.nio.ByteBuffer;

View File

@ -1,9 +1,9 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import org.warp.jcwdb.BlockInfo;
import it.cavallium.strangedb.BlockInfo;
import java.io.IOException;
import java.util.LinkedList;

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;
import java.util.concurrent.Future;

View File

@ -1,8 +1,8 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import it.cavallium.strangedb.annotations.*;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.annotations.*;
import it.cavallium.strangedb.EnhancedObject;
import java.io.IOException;
import java.lang.reflect.Field;
@ -19,13 +19,13 @@ public class DatabaseDataInitializer implements IDataInitializer {
}
@Override
public void initializeDBObject(EnhancedObject obj) throws IOException {
initializeDBObjectFields(obj);
initializeDBObjectPrimitiveFields(obj);
initializeDBObjectProperties(obj);
public void initializeDbObject(EnhancedObject obj) throws IOException {
initializeDbObjectFields(obj);
initializeDbObjectPrimitiveFields(obj);
initializeDbObjectProperties(obj);
}
private void initializeDBObjectFields(EnhancedObject obj) throws IOException {
private void initializeDbObjectFields(EnhancedObject obj) throws IOException {
// Declare the variables needed to get the biggest field Id
Field[] unorderedFields = objectsIO.getFields(obj);
// Find the biggest field Id
@ -36,13 +36,13 @@ public class DatabaseDataInitializer implements IDataInitializer {
// Declare the other variables
Field[] fields = new Field[biggestFieldId + 1];
DBDataType[] orderedFieldTypes = new DBDataType[biggestFieldId + 1];
DbDataType[] orderedFieldTypes = new DbDataType[biggestFieldId + 1];
// Load all fields metadata and load them
for (Field field : unorderedFields) {
DBField fieldAnnotation = field.getAnnotation(DBField.class);
DbField fieldAnnotation = field.getAnnotation(DbField.class);
int fieldId = fieldAnnotation.id();
DBDataType fieldType = fieldAnnotation.type();
DbDataType fieldType = fieldAnnotation.type();
objectsIO.loadField(obj, field, fieldType, fieldUIDs[fieldId]);
fields[fieldId] = field;
orderedFieldTypes[fieldId] = fieldType;
@ -51,7 +51,7 @@ public class DatabaseDataInitializer implements IDataInitializer {
obj.setFields(fields, orderedFieldTypes, fieldUIDs);
}
private void initializeDBObjectPrimitiveFields(EnhancedObject obj) throws IOException {
private void initializeDbObjectPrimitiveFields(EnhancedObject obj) throws IOException {
// Declare the variables needed to get the biggest field Id
Field[] unorderedFields = objectsIO.getPrimitiveFields(obj);
// Find the biggest field Id
@ -62,14 +62,14 @@ public class DatabaseDataInitializer implements IDataInitializer {
// Declare the other variables
Field[] fields = new Field[biggestFieldId + 1];
DBPrimitiveType[] orderedFieldTypes = new DBPrimitiveType[biggestFieldId + 1];
DbPrimitiveType[] orderedFieldTypes = new DbPrimitiveType[biggestFieldId + 1];
// Load all fields metadata and load them
try {
for (Field field : unorderedFields) {
DBPrimitiveField fieldAnnotation = field.getAnnotation(DBPrimitiveField.class);
DbPrimitiveField fieldAnnotation = field.getAnnotation(DbPrimitiveField.class);
int fieldId = fieldAnnotation.id();
DBPrimitiveType fieldType = fieldAnnotation.type();
DbPrimitiveType fieldType = fieldAnnotation.type();
switch (fieldType) {
case BOOLEAN:
FieldUtils.writeField(field, obj, false, true);
@ -106,7 +106,7 @@ public class DatabaseDataInitializer implements IDataInitializer {
obj.setPrimitiveFields(fields, orderedFieldTypes, fieldDataUID);
}
private void initializeDBObjectProperties(EnhancedObject obj) throws IOException {
private void initializeDbObjectProperties(EnhancedObject obj) throws IOException {
// Declare the variables needed to get the biggest property Id
Method[] unorderedPropertyGetters = obj.getPropertyGetters();
Method[] unorderedPropertySetters = obj.getPropertySetters();
@ -120,7 +120,7 @@ public class DatabaseDataInitializer implements IDataInitializer {
long[] propertyUIDs = objectsIO.allocateNewUIDs(biggestPropertyId + 1);
for (Method property : unorderedPropertySetters) {
DBPropertySetter fieldAnnotation = property.getAnnotation(DBPropertySetter.class);
DbPropertySetter fieldAnnotation = property.getAnnotation(DbPropertySetter.class);
int propertyId = fieldAnnotation.id();
if (propertyId > biggestPropertyId) {
biggestPropertyId = propertyId;
@ -128,25 +128,25 @@ public class DatabaseDataInitializer implements IDataInitializer {
}
// Declare the other variables
DBDataType[] propertyTypes = new DBDataType[biggestPropertyId + 1];
DbDataType[] propertyTypes = new DbDataType[biggestPropertyId + 1];
Method[] propertyGetters = new Method[biggestPropertyId + 1];
Method[] propertySetters = new Method[biggestPropertyId + 1];
Map<String, DBPropertySetter> setterMethods = new LinkedHashMap<>();
Map<String, DBPropertyGetter> getterMethods = new LinkedHashMap<>();
Map<String, DbPropertySetter> setterMethods = new LinkedHashMap<>();
Map<String, DbPropertyGetter> getterMethods = new LinkedHashMap<>();
// Load the properties metadata
for (Method property : unorderedPropertyGetters) {
DBPropertyGetter propertyAnnotation = property.getAnnotation(DBPropertyGetter.class);
DbPropertyGetter propertyAnnotation = property.getAnnotation(DbPropertyGetter.class);
int propertyId = propertyAnnotation.id();
DBDataType propertyType = propertyAnnotation.type();
DbDataType propertyType = propertyAnnotation.type();
propertyTypes[propertyId] = propertyType;
propertyGetters[propertyId] = property;
getterMethods.put(property.getName(), propertyAnnotation);
}
for (Method property : unorderedPropertySetters) {
DBPropertySetter propertyAnnotation = property.getAnnotation(DBPropertySetter.class);
DbPropertySetter propertyAnnotation = property.getAnnotation(DbPropertySetter.class);
int propertyId = propertyAnnotation.id();
DBDataType propertyType = propertyAnnotation.type();
DbDataType propertyType = propertyAnnotation.type();
propertyTypes[propertyId] = propertyType;
propertySetters[propertyId] = property;
setterMethods.put(property.getName(), propertyAnnotation);

View File

@ -1,9 +1,9 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import it.unimi.dsi.fastutil.longs.LongList;
import org.warp.jcwdb.EnhancedObjectUpgrader;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import it.cavallium.strangedb.EnhancedObjectUpgrader;
import java.io.IOException;
import java.util.function.Supplier;
@ -23,19 +23,19 @@ public class DatabaseEnhancedObjectUpgrader implements EnhancedObjectUpgrader {
@Override
@SuppressWarnings("unchecked")
public Object getField(int id, DBDataType type, Supplier<Class<?>> enhancedClassType) throws IOException {
public Object getField(int id, DbDataType type, Supplier<Class<?>> enhancedClassType) throws IOException {
return objectsIO.loadData(type, fieldRefs[id], enhancedClassType);
}
@Override
@SuppressWarnings("unchecked")
public Object getMethod(int id, DBDataType type, Supplier<Class<?>> enhancedClassType) throws IOException {
public Object getMethod(int id, DbDataType type, Supplier<Class<?>> enhancedClassType) throws IOException {
return objectsIO.loadData(type, methodRefs[id], enhancedClassType);
}
@SuppressWarnings("unchecked")
@Override
public <T> T getPrimitiveField(int id, DBPrimitiveType type) throws IOException {
public <T> T getPrimitiveField(int id, DbPrimitiveType type) throws IOException {
LongList data = objectsIO.loadPrimitiveData(primitiveDataRef);
switch (type) {
case BOOLEAN:

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;

View File

@ -1,8 +1,9 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import it.cavallium.strangedb.annotations.*;
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
import it.unimi.dsi.fastutil.bytes.ByteArrayList;
import it.unimi.dsi.fastutil.chars.CharArrayList;
@ -11,8 +12,7 @@ import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongList;
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.annotations.*;
import it.cavallium.strangedb.EnhancedObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -117,7 +117,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
@SuppressWarnings("unchecked")
Object loadData(DBDataType propertyType, long dataReference, Supplier<Class<?>> returnType) throws IOException {
Object loadData(DbDataType propertyType, long dataReference, Supplier<Class<?>> returnType) throws IOException {
switch (propertyType) {
case ENHANCED_OBJECT:
return loadEnhancedObject(dataReference, (Class<? extends EnhancedObject>) returnType.get());
@ -130,7 +130,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
}
<T> void setData(long reference, DBDataType propertyType, T loadedPropertyValue) throws IOException {
<T> void setData(long reference, DbDataType propertyType, T loadedPropertyValue) throws IOException {
switch (propertyType) {
case OBJECT:
setObject(reference, loadedPropertyValue);
@ -144,13 +144,13 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
}
<T extends EnhancedObject> void setPrimitives(T enhancedObject, long reference, DBPrimitiveType[] types, Field[] fields)
<T extends EnhancedObject> void setPrimitives(T enhancedObject, long reference, DbPrimitiveType[] types, Field[] fields)
throws IOException {
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * fields.length);
try {
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
DBPrimitiveType type = types[i];
DbPrimitiveType type = types[i];
if (field == null) {
buffer.putLong(0);
} else {
@ -201,13 +201,13 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
final long[] fieldReferences = objectFullInfo.getFieldReferences();
final DBDataType[] fieldTypes = objectFullInfo.getFieldTypes();
final DbDataType[] fieldTypes = objectFullInfo.getFieldTypes();
final Field[] fields = objectFullInfo.getFields();
final long nativeFieldDataReference = objectFullInfo.getPrimitiveFieldDataReference();
final DBPrimitiveType[] nativeFieldTypes = objectFullInfo.getPrimitiveFieldTypes();
final DbPrimitiveType[] nativeFieldTypes = objectFullInfo.getPrimitiveFieldTypes();
final Field[] nativeFields = objectFullInfo.getPrimitiveFields();
final long[] propertyReferences = objectFullInfo.getPropertyReferences();
final DBDataType[] propertyTypes = objectFullInfo.getPropertyTypes();
final DbDataType[] propertyTypes = objectFullInfo.getPropertyTypes();
final Object[] propertyValues = objectFullInfo.getLoadedPropertyValues();
final int totalSize = Byte.BYTES + Integer.BYTES * 2 + fieldReferences.length * Long.BYTES
+ propertyReferences.length * Long.BYTES + Long.BYTES;
@ -335,7 +335,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
@Override
public void loadProperty(EnhancedObject obj, int propertyId, Method property, DBDataType propertyType,
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));
@ -361,7 +361,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
int biggestPropertyId = biggestGetter > biggestSetter ? biggestGetter : biggestSetter;
for (Method property : unorderedPropertySetters) {
DBPropertySetter fieldAnnotation = property.getAnnotation(DBPropertySetter.class);
DbPropertySetter fieldAnnotation = property.getAnnotation(DbPropertySetter.class);
int propertyId = fieldAnnotation.id();
if (propertyId > biggestPropertyId) {
biggestPropertyId = propertyId;
@ -369,25 +369,25 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
// Declare the other variables
DBDataType[] propertyTypes = new DBDataType[biggestPropertyId + 1];
DbDataType[] propertyTypes = new DbDataType[biggestPropertyId + 1];
Method[] propertyGetters = new Method[biggestPropertyId + 1];
Method[] propertySetters = new Method[biggestPropertyId + 1];
Map<String, DBPropertySetter> setterMethods = new LinkedHashMap<>();
Map<String, DBPropertyGetter> getterMethods = new LinkedHashMap<>();
Map<String, DbPropertySetter> setterMethods = new LinkedHashMap<>();
Map<String, DbPropertyGetter> getterMethods = new LinkedHashMap<>();
// Load the properties metadata
for (Method property : unorderedPropertyGetters) {
DBPropertyGetter propertyAnnotation = property.getAnnotation(DBPropertyGetter.class);
DbPropertyGetter propertyAnnotation = property.getAnnotation(DbPropertyGetter.class);
int propertyId = propertyAnnotation.id();
DBDataType propertyType = propertyAnnotation.type();
DbDataType propertyType = propertyAnnotation.type();
propertyTypes[propertyId] = propertyType;
propertyGetters[propertyId] = property;
getterMethods.put(property.getName(), propertyAnnotation);
}
for (Method property : unorderedPropertySetters) {
DBPropertySetter propertyAnnotation = property.getAnnotation(DBPropertySetter.class);
DbPropertySetter propertyAnnotation = property.getAnnotation(DbPropertySetter.class);
int propertyId = propertyAnnotation.id();
DBDataType propertyType = propertyAnnotation.type();
DbDataType propertyType = propertyAnnotation.type();
propertyTypes[propertyId] = propertyType;
propertySetters[propertyId] = property;
setterMethods.put(property.getName(), propertyAnnotation);
@ -400,7 +400,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
int getBiggestPropertyGetterId(Method[] unorderedPropertyGetters) {
int biggestPropertyId = -1;
for (Method property : unorderedPropertyGetters) {
DBPropertyGetter fieldAnnotation = property.getAnnotation(DBPropertyGetter.class);
DbPropertyGetter fieldAnnotation = property.getAnnotation(DbPropertyGetter.class);
int propertyId = fieldAnnotation.id();
if (propertyId > biggestPropertyId) {
biggestPropertyId = propertyId;
@ -412,7 +412,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
int getBiggestPropertySetterId(Method[] unorderedPropertySetters) {
int biggestPropertyId = -1;
for (Method property : unorderedPropertySetters) {
DBPropertySetter fieldAnnotation = property.getAnnotation(DBPropertySetter.class);
DbPropertySetter fieldAnnotation = property.getAnnotation(DbPropertySetter.class);
int propertyId = fieldAnnotation.id();
if (propertyId > biggestPropertyId) {
biggestPropertyId = propertyId;
@ -430,13 +430,13 @@ public class DatabaseObjectsIO implements IObjectsIO {
// Declare the other variables
Field[] fields = new Field[biggestFieldId + 1];
DBPrimitiveType[] orderedFieldTypes = new DBPrimitiveType[biggestFieldId + 1];
DbPrimitiveType[] orderedFieldTypes = new DbPrimitiveType[biggestFieldId + 1];
// Load all fields metadata
for (Field field : unorderedFields) {
DBPrimitiveField fieldAnnotation = field.getAnnotation(DBPrimitiveField.class);
DbPrimitiveField fieldAnnotation = field.getAnnotation(DbPrimitiveField.class);
int fieldId = fieldAnnotation.id();
DBPrimitiveType fieldType = fieldAnnotation.type();
DbPrimitiveType fieldType = fieldAnnotation.type();
fields[fieldId] = field;
orderedFieldTypes[fieldId] = fieldType;
}
@ -448,7 +448,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
try {
for (int id = 0; id < fields.length; id++) {
Field field = fields[id];
DBPrimitiveType type = orderedFieldTypes[id];
DbPrimitiveType type = orderedFieldTypes[id];
switch (type) {
case BOOLEAN:
@ -494,13 +494,13 @@ public class DatabaseObjectsIO implements IObjectsIO {
// Declare the other variables
Field[] fields = new Field[biggestFieldId + 1];
DBDataType[] orderedFieldTypes = new DBDataType[biggestFieldId + 1];
DbDataType[] orderedFieldTypes = new DbDataType[biggestFieldId + 1];
// Load all fields metadata and load them
for (Field field : unorderedFields) {
DBField fieldAnnotation = field.getAnnotation(DBField.class);
DbField fieldAnnotation = field.getAnnotation(DbField.class);
int fieldId = fieldAnnotation.id();
DBDataType fieldType = fieldAnnotation.type();
DbDataType fieldType = fieldAnnotation.type();
loadField(obj, field, fieldType, fieldReferences[fieldId]);
fields[fieldId] = field;
orderedFieldTypes[fieldId] = fieldType;
@ -509,11 +509,11 @@ public class DatabaseObjectsIO implements IObjectsIO {
obj.setFields(fields, orderedFieldTypes, fieldReferences);
}
<T extends EnhancedObject> void loadField(T obj, Field field, DBDataType fieldType, long fieldReference)
<T extends EnhancedObject> void loadField(T obj, Field field, DbDataType fieldType, long fieldReference)
throws IOException {
Object data = loadData(fieldType, fieldReference, field::getType);
try {
if (fieldType == DBDataType.OBJECT && data != null) {
if (fieldType == DbDataType.OBJECT && data != null) {
if (!field.getType().isInstance(data)) {
throw new IOException("There is an attempt to load an object of type " + data.getClass()
+ " into a field of type " + field.getType());
@ -526,17 +526,17 @@ public class DatabaseObjectsIO implements IObjectsIO {
}
<T extends EnhancedObject> Field[] getFields(T obj) {
return FieldUtils.getFieldsWithAnnotation(obj.getClass(), DBField.class);
return FieldUtils.getFieldsWithAnnotation(obj.getClass(), DbField.class);
}
<T extends EnhancedObject> Field[] getPrimitiveFields(T obj) {
return FieldUtils.getFieldsWithAnnotation(obj.getClass(), DBPrimitiveField.class);
return FieldUtils.getFieldsWithAnnotation(obj.getClass(), DbPrimitiveField.class);
}
int getBiggestFieldId(Field[] unorderedFields) {
int biggestFieldId = -1;
for (Field field : unorderedFields) {
DBField fieldAnnotation = field.getAnnotation(DBField.class);
DbField fieldAnnotation = field.getAnnotation(DbField.class);
int propertyId = fieldAnnotation.id();
if (propertyId > biggestFieldId) {
biggestFieldId = propertyId;
@ -548,7 +548,7 @@ public class DatabaseObjectsIO implements IObjectsIO {
int getBiggestPrimitiveFieldId(Field[] unorderedFields) {
int biggestFieldId = -1;
for (Field field : unorderedFields) {
DBPrimitiveField fieldAnnotation = field.getAnnotation(DBPrimitiveField.class);
DbPrimitiveField fieldAnnotation = field.getAnnotation(DbPrimitiveField.class);
int propertyId = fieldAnnotation.id();
if (propertyId > biggestFieldId) {
biggestFieldId = propertyId;
@ -576,14 +576,14 @@ public class DatabaseObjectsIO implements IObjectsIO {
T obj = toInstance(objectType);
// Check the serialized version
DBClass dbClass = objectType.getAnnotation(DBClass.class);
DbClass dbClass = objectType.getAnnotation(DbClass.class);
int classVersion = 0;
if (dbClass != null) {
classVersion = dbClass.version();
}
if (classVersion > serializedVersion) {
DatabaseEnhancedObjectUpgrader enhancedObjectUpgrader = new DatabaseEnhancedObjectUpgrader(this, fieldRefs, methodRefs, nativeFieldsRef);
dataInitializer.initializeDBObject(obj);
dataInitializer.initializeDbObject(obj);
obj.onUpgrade(serializedVersion, enhancedObjectUpgrader);
} else if (classVersion < serializedVersion) {
throw new IllegalStateException(

View File

@ -1,9 +1,9 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;
import java.nio.ByteBuffer;
import static org.warp.jcwdb.database.IBlocksMetadata.EMPTY_BLOCK_ID;
import static it.cavallium.strangedb.database.IBlocksMetadata.EMPTY_BLOCK_ID;
public class DatabaseReferencesIO implements IReferencesIO {

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -8,8 +8,8 @@ import java.nio.file.StandardOpenOption;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static org.warp.jcwdb.database.IBlocksMetadata.EMPTY_BLOCK_ID;
import static org.warp.jcwdb.database.IBlocksMetadata.ERROR_BLOCK_ID;
import static it.cavallium.strangedb.database.IBlocksMetadata.EMPTY_BLOCK_ID;
import static it.cavallium.strangedb.database.IBlocksMetadata.ERROR_BLOCK_ID;
public class DatabaseReferencesMetadata implements IReferencesMetadata {
private final AsynchronousFileChannel metaFileChannel;

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import it.unimi.dsi.fastutil.longs.*;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
@ -9,7 +9,7 @@ import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static org.warp.jcwdb.database.IBlocksMetadata.ERROR_BLOCK_ID;
import static it.cavallium.strangedb.database.IBlocksMetadata.ERROR_BLOCK_ID;
public class DatabaseReferencesMetadataCache {

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;
import java.util.concurrent.Future;

View File

@ -1,23 +1,23 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import java.lang.reflect.Field;
public class EnhancedObjectFullInfo {
private final int version;
private final long[] fieldReferences;
private final DBDataType[] fieldTypes;
private final DbDataType[] fieldTypes;
private final Field[] fields;
private final long primitiveFieldDataReference;
private final DBPrimitiveType[] primitiveFieldTypes;
private final DbPrimitiveType[] primitiveFieldTypes;
private final Field[] primitiveFields;
private final long[] propertyReferences;
private final DBDataType[] propertyTypes;
private final DbDataType[] propertyTypes;
private final Object[] loadedPropertyValues;
public EnhancedObjectFullInfo(int version, long[] fieldReferences, DBDataType[] fieldTypes, Field[] fields, long primitiveFieldDataReference, DBPrimitiveType[] primitiveFieldTypes, Field[] primitiveFields, long[] propertyReferences, DBDataType[] propertyTypes, Object[] loadedPropertyValues) {
public EnhancedObjectFullInfo(int version, long[] fieldReferences, DbDataType[] fieldTypes, Field[] fields, long primitiveFieldDataReference, DbPrimitiveType[] primitiveFieldTypes, Field[] primitiveFields, long[] propertyReferences, DbDataType[] propertyTypes, Object[] loadedPropertyValues) {
this.version = version;
if (version > 255) {
throw new IllegalArgumentException();
@ -41,7 +41,7 @@ public class EnhancedObjectFullInfo {
return fieldReferences;
}
DBDataType[] getFieldTypes() {
DbDataType[] getFieldTypes() {
return fieldTypes;
}
@ -53,7 +53,7 @@ public class EnhancedObjectFullInfo {
return primitiveFieldDataReference;
}
public DBPrimitiveType[] getPrimitiveFieldTypes() {
public DbPrimitiveType[] getPrimitiveFieldTypes() {
return primitiveFieldTypes;
}
@ -65,7 +65,7 @@ public class EnhancedObjectFullInfo {
return propertyReferences;
}
DBDataType[] getPropertyTypes() {
DbDataType[] getPropertyTypes() {
return propertyTypes;
}

View File

@ -1,8 +1,6 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
public interface IBlocksIO {

View File

@ -1,6 +1,6 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import org.warp.jcwdb.BlockInfo;
import it.cavallium.strangedb.BlockInfo;
import java.io.IOException;

View File

@ -0,0 +1,9 @@
package it.cavallium.strangedb.database;
import it.cavallium.strangedb.EnhancedObject;
import java.io.IOException;
public interface IDataInitializer {
void initializeDbObject(EnhancedObject obj) throws IOException;
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;

View File

@ -1,6 +1,6 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import org.warp.jcwdb.EnhancedObject;
import it.cavallium.strangedb.EnhancedObject;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.*;
import java.nio.ByteBuffer;

View File

@ -1,9 +1,9 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.annotations.DbDataType;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongList;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.annotations.DBDataType;
import java.io.IOException;
import java.lang.reflect.Method;
@ -47,7 +47,7 @@ public interface IObjectsIO {
return reference;
}
void loadProperty(EnhancedObject enhancedObject, int propertyId, Method propertyGetter, DBDataType propertyType, long propertyUID) throws IOException;
void loadProperty(EnhancedObject enhancedObject, int propertyId, Method propertyGetter, DbDataType propertyType, long propertyUID) throws IOException;
void registerClass(Class<?> type, int id);

View File

@ -1,8 +1,6 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
public interface IReferencesIO {

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.database;
package it.cavallium.strangedb.database;
import java.io.IOException;

View File

@ -1,6 +1,4 @@
package org.warp.jcwdb.database;
import java.io.IOException;
package it.cavallium.strangedb.database;
public interface Long2LongConsumer {
void accept(long a, long b);

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.functionalinterfaces;
package it.cavallium.strangedb.functionalinterfaces;
import java.io.IOException;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.functionalinterfaces;
package it.cavallium.strangedb.functionalinterfaces;
import java.io.IOException;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.functionalinterfaces;
package it.cavallium.strangedb.functionalinterfaces;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.functionalinterfaces;
package it.cavallium.strangedb.functionalinterfaces;
import java.io.IOException;

View File

@ -1,19 +1,19 @@
package org.warp.jcwdb.lists;
package it.cavallium.strangedb.lists;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBField;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbField;
import java.io.IOException;
public class EnhancedObjectJCWDBList<T extends EnhancedObject> extends JCWDBList<T> {
public class EnhancedObjectStrandeDbList<T extends EnhancedObject> extends StrandeDbList<T> {
@DBField(id = 0, type = DBDataType.REFERENCES_LIST)
@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;
@Override
@ -21,11 +21,11 @@ public class EnhancedObjectJCWDBList<T extends EnhancedObject> extends JCWDBList
return indices;
}
public EnhancedObjectJCWDBList() {
public EnhancedObjectStrandeDbList() {
super();
}
public EnhancedObjectJCWDBList(IDatabaseTools databaseTools, Class<T> type) throws IOException {
public EnhancedObjectStrandeDbList(IDatabaseTools databaseTools, Class<T> type) throws IOException {
super(databaseTools);
this.type = type;
indices = new LongArrayList();

View File

@ -1,15 +1,15 @@
package org.warp.jcwdb.lists;
package it.cavallium.strangedb.lists;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBField;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbField;
import java.io.IOException;
public class ObjectJCWDBList<T> extends JCWDBList<T> {
public class ObjectStrandeDbList<T> extends StrandeDbList<T> {
@DBField(id = 0, type = DBDataType.REFERENCES_LIST)
@DbField(id = 0, type = DbDataType.REFERENCES_LIST)
private LongArrayList indices;
@Override
@ -17,11 +17,11 @@ public class ObjectJCWDBList<T> extends JCWDBList<T> {
return indices;
}
public ObjectJCWDBList() {
public ObjectStrandeDbList() {
super();
}
public ObjectJCWDBList(IDatabaseTools databaseTools) throws IOException {
public ObjectStrandeDbList(IDatabaseTools databaseTools) throws IOException {
super(databaseTools);
indices = new LongArrayList();
}

View File

@ -1,23 +1,23 @@
package org.warp.jcwdb.lists;
package it.cavallium.strangedb.lists;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import java.io.IOException;
import java.util.StringJoiner;
public abstract class JCWDBList<T> extends EnhancedObject {
public abstract class StrandeDbList<T> extends EnhancedObject {
private final Object indicesAccessLock = new Object();
protected abstract LongArrayList getIndices();
public JCWDBList() {
public StrandeDbList() {
}
public JCWDBList(IDatabaseTools databaseTools) throws IOException {
public StrandeDbList(IDatabaseTools databaseTools) throws IOException {
super(databaseTools);
}
@ -87,7 +87,7 @@ public abstract class JCWDBList<T> extends EnhancedObject {
@Override
public String toString() {
return new StringJoiner(", ", JCWDBList.class.getSimpleName() + "[", "]")
return new StringJoiner(", ", StrandeDbList.class.getSimpleName() + "[", "]")
.add(getIndices().size() + " items")
.toString();
}

View File

@ -1,55 +0,0 @@
package org.warp.jcwdb;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import java.io.IOException;
import java.util.function.Supplier;
public interface EnhancedObjectUpgrader {
<T> T getPrimitiveField(int id, DBPrimitiveType integer) throws IOException;
default int getPrimitiveBoolean(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.BOOLEAN);
}
default int getPrimitiveByte(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.BYTE);
}
default int getPrimitiveShort(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.SHORT);
}
default int getPrimitiveChar(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.CHAR);
}
default int getPrimitiveInt(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.INTEGER);
}
default long getPrimitiveLong(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.LONG);
}
default float getPrimitiveFloat(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.FLOAT);
}
default double getPrimitiveDouble(int id) throws IOException {
return getPrimitiveField(id, DBPrimitiveType.DOUBLE);
}
Object getField(int id, DBDataType type, Supplier<Class<?>> enhancedClassType) throws IOException;
default Object getField(int id, DBDataType type) throws IOException {
return getField(id, type, null);
}
Object getMethod(int id, DBDataType type, Supplier<Class<?>> enhancedClassType) throws IOException;
default Object getMethod(int id, DBDataType type) throws IOException {
return getField(id, type, null);
}
}

View File

@ -1,7 +0,0 @@
package org.warp.jcwdb.annotations;
public enum DBDataType {
ENHANCED_OBJECT,
OBJECT,
REFERENCES_LIST
}

View File

@ -1,12 +0,0 @@
package org.warp.jcwdb.annotations;
public enum DBPrimitiveType {
BOOLEAN,
BYTE,
SHORT,
CHAR,
INTEGER,
LONG,
FLOAT,
DOUBLE
}

View File

@ -1,9 +0,0 @@
package org.warp.jcwdb.database;
import org.warp.jcwdb.EnhancedObject;
import java.io.IOException;
public interface IDataInitializer {
void initializeDBObject(EnhancedObject obj) throws IOException;
}

View File

@ -1,15 +1,15 @@
package org.warp.jcwdb.tests;
package it.cavallium.strangedb.tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBField;
import org.warp.jcwdb.annotations.DBPropertyGetter;
import org.warp.jcwdb.annotations.DBPropertySetter;
import org.warp.jcwdb.utils.NTestUtils;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbField;
import it.cavallium.strangedb.annotations.DbPropertyGetter;
import it.cavallium.strangedb.annotations.DbPropertySetter;
import it.cavallium.strangedb.utils.NTestUtils;
import java.io.IOException;
@ -51,10 +51,10 @@ public class Clean {
public static class RootTwoClasses extends EnhancedObject {
@DBField(id = 0, type = DBDataType.ENHANCED_OBJECT)
@DbField(id = 0, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass class1;
@DBField(id = 1, type = DBDataType.ENHANCED_OBJECT)
@DbField(id = 1, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass class2;
public RootTwoClasses() {
@ -65,22 +65,22 @@ public class Clean {
super(databaseTools);
}
@DBPropertyGetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
@DbPropertyGetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass getClass3() {
return getProperty();
}
@DBPropertySetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
@DbPropertySetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
public void setClass3(NTestUtils.RootClass value) {
setProperty(value);
}
@DBPropertyGetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
@DbPropertyGetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass getClass4() {
return getProperty();
}
@DBPropertySetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
@DbPropertySetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
public void setClass4(NTestUtils.RootClass value) {
setProperty(value);
}

View File

@ -1,9 +1,9 @@
package org.warp.jcwdb.tests;
package it.cavallium.strangedb.tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.warp.jcwdb.database.Database;
import it.cavallium.strangedb.database.Database;
import java.io.IOException;
import java.nio.file.Files;

View File

@ -1,15 +1,15 @@
package org.warp.jcwdb.tests;
package it.cavallium.strangedb.tests;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbField;
import it.cavallium.strangedb.annotations.DbPropertyGetter;
import it.cavallium.strangedb.annotations.DbPropertySetter;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.utils.NTestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBField;
import org.warp.jcwdb.annotations.DBPropertyGetter;
import org.warp.jcwdb.annotations.DBPropertySetter;
import org.warp.jcwdb.utils.NTestUtils;
import java.io.IOException;
@ -48,10 +48,10 @@ public class MultipleEnhancedObjects {
public static class RootTwoClasses extends EnhancedObject {
@DBField(id = 0, type = DBDataType.ENHANCED_OBJECT)
@DbField(id = 0, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass class1;
@DBField(id = 1, type = DBDataType.ENHANCED_OBJECT)
@DbField(id = 1, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass class2;
public RootTwoClasses() {
@ -62,22 +62,22 @@ public class MultipleEnhancedObjects {
super(databaseTools);
}
@DBPropertyGetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
@DbPropertyGetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass getClass3() {
return getProperty();
}
@DBPropertySetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
@DbPropertySetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
public void setClass3(NTestUtils.RootClass value) {
setProperty(value);
}
@DBPropertyGetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
@DbPropertyGetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
public NTestUtils.RootClass getClass4() {
return getProperty();
}
@DBPropertySetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
@DbPropertySetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
public void setClass4(NTestUtils.RootClass value) {
setProperty(value);
}

View File

@ -0,0 +1,30 @@
package it.cavallium.strangedb.tests;
import it.cavallium.strangedb.annotations.DbPrimitiveField;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbField;
import java.io.IOException;
public class OldClass extends EnhancedObject {
@DbField(id = 0, type = DbDataType.OBJECT)
public String field1;
@DbPrimitiveField(id = 0, type = DbPrimitiveType.INTEGER)
public int field2;
@DbPrimitiveField(id = 2, type = DbPrimitiveType.INTEGER)
public int field4;
public OldClass() {
}
public OldClass(IDatabaseTools databaseTools) throws IOException {
super(databaseTools);
}
}

View File

@ -1,14 +1,14 @@
package org.warp.jcwdb.tests;
package it.cavallium.strangedb.tests;
import it.cavallium.strangedb.annotations.*;
import it.cavallium.strangedb.functionalinterfaces.RunnableWithIO;
import it.cavallium.strangedb.lists.EnhancedObjectStrandeDbList;
import it.cavallium.strangedb.lists.ObjectStrandeDbList;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import org.warp.jcwdb.functionalinterfaces.RunnableWithIO;
import org.warp.jcwdb.database.Database;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.lists.EnhancedObjectJCWDBList;
import org.warp.jcwdb.lists.ObjectJCWDBList;
import org.warp.jcwdb.VariableWrapper;
import org.warp.jcwdb.annotations.*;
import it.cavallium.strangedb.database.Database;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.VariableWrapper;
import java.io.IOException;
import java.nio.file.Files;
@ -52,23 +52,23 @@ public class Performance {
testS("Database root creation", 3000, Performance::regenDb, () -> db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new), () -> {});
final VariableWrapper<PreloadedListContainer> preloadedListContainer = new VariableWrapper<>(null);
final VariableWrapper<SimpleEnhancedObject> simpleEnhancedObjectContainer = new VariableWrapper<>(null);
testS("ObjectJCWDBList<Int> creation", 3000, () -> {
testS("ObjectStrandeDbList<Int> creation", 3000, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
}, () -> preloadedListContainer.var.list = new ObjectJCWDBList<>(db), () -> {});
testS("ObjectJCWDBList<Int>: Filling with 1000 items", 100, () -> {
}, () -> preloadedListContainer.var.list = new ObjectStrandeDbList<>(db), () -> {});
testS("ObjectStrandeDbList<Int>: Filling with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
}, () -> {
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectJCWDBList<EnhancedObject>: Filling with 1000 items", 100, () -> {
testS("ObjectStrandeDbList<EnhancedObject>: Filling with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectJCWDBList<>(db, SimpleEnhancedObject.class);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrandeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
@ -81,28 +81,28 @@ public class Performance {
preloadedListContainer.var.listOfEnhancedObj.add(simpleEnhancedObjectContainer.var);
}
}, () -> {});
testS("ObjectJCWDBList<Int>: Filling with 10000 items", 10, () -> {
testS("ObjectStrandeDbList<Int>: Filling with 10000 items", 10, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
}, () -> {
for (int i = 0; i < 10000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectJCWDBList<Int>: Filling with 100000 items", 1, () -> {
testS("ObjectStrandeDbList<Int>: Filling with 100000 items", 1, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
}, () -> {
for (int i = 0; i < 100000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {});
testS("ObjectJCWDBList<Int>: Loading 1000 items", 100, () -> {
testS("ObjectStrandeDbList<Int>: Loading 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
@ -111,10 +111,10 @@ public class Performance {
preloadedListContainer.var.list.get(i);
}
}, () -> {});
testS("ObjectJCWDBList<EnhancedObject>: Loading with 1000 items", 100, () -> {
testS("ObjectStrandeDbList<EnhancedObject>: Loading with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectJCWDBList<>(db, SimpleEnhancedObject.class);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrandeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
@ -130,10 +130,10 @@ public class Performance {
preloadedListContainer.var.listOfEnhancedObj.get(i);
}
}, () -> {});
testS("ObjectJCWDBList<Int>: Loading 10000 items", 10, () -> {
testS("ObjectStrandeDbList<Int>: Loading 10000 items", 10, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
for (int i = 0; i < 10000; i++) {
preloadedListContainer.var.list.add(1000);
}
@ -142,20 +142,20 @@ public class Performance {
preloadedListContainer.var.list.get(i);
}
}, () -> {});
testS("ObjectJCWDBList<Int>: getLast() with 1000 items", 100, () -> {
testS("ObjectStrandeDbList<Int>: getLast() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
}, () -> {
preloadedListContainer.var.list.getLast();
}, () -> {});
testS("ObjectJCWDBList<EnhancedObject>: getLast() with 1000 items", 100, () -> {
testS("ObjectStrandeDbList<EnhancedObject>: getLast() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectJCWDBList<>(db, SimpleEnhancedObject.class);
preloadedListContainer.var.listOfEnhancedObj = new EnhancedObjectStrandeDbList<>(db, SimpleEnhancedObject.class);
simpleEnhancedObjectContainer.var = new SimpleEnhancedObject(db);
simpleEnhancedObjectContainer.var.integerNumber = 10;
simpleEnhancedObjectContainer.var.longNumber = 10L;
@ -169,10 +169,10 @@ public class Performance {
}, () -> {
preloadedListContainer.var.listOfEnhancedObj.getLast();
}, () -> {});
testS("ObjectJCWDBList<Int>: size() with 1000 items", 100, () -> {
testS("ObjectStrandeDbList<Int>: size() with 1000 items", 100, () -> {
regenDb();
preloadedListContainer.var = db.loadRoot(PreloadedListContainer.class, PreloadedListContainer::new);
preloadedListContainer.var.list = new ObjectJCWDBList<>(db);
preloadedListContainer.var.list = new ObjectStrandeDbList<>(db);
for (int i = 0; i < 1000; i++) {
preloadedListContainer.var.list.add(1000);
}
@ -284,11 +284,11 @@ public class Performance {
public static class PreloadedListContainer extends EnhancedObject {
@DBField(id = 0, type = DBDataType.ENHANCED_OBJECT)
public ObjectJCWDBList<Integer> list;
@DbField(id = 0, type = DbDataType.ENHANCED_OBJECT)
public ObjectStrandeDbList<Integer> list;
@DBField(id = 1, type = DBDataType.ENHANCED_OBJECT)
public EnhancedObjectJCWDBList<SimpleEnhancedObject> listOfEnhancedObj;
@DbField(id = 1, type = DbDataType.ENHANCED_OBJECT)
public EnhancedObjectStrandeDbList<SimpleEnhancedObject> listOfEnhancedObj;
public PreloadedListContainer() {
@ -310,13 +310,13 @@ public class Performance {
}
@DBPropertyGetter(id = 0, type = DBDataType.ENHANCED_OBJECT)
public ObjectJCWDBList<Integer> getList() {
@DbPropertyGetter(id = 0, type = DbDataType.ENHANCED_OBJECT)
public ObjectStrandeDbList<Integer> getList() {
return getProperty();
}
@DBPropertySetter(id = 1, type = DBDataType.ENHANCED_OBJECT)
public void setList(ObjectJCWDBList<Integer> list) {
@DbPropertySetter(id = 1, type = DbDataType.ENHANCED_OBJECT)
public void setList(ObjectStrandeDbList<Integer> list) {
setProperty(list);
}
}
@ -330,13 +330,13 @@ public class Performance {
super(databaseTools);
}
@DBField(id = 0, type = DBDataType.OBJECT)
@DbField(id = 0, type = DbDataType.OBJECT)
public ArrayList<String> object;
@DBPrimitiveField(id = 0, type = DBPrimitiveType.INTEGER)
@DbPrimitiveField(id = 0, type = DbPrimitiveType.INTEGER)
public int integerNumber;
@DBPrimitiveField(id = 1, type = DBPrimitiveType.LONG)
@DbPrimitiveField(id = 1, type = DbPrimitiveType.LONG)
public long longNumber;
}
}

View File

@ -0,0 +1,44 @@
package it.cavallium.strangedb.tests;
import it.cavallium.strangedb.EnhancedObjectUpgrader;
import it.cavallium.strangedb.annotations.DbDataType;
import it.cavallium.strangedb.annotations.DbField;
import it.cavallium.strangedb.annotations.DbPrimitiveField;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import it.cavallium.strangedb.annotations.DbClass;
import java.io.IOException;
@DbClass(version = 1)
public class V2Class extends EnhancedObject {
@DbPrimitiveField(id = 0, type = DbPrimitiveType.LONG)
public long field1;
@DbPrimitiveField(id = 1, type = DbPrimitiveType.INTEGER)
public int field2;
@DbField(id = 0, type = DbDataType.OBJECT)
public String field4;
public V2Class() {
}
public V2Class(IDatabaseTools databaseTools) throws IOException {
super(databaseTools);
}
@Override
public void onUpgrade(int oldObjectVersion, EnhancedObjectUpgrader enhancedObjectUpgrader) throws IOException {
switch (oldObjectVersion) {
case 0: {
field1 = (long) enhancedObjectUpgrader.getPrimitiveInt(2);
field2 = enhancedObjectUpgrader.getPrimitiveInt(0);
field4 = (String) enhancedObjectUpgrader.getField(0, DbDataType.OBJECT);
break;
}
}
}
}

View File

@ -1,4 +1,4 @@
package org.warp.jcwdb.utils;
package it.cavallium.strangedb.utils;
import java.io.IOException;
import java.util.Objects;

View File

@ -0,0 +1,23 @@
package it.cavallium.strangedb.utils;
import it.cavallium.strangedb.annotations.DbPrimitiveField;
import it.cavallium.strangedb.annotations.DbPrimitiveType;
import it.cavallium.strangedb.database.Database;
import it.cavallium.strangedb.EnhancedObject;
import java.io.IOException;
public class NSimplestClass extends EnhancedObject {
@DbPrimitiveField(id = 0, type = DbPrimitiveType.BOOLEAN)
public boolean field1;
public NSimplestClass() {
}
public NSimplestClass(Database database) throws IOException {
super(database);
field1 = true;
}
}

View File

@ -1,11 +1,11 @@
package org.warp.jcwdb.utils;
package it.cavallium.strangedb.utils;
import it.cavallium.strangedb.annotations.*;
import it.cavallium.strangedb.functionalinterfaces.RunnableWithIO;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import org.warp.jcwdb.functionalinterfaces.RunnableWithIO;
import org.warp.jcwdb.database.Database;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.*;
import it.cavallium.strangedb.database.Database;
import it.cavallium.strangedb.EnhancedObject;
import it.cavallium.strangedb.database.IDatabaseTools;
import java.io.File;
import java.io.IOException;
@ -211,31 +211,31 @@ public class NTestUtils {
public static class RootClass extends EnhancedObject {
@DBPrimitiveField(id = 0, type = DBPrimitiveType.BOOLEAN)
@DbPrimitiveField(id = 0, type = DbPrimitiveType.BOOLEAN)
public boolean field1;
@DBPrimitiveField(id = 1, type = DBPrimitiveType.BYTE)
@DbPrimitiveField(id = 1, type = DbPrimitiveType.BYTE)
public byte field2;
@DBPrimitiveField(id = 2, type = DBPrimitiveType.SHORT)
@DbPrimitiveField(id = 2, type = DbPrimitiveType.SHORT)
public short field3;
@DBPrimitiveField(id = 3, type = DBPrimitiveType.CHAR)
@DbPrimitiveField(id = 3, type = DbPrimitiveType.CHAR)
public char field4;
@DBPrimitiveField(id = 4, type = DBPrimitiveType.INTEGER)
@DbPrimitiveField(id = 4, type = DbPrimitiveType.INTEGER)
public int field5;
@DBPrimitiveField(id = 5, type = DBPrimitiveType.LONG)
@DbPrimitiveField(id = 5, type = DbPrimitiveType.LONG)
public long field6;
@DBField(id = 0, type = DBDataType.OBJECT)
@DbField(id = 0, type = DbDataType.OBJECT)
public String field7;
@DBField(id = 1, type = DBDataType.REFERENCES_LIST)
@DbField(id = 1, type = DbDataType.REFERENCES_LIST)
public LongArrayList field8;
@DBField(id = 2, type = DBDataType.ENHANCED_OBJECT)
@DbField(id = 2, type = DbDataType.ENHANCED_OBJECT)
public NSimplestClass field9;
public RootClass() {
@ -246,32 +246,32 @@ public class NTestUtils {
super(databaseTools);
}
@DBPropertyGetter(id = 0, type = DBDataType.OBJECT)
@DbPropertyGetter(id = 0, type = DbDataType.OBJECT)
public String get7() {
return getProperty();
}
@DBPropertyGetter(id = 1, type = DBDataType.REFERENCES_LIST)
@DbPropertyGetter(id = 1, type = DbDataType.REFERENCES_LIST)
public LongArrayList get8() {
return getProperty();
}
@DBPropertyGetter(id = 2, type = DBDataType.ENHANCED_OBJECT)
@DbPropertyGetter(id = 2, type = DbDataType.ENHANCED_OBJECT)
public NSimplestClass get9() {
return getProperty();
}
@DBPropertySetter(id = 0, type = DBDataType.OBJECT)
@DbPropertySetter(id = 0, type = DbDataType.OBJECT)
public void set7(String val) {
setProperty(val);
}
@DBPropertySetter(id = 1, type = DBDataType.REFERENCES_LIST)
@DbPropertySetter(id = 1, type = DbDataType.REFERENCES_LIST)
public void set8(LongArrayList val) {
setProperty(val);
}
@DBPropertySetter(id = 2, type = DBDataType.ENHANCED_OBJECT)
@DbPropertySetter(id = 2, type = DbDataType.ENHANCED_OBJECT)
public void set9(NSimplestClass val) {
setProperty(val);
}

View File

@ -1,30 +0,0 @@
package org.warp.jcwdb.tests;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBField;
import org.warp.jcwdb.annotations.DBPrimitiveField;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import java.io.IOException;
public class OldClass extends EnhancedObject {
@DBField(id = 0, type = DBDataType.OBJECT)
public String field1;
@DBPrimitiveField(id = 0, type = DBPrimitiveType.INTEGER)
public int field2;
@DBPrimitiveField(id = 2, type = DBPrimitiveType.INTEGER)
public int field4;
public OldClass() {
}
public OldClass(IDatabaseTools databaseTools) throws IOException {
super(databaseTools);
}
}

View File

@ -1,44 +0,0 @@
package org.warp.jcwdb.tests;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.EnhancedObjectUpgrader;
import org.warp.jcwdb.database.IDatabaseTools;
import org.warp.jcwdb.annotations.DBClass;
import org.warp.jcwdb.annotations.DBDataType;
import org.warp.jcwdb.annotations.DBField;
import org.warp.jcwdb.annotations.DBPrimitiveField;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import java.io.IOException;
@DBClass(version = 1)
public class V2Class extends EnhancedObject {
@DBPrimitiveField(id = 0, type = DBPrimitiveType.LONG)
public long field1;
@DBPrimitiveField(id = 1, type = DBPrimitiveType.INTEGER)
public int field2;
@DBField(id = 0, type = DBDataType.OBJECT)
public String field4;
public V2Class() {
}
public V2Class(IDatabaseTools databaseTools) throws IOException {
super(databaseTools);
}
@Override
public void onUpgrade(int oldObjectVersion, EnhancedObjectUpgrader enhancedObjectUpgrader) throws IOException {
switch (oldObjectVersion) {
case 0: {
field1 = (long) enhancedObjectUpgrader.getPrimitiveInt(2);
field2 = enhancedObjectUpgrader.getPrimitiveInt(0);
field4 = (String) enhancedObjectUpgrader.getField(0, DBDataType.OBJECT);
break;
}
}
}
}

View File

@ -1,23 +0,0 @@
package org.warp.jcwdb.utils;
import org.warp.jcwdb.database.Database;
import org.warp.jcwdb.EnhancedObject;
import org.warp.jcwdb.annotations.DBPrimitiveField;
import org.warp.jcwdb.annotations.DBPrimitiveType;
import java.io.IOException;
public class NSimplestClass extends EnhancedObject {
@DBPrimitiveField(id = 0, type = DBPrimitiveType.BOOLEAN)
public boolean field1;
public NSimplestClass() {
}
public NSimplestClass(Database database) throws IOException {
super(database);
field1 = true;
}
}