1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

DAO abstractions and updated 'npc' sql file

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-23 12:51:52 -03:00
parent 66d5fee187
commit 1909bb06cc
41 changed files with 42265 additions and 41874 deletions

View File

@@ -36,7 +36,7 @@ import com.l2jserver.service.game.npc.NPCServiceImpl;
import com.l2jserver.service.game.pathing.MapperPathingService;
import com.l2jserver.service.game.pathing.PathingService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
import com.l2jserver.service.game.scripting.PreCompiledScriptingService;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.spawn.SpawnServiceImpl;
import com.l2jserver.service.game.template.ScriptTemplateService;
@@ -78,7 +78,7 @@ public class ServiceModule extends AbstractModule {
.in(Scopes.SINGLETON);
bind(NetworkService.class).to(NettyNetworkService.class).in(
Scopes.SINGLETON);
bind(ScriptingService.class).to(ScriptingServiceImpl.class).in(
bind(ScriptingService.class).to(PreCompiledScriptingService.class).in(
Scopes.SINGLETON);
bind(TemplateService.class).to(ScriptTemplateService.class).in(
Scopes.SINGLETON);

View File

@@ -17,6 +17,8 @@
package com.l2jserver.service.database;
import com.google.inject.Inject;
import com.l2jserver.model.Model;
import com.l2jserver.model.id.ID;
/**
* Abstract DAO implementations. Store an instance of {@link DatabaseService}.
@@ -26,7 +28,8 @@ import com.google.inject.Inject;
* @param <T>
* the dao object type
*/
public abstract class AbstractDAO<T> implements DataAccessObject<T> {
public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
implements DataAccessObject<T, I> {
/**
* The database service instance
*/
@@ -37,6 +40,19 @@ public abstract class AbstractDAO<T> implements DataAccessObject<T> {
this.database = database;
}
@Override
public boolean save(T object) {
switch (object.getObjectState()) {
case NOT_STORED:
return insert(object);
case STORED:
return update(object);
case ORPHAN:
return delete(object);
}
return false;
}
/**
* @return the database service
*/

View File

@@ -16,6 +16,10 @@
*/
package com.l2jserver.service.database;
import com.l2jserver.model.Model;
import com.l2jserver.model.id.ID;
import com.l2jserver.service.cache.IgnoreCaching;
/**
* The DAO interface
* <p>
@@ -28,6 +32,53 @@ package com.l2jserver.service.database;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface DataAccessObject<T> {
public interface DataAccessObject<O extends Model<?>, I extends ID<?>> {
/**
* Load the instance represented by <tt>id</tt> from the database
*
* @param id
* the id
*/
O select(I id);
/**
* Save the instance to the database. If a new database entry was created
* returns true.
*
* @param object
* the object
* @return true if the row was inserted or updated
*/
@IgnoreCaching
boolean save(O object);
/**
* Inserts the instance in the database.
*
* @param object
* the object
* @return true if the row was inserted
*/
@IgnoreCaching
boolean insert(O object);
/**
* Updates the instance in the database.
*
* @param object
* the object
* @return true if the row was updated
*/
@IgnoreCaching
boolean update(O object);
/**
* Deletes the instance in the database.
*
* @param object
* the object
* @return true if the row was deleted
*/
@IgnoreCaching
boolean delete(O object);
}

View File

@@ -91,7 +91,7 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
for (final NPC npc : npcs) {
spawnService.spawn(npc, null);
}
return null;
return npcs;
}
@Override

View File

@@ -42,18 +42,19 @@ import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
import com.l2jserver.util.factory.CollectionFactory;
/**
* Default {@link ScriptingService} implementation
* This alternative {@link ScriptingService} uses an cache to speed up the
* server startup at the cost of not being capable of recompiling templates.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Depends(LoggingService.class)
public class ScriptingServiceImpl extends AbstractService implements
public class PreCompiledScriptingService extends AbstractService implements
ScriptingService {
/**
* Logger for script context
*/
private static final Logger log = LoggerFactory
.getLogger(ScriptingServiceImpl.class);
.getLogger(PreCompiledScriptingService.class);
private final Injector injector;
@@ -63,7 +64,7 @@ public class ScriptingServiceImpl extends AbstractService implements
private final Set<ScriptContext> contexts = CollectionFactory.newSet();
@Inject
public ScriptingServiceImpl(Injector injector) {
public PreCompiledScriptingService(Injector injector) {
this.injector = injector;
}