}\r
\r
/**\r
- * Returns the smallest next free id, if includeAudit is <code>true</code> the audit table is also considered in computation\r
+ * Returns the smallest next free id, if includeAudit is <code>true</code> the audit\r
+ * table is also considered in computation\r
* @throws NumberFormatException\r
* @throws SQLException\r
*/\r
protected int getMaxId1(ICdmDataSource datasource, String tableName, boolean includeAudit, IProgressMonitor monitor, CaseType caseType,\r
SchemaUpdateResult result) throws SQLException {\r
\r
- String sql = "SELECT max(id) FROM " +caseType.transformTo(tableName);\r
+ return getMaxIdentifier(datasource, tableName, "id", includeAudit, monitor, caseType, result);\r
+ }\r
+\r
+ protected int getMaxIdentifier(ICdmDataSource datasource, String tableName, String idAttrName, boolean includeAudit, IProgressMonitor monitor, CaseType caseType,\r
+ SchemaUpdateResult result) throws SQLException {\r
+\r
+ String sql = "SELECT max("+idAttrName+") FROM " +caseType.transformTo(tableName);\r
Integer maxId = getInteger(datasource, sql, 0);\r
\r
Integer maxIdAud = -1;\r
if(includeAudit){\r
- sql = "SELECT max(id) FROM " +caseType.transformTo(tableName + "_AUD");\r
+ sql = "SELECT max("+idAttrName+") FROM " +caseType.transformTo(tableName + "_AUD");\r
maxIdAud = getInteger(datasource, sql, 0);\r
}\r
return Math.max(maxId, maxIdAud) + 1;\r
}\r
\r
+\r
+ /**\r
+ * Creates a new entry in the AuditEvent table\r
+ * @return the revision number of the the new audit event\r
+ */\r
+ protected long createAuditEvent(ICdmDataSource datasource, CaseType caseType, IProgressMonitor monitor,\r
+ SchemaUpdateResult result) throws SQLException {\r
+ String sql;\r
+ long rev;\r
+ sql = "INSERT INTO @@AuditEvent@@ (revisionnumber, date, timestamp, uuid) "\r
+ + " VALUES (%d, '%s', %d, '%s') ";\r
+ int newId = this.getMaxIdentifier(datasource, "AuditEvent", "revisionNumber", false, monitor, caseType, result);\r
+ long timeStamp = System.currentTimeMillis();\r
+ sql = caseType.replaceTableNames(String.format(sql, newId, this.getNowString(), timeStamp, UUID.randomUUID()));\r
+ datasource.executeUpdate(sql);\r
+ rev = newId;\r
+ return rev;\r
+ }\r
+\r
private Integer getInteger(ICdmDataSource datasource, String sql, int nullReplace) throws SQLException {\r
Object value = datasource.getSingleValue(sql);\r
if (value == null){\r