use of org.dbflute.exception.EntityAlreadyDeletedException in project dbflute-core by dbflute.
the class AbstractBehaviorWritable method helpInsertOrUpdateInternally.
protected <RESULT extends ENTITY> void helpInsertOrUpdateInternally(RESULT entity, InsertOption<CB> insOption, UpdateOption<CB> updOption) {
assertEntityNotNull(entity);
if (helpDetermineInsertOrUpdateDirectInsert(entity)) {
doCreate(entity, insOption);
return;
}
RuntimeException updateException = null;
try {
doModify(entity, updOption);
} catch (EntityAlreadyUpdatedException e) {
// already updated (or means not found)
updateException = e;
} catch (EntityAlreadyDeletedException e) {
// means not found
updateException = e;
} catch (OptimisticLockColumnValueNullException e) {
// means insert?
updateException = e;
}
if (updateException == null) {
return;
}
final CB cb = newConditionBean();
final Set<String> uniqueDrivenProperties = entity.myuniqueDrivenProperties();
if (uniqueDrivenProperties != null && !uniqueDrivenProperties.isEmpty()) {
for (String prop : uniqueDrivenProperties) {
final DBMeta dbmeta = entity.asDBMeta();
final ColumnInfo columnInfo = dbmeta.findColumnInfo(prop);
// already checked in update process
final Object value = columnInfo.read(entity);
cb.localCQ().invokeQueryEqual(columnInfo.getColumnDbName(), value);
}
} else {
cb.acceptPrimaryKeyMap(asDBMeta().extractPrimaryKeyMap(entity));
}
if (readCount(cb) == 0) {
// anyway if not found, insert
doCreate(entity, insOption);
} else {
throw updateException;
}
}
use of org.dbflute.exception.EntityAlreadyDeletedException in project dbflute-core by dbflute.
the class AbstractBehaviorReadable method toRelationOptional.
// ===================================================================================
// Optional Handling
// =================
/**
* Create present or null entity as relation optional.
* @param relationTitle The title of relation for exception message. (NotNull)
* @param relationRow The entity instance of relation row. (NullAllowed)
* @return The optional object for the entity, which has present or null entity. (NotNull)
*/
protected Object toRelationOptional(final String relationTitle, Object relationRow) {
assertObjectNotNull("relationTitle", relationTitle);
final RelationOptionalFactory factory = xgetROpFactory();
final Object result;
if (relationRow != null) {
result = factory.createOptionalPresentEntity(relationRow);
} else {
result = factory.createOptionalNullEntity(new OptionalThingExceptionThrower() {
public void throwNotFoundException() {
String msg = "Not found the relation row for: " + relationTitle;
throw new EntityAlreadyDeletedException(msg);
}
});
}
return result;
}
use of org.dbflute.exception.EntityAlreadyDeletedException in project dbflute-core by dbflute.
the class BehaviorExceptionThrower method throwUpdateEntityAlreadyDeletedException.
public <ENTITY extends Entity> void throwUpdateEntityAlreadyDeletedException(ENTITY entity) {
final ExceptionMessageBuilder br = createExceptionMessageBuilder();
br.addNotice("Not found the updated entity. (might be deleted?)");
setupEntityElement(br, entity);
final String msg = br.buildExceptionMessage();
// basically treated as application exception
throw new EntityAlreadyDeletedException(msg);
}
use of org.dbflute.exception.EntityAlreadyDeletedException in project dbflute-core by dbflute.
the class BehaviorExceptionThrower method throwSelectEntityAlreadyDeletedException.
// ===================================================================================
// Select
// ======
public void throwSelectEntityAlreadyDeletedException(Object searchKey) {
final ExceptionMessageBuilder br = createExceptionMessageBuilder();
br.addNotice("Not found the entity by the condition. (might be deleted?)");
br.addItem("Advice");
br.addElement("Please confirm the existence of your target record on your database.");
br.addElement("Does the target record really created before this operation?");
br.addElement("Has the target record been deleted by other thread?");
br.addElement("It is precondition that the record exists on your database.");
setupSearchKeyElement(br, searchKey);
final String msg = br.buildExceptionMessage();
// basically treated as application exception
throw new EntityAlreadyDeletedException(msg);
}
use of org.dbflute.exception.EntityAlreadyDeletedException in project dbflute-core by dbflute.
the class TnAbstractBatchHandler method handleBatchUpdateResultWithOptimisticLockByResult.
protected void handleBatchUpdateResultWithOptimisticLockByResult(List<?> list, int[] result) {
if (list.isEmpty()) {
// for safety
return;
}
final int[] updatedCountArray = result;
final int entityCount = list.size();
int index = 0;
boolean alreadyUpdated = false;
for (int oneUpdateCount : updatedCountArray) {
if (entityCount <= index) {
// for safety
break;
}
if (oneUpdateCount == 0) {
alreadyUpdated = true;
break;
} else if (oneUpdateCount > 1) {
String msg = "The entity updated two or more records in batch update:";
msg = msg + " entity=" + list.get(index);
msg = msg + " updatedCount=" + oneUpdateCount;
msg = msg + " allEntities=" + list;
throw new EntityDuplicatedException(msg);
}
++index;
}
if (alreadyUpdated) {
int updateCount = 0;
for (int oneUpdateCount : updatedCountArray) {
updateCount = updateCount + oneUpdateCount;
}
if (_optimisticLockHandling) {
throw new BatchEntityAlreadyUpdatedException(list.get(index), 0, updateCount);
} else {
String msg = "The entity was NOT found! (might be deleted?):";
msg = msg + " entity=" + list.get(index);
msg = msg + " updateCount=" + updateCount;
msg = msg + " allEntities=" + list;
throw new EntityAlreadyDeletedException(msg);
}
}
}
Aggregations