Search in sources :

Example 1 with LockMode

use of com.revolsys.record.schema.LockMode in project com.revolsys.open by revolsys.

the class JdbcUtils method getSelectSql.

public static String getSelectSql(final Query query) {
    final String tableName = query.getTypeName();
    final String dbTableName = getQualifiedTableName(tableName);
    String sql = query.getSql();
    final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
    RecordDefinition recordDefinition = query.getRecordDefinition();
    if (sql == null) {
        if (recordDefinition == null) {
            recordDefinition = new RecordDefinitionImpl(PathName.newPathName(tableName));
        // throw new IllegalArgumentException("Unknown table name " +
        // tableName);
        }
        final List<String> fieldNames = new ArrayList<>(query.getFieldNames());
        if (fieldNames.isEmpty()) {
            final List<String> recordDefinitionFieldNames = recordDefinition.getFieldNames();
            if (recordDefinitionFieldNames.isEmpty()) {
                fieldNames.add("T.*");
            } else {
                fieldNames.addAll(recordDefinitionFieldNames);
            }
        }
        final String fromClause = query.getFromClause();
        final LockMode lockMode = query.getLockMode();
        final boolean distinct = query.isDistinct();
        sql = newSelectSql(recordDefinition, "T", distinct, fromClause, fieldNames, query, orderBy, lockMode);
    } else {
        if (sql.toUpperCase().startsWith("SELECT * FROM ")) {
            final StringBuilder newSql = new StringBuilder("SELECT ");
            addColumnNames(newSql, recordDefinition, dbTableName);
            newSql.append(" FROM ");
            newSql.append(sql.substring(14));
            sql = newSql.toString();
        }
        if (!orderBy.isEmpty()) {
            final StringBuilder buffer = new StringBuilder(sql);
            addOrderBy(buffer, orderBy);
            sql = buffer.toString();
        }
    }
    return sql;
}
Also used : ArrayList(java.util.ArrayList) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) LockMode(com.revolsys.record.schema.LockMode) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

LockMode (com.revolsys.record.schema.LockMode)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)1 ArrayList (java.util.ArrayList)1