use of com.servoy.j2db.persistence.Relation in project servoy-client by Servoy.
the class RowManager method unregister.
void unregister(IRowListener fs) {
if (fsm.config.optimizedNotifyChange() && fs instanceof RelatedFoundSet) {
FlattenedSolution flattenedSolution = getFoundsetManager().getApplication().getFlattenedSolution();
RelatedFoundSet relatedFoundSet = (RelatedFoundSet) fs;
Relation relation = flattenedSolution.getRelation(relatedFoundSet.getRelationName());
if (relation != null && Relation.isValid(relation, flattenedSolution)) {
Object[] eqArgs = relatedFoundSet.getWhereArgs(true);
if (eqArgs != null) {
ConcurrentSoftvaluesMultimap<String, RelatedFoundSet> listenersByEqualValues = listenersByRelationEqualValues.get(relation.getName());
if (listenersByEqualValues != null) {
listenersByEqualValues.remove(createPKHashKey(eqArgs), relatedFoundSet);
}
}
}
}
listeners.remove(fs);
}
use of com.servoy.j2db.persistence.Relation in project servoy-client by Servoy.
the class RowManager method fireNotifyChange.
void fireNotifyChange(IRowListener skip, Row row, String pkHashKey, Object[] changedColumns, int eventType, boolean isAggregateChange, boolean skipFSM) {
List<IRowListener> toNotify = new ArrayList<>();
if (eventType == RowEvent.INSERT && fsm.config.optimizedNotifyChange()) {
FlattenedSolution flattenedSolution = getFoundsetManager().getApplication().getFlattenedSolution();
listenersByRelationEqualValues.entrySet().stream().forEach(entry -> {
Relation relation = flattenedSolution.getRelation(entry.getKey());
List<Column> columns = relation.getForeignColumnsForEqualConditions(flattenedSolution);
if (!columns.isEmpty()) {
Object[] eqArgs = columns.stream().map(column -> row.getValue(column.getDataProviderID())).toArray();
String eqHash = RowManager.createPKHashKey(eqArgs);
toNotify.addAll(entry.getValue().get(eqHash));
}
});
} else {
// add all related foundsets
listenersByRelationEqualValues.values().stream().map(ConcurrentSoftvaluesMultimap::allValues).forEach(toNotify::addAll);
}
toNotify.addAll(listeners.keySet());
toNotify.remove(skip);
if (!toNotify.isEmpty()) {
RowEvent e = new RowEvent(this, row, pkHashKey, eventType, changedColumns, isAggregateChange);
toNotify.forEach(listener -> listener.notifyChange(e));
}
if (!skipFSM)
fsm.notifyChange(sheet.getTable());
}
use of com.servoy.j2db.persistence.Relation in project servoy-client by Servoy.
the class RowManager method register.
void register(IRowListener fs) {
boolean listenersByEqualValuesAdded = false;
if (fsm.config.optimizedNotifyChange() && fs instanceof RelatedFoundSet) {
FlattenedSolution flattenedSolution = getFoundsetManager().getApplication().getFlattenedSolution();
RelatedFoundSet relatedFoundSet = (RelatedFoundSet) fs;
Relation relation = flattenedSolution.getRelation(relatedFoundSet.getRelationName());
if (relation != null && Relation.isValid(relation, flattenedSolution)) {
Object[] eqArgs = relatedFoundSet.getWhereArgs(true);
if (eqArgs != null && !stream(eqArgs).anyMatch(DbIdentValue.class::isInstance)) {
ConcurrentSoftvaluesMultimap<String, RelatedFoundSet> listenersByEqualValues = listenersByRelationEqualValues.get(relation.getName());
if (listenersByEqualValues == null) {
listenersByEqualValues = new ConcurrentSoftvaluesMultimap<String, RelatedFoundSet>();
ConcurrentSoftvaluesMultimap<String, RelatedFoundSet> prevValue = listenersByRelationEqualValues.putIfAbsent(relation.getName(), listenersByEqualValues);
if (prevValue != null)
listenersByEqualValues = prevValue;
}
listenersByEqualValues.add(createPKHashKey(eqArgs), relatedFoundSet);
listenersByEqualValuesAdded = true;
}
}
}
if (!listenersByEqualValuesAdded) {
listeners.put(fs, dummy);
}
}
use of com.servoy.j2db.persistence.Relation in project servoy-client by Servoy.
the class LookupListModel method fillRelatedValueListValues.
/**
* @param txt
* @throws RemoteException
* @throws Exception
*/
private void fillRelatedValueListValues(IRecordInternal parentState, String filter) throws ServoyException {
if (parentState == null)
return;
String txt = filter;
ValueList valueList = ((LookupValueList) lookup).getValueList();
Relation[] relations = application.getFlattenedSolution().getRelationSequence(valueList.getRelationName());
Pair<QuerySelect, BaseQueryTable> pair = RelatedValueList.createRelatedValuelistQuery(application, valueList, relations, parentState);
if (pair == null) {
return;
}
QuerySelect select = pair.getLeft();
BaseQueryTable qTable = pair.getRight();
generateWherePart(txt, valueList, select, qTable);
try {
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), select);
if (// apply name as filter on column valuelist_name in creationSQLParts
nameFilter != null) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(nameFilter);
}
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), qTable.getName(), null, null);
trackingInfo.setTrackingData(select.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, select, null, tableFilterParams, true, 0, 100, IDataServer.VALUELIST_QUERY, trackingInfo);
String[] displayFormat = (lookup instanceof LookupValueList) ? ((LookupValueList) lookup).getDisplayFormat() : null;
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = processRow(set.getRow(i));
DisplayString display = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
if (display != null) {
alDisplay.add(display);
alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
}
hadMoreRows = set.hadMoreRows();
} catch (RemoteException e) {
throw new RepositoryException(e);
}
}
use of com.servoy.j2db.persistence.Relation in project servoy-client by Servoy.
the class DBValueList method getShowDataproviders.
public static List<String> getShowDataproviders(ValueList valueList, Table callingTable, String dataProviderID, IFoundSetManagerInternal foundSetManager) throws RepositoryException {
if (valueList == null) {
return null;
}
FlattenedSolution flattenedSolution = foundSetManager.getApplication().getFlattenedSolution();
// Find destination table in case dataProviderID is related
String[] split = dataProviderID.split("\\.");
String dataSource = callingTable.getDataSource();
for (// first parts are relation names, last part is column name
int i = 0; // first parts are relation names, last part is column name
i < split.length - 1; // first parts are relation names, last part is column name
i++) {
Relation relation = flattenedSolution.getRelation(split[i]);
if (relation == null || !relation.getPrimaryDataSource().equals(dataSource)) {
return null;
}
dataSource = relation.getForeignDataSource();
}
Table table = (Table) foundSetManager.getTable(dataSource);
String columnName = split[split.length - 1];
String prefix = dataProviderID.substring(0, dataProviderID.length() - columnName.length());
// first try fallback value list,
ValueList usedValueList = flattenedSolution.getValueList(valueList.getFallbackValueListID());
Relation valuelistSortRelation = flattenedSolution.getValuelistSortRelation(usedValueList, table, columnName, foundSetManager);
if (valuelistSortRelation == null) {
// then try regular value list
usedValueList = valueList;
valuelistSortRelation = flattenedSolution.getValuelistSortRelation(usedValueList, table, columnName, foundSetManager);
}
if (valuelistSortRelation == null) {
return null;
}
List<String> showDataproviders = new ArrayList<String>(3);
int showValues = usedValueList.getShowDataProviders();
if ((showValues & 1) != 0) {
showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID1());
}
if ((showValues & 2) != 0) {
showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID2());
}
if ((showValues & 4) != 0) {
showDataproviders.add(prefix + valuelistSortRelation.getName() + '.' + usedValueList.getDataProviderID3());
}
return showDataproviders;
}
Aggregations