1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 15:33:00 +00:00

Fixes item pick animation and renames few packets

This commit is contained in:
2011-12-16 01:21:23 -02:00
parent 3059931d36
commit 82f6bcbc1c
39 changed files with 322 additions and 215 deletions

View File

@@ -51,42 +51,39 @@ public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
}
@Override
public boolean save(T object) {
public int save(T object) {
return save(object, false);
}
@Override
public boolean save(T object, boolean force) {
public int save(T object, boolean force) {
switch (object.getObjectDesire()) {
case INSERT:
return insert(object);
return insertObjects(wrap(object));
case UPDATE:
return update(object);
return updateObjects(wrap(object));
case DELETE:
return delete(object);
return deleteObjects(wrap(object));
case NONE:
return (force ? update(object) : false);
return (force ? updateObjects(wrap(object)) : 0);
default:
return false;
return 0;
}
}
@Override
@SuppressWarnings("unchecked")
public boolean insert(T object) {
return insertObjects(object) > 0;
public void insert(T object) {
insertObjects(wrap(object));
}
@Override
@SuppressWarnings("unchecked")
public boolean update(T object) {
return updateObjects(object) > 0;
public void update(T object) {
updateObjects(wrap(object));
}
@Override
@SuppressWarnings("unchecked")
public boolean delete(T object) {
return deleteObjects(object) > 0;
public void delete(T object) {
deleteObjects(wrap(object));
}
@Override
@@ -128,4 +125,6 @@ public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
public DatabaseService getDatabase() {
return database;
}
protected abstract T[] wrap(Model<?>... objects);
}

View File

@@ -311,7 +311,7 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
.getDAO(object.getClass());
if (dao == null)
continue;
if (dao.save(object)) {
if (dao.save(object) > 0) {
objects++;
}
}
@@ -548,6 +548,7 @@ public abstract class AbstractJDBCDatabaseService extends AbstractService
}
}
}
conn.commit();
return rows;
} finally {
st.close();

View File

@@ -210,7 +210,7 @@ public abstract class AbstractOrientDatabaseService extends AbstractService
@SuppressWarnings("unchecked")
final DataAccessObject<Model<?>, ?> dao = daoResolver
.getDAO(object.getClass());
if (dao.save(object)) {
if (dao.save(object) > 0) {
objects++;
}
}

View File

@@ -70,10 +70,10 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
*
* @param object
* the object
* @return true if the row was inserted or updated
* @return the number of affected rows
* @see DataAccessObject#save(Model, boolean)
*/
boolean save(O object);
int save(O object);
/**
* Save the instance to the database. If a new database entry was created
@@ -83,61 +83,61 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
* the object
* @param force
* will force an save, even if the object has not changed
* @return true if the row was inserted or updated
* @return the number of affected rows
*/
boolean save(O object, boolean force);
int save(O object, boolean force);
/**
* Inserts the instance in the database.
*
* @param object
* the object
* @return true if the row was inserted
*/
boolean insert(O object);
void insert(O object);
/**
* Inserts several instances in the database using a transaction (if possible).
* Inserts several instances in the database using a transaction (if
* possible).
*
* @param objects
* the objects
* @return the number of inserted rows
*/
int insertObjects(@SuppressWarnings("unchecked") O... objects);
/**
* Updates the instance in the database.
*
* @param object
* the object
* @return true if the row was updated
*/
boolean update(O object);
void update(O object);
/**
* Updates several instances in the database using a transaction (if possible).
* Updates several instances in the database using a transaction (if
* possible).
*
* @param objects
* the objects
* @return the number of updated rows
*/
int updateObjects(@SuppressWarnings("unchecked") O... objects);
/**
* Deletes the instance in the database.
*
* @param object
* the object
* @return true if the row was deleted
*/
boolean delete(O object);
void delete(O object);
/**
* Deletes several instances in the database using an transaction (if possible).
* Deletes several instances in the database using an transaction (if
* possible).
*
* @param objects
* the objects
* @return the numver of deleted rows
* @return the number of deleted rows
*/
int deleteObjects(@SuppressWarnings("unchecked") O... objects);
}

View File

@@ -17,6 +17,7 @@
package com.l2jserver.util;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import com.l2jserver.util.factory.CollectionFactory;
@@ -27,14 +28,19 @@ import com.l2jserver.util.factory.CollectionFactory;
*/
public class ArrayUtils {
@SafeVarargs
@SuppressWarnings("unchecked")
public final static <T> T[] copyArrayExcept(T[] array, T... except) {
public final static <T> T[] copyArrayExcept(Class<T[]> type, T[] array,
T... except) {
final List<T> values = CollectionFactory.newList();
for (final T item : array) {
if (Arrays.binarySearch(except, item) < 0) {
if (Arrays.binarySearch(except, item, new Comparator<T>() {
@Override
public int compare(Object o1, Object o2) {
return (o1 == o2 ? 1 : 0);
}
}) >= 0) {
values.add(item);
}
}
return (T[]) values.toArray();
return Arrays.copyOf(values.toArray(), values.size(), type);
}
}