use of org.dbflute.exception.EntityDuplicatedException in project dbflute-core by dbflute.
the class BehaviorExceptionThrowerTest method test_throwEntityDuplicatedException.
public void test_throwEntityDuplicatedException() {
try {
createTarget().throwSelectEntityDuplicatedException("123", "foo", new Exception());
fail();
} catch (EntityDuplicatedException e) {
// OK
log(e.getMessage());
assertTrue(e.getMessage().contains("123"));
assertTrue(e.getMessage().contains("foo"));
}
}
use of org.dbflute.exception.EntityDuplicatedException in project dbflute-core by dbflute.
the class BehaviorExceptionThrower method throwUpdateEntityDuplicatedException.
public <ENTITY extends Entity> void throwUpdateEntityDuplicatedException(ENTITY entity, int count) {
final ExceptionMessageBuilder br = createExceptionMessageBuilder();
br.addNotice("The updated entity was duplicated. It should be the only one!");
br.addItem("Count");
br.addElement(count);
setupEntityElement(br, entity);
final String msg = br.buildExceptionMessage();
// basically no way if you use PK constraint
throw new EntityDuplicatedException(msg);
}
use of org.dbflute.exception.EntityDuplicatedException in project dbflute-core by dbflute.
the class BehaviorExceptionThrower method throwSelectEntityDuplicatedException.
public void throwSelectEntityDuplicatedException(String resultCountExp, Object searchKey, Throwable cause) {
final ExceptionMessageBuilder br = createExceptionMessageBuilder();
br.addNotice("Duplicate entity by the condition. (should be the only one)");
br.addItem("Advice");
br.addElement("Confirm your search condition. Is it really for the only one?");
br.addElement("And confirm your database. Does it really exist the only one?");
br.addElement("For example:");
br.addElement(" (x):");
br.addElement(" memberBhv.selectEntity(cb -> {");
br.addElement(" cb.query().setMemberName_LikeSearch(\"S\", op -> op.likePrefix());");
br.addElement(" }).alwaysPresent(...)");
br.addElement(" (o):");
br.addElement(" memberBhv.selectEntity(cb -> {");
br.addElement(" cb.query().setMemberId_Equal(3);");
br.addElement(" }).alwaysPresent(...)");
br.addItem("Result Count");
br.addElement(resultCountExp);
setupSearchKeyElement(br, searchKey);
final String msg = br.buildExceptionMessage();
if (cause != null) {
throw new EntityDuplicatedException(msg, cause);
} else {
throw new EntityDuplicatedException(msg);
}
}
use of org.dbflute.exception.EntityDuplicatedException 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