[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 (PreparedStatement statement = this.tx.getConnection().prepareStatement(sql)) {
try (ResultSet result = statement.executeQuery()) { try (ResultSet result = statement.executeQuery()) {
while (result.next()) { while (result.next()) {
keySet.add(result.getString(ELEMENT_TYPE)); //$NON-NLS-1$ keySet.add(result.getString(ELEMENT_TYPE));
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

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

View File

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

View File

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

View File

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

View File

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