use of com.servoy.j2db.IApplication in project servoy-client by Servoy.
the class RelatedValueList method fillWithQuery.
/**
* Fill using query in case of multi-level relation
*
* @param relations
* @throws ServoyException
* @throws RemoteException
*/
@SuppressWarnings("nls")
protected void fillWithQuery(Relation[] relations) throws RemoteException, ServoyException {
FoundSetManager foundSetManager = (FoundSetManager) application.getFoundSetManager();
Pair<QuerySelect, BaseQueryTable> pair = createRelatedValuelistQuery(application, valueList, relations, parentState);
if (pair == null) {
return;
}
QuerySelect select = pair.getLeft();
int showValues = valueList.getShowDataProviders();
int returnValues = valueList.getReturnDataProviders();
boolean showAndReturnAreSame = showValues == returnValues;
// perform the query
String serverName = relations[0].getForeignServerName();
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource()), IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, serverName, pair.getRight().getName(), null, null);
trackingInfo.setTrackingData(select.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet dataSet = application.getDataServer().performQuery(application.getClientID(), serverName, foundSetManager.getTransactionID(serverName), select, null, foundSetManager.getTableFilterParams(serverName, select), !select.isUnique(), 0, maxValuelistRows, IDataServer.VALUELIST_QUERY, trackingInfo);
try {
startBundlingEvents();
// add empty row
if (valueList.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS) {
// $NON-NLS-1$
addElement("");
realValues.add(null);
}
if (dataSet.getRowCount() >= maxValuelistRows && Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.client.report.max.valuelist.items", "true"))) {
if (application instanceof IApplication) {
((IApplication) application).reportJSWarning("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!");
} else {
application.reportJSError("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!", null);
}
}
String[] displayFormat = getDisplayFormat((Table) application.getFoundSetManager().getTable(pair.getRight().getDataSource()));
for (int i = 0; i < dataSet.getRowCount(); i++) {
Object[] row = CustomValueList.processRow(dataSet.getRow(i), showValues, returnValues);
Object element = null;
if (displayFormat != null)
element = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application).toString();
else
element = CustomValueList.handleRowData(valueList, concatShowValues, showValues, row, application);
if (showAndReturnAreSame && indexOf(element) != -1)
continue;
addElement(element);
realValues.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
} finally {
stopBundlingEvents();
}
isLoaded = true;
}
use of com.servoy.j2db.IApplication in project servoy-client by Servoy.
the class EditRecordList method stopEditing.
/**
* stop/save
*
* @param javascriptStop
* @param recordsToSave null means all records
* @return IRowChangeListener static final
*/
@SuppressWarnings("nls")
public int stopEditing(boolean javascriptStop, List<IRecord> recordsToSave) {
int stopped = stopEditingImpl(javascriptStop, recordsToSave, 0);
if ((stopped == ISaveConstants.VALIDATION_FAILED || stopped == ISaveConstants.SAVE_FAILED) && !javascriptStop) {
IApplication application = fsm.getApplication();
Solution solution = application.getSolution();
int mid = solution.getOnAutoSaveFailedMethodID();
if (mid > 0) {
ScriptMethod sm = application.getFlattenedSolution().getScriptMethod(mid);
if (sm != null) {
// the validation failed in a none javascript stop (so this was an autosave failure)
List<JSRecordMarkers> failedMarkers = failedRecords.stream().map(record -> record.getRecordMarkers()).collect(Collectors.toList());
try {
application.getScriptEngine().getScopesScope().executeGlobalFunction(sm.getScopeName(), sm.getName(), Utils.arrayMerge((new Object[] { failedMarkers.toArray() }), Utils.parseJSExpressions(solution.getFlattenedMethodArguments(IContentSpecConstants.PROPERTY_ONAUTOSAVEDFAILEDMETHODID))), false, false);
} catch (Exception e) {
application.reportJSError("Failed to run the solutions auto save failed method", e);
}
} else {
application.reportJSWarning("Solution " + application.getSolutionName() + " onautosavefailed method not found for id " + mid);
}
}
}
return stopped;
}
use of com.servoy.j2db.IApplication in project servoy-client by Servoy.
the class DBValueList method fill.
// also called by universal field valueChanged
@SuppressWarnings("nls")
private void fill() {
try {
if (table == null)
return;
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
List<SortColumn> sortColumns = foundSetManager.getSortColumns(table, valueList.getSortOptions());
FoundSet fs = (FoundSet) foundSetManager.getNewFoundSet(table, null, sortColumns);
if (fs == null) {
return;
}
if (// apply name as filter on column valuelist_name
valueList.getUseTableFilter()) {
// $NON-NLS-1$
fs.addFilterParam("valueList.nameColumn", NAME_COLUMN, "=", valueList.getName());
}
// we do nothing with related foundsets so don't touch these
fs.browseAllInternal();
// browse all could trigger also a fill
if (isLoaded)
return;
isLoaded = true;
int showValues = valueList.getShowDataProviders();
int returnValues = valueList.getReturnDataProviders();
int total = (showValues | returnValues);
// more than one value -> concat
boolean concatShowValues = willConcat(showValues);
boolean concatReturnValues = willConcat(returnValues);
boolean singleColumn = (total & 7) == 1 || (total & 7) == 2 || (total & 7) == 4;
try {
startBundlingEvents();
// add empty row
if (valueList.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS) {
// $NON-NLS-1$
addElement("");
realValues.add(null);
}
QuerySelect creationSQLParts = null;
if (singleColumn && fs.getSize() >= ((FoundSetManager) application.getFoundSetManager()).config.pkChunkSize() && !containsCalculation) {
creationSQLParts = createValuelistQuery(application, valueList, table);
}
if (creationSQLParts != null && creationSQLParts.isDistinct() && fs.getSize() >= ((FoundSetManager) application.getFoundSetManager()).config.pkChunkSize() && !containsCalculation) {
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), creationSQLParts);
if (// apply name as filter on column valuelist_name in creationSQLParts
valueList.getUseTableFilter()) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(new // $NON-NLS-1$
TableFilter(// $NON-NLS-1$
"dbValueList.nameFilter", // $NON-NLS-1$
table.getServerName(), // $NON-NLS-1$
table.getName(), // $NON-NLS-1$
table.getSQLName(), // $NON-NLS-1$
NAME_COLUMN, IBaseSQLCondition.EQUALS_OPERATOR, valueList.getName()));
}
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), table.getName(), null, null);
trackingInfo.setTrackingData(creationSQLParts.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, creationSQLParts, null, tableFilterParams, !creationSQLParts.isUnique(), 0, maxValuelistRows, IDataServer.VALUELIST_QUERY, trackingInfo);
if (set.getRowCount() >= maxValuelistRows) {
if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.client.report.max.valuelist.items", "true"))) {
if (application instanceof IApplication) {
((IApplication) application).reportJSWarning("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!");
} else {
application.reportJSError("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!", null);
}
}
}
String[] displayFormat = getDisplayFormat();
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = CustomValueList.processRow(set.getRow(i), showValues, returnValues);
Object displayValue = null;
if (displayFormat != null) {
displayValue = handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
} else {
displayValue = handleRowData(valueList, concatShowValues, showValues, row, application);
}
addElement(displayValue != null ? displayValue.toString() : displayValue);
realValues.add(handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
} else {
IRecordInternal[] array = fs.getRecords(0, maxValuelistRows);
String[] displayFormat = getDisplayFormat();
for (IRecordInternal r : array) {
if (r != null) {
Object val = handleRowData(valueList, displayFormat, concatShowValues, showValues, r, application);
Object rval = handleRowData(valueList, null, concatReturnValues, returnValues, r, application);
int index = indexOf(val);
if (index == -1 || !Utils.equalObjects(getRealElementAt(index), rval)) {
addElement(val);
realValues.add(rval);
}
}
}
if (fs.getSize() >= maxValuelistRows) {
if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.client.report.max.valuelist.items", "true"))) {
if (application instanceof IApplication) {
((IApplication) application).reportJSWarning("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!");
} else {
application.reportJSError("Valuelist " + getName() + " fully loaded with " + maxValuelistRows + " rows, more rows are discarded!!", null);
}
}
}
}
} finally {
stopBundlingEvents();
}
} catch (Exception ex) {
Debug.error(ex);
}
}
Aggregations