QQQ-14 update createDate, modifyDate to default to current

This commit is contained in:
2022-06-29 15:51:25 -05:00
parent c6c6fb3fcb
commit 6b79de525e
3 changed files with 16 additions and 0 deletions

View File

@ -25,6 +25,7 @@ package com.kingsrook.qqq.backend.module.rdbms.actions;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.OffsetDateTime;
import com.kingsrook.qqq.backend.core.model.actions.AbstractQTableRequest;
import com.kingsrook.qqq.backend.core.model.metadata.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.QFieldType;
@ -102,6 +103,14 @@ public abstract class AbstractRDBMSAction
}
}
//////////////////////////////////////////////////////
// todo - let this come from something in the field //
//////////////////////////////////////////////////////
if(value == null && (field.getName().equals("createDate") || field.getName().equals("modifyDate")))
{
value = OffsetDateTime.now();
}
return (value);
}
}

View File

@ -652,6 +652,12 @@ public class QueryManager
statement.setTimestamp(index, timestamp);
return (1);
}
else if(value instanceof OffsetDateTime)
{
Timestamp timestamp = new Timestamp(((OffsetDateTime) value).toEpochSecond() * MS_PER_SEC);
statement.setTimestamp(index, timestamp);
return (1);
}
else if(value instanceof LocalDateTime)
{
Timestamp timestamp = new Timestamp(((LocalDateTime) value).toEpochSecond(ZoneOffset.UTC) * MS_PER_SEC);

View File

@ -74,6 +74,7 @@ public class RDBMSInsertActionTest extends RDBMSActionTest
rowsFound++;
assertEquals(6, rs.getInt("id"));
assertEquals("James", rs.getString("first_name"));
assertNotNull(rs.getString("create_date"));
}
assertEquals(1, rowsFound);
}));