Search in sources :

Example 1 with DbSqlGenerator

use of jodd.db.oom.DbSqlGenerator in project jodd by oblac.

the class DbQueryBuilder method createAndPopulateDbQuery.

/**
	 * Prepares <code>DbQuery</code>.
	 */
public DbOomQuery createAndPopulateDbQuery(ProxyTargetInfo proxyTargetInfo, String query) {
    if (query == null) {
        query = resolveQuery(proxyTargetInfo);
        if (query == null) {
            throw new DbOomException("Query not resolved.");
        }
    }
    // sql generator
    DbSqlGenerator dbSqlGenerator = parsedSqlMap.get(query);
    if (dbSqlGenerator == null) {
        ParsedSql parsedSql = sql(query).parse();
        parsedSqlMap.put(query, parsedSql);
        dbSqlGenerator = parsedSql;
    }
    // db oom query
    DbOomQuery dbOomQuery = query(dbSqlGenerator);
    // parameter names
    String keyName = proxyTargetInfo.targetClass.getName() + "." + proxyTargetInfo.targetMethodName;
    String[] paramNames = methodParamNames.get(keyName);
    if (paramNames == null) {
        paramNames = resolveMethodParameterNames(proxyTargetInfo);
        methodParamNames.put(keyName, paramNames);
    }
    for (int i = 0; i < paramNames.length; i++) {
        String paramName = paramNames[i];
        dbOomQuery.setObject(paramName, proxyTargetInfo.arguments[i]);
    }
    return dbOomQuery;
}
Also used : DbOomException(jodd.db.oom.DbOomException) DbSqlGenerator(jodd.db.oom.DbSqlGenerator) DbOomQuery(jodd.db.oom.DbOomQuery) ParsedSql(jodd.db.oom.sqlgen.ParsedSql)

Aggregations

DbOomException (jodd.db.oom.DbOomException)1 DbOomQuery (jodd.db.oom.DbOomQuery)1 DbSqlGenerator (jodd.db.oom.DbSqlGenerator)1 ParsedSql (jodd.db.oom.sqlgen.ParsedSql)1