The Wayback Machine - https://web.archive.org/web/20200907135739/https://github.com/javalite/javalite/pull/250
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification to allow for custom dialects. #250

Open
wants to merge 3 commits into
base: master
from
Open

Conversation

@rob68
Copy link
Contributor

rob68 commented Apr 21, 2014

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<String> 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;
}

}

@ipolevoy ipolevoy force-pushed the javalite:master branch 2 times, most recently from f2f2f43 to 7e51945 Nov 29, 2016
@jfcabral
Copy link
Collaborator

jfcabral commented Aug 9, 2017

Hi @rob68, are you talking about IBM Informix DBs?
If so, I believe that it could be officially supported, using a similar strategy like it was done for IBM DB2, Oracle, SqlServer, which is to use an "express" or "developer" edition of the referred database.
After a quick search I've found 2 docker containers for IBM Informix that should do the trick:

IBM Informix Innovator-C eliminates the up-front licensing costs of developing popular database functionality for use in production (redistribution requires a separate license). The Innovator-C Edition is available on Linux, Windows and Mac platforms and is limited to one core and 2 GB of memory.

and

IBM Informix Developer Edition is free database software for application development and prototyping.

Even though it would also require the test suite, it does seem viable, doesn't it @ipolevoy?

@ipolevoy
Copy link
Member

ipolevoy commented Aug 9, 2017

we already installed a working docker with DB2, will be checking out a new PL: #622 soon.

@ipolevoy
Copy link
Member

ipolevoy commented Aug 9, 2017

technically speaking, ActiveJDBC is not complicated when it comes to generating SQL, so many more databases can be added to the mix.

@ipolevoy ipolevoy force-pushed the javalite:master branch from f8258bc to 05d9da3 Aug 9, 2019
ipolevoy added a commit that referenced this pull request Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.