mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Implements transient Model objects
This commit is contained in:
@@ -77,18 +77,21 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
|
|||||||
*/
|
*/
|
||||||
protected void desireUpdate() {
|
protected void desireUpdate() {
|
||||||
if (this.desire != ObjectDesire.INSERT
|
if (this.desire != ObjectDesire.INSERT
|
||||||
&& this.desire != ObjectDesire.DELETE) {
|
&& this.desire != ObjectDesire.DELETE
|
||||||
|
&& this.desire != ObjectDesire.TRANSIENT) {
|
||||||
log.debug("{} desires an update", this);
|
log.debug("{} desires an update", this);
|
||||||
this.desire = ObjectDesire.UPDATE;
|
this.desire = ObjectDesire.UPDATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this object desire to {@link Model.ObjectDesire#INSERT}. If the desire is
|
* Set this object desire to {@link Model.ObjectDesire#INSERT}. If the
|
||||||
* {@link Model.ObjectDesire#DELETE} the desire will not be changed.
|
* desire is {@link Model.ObjectDesire#DELETE} the desire will not be
|
||||||
|
* changed.
|
||||||
*/
|
*/
|
||||||
protected void desireInsert() {
|
protected void desireInsert() {
|
||||||
if (this.desire != ObjectDesire.DELETE) {
|
if (this.desire != ObjectDesire.DELETE
|
||||||
|
&& this.desire != ObjectDesire.TRANSIENT) {
|
||||||
log.debug("{} desires an insert", this);
|
log.debug("{} desires an insert", this);
|
||||||
this.desire = ObjectDesire.INSERT;
|
this.desire = ObjectDesire.INSERT;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,11 @@ public interface Model<T extends ID<?>> {
|
|||||||
* <p>
|
* <p>
|
||||||
* If tge object is not in the database nothing will happen.
|
* If tge object is not in the database nothing will happen.
|
||||||
*/
|
*/
|
||||||
DELETE;
|
DELETE,
|
||||||
|
/**
|
||||||
|
* The object is transient and is not meant to be inserted into the
|
||||||
|
* database
|
||||||
|
*/
|
||||||
|
TRANSIENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import com.l2jserver.model.id.ID;
|
|||||||
import com.l2jserver.service.core.threading.AbstractTask;
|
import com.l2jserver.service.core.threading.AbstractTask;
|
||||||
import com.l2jserver.service.core.threading.AsyncFuture;
|
import com.l2jserver.service.core.threading.AsyncFuture;
|
||||||
import com.l2jserver.service.core.threading.ThreadService;
|
import com.l2jserver.service.core.threading.ThreadService;
|
||||||
import com.l2jserver.service.database.DatabaseService.TransactionExecutor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract DAO implementations. Store an instance of {@link DatabaseService}.
|
* Abstract DAO implementations. Store an instance of {@link DatabaseService}.
|
||||||
@@ -94,17 +93,12 @@ public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
|
|||||||
@Override
|
@Override
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public final int saveObjects(final T... objects) {
|
public final int saveObjects(final T... objects) {
|
||||||
return database.transaction(new TransactionExecutor() {
|
|
||||||
@Override
|
|
||||||
public int perform() {
|
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
for (final T object : objects) {
|
for (final T object : objects) {
|
||||||
rows += save(object);
|
rows += save(object);
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
|
|||||||
@@ -142,8 +142,12 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int save(O object);
|
int save(O object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save several instances to the database using a transaction (if possible).
|
* Save several instances to the database. This method will only save if the
|
||||||
* This method will only save if the object has changed.
|
* object has changed.
|
||||||
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -152,8 +156,14 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int saveObjects(@SuppressWarnings("unchecked") O... objects);
|
int saveObjects(@SuppressWarnings("unchecked") O... objects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously save several instances to the database using a transaction
|
* Asynchronously save several instances to the database. This method will
|
||||||
* (if possible). This method will only save if the object has changed.
|
* only save if the object has changed.
|
||||||
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
|
* Also note that this method should not be used inside transactions,
|
||||||
|
* instead use {@link #saveObjects(Model...)}.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -185,8 +195,11 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int insert(O object);
|
int insert(O object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts several instances in the database using a transaction (if
|
* Inserts several instances in the database.
|
||||||
* possible).
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -195,8 +208,13 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int insertObjects(@SuppressWarnings("unchecked") O... objects);
|
int insertObjects(@SuppressWarnings("unchecked") O... objects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously insert several instances in the database using a
|
* Asynchronously insert several instances in the database.
|
||||||
* transaction (if possible).
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
|
* Also note that this method should not be used inside transactions,
|
||||||
|
* instead use {@link #insertObjects(Model...)}.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -216,8 +234,11 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int update(O object);
|
int update(O object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates several instances in the database using a transaction (if
|
* Updates several instances in the database.
|
||||||
* possible).
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -226,8 +247,13 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int updateObjects(@SuppressWarnings("unchecked") O... objects);
|
int updateObjects(@SuppressWarnings("unchecked") O... objects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously update several instances in the database using a
|
* Asynchronously update several instances in the database.
|
||||||
* transaction (if possible).
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
|
* Also note that this method should not be used inside transactions,
|
||||||
|
* instead use {@link #updateObjects(Model...)}.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -246,8 +272,11 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
void delete(O object);
|
void delete(O object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes several instances in the database using an transaction (if
|
* Deletes several instances in the database.
|
||||||
* possible).
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
@@ -256,8 +285,13 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
int deleteObjects(@SuppressWarnings("unchecked") O... objects);
|
int deleteObjects(@SuppressWarnings("unchecked") O... objects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously delete several instances in the database using a
|
* Asynchronously delete several instances in the database.
|
||||||
* transaction (if possible).
|
* <p>
|
||||||
|
* <b>Important note</b>: operations are not performed inside an
|
||||||
|
* transaction. If transactions are desired,
|
||||||
|
* {@link DatabaseService#transaction(TransactionExecutor)} should be used.
|
||||||
|
* Also note that this method should not be used inside transactions,
|
||||||
|
* instead use {@link #deleteObjects(Model...)}.
|
||||||
*
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* the objects
|
* the objects
|
||||||
|
|||||||
@@ -139,9 +139,8 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
* the {@link DataAccessObject DAO} resolver
|
* the {@link DataAccessObject DAO} resolver
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public AbstractOrientDatabaseService(
|
public AbstractOrientDatabaseService(CacheService cacheService,
|
||||||
CacheService cacheService, ThreadService threadService,
|
ThreadService threadService, DAOResolver daoResolver) {
|
||||||
DAOResolver daoResolver) {
|
|
||||||
super(OrientDatabaseConfiguration.class);
|
super(OrientDatabaseConfiguration.class);
|
||||||
this.cacheService = cacheService;
|
this.cacheService = cacheService;
|
||||||
this.threadService = threadService;
|
this.threadService = threadService;
|
||||||
@@ -457,10 +456,28 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
*/
|
*/
|
||||||
protected void updateDesire(Object object, ObjectDesire expected) {
|
protected void updateDesire(Object object, ObjectDesire expected) {
|
||||||
if (object instanceof Model) {
|
if (object instanceof Model) {
|
||||||
if (((Model<?>) object).getObjectDesire() == expected) {
|
if (((Model<?>) object).getObjectDesire() == ObjectDesire.TRANSIENT)
|
||||||
|
return;
|
||||||
|
if (((Model<?>) object).getObjectDesire() != expected)
|
||||||
|
return;
|
||||||
((Model<?>) object).setObjectDesire(ObjectDesire.NONE);
|
((Model<?>) object).setObjectDesire(ObjectDesire.NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if the object desire is not {@link ObjectDesire#TRANSIENT}
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* the object
|
||||||
|
* @return true if the object desire is {@link ObjectDesire#TRANSIENT}
|
||||||
|
*/
|
||||||
|
protected boolean testDesire(Object object) {
|
||||||
|
if (object instanceof Model) {
|
||||||
|
if (((Model<?>) object).getObjectDesire() == ObjectDesire.TRANSIENT)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -582,6 +599,9 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
final DocumentDatabaseRow row = new DocumentDatabaseRow();
|
final DocumentDatabaseRow row = new DocumentDatabaseRow();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final O object = iterator.next();
|
final O object = iterator.next();
|
||||||
|
if(testDesire(object))
|
||||||
|
continue;
|
||||||
|
|
||||||
row.setDocument(new ODocument(database, entity.getTableName()));
|
row.setDocument(new ODocument(database, entity.getTableName()));
|
||||||
|
|
||||||
mapper.insert(entity, object, row);
|
mapper.insert(entity, object, row);
|
||||||
@@ -667,6 +687,8 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
final DocumentDatabaseRow row = new DocumentDatabaseRow();
|
final DocumentDatabaseRow row = new DocumentDatabaseRow();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final O object = iterator.next();
|
final O object = iterator.next();
|
||||||
|
if(testDesire(object))
|
||||||
|
continue;
|
||||||
|
|
||||||
List<ODocument> documents = database
|
List<ODocument> documents = database
|
||||||
.query(new ONativeSynchQuery<OQueryContextNative>(
|
.query(new ONativeSynchQuery<OQueryContextNative>(
|
||||||
@@ -755,6 +777,8 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final O object = iterator.next();
|
final O object = iterator.next();
|
||||||
|
if(testDesire(object))
|
||||||
|
continue;
|
||||||
|
|
||||||
List<ODocument> documents = database
|
List<ODocument> documents = database
|
||||||
.query(new ONativeSynchQuery<OQueryContextNative>(
|
.query(new ONativeSynchQuery<OQueryContextNative>(
|
||||||
@@ -953,9 +977,7 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
if (object == null) {
|
if (object == null) {
|
||||||
object = mapper.select(entity, row);
|
object = mapper.select(entity, row);
|
||||||
updateCache(object, service);
|
updateCache(object, service);
|
||||||
if (object instanceof Model) {
|
updateDesire(object, ObjectDesire.INSERT);
|
||||||
((Model<?>) object).setObjectDesire(ObjectDesire.NONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -999,9 +1021,7 @@ public abstract class AbstractOrientDatabaseService extends
|
|||||||
if (object == null) {
|
if (object == null) {
|
||||||
object = mapper.select(entity, row);
|
object = mapper.select(entity, row);
|
||||||
updateCache(object, service);
|
updateCache(object, service);
|
||||||
if (object instanceof Model) {
|
updateDesire(object, ObjectDesire.INSERT);
|
||||||
((Model<?>) object).setObjectDesire(ObjectDesire.NONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (object != null)
|
if (object != null)
|
||||||
results.add(object);
|
results.add(object);
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
/**
|
/**
|
||||||
* The connection used inside a transaction from multiple DAOs.
|
* The connection used inside a transaction from multiple DAOs.
|
||||||
*/
|
*/
|
||||||
private ThreadLocal<Connection> transactionalConnection = new ThreadLocal<>();
|
private ThreadLocal<Connection> transaction = new ThreadLocal<>();
|
||||||
/**
|
/**
|
||||||
* The {@link Type} that will be mapped by the querydsl.
|
* The {@link Type} that will be mapped by the querydsl.
|
||||||
*/
|
*/
|
||||||
@@ -281,7 +281,7 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <M extends Model<?>, T extends RelationalPathBase<?>> void importData(
|
public <M extends Model<?>, T extends RelationalPathBase<?>> void importData(
|
||||||
java.nio.file.Path path, final T entity) throws IOException {
|
final java.nio.file.Path path, final T entity) throws IOException {
|
||||||
final Connection conn;
|
final Connection conn;
|
||||||
try {
|
try {
|
||||||
conn = dataSource.getConnection();
|
conn = dataSource.getConnection();
|
||||||
@@ -379,7 +379,7 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
try {
|
try {
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
|
|
||||||
transactionalConnection.set(conn);
|
transaction.set(new TransactionIsolatedConnection(conn));
|
||||||
final int rows = executor.perform();
|
final int rows = executor.perform();
|
||||||
|
|
||||||
conn.commit();
|
conn.commit();
|
||||||
@@ -388,8 +388,8 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
conn.rollback();
|
conn.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
transactionalConnection.set(null);
|
transaction.set(null);
|
||||||
transactionalConnection.remove();
|
transaction.remove();
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
@@ -425,39 +425,21 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
public <T> T query(Query<T> query) throws DatabaseException {
|
public <T> T query(Query<T> query) throws DatabaseException {
|
||||||
Preconditions.checkNotNull(query, "query");
|
Preconditions.checkNotNull(query, "query");
|
||||||
try {
|
try {
|
||||||
boolean inTransaction = true;
|
Connection conn = transaction.get();
|
||||||
Connection conn = transactionalConnection.get();
|
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
log.debug(
|
log.debug(
|
||||||
"Transactional connection for {} is not set, creating new connection",
|
"Transactional connection for {} is not set, creating new connection",
|
||||||
query);
|
query);
|
||||||
inTransaction = false;
|
|
||||||
conn = dataSource.getConnection();
|
conn = dataSource.getConnection();
|
||||||
}
|
}
|
||||||
log.debug("Executing query {} with {}", query, conn);
|
log.debug("Executing query {} with {}", query, conn);
|
||||||
try {
|
try {
|
||||||
if (!inTransaction) {
|
return query.query(engine.createSQLQueryFactory(conn), this);
|
||||||
conn.setAutoCommit(false);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return query
|
|
||||||
.query(engine.createSQLQueryFactory(conn), this);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (!inTransaction) {
|
// transaction wrappers does not allow closing, so this is safe
|
||||||
conn.commit();
|
// to do
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (!inTransaction) {
|
|
||||||
conn.rollback();
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
if (!inTransaction) {
|
|
||||||
conn.setAutoCommit(true);
|
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("Could not open database connection", e);
|
log.error("Could not open database connection", e);
|
||||||
throw new DatabaseException(e);
|
throw new DatabaseException(e);
|
||||||
@@ -558,10 +540,28 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
*/
|
*/
|
||||||
protected void updateDesire(Object object, ObjectDesire expected) {
|
protected void updateDesire(Object object, ObjectDesire expected) {
|
||||||
if (object instanceof Model) {
|
if (object instanceof Model) {
|
||||||
if (((Model<?>) object).getObjectDesire() == expected) {
|
if (((Model<?>) object).getObjectDesire() == ObjectDesire.TRANSIENT)
|
||||||
|
return;
|
||||||
|
if (((Model<?>) object).getObjectDesire() != expected)
|
||||||
|
return;
|
||||||
((Model<?>) object).setObjectDesire(ObjectDesire.NONE);
|
((Model<?>) object).setObjectDesire(ObjectDesire.NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests if the object desire is not {@link ObjectDesire#TRANSIENT}
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* the object
|
||||||
|
* @return true if the object desire is {@link ObjectDesire#TRANSIENT}
|
||||||
|
*/
|
||||||
|
protected boolean testDesire(Object object) {
|
||||||
|
if (object instanceof Model) {
|
||||||
|
if (((Model<?>) object).getObjectDesire() == ObjectDesire.TRANSIENT)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -670,6 +670,9 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final O object = iterator.next();
|
final O object = iterator.next();
|
||||||
|
if (testDesire(object))
|
||||||
|
continue;
|
||||||
|
|
||||||
final SQLInsertWritableDatabaseRow row = new SQLInsertWritableDatabaseRow(
|
final SQLInsertWritableDatabaseRow row = new SQLInsertWritableDatabaseRow(
|
||||||
factory.insert(entity));
|
factory.insert(entity));
|
||||||
mapper.insert(entity, object, row);
|
mapper.insert(entity, object, row);
|
||||||
@@ -751,6 +754,9 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final O object = iterator.next();
|
final O object = iterator.next();
|
||||||
|
if (testDesire(object))
|
||||||
|
continue;
|
||||||
|
|
||||||
final SQLUpdateWritableDatabaseRow row = new SQLUpdateWritableDatabaseRow(
|
final SQLUpdateWritableDatabaseRow row = new SQLUpdateWritableDatabaseRow(
|
||||||
factory.update(entity));
|
factory.update(entity));
|
||||||
// maps query to the values
|
// maps query to the values
|
||||||
@@ -825,6 +831,9 @@ public abstract class AbstractSQLDatabaseService extends
|
|||||||
int rows = 0;
|
int rows = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final O object = iterator.next();
|
final O object = iterator.next();
|
||||||
|
if (testDesire(object))
|
||||||
|
continue;
|
||||||
|
|
||||||
final SQLDeleteClause delete = factory.delete(entity);
|
final SQLDeleteClause delete = factory.delete(entity);
|
||||||
// maps query to the values
|
// maps query to the values
|
||||||
query(delete, object);
|
query(delete, object);
|
||||||
|
|||||||
@@ -0,0 +1,337 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of l2jserver2 <l2jserver2.com>.
|
||||||
|
*
|
||||||
|
* l2jserver2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* l2jserver2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with l2jserver2. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.l2jserver.service.database.sql;
|
||||||
|
|
||||||
|
import java.sql.Array;
|
||||||
|
import java.sql.Blob;
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.Clob;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.NClob;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLClientInfoException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.SQLWarning;
|
||||||
|
import java.sql.SQLXML;
|
||||||
|
import java.sql.Savepoint;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.sql.Struct;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps an {@link Connection} into as an unclosable and transaction-disabled
|
||||||
|
* {@link Connection}s
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
public class TransactionIsolatedConnection implements Connection {
|
||||||
|
/**
|
||||||
|
* The wrapped connection
|
||||||
|
*/
|
||||||
|
private final Connection connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param connection
|
||||||
|
* the connection
|
||||||
|
*/
|
||||||
|
public TransactionIsolatedConnection(Connection connection) {
|
||||||
|
super();
|
||||||
|
this.connection = connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void abort(Executor arg0) throws SQLException {
|
||||||
|
connection.abort(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearWarnings() throws SQLException {
|
||||||
|
connection.clearWarnings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws SQLException {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commit() throws SQLException {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Array createArrayOf(String arg0, Object[] arg1) throws SQLException {
|
||||||
|
return connection.createArrayOf(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Blob createBlob() throws SQLException {
|
||||||
|
return connection.createBlob();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Clob createClob() throws SQLException {
|
||||||
|
return connection.createClob();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NClob createNClob() throws SQLException {
|
||||||
|
return connection.createNClob();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SQLXML createSQLXML() throws SQLException {
|
||||||
|
return connection.createSQLXML();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Statement createStatement() throws SQLException {
|
||||||
|
return connection.createStatement();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Statement createStatement(int arg0, int arg1, int arg2)
|
||||||
|
throws SQLException {
|
||||||
|
return connection.createStatement(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Statement createStatement(int arg0, int arg1) throws SQLException {
|
||||||
|
return connection.createStatement(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Struct createStruct(String arg0, Object[] arg1) throws SQLException {
|
||||||
|
return connection.createStruct(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAutoCommit() throws SQLException {
|
||||||
|
return connection.getAutoCommit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCatalog() throws SQLException {
|
||||||
|
return connection.getCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Properties getClientInfo() throws SQLException {
|
||||||
|
return connection.getClientInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClientInfo(String arg0) throws SQLException {
|
||||||
|
return connection.getClientInfo(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHoldability() throws SQLException {
|
||||||
|
return connection.getHoldability();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseMetaData getMetaData() throws SQLException {
|
||||||
|
return connection.getMetaData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNetworkTimeout() throws SQLException {
|
||||||
|
return connection.getNetworkTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSchema() throws SQLException {
|
||||||
|
return connection.getSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTransactionIsolation() throws SQLException {
|
||||||
|
return connection.getTransactionIsolation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||||
|
return connection.getTypeMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
|
return connection.getWarnings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() throws SQLException {
|
||||||
|
return connection.isClosed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReadOnly() throws SQLException {
|
||||||
|
return connection.isReadOnly();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(int arg0) throws SQLException {
|
||||||
|
return connection.isValid(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWrapperFor(Class<?> arg0) throws SQLException {
|
||||||
|
return connection.isWrapperFor(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String nativeSQL(String arg0) throws SQLException {
|
||||||
|
return connection.nativeSQL(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallableStatement prepareCall(String arg0, int arg1, int arg2,
|
||||||
|
int arg3) throws SQLException {
|
||||||
|
return connection.prepareCall(arg0, arg1, arg2, arg3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallableStatement prepareCall(String arg0, int arg1, int arg2)
|
||||||
|
throws SQLException {
|
||||||
|
return connection.prepareCall(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallableStatement prepareCall(String arg0) throws SQLException {
|
||||||
|
return connection.prepareCall(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String arg0, int arg1, int arg2,
|
||||||
|
int arg3) throws SQLException {
|
||||||
|
return connection.prepareStatement(arg0, arg1, arg2, arg3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String arg0, int arg1, int arg2)
|
||||||
|
throws SQLException {
|
||||||
|
return connection.prepareStatement(arg0, arg1, arg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String arg0, int arg1)
|
||||||
|
throws SQLException {
|
||||||
|
return connection.prepareStatement(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String arg0, int[] arg1)
|
||||||
|
throws SQLException {
|
||||||
|
return connection.prepareStatement(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String arg0, String[] arg1)
|
||||||
|
throws SQLException {
|
||||||
|
return connection.prepareStatement(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedStatement prepareStatement(String arg0) throws SQLException {
|
||||||
|
return connection.prepareStatement(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void releaseSavepoint(Savepoint arg0) throws SQLException {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rollback() throws SQLException {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rollback(Savepoint arg0) throws SQLException {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAutoCommit(boolean arg0) throws SQLException {
|
||||||
|
// DO NOTHING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCatalog(String arg0) throws SQLException {
|
||||||
|
connection.setCatalog(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientInfo(Properties arg0) throws SQLClientInfoException {
|
||||||
|
connection.setClientInfo(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClientInfo(String arg0, String arg1)
|
||||||
|
throws SQLClientInfoException {
|
||||||
|
connection.setClientInfo(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHoldability(int arg0) throws SQLException {
|
||||||
|
connection.setHoldability(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNetworkTimeout(Executor arg0, int arg1) throws SQLException {
|
||||||
|
connection.setNetworkTimeout(arg0, arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReadOnly(boolean arg0) throws SQLException {
|
||||||
|
connection.setReadOnly(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Savepoint setSavepoint() throws SQLException {
|
||||||
|
return connection.setSavepoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Savepoint setSavepoint(String arg0) throws SQLException {
|
||||||
|
return connection.setSavepoint(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSchema(String arg0) throws SQLException {
|
||||||
|
connection.setSchema(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTransactionIsolation(int arg0) throws SQLException {
|
||||||
|
connection.setTransactionIsolation(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException {
|
||||||
|
connection.setTypeMap(arg0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T unwrap(Class<T> arg0) throws SQLException {
|
||||||
|
return connection.unwrap(arg0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user