@Test(expected = IllegalArgumentException.class) public void testNoTableName() throws Exception { db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*","","",null,null); }
@Override public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) { if (StringUtils.isEmpty(tableName)) { throw new IllegalArgumentException("Table name cannot be null or empty"); } final StringBuilder query = new StringBuilder("SELECT "); if (limit != null && offset == null){ query.append("TOP "); query.append(limit); query.append(" "); } if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) { query.append("*"); } else { query.append(columnNames); } query.append(" FROM "); query.append(tableName); if (!StringUtils.isEmpty(whereClause)) { query.append(" WHERE "); query.append(whereClause); } if (!StringUtils.isEmpty(orderByClause)) { query.append(" ORDER BY "); query.append(orderByClause); } if (offset != null && limit != null && limit > 0) { if (StringUtils.isEmpty(orderByClause)) { throw new IllegalArgumentException("Order by clause cannot be null or empty when using row paging"); } query.append(" OFFSET "); query.append(offset); query.append(" ROWS"); query.append(" FETCH NEXT "); query.append(limit); query.append(" ROWS ONLY"); } return query.toString(); }
MSSQLDatabaseAdapter implements DatabaseAdapter { @Override public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) { if (StringUtils.isEmpty(tableName)) { throw new IllegalArgumentException("Table name cannot be null or empty"); } final StringBuilder query = new StringBuilder("SELECT "); if (limit != null && offset == null){ query.append("TOP "); query.append(limit); query.append(" "); } if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) { query.append("*"); } else { query.append(columnNames); } query.append(" FROM "); query.append(tableName); if (!StringUtils.isEmpty(whereClause)) { query.append(" WHERE "); query.append(whereClause); } if (!StringUtils.isEmpty(orderByClause)) { query.append(" ORDER BY "); query.append(orderByClause); } if (offset != null && limit != null && limit > 0) { if (StringUtils.isEmpty(orderByClause)) { throw new IllegalArgumentException("Order by clause cannot be null or empty when using row paging"); } query.append(" OFFSET "); query.append(offset); query.append(" ROWS"); query.append(" FETCH NEXT "); query.append(limit); query.append(" ROWS ONLY"); } return query.toString(); } }
MSSQLDatabaseAdapter implements DatabaseAdapter { @Override public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) { if (StringUtils.isEmpty(tableName)) { throw new IllegalArgumentException("Table name cannot be null or empty"); } final StringBuilder query = new StringBuilder("SELECT "); if (limit != null && offset == null){ query.append("TOP "); query.append(limit); query.append(" "); } if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) { query.append("*"); } else { query.append(columnNames); } query.append(" FROM "); query.append(tableName); if (!StringUtils.isEmpty(whereClause)) { query.append(" WHERE "); query.append(whereClause); } if (!StringUtils.isEmpty(orderByClause)) { query.append(" ORDER BY "); query.append(orderByClause); } if (offset != null && limit != null && limit > 0) { if (StringUtils.isEmpty(orderByClause)) { throw new IllegalArgumentException("Order by clause cannot be null or empty when using row paging"); } query.append(" OFFSET "); query.append(offset); query.append(" ROWS"); query.append(" FETCH NEXT "); query.append(limit); query.append(" ROWS ONLY"); } return query.toString(); }  }
MSSQLDatabaseAdapter implements DatabaseAdapter { @Override public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) { if (StringUtils.isEmpty(tableName)) { throw new IllegalArgumentException("Table name cannot be null or empty"); } final StringBuilder query = new StringBuilder("SELECT "); if (limit != null && offset == null){ query.append("TOP "); query.append(limit); query.append(" "); } if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) { query.append("*"); } else { query.append(columnNames); } query.append(" FROM "); query.append(tableName); if (!StringUtils.isEmpty(whereClause)) { query.append(" WHERE "); query.append(whereClause); } if (!StringUtils.isEmpty(orderByClause)) { query.append(" ORDER BY "); query.append(orderByClause); } if (offset != null && limit != null && limit > 0) { if (StringUtils.isEmpty(orderByClause)) { throw new IllegalArgumentException("Order by clause cannot be null or empty when using row paging"); } query.append(" OFFSET "); query.append(offset); query.append(" ROWS"); query.append(" FETCH NEXT "); query.append(limit); query.append(" ROWS ONLY"); } return query.toString(); }  @Override String getName(); @Override String getDescription(); @Override String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset); }
MSSQLDatabaseAdapter implements DatabaseAdapter { @Override public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset) { if (StringUtils.isEmpty(tableName)) { throw new IllegalArgumentException("Table name cannot be null or empty"); } final StringBuilder query = new StringBuilder("SELECT "); if (limit != null && offset == null){ query.append("TOP "); query.append(limit); query.append(" "); } if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) { query.append("*"); } else { query.append(columnNames); } query.append(" FROM "); query.append(tableName); if (!StringUtils.isEmpty(whereClause)) { query.append(" WHERE "); query.append(whereClause); } if (!StringUtils.isEmpty(orderByClause)) { query.append(" ORDER BY "); query.append(orderByClause); } if (offset != null && limit != null && limit > 0) { if (StringUtils.isEmpty(orderByClause)) { throw new IllegalArgumentException("Order by clause cannot be null or empty when using row paging"); } query.append(" OFFSET "); query.append(offset); query.append(" ROWS"); query.append(" FETCH NEXT "); query.append(limit); query.append(" ROWS ONLY"); } return query.toString(); }  @Override String getName(); @Override String getDescription(); @Override String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Long limit, Long offset);  }