use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.
the class JSDatabaseManager method js_updateTableFilterParam.
/**
* Updates a previously defined table filter. Server/Table should not be changed.
*
* @sample var success = databaseManager.updateTableFilterParam('admin', 'higNumberedMessagesRule', query)
*
* @param serverName The name of the database server connection.
* @param filterName The name of the filter that should be updated.
* @param query condition to filter on.
*
* @return true if the filter could be updated.
*/
public boolean js_updateTableFilterParam(String serverName, String filterName, QBSelect query) throws ServoyException {
if (serverName == null || filterName == null)
return false;
checkAuthorized();
IFoundSetManagerInternal foundSetManager = application.getFoundSetManager();
ITable table = foundSetManager.getTable(query.getDataSource());
return foundSetManager.updateTableFilterParam(table.getServerName(), filterName, table, // make a deep clone and clone Table as well in case the same table is used in a new query.
new QueryTableFilterdefinition(AbstractBaseQuery.deepClone(query.build(), true)));
}
use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.
the class JSDatabaseManager method addTableFilterParamInternal.
private boolean addTableFilterParamInternal(String serverName, String tableName, String dataprovider, String operator, Object value, String filterName) throws ServoyException {
checkAuthorized();
try {
if (value instanceof Wrapper) {
value = ((Wrapper) value).unwrap();
}
IServer server = application.getSolution().getServer(serverName);
if (server == null) {
application.reportJSError("Table filter not applied to unknown server '" + serverName + "', tableName = '" + tableName + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "', value = '" + value + "', filterName = '" + filterName + "'", null);
return false;
}
ITable table = null;
if (tableName != null) {
table = server.getTable(tableName);
if (table == null) {
application.reportJSError("Table filter not applied to unknown table: serverName = '" + serverName + "', tableName = '" + tableName + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "', value = '" + value + "', filterName = '" + filterName + "'", null);
return false;
}
}
// else table remains null: apply to all tables with that column
DataproviderTableFilterdefinition dataproviderTableFilterdefinition = application.getFoundSetManager().createDataproviderTableFilterdefinition(table, dataprovider, operator, value);
if (dataproviderTableFilterdefinition == null) {
application.reportJSError("Table filter not created, column not found in table or operator invalid, filterName = '" + filterName + "', serverName = '" + serverName + "', table = '" + table + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "'", null);
return false;
}
return (((FoundSetManager) application.getFoundSetManager()).addTableFilterParam(filterName, serverName, table, dataproviderTableFilterdefinition));
} catch (Exception ex) {
Debug.error(ex);
}
return false;
}
use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.
the class SortModel method setValue.
void setValue(IApplication app, String notused) {
application = app;
try {
FormManager fm = (FormManager) application.getFormManager();
FormController fc = fm.getCurrentMainShowingFormController();
if (fc != null) {
Form form = fc.getForm();
ITable t = application.getFoundSetManager().getTable(form.getDataSource());
if (t != null) {
List<SortColumn> list = application.getFoundSetManager().getSortColumns(t, form.getInitialSort());
init(app, t, list);
}
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.
the class SQLGenerator method createExistsCondition.
public static ISQLCondition createExistsCondition(IDataProviderHandler flattenedSolution, QuerySelect sqlSelect, ISQLCondition condition, List<IRelation> relations, BaseQueryTable columnTable, IGlobalValueEntry provider, BaseQueryColumn[] pkQueryColumns) throws RepositoryException {
// exists (select 1 from innermain join related1 ... join relatedn where innermain.pk = main.pk having aggregate(relatedn))
if (relations.size() == 0) {
// searching for aggregate in main table, does no make sense.. ignore in search
return null;
}
QuerySelect existsSelect = new QuerySelect(new QueryTable(sqlSelect.getTable().getName(), sqlSelect.getTable().getDataSource(), sqlSelect.getTable().getCatalogName(), sqlSelect.getTable().getSchemaName()));
existsSelect.addColumn(new QueryColumnValue(Integer.valueOf(1), null, true));
// innermain.pk = main.pk
QueryColumn[] innerPkColumns = new QueryColumn[pkQueryColumns.length];
for (int p = 0; p < pkQueryColumns.length; p++) {
BaseQueryColumn pk = pkQueryColumns[p];
innerPkColumns[p] = new QueryColumn(existsSelect.getTable(), pk.getId(), pk.getName(), pk.getColumnType().getSqlType(), pk.getColumnType().getLength(), pk.getColumnType().getScale(), pk.getNativeTypename(), pk.getFlags(), pk.isIdentity());
// group by on the inner pk, some dbs (hxtt dbf) require that
existsSelect.addGroupBy(innerPkColumns[p]);
}
existsSelect.addCondition("AGGREGATE-SEARCH", new // $NON-NLS-1$
SetCondition(// $NON-NLS-1$
new int[] { IBaseSQLCondition.EQUALS_OPERATOR }, // $NON-NLS-1$
innerPkColumns, pkQueryColumns, true));
// add the joins
BaseQueryTable prevTable = existsSelect.getTable();
for (IRelation relation : relations) {
ITable foreignTable = flattenedSolution.getTable(relation.getForeignDataSource());
QueryTable foreignQtable = new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema());
existsSelect.addJoin(createJoin(flattenedSolution, relation, prevTable, foreignQtable, true, provider));
prevTable = foreignQtable;
}
existsSelect.addHaving(AbstractBaseQuery.relinkTable(columnTable, prevTable, condition));
return new ExistsCondition(existsSelect, true);
}
use of com.servoy.j2db.persistence.ITable in project servoy-client by Servoy.
the class ViewFoundSet method getTable.
@Override
public ITable getTable() {
if (table == null) {
try {
table = manager.getTable(getDataSource());
if (table == null) {
table = new Table(IServer.VIEW_SERVER, DataSourceUtils.getViewDataSourceName(getDataSource()), true, ITable.VIEW, null, null);
((Table) table).setDataSource(getDataSource());
for (IQuerySelectValue col : select.getColumns()) {
Column newCol = null;
QueryColumn qCol = col.getColumn();
if (qCol != null && qCol.getTable() != null) {
ITable colTable = manager.getTable(qCol.getTable().getDataSource());
if (colTable != null) {
Column column = colTable.getColumn(qCol.getName());
if (column != null) {
String colname = getColunmName(col, qCol);
newCol = table.createNewColumn(DummyValidator.INSTANCE, colname, column.getType(), column.getLength(), column.getScale(), column.getAllowNull());
if (column.getColumnInfo() != null) {
DatabaseUtils.createNewColumnInfo(manager.getApplication().getFlattenedSolution().getPersistFactory().getNewElementID(null), newCol, false);
newCol.getColumnInfo().copyFrom(column.getColumnInfo());
}
}
}
}
if (newCol == null) {
// existing database column not found, create column on the fly
BaseColumnType columnType = col.getColumnType();
if (columnType == null) {
columnType = ColumnType.getColumnType(IColumnTypes.TEXT);
}
String colname = getColunmName(col, qCol);
table.createNewColumn(DummyValidator.INSTANCE, colname, columnType.getSqlType(), columnType.getLength(), columnType.getScale(), true);
}
}
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
return table;
}
Aggregations