Refactor transaction logging to simple SLF4J use

This commit is contained in:
Robin Bygrave committed 2013-04-15 23:16:08 +12:00
1 parent b5ef07bab9
commit cbd7b5e912
60 files changed
+2976 -4529

No files matched your search

@@ -1,116 +1,115 @@
package com.avaje.ebeaninternal.server.deploy;
/**
* Used to provide context during sql construction.
*/
public interface DbSqlContext {
/**
* Add a join to the sql query.
*/
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2);
/**
* Add a join to the sql query.
*/
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2);
public void pushSecondaryTableAlias(String alias);
public void pushSecondaryTableAlias(String alias);
/**
* Push the current table alias onto the stack.
*/
public void pushTableAlias(String tableAlias);
/**
* Push the current table alias onto the stack.
*/
public void pushTableAlias(String tableAlias);
/**
* Pop the current table alias from the stack.
*/
public void popTableAlias();
/**
* Pop the current table alias from the stack.
*/
public void popTableAlias();
/**
* Add an encrypted property which will require additional binding.
*/
public void addEncryptedProp(BeanProperty prop);
/**
* Add an encrypted property which will require additional binding.
*/
public void addEncryptedProp(BeanProperty prop);
/**
* Return a list of encrypted properties which require additional binding.
*/
public BeanProperty[] getEncryptedProps();
/**
* Return a list of encrypted properties which require additional binding.
*/
public BeanProperty[] getEncryptedProps();
/**
* Append a char directly to the SQL buffer.
*/
public DbSqlContext append(char s);
/**
* Append a char directly to the SQL buffer.
*/
public DbSqlContext append(char s);
/**
* Append a string directly to the SQL buffer.
*/
public DbSqlContext append(String s);
/**
* Append a string directly to the SQL buffer.
*/
public DbSqlContext append(String s);
/**
* Peek the current table alias.
*/
public String peekTableAlias();
/**
* Peek the current table alias.
*/
public String peekTableAlias();
/**
* Add a raw column to the sql.
*/
public void appendRawColumn(String rawcolumnWithTableAlias);
/**
* Add a raw column to the sql.
*/
public void appendRawColumn(String rawcolumnWithTableAlias);
/**
* Append a column with an explicit table alias.
*/
public void appendColumn(String tableAlias, String column);
/**
* Append a column with an explicit table alias.
*/
public void appendColumn(String tableAlias, String column);
/**
* Append a column with the current table alias.
*/
public void appendColumn(String column);
/**
* Append a column with the current table alias.
*/
public void appendColumn(String column);
/**
* Append a Sql Formula select. This converts the "${ta}" keyword to the
* current table alias.
*/
public void appendFormulaSelect(String sqlFormulaSelect);
/**
* Append a Sql Formula select. This converts the "${ta}" keyword to the
* current table alias.
*/
public void appendFormulaSelect(String sqlFormulaSelect);
/**
* Append a Sql Formula join. This converts the "${ta}" keyword to the
* current table alias.
*/
public void appendFormulaJoin(String sqlFormulaJoin, boolean forceOuterJoin);
/**
* Append a Sql Formula join. This converts the "${ta}" keyword to the current
* table alias.
*/
public void appendFormulaJoin(String sqlFormulaJoin, boolean forceOuterJoin);
/**
* Return the current content length.
*/
public int length();
/**
* Return the current content length.
*/
public int length();
/**
* Return the current context of the sql context.
*/
public String getContent();
/**
* Return the current context of the sql context.
*/
public String getContent();
/**
* Return the current join node.
*/
public String peekJoin();
/**
* Return the current join node.
*/
public String peekJoin();
/**
* Push a join node onto the stack.
*/
public void pushJoin(String prefix);
/**
* Push a join node onto the stack.
*/
public void pushJoin(String prefix);
/**
* Pop a join node off the stack.
*/
public void popJoin();
/**
* Pop a join node off the stack.
*/
public void popJoin();
/**
* Return a table alias without many where clause joins.
* Typically this is for the select clause (fetch joins).
*/
public String getTableAlias(String prefix);
/**
* Return a table alias without many where clause joins. Typically this is for
* the select clause (fetch joins).
*/
public String getTableAlias(String prefix);
/**
* Return a table alias that takes into account many where joins.
*/
public String getTableAliasManyWhere(String prefix);
/**
* Return a table alias that takes into account many where joins.
*/
public String getTableAliasManyWhere(String prefix);
public String getRelativePrefix(String propName);
public String getRelativePrefix(String propName);
}
@@ -15,194 +15,189 @@ import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
*/
public final class TableJoin {
public static final String NEW_LINE = "\n";
public static final String LEFT_OUTER = "left outer join";
public static final String LEFT_OUTER = "left outer join";
public static final String JOIN = "join";
/**
* Flag set when the imported key maps to the primary key.
* This occurs for intersection tables (ManyToMany).
*/
private final boolean importedPrimaryKey;
/**
* The joined table.
*/
private final String table;
/**
* The type of join. LEFT OUTER etc.
*/
private final String type;
public static final String JOIN = "join";
/**
* The persist cascade info.
*/
private final BeanCascadeInfo cascadeInfo;
/**
* Properties as an array.
*/
private final BeanProperty[] properties;
/**
* Columns as an array.
*/
private final TableJoinColumn[] columns;
/**
* Flag set when the imported key maps to the primary key. This occurs for
* intersection tables (ManyToMany).
*/
private final boolean importedPrimaryKey;
/**
* Create a TableJoin.
*/
public TableJoin(DeployTableJoin deploy, LinkedHashMap<String,BeanProperty> propMap) {
this.importedPrimaryKey = deploy.isImportedPrimaryKey();
this.table = InternString.intern(deploy.getTable());
this.type = InternString.intern(deploy.getType());
this.cascadeInfo = deploy.getCascadeInfo();
DeployTableJoinColumn[] deployCols = deploy.columns();
this.columns = new TableJoinColumn[deployCols.length];
for (int i = 0; i < deployCols.length; i++) {
this.columns[i] = new TableJoinColumn(deployCols[i]);
}
DeployBeanProperty[] deployProps = deploy.properties();
if (deployProps.length > 0 && propMap == null){
throw new NullPointerException("propMap is null?");
}
this.properties = new BeanProperty[deployProps.length];
for (int i = 0; i < deployProps.length; i++) {
BeanProperty prop = propMap.get(deployProps[i].getName());
this.properties[i] = prop;
}
/**
* The joined table.
*/
private final String table;
/**
* The type of join. LEFT OUTER etc.
*/
private final String type;
/**
* The persist cascade info.
*/
private final BeanCascadeInfo cascadeInfo;
/**
* Properties as an array.
*/
private final BeanProperty[] properties;
/**
* Columns as an array.
*/
private final TableJoinColumn[] columns;
/**
* Create a TableJoin.
*/
public TableJoin(DeployTableJoin deploy, LinkedHashMap<String, BeanProperty> propMap) {
this.importedPrimaryKey = deploy.isImportedPrimaryKey();
this.table = InternString.intern(deploy.getTable());
this.type = InternString.intern(deploy.getType());
this.cascadeInfo = deploy.getCascadeInfo();
DeployTableJoinColumn[] deployCols = deploy.columns();
this.columns = new TableJoinColumn[deployCols.length];
for (int i = 0; i < deployCols.length; i++) {
this.columns[i] = new TableJoinColumn(deployCols[i]);
}
/**
* Create a tableJoin based on this object but with different alias.
*/
public TableJoin createWithAlias(String localAlias, String foreignAlias) {
return new TableJoin(this, localAlias, foreignAlias);
}
/**
* Construct a copy but with different table alias'.
*/
private TableJoin(TableJoin join, String localAlias, String foreignAlias){
// copy the immutable fields
this.importedPrimaryKey = join.importedPrimaryKey;
this.table = join.table;
this.type = join.type;
this.cascadeInfo = join.cascadeInfo;
this.properties = join.properties;
this.columns = join.columns;
}
public String toString() {
StringBuilder sb = new StringBuilder(30);
sb.append(type).append(" ").append(table).append(" ");
for (int i = 0; i < columns.length; i++) {
sb.append(columns[i]).append(" ");
}
return sb.toString();
DeployBeanProperty[] deployProps = deploy.properties();
if (deployProps.length > 0 && propMap == null) {
throw new NullPointerException("propMap is null?");
}
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
for (int i = 0, x = properties.length; i < x; i++) {
properties[i].appendSelect(ctx, subQuery);
}
}
public void load(SqlBeanLoad sqlBeanLoad) throws SQLException {
for (int i = 0, x = properties.length; i < x; i++) {
properties[i].load(sqlBeanLoad);
}
}
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
for (int i = 0, x = properties.length; i < x; i++) {
properties[i].readSet(ctx, bean, type);
}
return null;
}
/**
* Return true if the imported foreign key maps to the primary key.
*/
public boolean isImportedPrimaryKey() {
return importedPrimaryKey;
}
/**
* Return the persist info.
*/
public BeanCascadeInfo getCascadeInfo() {
return cascadeInfo;
this.properties = new BeanProperty[deployProps.length];
for (int i = 0; i < deployProps.length; i++) {
BeanProperty prop = propMap.get(deployProps[i].getName());
this.properties[i] = prop;
}
/**
* Return the join columns.
*/
public TableJoinColumn[] columns() {
return columns;
}
}
/**
* For secondary table joins returns the properties mapped to that table.
*/
public BeanProperty[] properties() {
return properties;
}
/**
* Create a tableJoin based on this object but with different alias.
*/
public TableJoin createWithAlias(String localAlias, String foreignAlias) {
/**
* Return the joined table name.
*/
public String getTable() {
return table;
}
return new TableJoin(this, localAlias, foreignAlias);
}
/**
* Return the type of join. LEFT OUTER JOIN etc.
*/
public String getType() {
return type;
}
/**
* Construct a copy but with different table alias'.
*/
private TableJoin(TableJoin join, String localAlias, String foreignAlias) {
/**
* Return true if this join is a left outer join.
*/
public boolean isOuterJoin() {
return type.equals(LEFT_OUTER);
}
public boolean addJoin(boolean forceOuterJoin, String prefix, DbSqlContext ctx) {
// copy the immutable fields
this.importedPrimaryKey = join.importedPrimaryKey;
this.table = join.table;
this.type = join.type;
this.cascadeInfo = join.cascadeInfo;
this.properties = join.properties;
this.columns = join.columns;
}
String[] names = SplitName.split(prefix);
String a1 = ctx.getTableAlias(names[0]);
String a2 = ctx.getTableAlias(prefix);
public String toString() {
StringBuilder sb = new StringBuilder(30);
sb.append(type).append(" ").append(table).append(" ");
for (int i = 0; i < columns.length; i++) {
sb.append(columns[i]).append(" ");
}
return sb.toString();
}
return addJoin(forceOuterJoin, a1, a2, ctx);
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
for (int i = 0, x = properties.length; i < x; i++) {
properties[i].appendSelect(ctx, subQuery);
}
public boolean addJoin(boolean forceOuterJoin, String a1, String a2, DbSqlContext ctx) {
ctx.addJoin(forceOuterJoin?LEFT_OUTER:type, table, columns(), a1, a2);
return forceOuterJoin || LEFT_OUTER.equals(type);
}
public void load(SqlBeanLoad sqlBeanLoad) throws SQLException {
for (int i = 0, x = properties.length; i < x; i++) {
properties[i].load(sqlBeanLoad);
}
/**
* Explicitly add a (non-outer) join.
*/
public void addInnerJoin(String a1, String a2, DbSqlContext ctx) {
ctx.addJoin(JOIN, table, columns(), a1, a2);
}
public Object readSet(DbReadContext ctx, Object bean, Class<?> type) throws SQLException {
for (int i = 0, x = properties.length; i < x; i++) {
properties[i].readSet(ctx, bean, type);
}
return null;
}
/**
* Return true if the imported foreign key maps to the primary key.
*/
public boolean isImportedPrimaryKey() {
return importedPrimaryKey;
}
/**
* Return the persist info.
*/
public BeanCascadeInfo getCascadeInfo() {
return cascadeInfo;
}
/**
* Return the join columns.
*/
public TableJoinColumn[] columns() {
return columns;
}
/**
* For secondary table joins returns the properties mapped to that table.
*/
public BeanProperty[] properties() {
return properties;
}
/**
* Return the joined table name.
*/
public String getTable() {
return table;
}
/**
* Return the type of join. LEFT OUTER JOIN etc.
*/
public String getType() {
return type;
}
/**
* Return true if this join is a left outer join.
*/
public boolean isOuterJoin() {
return type.equals(LEFT_OUTER);
}
public boolean addJoin(boolean forceOuterJoin, String prefix, DbSqlContext ctx) {
String[] names = SplitName.split(prefix);
String a1 = ctx.getTableAlias(names[0]);
String a2 = ctx.getTableAlias(prefix);
return addJoin(forceOuterJoin, a1, a2, ctx);
}
public boolean addJoin(boolean forceOuterJoin, String a1, String a2, DbSqlContext ctx) {
ctx.addJoin(forceOuterJoin ? LEFT_OUTER : type, table, columns(), a1, a2);
return forceOuterJoin || LEFT_OUTER.equals(type);
}
/**
* Explicitly add a (non-outer) join.
*/
public void addInnerJoin(String a1, String a2, DbSqlContext ctx) {
ctx.addJoin(JOIN, table, columns(), a1, a2);
}
}