I now detail a basic example of archiving the case audit trail to a Biz DB.
I created the following table in my Biz schema
AUDIT_TIME is defined as TIMESTAMP the rest are varchars.
I now create a utility class to do the DB insert -
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
public class AuditBizDB {
public AuditBizDB() {
super();
}
public String writeAudit2DB(String caseId, Date auditDate, String msgType, String msg) {
Connection conn = null;
Timestamp auditDateTime = getTimestamp(auditDate);
try {
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",
"niall", "niall");
PreparedStatement insertAudit = null;
String insertSQL =
"INSERT INTO NIALL.AUDIT4CASE (CASE_ID, AUDIT_TIME, AUDIT_MSG, AUDIT_MSG_TYPE) VALUES (?, ?, ?, ? )";
insertAudit = conn.prepareStatement(insertSQL);
insertAudit.setString(1, caseId);
insertAudit.setTimestamp(2, auditDateTime );
insertAudit.setString(3, msg);
insertAudit.setString(4, msgType);
insertAudit.execute();
conn.commit();
conn.close();
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
}
return "success";
}
private static java.sql.Timestamp getTimestamp(java.util.Date today) {
return new java.sql.Timestamp(today.getTime());
}
}
I call this from the existing auditing methods of my CaseAPI client -
etc.
I re-run my tester and see the following output in my DB.
No comments:
Post a Comment