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);
}
}
Aggregations