Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions nbactions.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath net.certifi.audittablegen.AuditTableGen -d capturagp -s localhost --driver postgresql url jdbc:postgresql://localhost:5432/capturagp?searchpath=public -u postgres -p -xxx --schema public</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>runtime</exec.classpathScope>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath net.certifi.audittablegen.AuditTableGen -d capturagp -s localhost --driver postgresql url jdbc:postgresql://localhost:5432/capturagp?searchpath=public -u postgres -p -xxx --schema public</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>runtime</exec.classpathScope>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath net.certifi.audittablegen.AuditTableGen -d capturagp -s localhost --driver postgresql url jdbc:postgresql://localhost:5432/capturagp?searchpath=public -u postgres -p -xxx --schema public</exec.args>
<exec.executable>${profiler.java}</exec.executable>
<profiler.action>profile</profiler.action>
</properties>
</action>
</actions>
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath net.certifi.audittablegen.AuditTableGen -d postgres -s localhost --driver postgresql url jdbc:postgresql://localhost:5432/postgres?searchpath=public -u cservin -p -xxx --schema audit_table</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>runtime</exec.classpathScope>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath net.certifi.audittablegen.AuditTableGen -d postgres -s localhost --driver postgresql url jdbc:postgresql://localhost:5432/postgres?searchpath=public -u cservin -p -xxx --schema audit_table</exec.args>
<exec.executable>java</exec.executable>
<exec.classpathScope>runtime</exec.classpathScope>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.2:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath net.certifi.audittablegen.AuditTableGen -d postgres -s localhost --driver postgresql url jdbc:postgresql://localhost:5432/postgres?searchpath=public -u cservin -p -xxx --schema audit_table</exec.args>
<exec.executable>${profiler.java}</exec.executable>
<profiler.action>profile</profiler.action>
</properties>
</action>
</actions>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>net.certifi</groupId>
<artifactId>AuditTableGen</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.4</version>
<packaging>jar</packaging>

<name>AuditTableGen</name>
Expand Down
84 changes: 79 additions & 5 deletions src/main/java/net/certifi/audittablegen/ChangeSourceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package net.certifi.audittablegen;

