use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class AngularIndexPageWriter method getFlattenedSolution.
private static Pair<FlattenedSolution, Boolean> getFlattenedSolution(String solutionName, String clientnr, HttpServletRequest request, HttpServletResponse response) {
INGClientWebsocketSession wsSession = null;
HttpSession httpSession = request.getSession(false);
if (clientnr != null && httpSession != null) {
wsSession = (INGClientWebsocketSession) WebsocketSessionManager.getSession(CLIENT_ENDPOINT, httpSession, Integer.parseInt(clientnr));
}
FlattenedSolution fs = null;
boolean closeFS = false;
if (wsSession != null) {
fs = wsSession.getClient().getFlattenedSolution();
}
if (fs == null) {
try {
closeFS = true;
IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
if (applicationServerUnavailable(response, as)) {
return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
}
SolutionMetaData solutionMetaData = (SolutionMetaData) ApplicationServerRegistry.get().getLocalRepository().getRootObjectMetaData(solutionName, SOLUTIONS);
if (solutionMissing(response, solutionName, solutionMetaData)) {
return new Pair<FlattenedSolution, Boolean>(null, Boolean.FALSE);
}
fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {
@Override
public IRepository getRepository() {
return ApplicationServerRegistry.get().getLocalRepository();
}
});
} catch (Exception e) {
Debug.error("error loading solution: " + solutionName + " for clientnr: " + clientnr, e);
}
}
return new Pair<FlattenedSolution, Boolean>(fs, Boolean.valueOf(closeFS));
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class RelatedValueList method createRelatedValuelistQuery.
public static Pair<QuerySelect, BaseQueryTable> createRelatedValuelistQuery(IServiceProvider application, ValueList valueList, Relation[] relations, IRecordInternal parentState) throws ServoyException {
if (parentState == null) {
return null;
}
FoundSetManager foundSetManager = (FoundSetManager) application.getFoundSetManager();
SQLGenerator sqlGenerator = foundSetManager.getSQLGenerator();
IGlobalValueEntry scopesScopeProvider = foundSetManager.getScopesScopeProvider();
SQLSheet childSheet = sqlGenerator.getCachedTableSQLSheet(relations[0].getPrimaryDataSource());
// this returns quickly if it already has a sheet for that relation, but optimize further?
sqlGenerator.makeRelatedSQL(childSheet, relations[0]);
QuerySelect select = AbstractBaseQuery.deepClone((QuerySelect) childSheet.getRelatedSQLDescription(relations[0].getName()).getSQLQuery());
Object[] relationWhereArgs = foundSetManager.getRelationWhereArgs(parentState, relations[0], false);
if (relationWhereArgs == null) {
return null;
}
TablePlaceholderKey placeHolderKey = SQLGenerator.createRelationKeyPlaceholderKey(select.getTable(), relations[0].getName());
if (!select.setPlaceholderValue(placeHolderKey, relationWhereArgs)) {
// $NON-NLS-1$//$NON-NLS-2$
Debug.error(new RuntimeException("Could not set relation placeholder " + placeHolderKey + " in query " + select));
return null;
}
FlattenedSolution fs = application.getFlattenedSolution();
BaseQueryTable lastTable = select.getTable();
ITable foreignTable = fs.getTable(relations[0].getForeignDataSource());
for (int i = 1; i < relations.length; i++) {
foreignTable = fs.getTable(relations[i].getForeignDataSource());
ISQLTableJoin join = SQLGenerator.createJoin(application.getFlattenedSolution(), relations[i], lastTable, new QueryTable(foreignTable.getSQLName(), foreignTable.getDataSource(), foreignTable.getCatalog(), foreignTable.getSchema()), true, scopesScopeProvider);
select.addJoin(join);
lastTable = join.getForeignTable();
}
List<SortColumn> defaultSort = foundSetManager.getSortColumns(relations[relations.length - 1].getForeignDataSource(), valueList.getSortOptions());
foundSetManager.getSQLGenerator().addSorts(select, lastTable, scopesScopeProvider, foreignTable, defaultSort, true, true);
int showValues = valueList.getShowDataProviders();
int returnValues = valueList.getReturnDataProviders();
int total = (showValues | returnValues);
ArrayList<IQuerySelectValue> columns = new ArrayList<IQuerySelectValue>();
if ((total & 1) != 0) {
columns.add(getQuerySelectValue(foreignTable, lastTable, valueList.getDataProviderID1()));
}
if ((total & 2) != 0) {
columns.add(getQuerySelectValue(foreignTable, lastTable, valueList.getDataProviderID2()));
}
if ((total & 4) != 0) {
columns.add(getQuerySelectValue(foreignTable, lastTable, valueList.getDataProviderID3()));
}
select.setColumns(columns);
// not allowed in all situations
select.setDistinct(false);
return new Pair<QuerySelect, BaseQueryTable>(select, lastTable);
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class RowManager method addCalculationRelationDependency.
/**
* Calculation depends on relation identified by whereArgsHash.
* @param whereArgsHash
* @param relationName
* @param dependingDataSource
* @param dependingPkHashKey
* @param dependingCalc
*/
public void addCalculationRelationDependency(String whereArgsHash, String relationName, String dependingDataSource, String dependingPkHashKey, String dependingCalc) {
// keep a global list of relations that some calcs depend on
boolean first;
synchronized (relationsUsedInCalcs) {
first = relationsUsedInCalcs.size() == 0;
Set<String> dependingCalcs = relationsUsedInCalcs.get(relationName);
if (dependingCalcs == null) {
dependingCalcs = new HashSet<String>();
relationsUsedInCalcs.put(relationName, dependingCalcs);
}
dependingCalcs.add(dependingCalc);
}
// add a relation dependency for the calc
SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = pkRowMap.get(dependingPkHashKey);
if (sr != null) {
synchronized (sr) {
Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
if (data == null) {
data = new Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>(null, null);
sr.setData(data);
}
CalculationDependencyData rowRefs = data.getRight();
if (rowRefs == null) {
rowRefs = new CalculationDependencyData();
data.setRight(rowRefs);
}
rowRefs.addRelationDependency(dependingCalc, new RelationDependency(relationName, whereArgsHash));
}
}
if (first) {
// listen for foundset events to all foundsets
fsm.addGlobalFoundsetEventListener(this);
}
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class RowManager method removeRowReferences.
/**
* Remove references in other RowManagers to this row.
* @param pkHashKey
* @param calc, null for all
*/
public void removeRowReferences(String pkHashKey, String calc) {
SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = pkRowMap.get(pkHashKey);
if (sr != null) {
CalculationDependencyData rowRefs = null;
synchronized (sr) {
// check the calculation dependencies registered for the calc
Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
if (data != null) {
CalculationDependencyData calcRowrefs = data.getRight();
if (calcRowrefs != null) {
// remove both row refs and relation dependencies
if (calc == null) {
rowRefs = calcRowrefs;
data.setRight(null);
} else {
List<RowReference> refs = calcRowrefs.removeReferences(calc);
if (refs != null) {
rowRefs = new CalculationDependencyData();
rowRefs.putRowReferences(calc, refs);
}
}
}
}
}
if (rowRefs != null) {
String dataSource = fsm.getDataSource(sheet.getTable());
for (Entry<String, List<RowReference>> entry : rowRefs.getRowReferencesEntrySet()) {
for (RowReference reference : entry.getValue()) {
try {
getFoundsetManager().getRowManager(reference.dataSource).removeCalculationDependency(reference.pkHashKey, reference.dataproviderId, dataSource, pkHashKey, entry.getKey());
} catch (ServoyException e) {
Debug.log(e);
}
}
}
}
}
}
Aggregations