summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-07-23 20:06:17 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-07-23 20:06:17 +0000
commit2dac6dea22e8ad78999913c4b4b1dd2e87c43700 (patch)
tree5c3a003d66d7a67cf6051304c55adc833ad53037 /src/main/java/com/amazon/carbonado/repo
parentccb7ca2b0d7bde5a2577b373eb289887bb25c58a (diff)
Detect if reload after insert fails and try to provide explanation as to cause.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java
index 0dc9d38..d2b5a1e 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java
@@ -27,10 +27,12 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.EnumSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
+
import org.cojen.classfile.ClassFile;
import org.cojen.classfile.CodeBuilder;
import org.cojen.classfile.Label;
@@ -43,6 +45,8 @@ import org.cojen.util.ClassInjector;
import org.cojen.util.KeyFactory;
import org.cojen.util.SoftValuedHashMap;
+import org.joda.time.ReadableInstant;
+
import com.amazon.carbonado.FetchException;
import com.amazon.carbonado.OptimisticLockException;
import com.amazon.carbonado.PersistException;
@@ -792,7 +796,34 @@ class JDBCStorableGenerator<S extends Storable> {
b.invokeVirtual(MasterStorableGenerator.DO_TRY_LOAD_MASTER_METHOD_NAME,
TypeDesc.BOOLEAN,
new TypeDesc[] {jdbcSupportType, connectionType, lobArrayType});
- b.pop();
+ Label reloaded = b.createLabel();
+ b.ifZeroComparisonBranch(reloaded, "!=");
+
+ String message = "Reload after insert failed, " +
+ "possibly because database changed the primary key: ";
+
+ for (JDBCStorableProperty<S> prop : mInfo.getPrimaryKeyProperties().values()) {
+ Class type = prop.getType();
+ if (Date.class.isAssignableFrom(type) ||
+ ReadableInstant.class.isAssignableFrom(type))
+ {
+ message += "Property type of date may have been truncated: " +
+ prop.getName() + ": ";
+ }
+ }
+
+ TypeDesc persistExType = TypeDesc.forClass(PersistException.class);
+ b.newObject(persistExType);
+ b.dup();
+ b.loadConstant(message);
+ b.loadThis();
+ b.invokeVirtual(TO_STRING_KEY_ONLY_METHOD_NAME, TypeDesc.STRING, null);
+ b.invokeVirtual(TypeDesc.STRING, "concat",
+ TypeDesc.STRING, new TypeDesc[] {TypeDesc.STRING});
+ b.invokeConstructor(persistExType, new TypeDesc[] {TypeDesc.STRING});
+ b.throwObject();
+
+ reloaded.setLocation();
}
// Note: yieldConAndHandleException is not called, allowing any