diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java index 85bd447fa..4ac3136d8 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/orientdb/AbstractOrientDatabaseService.java @@ -217,6 +217,10 @@ public abstract class AbstractOrientDatabaseService extends AbstractService } } + // database.getStorage().addUser(); + database.getLevel1Cache().setEnable(false); + database.getLevel2Cache().setEnable(false); + database.close(); // check if automatic schema update is enabled @@ -349,7 +353,6 @@ public abstract class AbstractOrientDatabaseService extends AbstractService final ODatabaseDocumentTx database = ODatabaseDocumentPool.global() .acquire(config.getUrl(), config.getUsername(), config.getPassword()); - log.info("Updating {} schema definition", table); boolean newSchema = false; @@ -490,7 +493,6 @@ public abstract class AbstractOrientDatabaseService extends AbstractService extends AbstractQuery { private final InsertMapper mapper; private final Iterator iterator; - @SuppressWarnings("unused") private final Path primaryKey; protected final E e; @@ -559,6 +561,7 @@ public abstract class AbstractOrientDatabaseService extends AbstractService } @Override + @SuppressWarnings("unchecked") public final Integer query(ODatabaseDocumentTx database, DatabaseService service) { int rows = 0; @@ -569,8 +572,14 @@ public abstract class AbstractOrientDatabaseService extends AbstractService mapper.insert(e, object, row); - // TODO generate unique id row.getDocument().save(); + if (primaryKey != null && object instanceof Model) { + final Long rawID = row.getDocument().getIdentity() + .getClusterPosition(); + final ID id = mapper.getPrimaryKeyMapper() + .createID((RI) rawID); + ((Model>) object).setID(id); + } rows++; updateDesire(object, ObjectDesire.INSERT); diff --git a/l2jserver2-common/src/main/java/com/l2jserver/util/QPathUtils.java b/l2jserver2-common/src/main/java/com/l2jserver/util/QPathUtils.java index d99276b62..ef5342c46 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/util/QPathUtils.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/util/QPathUtils.java @@ -116,7 +116,7 @@ public class QPathUtils { return false; final ColumnNullable nullable = field .getAnnotation(ColumnNullable.class); - if (nullable == null) { + if (nullable != null) { return true; } else { return false; diff --git a/l2jserver2-gameserver/pom.xml b/l2jserver2-gameserver/pom.xml index 036fe0c4f..270f4e59a 100644 --- a/l2jserver2-gameserver/pom.xml +++ b/l2jserver2-gameserver/pom.xml @@ -21,6 +21,7 @@ src/main/assembly/distribution-mysql5-bin.xml + src/main/assembly/distribution-orientdb-bin.xml src/main/assembly/distribution-h2-bin.xml src/main/assembly/distribution-derby-bin.xml src/main/assembly/distribution-src.xml diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml index c9b181875..fe4666c6a 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-derby-bin.xml @@ -18,8 +18,7 @@ .gitignore data/cache/** data/pathing.db - data/database/h2/** - data/database/orientdb/** + data/database/** @@ -44,6 +43,7 @@ mysql:* com.h2database:* + com.orientechnologies:* diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml index d6f223dfa..c4936ccf8 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-h2-bin.xml @@ -18,8 +18,7 @@ .gitignore data/cache/** data/pathing.db - data/database/derby/** - data/database/orientdb/** + data/database/** @@ -44,6 +43,7 @@ mysql:* org.apache.derby:* + com.orientechnologies:* diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml index 9eda1fdc3..f2f4e0891 100644 --- a/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml +++ b/l2jserver2-gameserver/src/main/assembly/distribution-mysql5-bin.xml @@ -43,6 +43,7 @@ com.h2database:* org.apache.derby:* + com.orientechnologies:* diff --git a/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml b/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml new file mode 100644 index 000000000..22b45c7ee --- /dev/null +++ b/l2jserver2-gameserver/src/main/assembly/distribution-orientdb-bin.xml @@ -0,0 +1,50 @@ + + orientdb-bin + + zip + + + + + ${project.basedir} + / + + data/** + + + .gitignore + data/cache/** + data/pathing.db + data/database/** + + + + ${project.basedir}/distribution/global + / + + + + + ${project.build.directory}/${project.artifactId}-${project.version}.jar + / + l2jserver2.jar + 0755 + + + + + /libs + true + false + runtime + + mysql:* + com.h2database:* + org.apache.derby:* + + + + \ No newline at end of file diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/template/SkillTemplate.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/template/SkillTemplate.java index eeaaec339..ac5a5be0c 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/template/SkillTemplate.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/template/SkillTemplate.java @@ -16,7 +16,7 @@ */ package com.l2jserver.model.template; -import java.util.Collections; +import java.util.Arrays; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -33,7 +33,6 @@ import com.l2jserver.model.id.object.ActorID; import com.l2jserver.model.id.template.SkillTemplateID; import com.l2jserver.model.template.effect.EffectTemplate; import com.l2jserver.model.template.effect.TeleportEffectTemplate; -import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.jaxb.SkillTemplateIDAdapter; /** @@ -61,7 +60,7 @@ public class SkillTemplate extends AbstractTemplate { protected int maximumLevel = 1; @XmlElements({ @XmlElement(name = "teleport", type = TeleportEffectTemplate.class) }) - protected List effects = CollectionFactory.newList(); + protected EffectTemplate[] effects; /** * Create a new {@link Skill} @@ -127,7 +126,7 @@ public class SkillTemplate extends AbstractTemplate { * @return the effects */ public List getEffects() { - return Collections.unmodifiableList(effects); + return Arrays.asList(effects); } /** diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/npc/NPCStats.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/npc/NPCStats.java index 355cb6055..2ab2451db 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/npc/NPCStats.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/npc/NPCStats.java @@ -207,7 +207,7 @@ public class NPCStats extends ActorStats { /** * The NPC calculator */ - private static final NPCCalculator calculator = new NPCCalculator(); + private final NPCCalculator calculator = new NPCCalculator(); /** * Creates a new {@link NPCStats} and adds default calculators diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/mapper/ChatMessageMapper.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/mapper/ChatMessageMapper.java index acc413f2a..e333f8757 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/mapper/ChatMessageMapper.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/mapper/ChatMessageMapper.java @@ -87,17 +87,17 @@ public class ChatMessageMapper extends } @Override - public void insert(QLogChat e, ChatMessage onject, WritableDatabaseRow row) { - row.set(e.type, onject.getType()) - .set(e.sender, onject.getSender().getID()) - .set(e.date, onject.getDate()) - .set(e.message, onject.getMessage()); - switch (onject.getType()) { + public void insert(QLogChat e, ChatMessage object, WritableDatabaseRow row) { + row.set(e.type, object.getType()) + .set(e.sender, object.getSender().getID()) + .set(e.date, object.getDate()) + .set(e.message, object.getMessage()); + switch (object.getType()) { case SHOUT: - row.set(e.channelId, onject.getTarget().getID()); + row.set(e.channelId, object.getTarget().getID()); break; default: - row.set(e.channelId, onject.getChannelID()); + row.set(e.channelId, object.getChannelID()); break; } } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/util/calculator/ComplexCalculator.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/util/calculator/ComplexCalculator.java index c7c190c19..30354c12a 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/util/calculator/ComplexCalculator.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/util/calculator/ComplexCalculator.java @@ -17,13 +17,12 @@ package com.l2jserver.util.calculator; import java.io.Serializable; -import java.util.Collections; +import java.util.Arrays; import java.util.Comparator; import java.util.EnumMap; -import java.util.List; import java.util.Map.Entry; -import com.l2jserver.util.factory.CollectionFactory; +import org.apache.commons.lang3.ArrayUtils; /** * An calculator is used to compute data and outputs its result. Note also, that @@ -41,7 +40,7 @@ public class ComplexCalculator> /** * List of operations in this calculator */ - private EnumMap>> functions; + private EnumMap[]> functions; /** * Creates a new empty calculator. Functions can be add using @@ -52,7 +51,7 @@ public class ComplexCalculator> */ public ComplexCalculator(Class type) { super(0x00, null); - functions = new EnumMap>>(type); + functions = new EnumMap[]>(type); } /** @@ -84,7 +83,7 @@ public class ComplexCalculator> @SafeVarargs public ComplexCalculator(V value, Function... functions) { super(0x00, value); - this.functions = new EnumMap>>( + this.functions = new EnumMap[]>( value.getDeclaringClass()); add(functions); } @@ -103,10 +102,13 @@ public class ComplexCalculator> this(type); add(functions); for (final Function func : functions) { - getList(func.type()).add(func); + Function[] funcs = getList(func.type()); + funcs = Arrays.copyOf(funcs, funcs.length + 1); + funcs[funcs.length - 1] = func; + setList(func.type(), funcs); } - for (final List> funcs : this.functions.values()) { - Collections.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); + for (final Function[] funcs : this.functions.values()) { + Arrays.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); } } @@ -120,10 +122,11 @@ public class ComplexCalculator> * the operation */ public void add(Function function) { - getList(function.type()).add(function); - for (final List> funcs : functions.values()) { - Collections.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); - } + Function[] funcs = getList(function.type()); + funcs = Arrays.copyOf(funcs, funcs.length + 1); + funcs[funcs.length - 1] = function; + setList(function.type(), funcs); + Arrays.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); } /** @@ -138,7 +141,10 @@ public class ComplexCalculator> @SafeVarargs public final void add(Function... functions) { for (final Function func : functions) { - getList(func.type()).add(func); + Function[] funcs = getList(func.type()); + funcs = Arrays.copyOf(funcs, funcs.length + 1); + funcs[funcs.length - 1] = func; + setList(func.type(), funcs); } sort(); } @@ -155,7 +161,10 @@ public class ComplexCalculator> @SafeVarargs public final void addNoSort(Function... functions) { for (final Function func : functions) { - getList(func.type()).add(func); + Function[] funcs = getList(func.type()); + funcs = Arrays.copyOf(funcs, funcs.length + 1); + funcs[funcs.length - 1] = func; + setList(func.type(), funcs); } } @@ -166,15 +175,22 @@ public class ComplexCalculator> * the operation */ public void remove(Function function) { - getList(function.type()).remove(function); + Function[] funcs = getList(function.type()); + int index = Arrays.binarySearch(funcs, function); + if (index >= 0) { + funcs = ArrayUtils.remove(funcs, index); + } + setList(function.type(), funcs); } - + /** * Removes all functions from type - * @param type the type + * + * @param type + * the type */ public void remove(V type) { - getList(type).clear(); + setList(type, null); } /** @@ -199,7 +215,7 @@ public class ComplexCalculator> } } } else if (calculator instanceof ComplexCalculator) { - for (final Entry>> e : ((ComplexCalculator) calculator).functions + for (final Entry[]> e : ((ComplexCalculator) calculator).functions .entrySet()) { for (final Function function : e.getValue()) { if (function instanceof Calculator) { @@ -233,7 +249,7 @@ public class ComplexCalculator> } } } else if (calculator instanceof ComplexCalculator) { - for (final Entry>> e : ((ComplexCalculator) calculator).functions + for (final Entry[]> e : ((ComplexCalculator) calculator).functions .entrySet()) { for (final Function function : e.getValue()) { if (function instanceof Calculator) { @@ -248,8 +264,8 @@ public class ComplexCalculator> } public void sort() { - for (final List> funcs : functions.values()) { - Collections.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); + for (final Function[] funcs : functions.values()) { + Arrays.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE); } } @@ -275,15 +291,20 @@ public class ComplexCalculator> return calculate(v, ctx, 0); } - private List> getList(V value) { - List> list = functions.get(value); + @SuppressWarnings("unchecked") + private Function[] getList(V value) { + Function[] list = functions.get(value); if (list == null) { - list = CollectionFactory.newList(); + list = new Function[0]; functions.put(value, list); } return list; } + private void setList(V value, Function[] func) { + functions.put(value, func); + } + public static class FunctionOrderComparator implements Comparator>, Serializable { private static final long serialVersionUID = 1L; diff --git a/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java b/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java index 93a9dca1d..e04c501f0 100644 --- a/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java +++ b/l2jserver2-gameserver/src/test/java/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAOTest.java @@ -54,6 +54,7 @@ public class MySQL5CharacterDAOTest { injector.getInstance(ServiceManager.class).start(WorldService.class); final CharacterDAO dao = injector.getInstance(CharacterDAO.class); + final L2Character char1 = dao.select(injector.getInstance( CharacterIDProvider.class).resolveID(268437456)); final L2Character char2 = dao.select(injector.getInstance(