use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class SwingForm method getFormContext.
public JSDataSet getFormContext() {
SwingForm current = this;
FormLookupPanel currentLookupPanel = null;
SpecialTabPanel currentTabPanel = null;
String currentBeanName = null;
SpecialSplitPane currentSplitPane = null;
IDataSet set = new BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
new String[] { "containername", "formname", "tabpanel/splitpane/accordion/beanname", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
set.addRow(new Object[] { null, current.formController.getName(), null, null, null, null });
Container parent = getParent();
while (parent != null) {
if (parent instanceof SpecialTabPanel) {
currentTabPanel = (SpecialTabPanel) parent;
} else if (parent instanceof SpecialSplitPane) {
currentSplitPane = (SpecialSplitPane) parent;
} else if (parent instanceof FormLookupPanel) {
currentLookupPanel = (FormLookupPanel) parent;
} else if (parent instanceof IServoyAwareBean && parent instanceof IComponent) {
currentBeanName = ((IComponent) parent).getName();
} else if (parent instanceof SwingForm) {
current = (SwingForm) parent;
if (currentTabPanel != null) {
ITabPaneAlike panel = currentTabPanel.getEnclosingComponent();
int index = -1;
String tabName = null;
if (currentLookupPanel != null) {
index = panel.getTabIndex(currentLookupPanel);
if (index != -1) {
tabName = panel.getNameAt(index);
}
}
set.addRow(0, new Object[] { null, current.formController.getName(), currentTabPanel.getName(), tabName, new Integer(index), new Integer(index + 1) });
} else if (currentBeanName != null) {
set.addRow(0, new Object[] { null, current.formController.getName(), currentBeanName, null, null, null });
} else if (currentSplitPane != null) {
int idx = currentLookupPanel != null && currentLookupPanel.equals(currentSplitPane.getLeftForm()) ? 0 : 1;
set.addRow(0, new Object[] { null, current.formController.getName(), currentSplitPane.getName(), currentSplitPane.getTabNameAt(idx), new Integer(idx + 1), new Integer(idx + 1) });
} else {
set.addRow(0, new Object[] { null, current.formController.getName(), null, null, null, null });
}
currentBeanName = null;
currentTabPanel = null;
currentLookupPanel = null;
currentSplitPane = null;
} else if (parent instanceof MainPanel) {
String containerName = ((MainPanel) parent).getContainerName();
if (containerName != null) {
for (int i = 0; i < set.getRowCount(); i++) {
set.getRow(i)[0] = containerName;
}
}
return new JSDataSet(formController.getApplication(), set);
}
parent = parent.getParent();
}
return new JSDataSet(formController.getApplication(), set);
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class PartNode method process.
public List<DataRendererDefinition> process(FormPreviewPanel fpp, FoundSet fs, Table table, QuerySelect sqlString) throws Exception {
// Selection model must be in print mode to be able to set the selection to -1 . Otherwise is not allowed by the selectionModel
((ISwingFoundSet) fs).getSelectionModel().hideSelectionForPrinting();
// this is needed because we must keep sql the same in foundset during printing
FoundSet rootSet = (FoundSet) fs.copy(false);
foundSets.add(rootSet);
IApplication app = fpp.getApplication();
// retval
List<DataRendererDefinition> list = new ArrayList<DataRendererDefinition>();
if (part != null && (part.getPartType() == Part.LEADING_SUBSUMMARY || part.getPartType() == Part.TRAILING_SUBSUMMARY || isLeadingAndTrailingSubsummary)) {
QuerySelect newSQLString = AbstractBaseQuery.deepClone(sqlString);
IDataServer server = app.getDataServer();
// build the sql parts based on sort columns
ArrayList<IQuerySelectValue> selectCols = new ArrayList<IQuerySelectValue>();
ArrayList<QueryColumn> groupbyCols = new ArrayList<QueryColumn>();
ArrayList<QuerySort> sortbyCols = new ArrayList<QuerySort>();
for (SortColumn element : sortColumns) {
BaseQueryTable queryTable = sqlString.getTable();
Relation[] relations = element.getRelations();
if (relations != null) {
for (Relation relation : relations) {
ISQLTableJoin join = (ISQLTableJoin) sqlString.getJoin(queryTable, relation.getName());
if (join == null) {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.log("Missing relation " + relation.getName() + " in join condition for form on table " + table.getName());
} else {
queryTable = join.getForeignTable();
}
}
}
Column column = (Column) element.getColumn();
QueryColumn queryColumn = column.queryColumn(queryTable);
selectCols.add(queryColumn);
groupbyCols.add(queryColumn);
sortbyCols.add(new QuerySort(queryColumn, element.getSortOrder() == SortColumn.ASCENDING, fs.getFoundSetManager().getSortOptions(column)));
}
// make sql
for (AggregateVariable ag : allAggregates) {
selectCols.add(new QueryAggregate(ag.getType(), new QueryColumn(newSQLString.getTable(), -1, ag.getColumnNameToAggregate(), ag.getDataProviderType(), ag.getLength(), 0, null, ag.getFlags()), ag.getName()));
}
newSQLString.setColumns(selectCols);
newSQLString.setGroupBy(groupbyCols);
ArrayList<IQuerySort> oldSort = newSQLString.getSorts();
// fix the sort (if columns not are selected of used in groupby they cannot be used in sort)
newSQLString.setSorts(sortbyCols);
FoundSetManager foundSetManager = ((FoundSetManager) app.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
IDataSet data = server.performQuery(app.getClientID(), table.getServerName(), transaction_id, newSQLString, null, foundSetManager.getTableFilterParams(table.getServerName(), newSQLString), false, 0, foundSetManager.config.pkChunkSize() * 4, IDataServer.PRINT_QUERY);
// create a new FoundSet with 'data' and with right 'table', 'where','whereArgs'
SubSummaryFoundSet newSet = new SubSummaryFoundSet(app.getFoundSetManager(), rootSet, sortColumns, allAggregates, data, table);
// restore the sort for child body parts
newSQLString.setSorts(oldSort);
// make new where for use in sub queries
for (QuerySort sortbyCol : sortbyCols) {
QueryColumn sc = (QueryColumn) (sortbyCol).getColumn();
newSQLString.addCondition(SQLGenerator.CONDITION_SEARCH, new CompareCondition(IBaseSQLCondition.EQUALS_OPERATOR, sc, new Placeholder(new TablePlaceholderKey(sc.getTable(), '#' + sc.getName()))));
}
int count = newSet.getSize();
for (int ii = 0; ii < count; ii++) {
// make copy for setting sort column
QuerySelect newSQLStringCopy = AbstractBaseQuery.deepClone(newSQLString);
// handle the child first, this puts the rootset in the right state! for use of related(!) fields in the subsums
// THIS is EXTREMELY important for correct printing, see also SubSummaryFoundSet.queryForRelatedFoundSet
List<DataRendererDefinition> childRetval = null;
IFoundSetInternal curLeafFoundSet = null;
if (child != null) {
for (int i = 0; i < sortbyCols.size(); i++) {
QueryColumn sc = (QueryColumn) (sortbyCols.get(i)).getColumn();
TablePlaceholderKey placeholderKey = new TablePlaceholderKey(sc.getTable(), '#' + sc.getName());
if (!newSQLStringCopy.setPlaceholderValue(placeholderKey, data.getRow(ii)[i])) {
Debug.error(// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
new RuntimeException("Could not set placeholder " + placeholderKey + " in query " + newSQLStringCopy + "-- continuing"));
}
}
childRetval = child.process(fpp, rootSet, table, newSQLStringCopy);
curLeafFoundSet = child.getCurrentLeafFoundSet();
}
SubSummaryFoundSet.PrintState state = (SubSummaryFoundSet.PrintState) newSet.getRecord(ii);
state.setDelegate(curLeafFoundSet);
if (part.getPartType() == Part.LEADING_SUBSUMMARY) {
state.doAggregatesLookup();
list.add(new DataRendererDefinition(fpp, renderParent, part, renderer, state));
}
if (childRetval != null) {
list.addAll(childRetval);
}
if (isLeadingAndTrailingSubsummary) {
state.doAggregatesLookup();
list.add(new DataRendererDefinition(fpp, renderParent, second_part, second_renderer, state));
} else if (part.getPartType() == Part.TRAILING_SUBSUMMARY) {
state.doAggregatesLookup();
list.add(new DataRendererDefinition(fpp, renderParent, part, renderer, state));
}
}
} else // for handeling (virtual) body part
{
rootSet.browseAll(sqlString);
int count = app.getFoundSetManager().getFoundSetCount(rootSet);
for (int ii = 0; ii < count; ii++) {
currentLeafFoundSet = rootSet;
list.add(new DataRendererDefinition(fpp, renderParent, part, renderer, rootSet, ii));
}
}
return list;
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class ClientStub method notifyDataChange.
public void notifyDataChange(final String server_name, final String table_name, final IDataSet pks, final int sql_action, final Object[] insertColumnData) {
if (client.isShutDown())
return;
if (Debug.tracing()) {
Debug.trace(// $NON-NLS-1$//$NON-NLS-2$
"Notify Data Change get from the server for dataserver: " + server_name + " table: " + table_name + ". Pks: " + (pks != null ? "not null" : "null") + ". Action type: " + sql_action);
}
synchronized (datachanges) {
datachanges.push(new Object[] { server_name, table_name, pks, new Integer(sql_action), insertColumnData });
if (datachangesHandler == null) {
datachangesHandler = new Runnable() {
public void run() {
while (datachangesHandler != null) {
final Object[] array;
synchronized (datachanges) {
if (datachanges.isEmpty()) {
// done
datachangesHandler = null;
break;
}
array = datachanges.pop();
}
client.invokeLater(new Runnable() {
public void run() {
if (client.isShutDown() || !client.isSolutionLoaded())
return;
String sname = (String) array[0];
String tname = (String) array[1];
IDataSet pksDataSet = (IDataSet) array[2];
int action = ((Integer) array[3]).intValue();
Object[] insertColumndata = (Object[]) array[4];
IDataServer ds = client.getDataServer();
if (ds instanceof DataServerProxy) {
// possibly switched from multiple servers to the same destination server.
for (String srv : ((DataServerProxy) ds).getReverseMappedServerNames(sname)) {
((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(srv, tname), pksDataSet, action, insertColumndata);
}
return;
}
// not switched
((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(sname, tname), pksDataSet, action, insertColumndata);
}
});
}
}
};
client.getScheduledExecutor().execute(datachangesHandler);
}
}
}
use of com.servoy.j2db.dataprocessing.IDataSet in project servoy-client by Servoy.
the class ValueListPropertyType method toSabloComponentValue.
@Override
public ValueListTypeSabloValue toSabloComponentValue(Object rhinoValue, ValueListTypeSabloValue previousComponentValue, PropertyDescription pd, IWebObjectContext webObjectContext) {
if (rhinoValue == null || RhinoConversion.isUndefinedOrNotFound(rhinoValue))
return null;
if (previousComponentValue == null) {
return rhinoValue instanceof String ? createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext) : null;
}
if (!previousComponentValue.isInitialized()) {
if (rhinoValue instanceof String) {
// weird; but we are going to create a new value anyway so it doesn't matter much
return createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext);
} else {
// we cannot set values from a dataset if the previous value is not ready for it
Debug.error("Trying to make changes (assignment) to an uninitialized valuelist property (this is not allowed): " + pd + " of " + webObjectContext, new RuntimeException());
return previousComponentValue;
}
}
ParsedFormat format = null;
int type = -1;
IValueList list = previousComponentValue.getValueList();
if (list.getName().equals(rhinoValue)) {
// no need to create a new value if we have the same valuelist name
return previousComponentValue;
}
ValueListTypeSabloValue newValue;
IValueList newVl = null;
// see if it's a component.setValuelistItems (legacy) equivalent
if (list != null && list instanceof CustomValueList && (rhinoValue instanceof JSDataSet || rhinoValue instanceof IDataSet)) {
// here we create a NEW, separate (runtime) custom valuelist instance for this component only (no longer the 'global' custom valuelist with that name that can be affected by application.setValuelistItems(...))
INGApplication application = previousComponentValue.getDataAdapterList().getApplication();
ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
format = ((CustomValueList) list).getFormat();
type = ((CustomValueList) list).getValueType();
newVl = ValueListFactory.fillRealValueList(application, valuelist, IValueListConstants.CUSTOM_VALUES, format, type, rhinoValue);
if (newVl != null) {
previousComponentValue.setNewCustomValuelistInstance(newVl, rhinoValue);
newValue = previousComponentValue;
} else {
// should never happen; ValueListFactory.fillRealValueList seems to always return non-null
Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed for an unknown reason; dataset: " + rhinoValue, new RuntimeException());
// just keep old value
newValue = previousComponentValue;
}
} else {
Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed. Assigning a dataset is ONLY allowed for custom valuelists; dataset: " + rhinoValue, new RuntimeException());
newValue = previousComponentValue;
}
} else if (rhinoValue instanceof String) {
// the Rhino value is a different valuelist name; create a full new one
newValue = createValuelistSabloValueByNameFromRhino((String) rhinoValue, pd, webObjectContext);
} else {
Debug.error("Assignment to Valuelist typed property '" + pd.getName() + "' of component '" + webObjectContext + "' failed. Assigning this value is not supported: " + rhinoValue, new RuntimeException());
// whatever was set here is not supported; so keep the previous value
newValue = previousComponentValue;
}
return newValue;
}
use of com.servoy.j2db.dataprocessing.IDataSet 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