[Minor] code cleanup

This commit is contained in:
Robert von Burg 2014-09-14 12:20:49 +02:00
parent 376278cc25
commit bba96ef447
6 changed files with 53 additions and 49 deletions

View File

@ -134,7 +134,7 @@ public class PostgreSqlAuditDao implements AuditDao {
try (PreparedStatement statement = this.tx.getConnection().prepareStatement(sql)) {
try (ResultSet result = statement.executeQuery()) {
while (result.next()) {
keySet.add(result.getString(ELEMENT_TYPE)); //$NON-NLS-1$
keySet.add(result.getString(ELEMENT_TYPE));
}
}
} catch (SQLException e) {

View File

@ -58,13 +58,13 @@ public class PostgreSqlAuditQueryVisitor implements AuditQueryVisitor {
}
public String getSql() {
if (sqlAsString != null)
return sqlAsString;
if (this.sqlAsString != null)
return this.sqlAsString;
this.sql.append("\nwhere\n");
this.sql.append(this.sb.toString());
sqlAsString = this.sql.toString();
return sqlAsString;
this.sqlAsString = this.sql.toString();
return this.sqlAsString;
}
@Override
@ -120,21 +120,21 @@ public class PostgreSqlAuditQueryVisitor implements AuditQueryVisitor {
ensureAnd();
this.sb.append(this.indent);
if (accessTypes.length == 1) {
sb.append(PostgreSqlAuditDao.ACCESS_TYPE + " = ?");
sb.append(PostgreSqlAuditDao.ACCESS_TYPE_TYPE);
sb.append("\n");
this.sb.append(PostgreSqlAuditDao.ACCESS_TYPE + " = ?");
this.sb.append(PostgreSqlAuditDao.ACCESS_TYPE_TYPE);
this.sb.append("\n");
this.values.add(accessTypes[0].name());
} else {
sb.append(PostgreSqlAuditDao.ACCESS_TYPE + " in (");
this.sb.append(PostgreSqlAuditDao.ACCESS_TYPE + " in (");
for (int i = 0; i < accessTypes.length; i++) {
sb.append("?");
sb.append(PostgreSqlAuditDao.ACCESS_TYPE_TYPE);
values.add(accessTypes[i].name());
this.sb.append("?");
this.sb.append(PostgreSqlAuditDao.ACCESS_TYPE_TYPE);
this.values.add(accessTypes[i].name());
if (i < accessTypes.length - 1)
sb.append(", ");
this.sb.append(", ");
}
sb.append(" )\n");
sb.append("\n");
this.sb.append(" )\n");
this.sb.append("\n");
}
}
}

View File

@ -32,10 +32,12 @@ public class PostgreSqlOrderQueryVisitor extends PostgreSqlQueryVisitor implemen
super(fields);
}
@Override
protected String getClassName() {
return Tags.ORDER;
}
@Override
protected String getTableName() {
return PostgreSqlOrderDao.ORDERS;
}
@ -47,8 +49,8 @@ public class PostgreSqlOrderQueryVisitor extends PostgreSqlQueryVisitor implemen
@Override
public void visit(StateSelection selection) {
sb.append(indent);
sb.append("state = ?::order_state\n");
values.add(selection.getState().name());
this.sb.append(this.indent);
this.sb.append("state = ?::order_state\n");
this.values.add(selection.getState().name());
}
}

View File

@ -75,23 +75,23 @@ public abstract class PostgreSqlQueryVisitor implements StrolchRootElementSelect
}
public String getSql() {
if (sqlAsString != null)
return sqlAsString;
if (this.sqlAsString != null)
return this.sqlAsString;
this.sql.append("\nwhere\n");
this.sql.append(this.indent);
if (this.any) {
this.sql.append("type = ?");
sqlAsString = this.sql.toString();
return sqlAsString;
this.sqlAsString = this.sql.toString();
return this.sqlAsString;
}
this.sql.append("type = ? and\n");
this.sql.append(this.sb.toString());
sqlAsString = this.sql.toString();
return sqlAsString;
this.sqlAsString = this.sql.toString();
return this.sqlAsString;
}
/**
@ -235,42 +235,42 @@ public abstract class PostgreSqlQueryVisitor implements StrolchRootElementSelect
xpath = xpath.replace("${bagKey}", selection.getBagKey());
xpath = xpath.replace("${paramKey}", selection.getParamKey());
sb.append(this.indent);
sb.append("id in (\n");
sb.append(this.indent);
sb.append(" SELECT id\n");
sb.append(this.indent);
sb.append(" FROM (\n");
sb.append(this.indent);
sb.append(" SELECT id, UNNEST(");
sb.append(xpath);
sb.append("\n");
sb.append(this.indent);
sb.append("from ");
sb.append(getTableName());
sb.append("\n");
sb.append(this.indent);
sb.append(") AS alias\n");
sb.append(this.indent);
sb.append("WHERE ");
this.sb.append(this.indent);
this.sb.append("id in (\n");
this.sb.append(this.indent);
this.sb.append(" SELECT id\n");
this.sb.append(this.indent);
this.sb.append(" FROM (\n");
this.sb.append(this.indent);
this.sb.append(" SELECT id, UNNEST(");
this.sb.append(xpath);
this.sb.append("\n");
this.sb.append(this.indent);
this.sb.append("from ");
this.sb.append(getTableName());
this.sb.append("\n");
this.sb.append(this.indent);
this.sb.append(") AS alias\n");
this.sb.append(this.indent);
this.sb.append("WHERE ");
if (selection.getMatchMode().isEquals()) {
if (selection.getMatchMode().isCaseSensitve()) {
sb.append("content = ?\n");
this.sb.append("content = ?\n");
} else {
sb.append("content ILIKE ?\n");
this.sb.append("content ILIKE ?\n");
}
} else {
value = "%" + value + "%";
if (selection.getMatchMode().isCaseSensitve()) {
sb.append("content LIKE ?\n");
this.sb.append("content LIKE ?\n");
} else {
sb.append("content ILIKE ?\n");
this.sb.append("content ILIKE ?\n");
}
}
sb.append(this.indent);
sb.append(")\n");
this.sb.append(this.indent);
this.sb.append(")\n");
this.values.add(value);
}

View File

@ -30,10 +30,12 @@ public class PostgreSqlResourceQueryVisitor extends PostgreSqlQueryVisitor imple
super(fields);
}
@Override
protected String getClassName() {
return Tags.RESOURCE;
}
@Override
protected String getTableName() {
return PostgreSqlResourceDao.RESOURCES;
}

View File

@ -100,7 +100,7 @@ public class PostgreSqlStrolchTransaction extends AbstractTransaction {
public AuditDao getAuditDao() {
if (this.auditDao == null)
this.auditDao = new PostgreSqlAuditDao(this);
return (AuditDao) this.auditDao;
return this.auditDao;
}
Connection getConnection() {