javalite/activejdbc — pull request #250 by rob68 (2014-04-21 13:18:22+00:00)
Title: Modification to allow for custom dialects.

Because some JDBC drivers like Informix require a license, AciveJDBC can't add a dialect for it since it can't be fully supported. This modification allows for adding custom dialects to ActiveJDBC.

Added a getObject to DefaultDialect to allow for overriding the ResultSet getObject method and added a dialects property to the activejdbc.properties file to allow custom dialects that are not officially supported by ActiveJDBC.

Informix Dialect:

public class InformixDialect extends DefaultDialect {

/**
* Generates adds limit, offset and order bys to a sub-query
*
* @param tableName name of table. If table name is null, then the subQuery parameter is considered to be a full query, and all that needs to be done is to
* add limit, offset and order bys
* @param subQuery sub-query or a full query
* @param orderBys
* @param limit
* @param offset
* @return query with
*/
@Override
public String formSelect(String tableName, String subQuery, List orderBys, long limit, long offset) {

String fullQuery;
if (tableName == null){
fullQuery = subQuery;
} else {
fullQuery = "SELECT";

if(offset != -1){
fullQuery += " SKIP " + offset;
}
if(limit != -1){
fullQuery += " LIMIT " + limit;
}

fullQuery += " * FROM " + tableName;
if (!Util.blank(subQuery)) {
String where = " WHERE ";

if (!groupByPattern.matcher(subQuery.toLowerCase().trim()).find() &&
!orderByPattern.matcher(subQuery.toLowerCase().trim()).find()) {
fullQuery += where;
}
fullQuery += " " + subQuery;
}
}

if(!orderBys.isEmpty()){
fullQuery += " ORDER BY " + Util.join(orderBys, ", ");
}

return fullQuery;
}

@Override
public Object getObject(ResultSet rs, int columnIndex) throws SQLException {
Object value = super.getObject(rs, columnIndex);

// Informix 3.70.JC8 getObject returns a String for TEXT objects instead of bytes.
// This causes problems when the object is encoded.
if (value == null && rs.getMetaData().getColumnTypeName(columnIndex).equalsIgnoreCase("TEXT")) {
value = rs.getBytes(columnIndex);
}

return value;
}
}