mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-13 10:42:54 +00:00
DAO abstractions and updated 'npc' sql file
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user