@Test public void testInlinedBindValuesForDatetime() throws Exception { jOOQAbstractTest.reset = false; Date d1 = Date.valueOf("1981-07-10"); Time t1 = Time.valueOf("12:01:15"); Timestamp ts1 = Timestamp.valueOf("1981-07-10 12:01:15"); Factory create = create(new Settings() .withStatementType(StatementType.STATIC_STATEMENT)); DATE date = create.newRecord(TDates()); date.setValue(TDates_ID(), 1); assertEquals(1, date.store()); date.setValue(TDates_ID(), 2); date.setValue(TDates_D(), d1); date.setValue(TDates_T(), t1); date.setValue(TDates_TS(), ts1); assertEquals(1, date.store()); Result<Record> dates = create.select(TDates_ID(), TDates_D(), TDates_T(), TDates_TS()) .from(TDates()) .orderBy(TDates_ID()) .fetch(); assertEquals(2, dates.size()); assertEquals(asList(1, 2), dates.getValues(TDates_ID())); assertEquals(asList(1, null, null, null), asList(dates.get(0).intoArray())); assertEquals(asList((Object) 2, d1, t1, ts1), asList(dates.get(1).intoArray())); }
@Test public void testUpdatablesVersionAndTimestamp() throws Exception { if (TBook_REC_TIMESTAMP() == null && TBook_REC_VERSION() == null) { log.info("SKIPPING", "Record version and timestamp tests"); } jOOQAbstractTest.reset = false; Factory create = create(new Settings().withExecuteWithOptimisticLocking(true)); boolean t = TBook_REC_TIMESTAMP() != null; boolean v = TBook_REC_VERSION() != null; // Test data integrity check // ------------------------- if (t) assertEquals(2, create.selectCount().from(TBook()).where(TBook_REC_TIMESTAMP().isNotNull()).fetchOne(0)); if (v) assertEquals(2, create.selectCount().from(TBook()).where(TBook_REC_VERSION().isNotNull()).fetchOne(0)); // Version and timestamp shouldn't change when there are constraint violations // ------------------------- B book1 = create.newRecord(TBook()); book1.setValue(TBook_ID(), 5); try { book1.store(); fail(); } catch (DataAccessException expected) {} if (t) assertNull(book1.getValue(TBook_REC_TIMESTAMP())); if (v) assertNull(book1.getValue(TBook_REC_VERSION())); // Test non-nullability of version and timestamp for new books // ------------------------- B book2 = newBook(5); assertEquals(1, book2.store()); Timestamp t2 = t ? book2.getValue(TBook_REC_TIMESTAMP()) : null; Integer v2 = v ? book2.getValue(TBook_REC_VERSION()) : null; if (t) assertNotNull(t2); if (v) assertNotNull(v2); // Test immutability of version and timestamp for non-stored books // ------------------------- book2.refresh(); assertEquals(0, book2.store()); assertEquals(t2, t ? book2.getValue(TBook_REC_TIMESTAMP()) : null); assertEquals(v2, v ? book2.getValue(TBook_REC_VERSION()) : null); // Test resetting of version and timestamp for copied books // ------------------------- B book3 = book2.copy(); book3.setValue(TBook_ID(), 6); assertEquals(1, book3.store()); Timestamp t3 = t ? book3.getValue(TBook_REC_TIMESTAMP()) : null; Integer v3 = v ? book3.getValue(TBook_REC_VERSION()) : null; if (t) assertNotNull(t3); if (v) assertNotNull(v3); if (t && t2 != null) assertFalse(t2.equals(t3)); if (v && v2 != null) assertFalse(v2.equals(v3)); // Check if updating all records will lead to updated version and timestamp values // ------------------------- // BOOK[ID=4] has version and timestamp set to null B book4 = create().fetchOne(TBook(), TBook_ID().equal(4)); book4.setValue(TBook_TITLE(), "Blah"); assertEquals(1, book4.store()); Timestamp t4 = t ? book4.getValue(TBook_REC_TIMESTAMP()) : null; Integer v4 = v ? book4.getValue(TBook_REC_VERSION()) : null; if (t) assertNotNull(t4); if (v) assertEquals(Integer.valueOf(1), v4); book4.refresh(); if (t) assertEquals(t4, book4.getValue(TBook_REC_TIMESTAMP())); if (v) assertEquals(v4, book4.getValue(TBook_REC_VERSION())); // Increment both values book4.setValue(TBook_TITLE(), "Blah 1"); assertEquals(1, book4.store()); Timestamp t4a = t ? book4.getValue(TBook_REC_TIMESTAMP()) : null; Integer v4a = v ? book4.getValue(TBook_REC_VERSION()) : null; if (t) assertNotNull(t4a); if (v) assertEquals(Integer.valueOf(2), v4a); book4.refresh(); if (t) assertEquals(t4a, book4.getValue(TBook_REC_TIMESTAMP())); if (v) assertEquals(v4a, book4.getValue(TBook_REC_VERSION())); // Don't change the book assertEquals(0, book4.store()); if (t) assertEquals(t4a, book4.getValue(TBook_REC_TIMESTAMP())); if (v) assertEquals(v4a, book4.getValue(TBook_REC_VERSION())); book4.refresh(); if (t) assertEquals(t4a, book4.getValue(TBook_REC_TIMESTAMP())); if (v) assertEquals(v4a, book4.getValue(TBook_REC_VERSION())); }