[#3237] UpdatableRecord.store() executes INSERT instead of UPDATE when nullable primary keys are NULL

This commit is contained in:
Lukas Eder 2014-05-20 15:51:12 +02:00
parent 29ef5221a8
commit 3f58268f77
5 changed files with 46 additions and 4 deletions

View File

@ -879,6 +879,10 @@ public abstract class BaseTest<
return new Timestamp(0).toString();
}
protected final void clean(Table<?>... tables) {
delegate.clean(tables);
}
protected final void assertCountAuthors(int count) {
assertEquals(count, (int) create().selectCount().from(TAuthor()).fetchOne(0, Integer.class));
}

View File

@ -955,11 +955,14 @@ xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxx
xxxxx
xxxxxx xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxxxx
xxxxxxxxxxxxx xxxxxx x xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx xxxxxxxxx
xxxxxxxxxxxxxxxxxx
@ -967,12 +970,22 @@ xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx xxxxxxx
xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx xxxxxxxx
xxxxxxxxxxxxxxxxxx
@ -980,18 +993,23 @@ xxxxxx xxxxx xxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxx xxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx xxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x
xxxxx
xxxxxx xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x
xxxxxxxxxxxxxx
xxxxxxxxxxxx xx x xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxx xx x xxxxxxxxxxxxxxxxxxxxxxxxxxx
xx xxxxxxx xxxxx xxxxxxx xx xxxxx
xxxxxxxxxxxxxxx
xxxxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxxxx

View File

@ -270,6 +270,7 @@ public abstract class jOOQAbstractTest<
public static String jdbcURL;
public static String jdbcSchema;
public static Map<String, String> scripts = new HashMap<String, String>();
public static Table<?>[] clean;
protected void execute(String script) throws Exception {
Statement stmt = null;
@ -457,6 +458,17 @@ public abstract class jOOQAbstractTest<
reset = true;
execute(getResetScript());
}
if (clean != null && clean.length > 0) {
for (Table<?> table : clean) {
try {
create().delete(table);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
}
@After
@ -464,6 +476,10 @@ public abstract class jOOQAbstractTest<
connection.setAutoCommit(autocommit);
}
public void clean(Table<?>... tables) {
this.clean = tables;
}
@BeforeClass
public static void testStart() throws Exception {
log.info("STARTING");

View File

@ -107,8 +107,9 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* <ul>
* <li>If this record was created by client code, an <code>INSERT</code>
* statement is executed</li>
* <li>If this record was loaded by jOOQ, but the primary key value was
* changed, an <code>INSERT</code> statement is executed. jOOQ expects that
* <li>If this record was loaded by jOOQ and the primary key value was
* changed, an <code>INSERT</code> statement is executed (unless
* {@link Settings#isUpdatablePrimaryKeys()} is set). jOOQ expects that
* primary key values will never change due to the principle of
* normalisation in RDBMS. So if client code changes primary key values,
* this is interpreted by jOOQ as client code wanting to duplicate this

View File

@ -155,8 +155,11 @@ public class UpdatableRecordImpl<R extends UpdatableRecord<R>> extends TableReco
// [#2764] Primary key value changes are interpreted as record copies
else {
// If any primary key value is null or changed, execute an insert
if (getValue(field) == null || getValue0(field).isChanged()) {
// If any primary key value is null or changed
if (getValue0(field).isChanged() ||
// [#3237] or if a NOT NULL primary key value is null, then execute an INSERT
(field.getDataType().nullable() == false && getValue(field) == null)) {
executeUpdate = false;
break;
}