import java.util.*;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.commons.collections.map.CaseInsensitiveMap;
import org.apache.commons.lang3.exception.ContextedRuntimeException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -77,6 +79,7 @@ public class ChangeSourceFactory {
break;
case iddatatype:
auditIdTypeName = attrib.getValue();
break;
case userdatatype:
auditUserTypeName = attrib.getValue();
break;
Expand Down Expand Up @@ -133,10 +136,20 @@ Boolean isPatternMatch(String str, String pattern) {
//TODO: this is where regexp or wildcard pattern matching should go
if (pattern.isEmpty()
|| pattern.equals("*")
|| pattern.toLowerCase().equals(str.toLowerCase())) {
|| pattern.toLowerCase().equals(str.toLowerCase()) ) {
return Boolean.TRUE;
}

try {
Pattern p = Pattern.compile( pattern, Pattern.CASE_INSENSITIVE|Pattern.UNICODE_CASE );
if ( p != null && p.matcher( str ).matches() ) return Boolean.TRUE;

} catch( IllegalArgumentException x) {

logger.warn( "Invalid Regexp " + x.getMessage() );
}


return Boolean.FALSE;

}
Expand Down Expand Up @@ -295,7 +308,7 @@ List<DBChangeUnit> getDBChangeList(TableDef baseTableDef){
workUnit.setColumnName(auditActionColumn);
workUnit.setTableName(auditTableName);
workUnit.setTypeName(auditActionTypeName); //insert, update, or delete
workUnit.setSize(6);
workUnit.setSize(1);
workUnit.setDecimalSize(0);
tableChangeUnits.add(workUnit);

Expand Down Expand Up @@ -330,14 +343,69 @@ List<DBChangeUnit> getDBChangeList(TableDef baseTableDef){

//end of table
tableChangeUnits.add(new DBChangeUnit(DBChangeType.end));

// populate the table
tableChangeUnits.add( new DBChangeUnit(DBChangeType.begin) );
workUnit = new DBChangeUnit(DBChangeType.fillAuditTable);
workUnit.setAuditTableName( auditTableName );
workUnit.setTypeName( baseTableName );
tableChangeUnits.add(workUnit);

// fill all columns on the base table
for (ColumnDef baseColumn : baseTableDef.getColumns()) {
workUnit = new DBChangeUnit(DBChangeType.addColumn);
workUnit.setColumnName(baseColumn.getName());
workUnit.setTableName(auditTableName);
workUnit.setTypeName(baseColumn.getTypeName());
workUnit.setSize(baseColumn.getSize());
workUnit.setDecimalSize(baseColumn.getDecimalSize());
tableChangeUnits.add(workUnit);
}

//action
workUnit = new DBChangeUnit(DBChangeType.addTriggerAction);
workUnit.setColumnName(auditActionColumn);
workUnit.setTableName(baseTableName);
workUnit.setAuditTableName(auditTableName);
tableChangeUnits.add(workUnit);

//user
workUnit = new DBChangeUnit(DBChangeType.addTriggerUser);
workUnit.setColumnName(auditUserColumn);
workUnit.setTableName(baseTableName);
workUnit.setAuditTableName(auditTableName);
tableChangeUnits.add(workUnit);

//timestamp
workUnit = new DBChangeUnit(DBChangeType.addTriggerTimeStamp);
workUnit.setColumnName(auditTimeStampColumn);
workUnit.setTableName(baseTableName);
workUnit.setAuditTableName(auditTableName);
tableChangeUnits.add(workUnit);

//sessionuser
if (!sessionUserSQL.isEmpty()) {
workUnit = new DBChangeUnit(DBChangeType.addTriggerSessionUser);
workUnit.setColumnName(sessionUserColumn);
workUnit.setTableName(baseTableName);
workUnit.setAuditTableName(auditTableName);
tableChangeUnits.add(workUnit);
}
else {

workUnit = new DBChangeUnit(DBChangeType.end);
workUnit.setTableName(baseTableName);
workUnit.setAuditTableName(auditTableName);
tableChangeUnits.add(workUnit);

} else {
//alter table
//there might not be any changes, so store up any changes in
//a temporary list, and evaluate.
alterTableChangeUnits.add(new DBChangeUnit(DBChangeType.begin));
workUnit = new DBChangeUnit(DBChangeType.alterTable);
workUnit.setTableName(auditTableName);
workUnit.setTableName(baseTableName);
workUnit.setAuditTableName( auditTableName );
workUnit.setTableDef( baseTableDef );
alterTableChangeUnits.add(workUnit);

//to make this a little easier, get a map for the column list
Expand Down Expand Up @@ -391,6 +459,7 @@ List<DBChangeUnit> getDBChangeList(TableDef baseTableDef){
workUnit = new DBChangeUnit(DBChangeType.addColumn);
workUnit.setColumnName(sessionUserColumn);
workUnit.setTableName(auditTableName);
workUnit.setAuditTableName( auditTableName );
workUnit.setTypeName(sessionUserTypeName);
workUnit.setSize(sessionUserDataSize);
workUnit.setDecimalSize(0);
Expand Down Expand Up @@ -460,6 +529,7 @@ else if (auditColumn.getTypeName().equalsIgnoreCase(baseColumn.getTypeName())
//new column
workUnit = new DBChangeUnit(DBChangeType.addColumn);
workUnit.setTableName(auditTableName);
workUnit.setAuditTableName( auditTableName );
workUnit.setColumnName(baseColumn.getName());
workUnit.setTypeName(baseColumn.getTypeName());
workUnit.setSize(baseColumn.getSize());
Expand All @@ -469,7 +539,11 @@ else if (auditColumn.getTypeName().equalsIgnoreCase(baseColumn.getTypeName())
}

//end of table
alterTableChangeUnits.add(new DBChangeUnit(DBChangeType.end));
workUnit = new DBChangeUnit( DBChangeType.end );
workUnit.setTableName( baseTableName );
workUnit.setAuditTableName( auditTableName );
workUnit.setTableDef( baseTableDef );
alterTableChangeUnits.add( workUnit );

//add the workUnits to the return value
if (!renameColumnChangeUnits.isEmpty()){
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/certifi/audittablegen/ColumnDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public void setDataTypeDef(DataTypeDef dataTypeDef) {
this.dataTypeDef = dataTypeDef;
}

@Override
public String toString() {
return "ColumnDef{" + "name=" + name + ", typeName=" + typeName + ", sqlType=" + sqlType + ", size=" + size + ", decimalSize=" + decimalSize + ", dataTypeDef=" + dataTypeDef + ", sourceMeta=" + sourceMeta + '}';
}

}
1 change: 1 addition & 0 deletions src/main/java/net/certifi/audittablegen/DBChangeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public enum DBChangeType {
addTriggerUser,
addTriggerTimeStamp,
addTriggerSessionUser,
fillAuditTable,
notSet;
}
28 changes: 26 additions & 2 deletions src/main/java/net/certifi/audittablegen/DBChangeUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,17 @@ public class DBChangeUnit {
int size = 0;
int decimalSize = 0;
Boolean identity = Boolean.FALSE;
TableDef tableDef = null;
//DataTypeDef dataTypeDef = null;

public TableDef getTableDef() {
return tableDef;
}

public void setTableDef(TableDef tableDef) {
this.tableDef = tableDef;
}

public DBChangeUnit( DBChangeType changeType) {
this.changeType = changeType;
}
Expand Down Expand Up @@ -290,6 +299,7 @@ else if ( workListTag == DBChangeType.notSet){
case alterTable:
case createTriggers:
case dropTriggers:
case fillAuditTable:
if (!beginTag){
//begin tag missing.
//could be implied, but treat as error condition.
Expand All @@ -312,7 +322,8 @@ else if (workListTag != DBChangeType.notSet){
valid = false;
}
else if (workListTag != DBChangeType.createTable
&& workListTag != DBChangeType.alterTable) {
&& workListTag != DBChangeType.alterTable
&& workListTag != DBChangeType.fillAuditTable ) {
logger.info ("improperly formed List<DBChangeType>. Unit{%s} not of valid for {%s} at element %d",
unit.getChangeType().toString(), workListTag.toString(), i);
valid = false;
Expand Down Expand Up @@ -340,14 +351,27 @@ else if (workListTag != DBChangeType.createTable
case fireOnInsert:
case fireOnUpdate:
case fireOnDelete:
if (beginTag == false){
logger.info ("improperly formed List<DBChangeType>. Missing [begin] before element %d", i);
}
if (workListTag != DBChangeType.createTriggers){
throw new RuntimeException ("improperly formed List<DBChangeType>. Unit{" +
unit.getChangeType().toString() + "} not of valid for {"
+ workListTag.toString() +"}");
}
else {
valid = validateUnit(unit, parentUnit);
}
break;
case addTriggerAction:
case addTriggerTimeStamp:
case addTriggerUser:
case addTriggerSessionUser:
if (beginTag == false){
logger.info ("improperly formed List<DBChangeType>. Missing [begin] before element %d", i);
}
if (workListTag != DBChangeType.createTriggers){
if (workListTag != DBChangeType.createTriggers
&& workListTag != DBChangeType.fillAuditTable ){
throw new RuntimeException ("improperly formed List<DBChangeType>. Unit{" +
unit.getChangeType().toString() + "} not of valid for {"
+ workListTag.toString() +"}");
Expand Down
Loading