Search in sources :

Example 11 with QueryColumnValue

use of com.servoy.j2db.query.QueryColumnValue in project servoy-client by Servoy.

the class Messages method loadMessagesFromDatabaseRepositorySinglefilter.

private static void loadMessagesFromDatabaseRepositorySinglefilter(IServer server, Table table, String clientId, IDataServer dataServer, Properties properties, Properties localeProperties, Locale language, int loadingType, String searchKey, String searchText, Column filterColumn, String singleColumnValueFilter, IFoundSetManagerInternal fm) throws RemoteException, ServoyException {
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
    Debug.trace("Loading messages from DB: Server: " + server.getName() + " Table: " + table.getName() + " Language: " + language);
    if (loadingType == ALL_LOCALES || loadingType == DEFAULT_LOCALE) {
        QueryTable messagesTable = new QueryTable(table.getSQLName(), table.getDataSource(), table.getCatalog(), table.getSchema());
        QuerySelect sql = new QuerySelect(messagesTable);
        // $NON-NLS-1$
        QueryColumn msgKey = new QueryColumn(messagesTable, -1, "message_key", Types.VARCHAR, 150, 0, null, 0);
        // $NON-NLS-1$
        QueryColumn msgVal = new QueryColumn(messagesTable, -1, "message_value", Types.VARCHAR, 2000, 0, null, 0);
        // $NON-NLS-1$
        QueryColumn msgLang = new QueryColumn(messagesTable, -1, "message_language", Types.VARCHAR, 150, 0, null, 0);
        sql.addColumn(msgKey);
        sql.addColumn(msgVal);
        // $NON-NLS-1$
        String condMessages = "MESSAGES";
        sql.addCondition(condMessages, new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR | IBaseSQLCondition.ORNULL_MODIFIER, msgLang, new QueryColumnValue("", null)));
        if (filterColumn != null) {
            QueryColumn columnFilter = filterColumn.queryColumn(messagesTable);
            CompareCondition cc = new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, columnFilter, new QueryColumnValue(singleColumnValueFilter, null));
            sql.addCondition(condMessages, cc);
        }
        // Filter to only include records with the default (null) value for columns flagged as Tenant column
        for (Column column : table.getTenantColumns()) {
            CompareCondition cc = new CompareCondition(IBaseSQLCondition.ISNULL_OPERATOR, column.queryColumn(messagesTable), null);
            sql.addCondition("_svy_tenant_id_filter_" + column.getName(), cc);
        }
        if (searchKey != null || searchText != null) {
            QueryTable subselectTable = new QueryTable(table.getSQLName(), table.getDataSource(), table.getCatalog(), table.getSchema());
            QuerySelect subselect = new QuerySelect(subselectTable);
            // $NON-NLS-1$
            QueryColumn msgKeySub = new QueryColumn(subselectTable, -1, "message_key", Types.VARCHAR, 150, 0, null, 0);
            // $NON-NLS-1$
            QueryColumn msgValueSub = new QueryColumn(subselectTable, -1, "message_value", Types.VARCHAR, 2000, 0, null, 0);
            // $NON-NLS-1$
            QueryColumn msgLangSub = new QueryColumn(subselectTable, -1, "message_language", Types.VARCHAR, 150, 0, null, 0);
            subselect.addColumn(msgKeySub);
            // $NON-NLS-1$
            String condSearch = "SEARCH";
            if (searchKey != null) {
                subselect.addCondition(condSearch, new CompareCondition(IBaseSQLCondition.LIKE_OPERATOR, msgKeySub, new QueryColumnValue('%' + searchKey + '%', null)));
            }
            if (searchText != null) {
                subselect.addConditionOr(condSearch, new CompareCondition(IBaseSQLCondition.LIKE_OPERATOR, msgValueSub, new QueryColumnValue('%' + searchText + '%', null)));
            }
            // $NON-NLS-1$
            String condLang = "LANGUAGE";
            subselect.addCondition(condLang, new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, msgLangSub, new QueryColumnValue(localeToString(language), null)));
            subselect.addConditionOr(condLang, // $NON-NLS-1$
            new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR | IBaseSQLCondition.ORNULL_MODIFIER, msgLangSub, new QueryColumnValue("", null)));
            sql.addCondition(condMessages, new SetCondition(IBaseSQLCondition.EQUALS_OPERATOR, new QueryColumn[] { msgKey }, subselect, true));
        }
        // $NON-NLS-1$
        if (Debug.tracing())
            Debug.trace("Loading messages from DB: SQL: " + sql);
        IDataSet set = dataServer.performQuery(clientId, server.getName(), null, sql, null, fm != null ? fm.getTableFilterParams(server.getName(), sql) : null, false, 0, Integer.MAX_VALUE, IDataServer.MESSAGES_QUERY);
        for (int i = 0; i < set.getRowCount(); i++) {
            Object[] row = set.getRow(i);
            if (row[0] != null && row[1] != null) {
                properties.setProperty((String) row[0], (String) row[1]);
            }
        }
    }
    if (loadingType == ALL_LOCALES || loadingType == SPECIFIED_LANGUAGE) {
        fillLocaleMessages(clientId, dataServer, table, server.getName(), filterColumn, singleColumnValueFilter, searchKey, searchText, language, localeProperties != null ? localeProperties : properties, SPECIFIED_LANGUAGE, fm);
    }
    if (loadingType == ALL_LOCALES || loadingType == SPECIFIED_LOCALE) {
        fillLocaleMessages(clientId, dataServer, table, server.getName(), filterColumn, singleColumnValueFilter, searchKey, searchText, language, localeProperties != null ? localeProperties : properties, SPECIFIED_LOCALE, fm);
    }
}
Also used : QueryColumnValue(com.servoy.j2db.query.QueryColumnValue) QueryColumn(com.servoy.j2db.query.QueryColumn) Column(com.servoy.j2db.persistence.Column) QueryColumn(com.servoy.j2db.query.QueryColumn) CompareCondition(com.servoy.j2db.query.CompareCondition) SetCondition(com.servoy.j2db.query.SetCondition) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) QuerySelect(com.servoy.j2db.query.QuerySelect) QueryTable(com.servoy.j2db.query.QueryTable)

Aggregations

QueryColumnValue (com.servoy.j2db.query.QueryColumnValue)11 QueryColumn (com.servoy.j2db.query.QueryColumn)9 QueryTable (com.servoy.j2db.query.QueryTable)8 QuerySelect (com.servoy.j2db.query.QuerySelect)7 Column (com.servoy.j2db.persistence.Column)6 BaseQueryColumn (com.servoy.base.query.BaseQueryColumn)5 CompareCondition (com.servoy.j2db.query.CompareCondition)5 BaseQueryTable (com.servoy.base.query.BaseQueryTable)4 IColumn (com.servoy.j2db.persistence.IColumn)4 IQuerySelectValue (com.servoy.j2db.query.IQuerySelectValue)4 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)3 Placeholder (com.servoy.j2db.query.Placeholder)3 SetCondition (com.servoy.j2db.query.SetCondition)3 ArrayList (java.util.ArrayList)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)2 ExistsCondition (com.servoy.j2db.query.ExistsCondition)2 QueryAggregate (com.servoy.j2db.query.QueryAggregate)2 TablePlaceholderKey (com.servoy.j2db.query.TablePlaceholderKey)2 SafeArrayList (com.servoy.j2db.util.SafeArrayList)2 TreeMap (java.util.TreeMap)2