use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class RowManager method addCalculationDependencyBackReference.
/**
* Rowmanager(dataSource) keeps a calculation dependency for my calc in row(pkHashKey).
* @param dataSource
* @param pkHashKey
* @param calc
*/
private void addCalculationDependencyBackReference(RowReference rowReference, String pkHashKey, String calc) {
SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = pkRowMap.get(pkHashKey);
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.addRowReference(calc, rowReference);
}
}
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class RowManager method deleteRow.
void deleteRow(IRowListener src, Row r, boolean tracking, boolean partOfBiggerDelete) throws ServoyException {
// $NON-NLS-1$
if (r.getRowManager() != this)
throw new IllegalArgumentException("I'm not the row manager from row");
// prevent it processed by any update, changed is false now
r.flagExistInDB();
if (!partOfBiggerDelete) {
QueryDelete sqlDelete = AbstractBaseQuery.deepClone((QueryDelete) sheet.getSQLDescription(SQLSheet.DELETE).getSQLQuery());
Object[] pk = r.getPK();
if (!sqlDelete.setPlaceholderValue(new TablePlaceholderKey(sqlDelete.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY), pk)) {
Debug.error(new RuntimeException(// $NON-NLS-1$
"Could not set placeholder " + new TablePlaceholderKey(sqlDelete.getTable(), SQLGenerator.PLACEHOLDER_PRIMARY_KEY) + " in query " + sqlDelete + // $NON-NLS-1$ //$NON-NLS-2$
"-- continuing"));
}
IDataSet pks = new BufferedDataSet();
pks.addRow(pk);
ISQLStatement[] stats_a = new ISQLStatement[1];
String tid = null;
GlobalTransaction gt = fsm.getGlobalTransaction();
if (gt != null) {
tid = gt.getTransactionID(sheet.getServerName());
}
SQLStatement statement = new SQLStatement(ISQLActionTypes.DELETE_ACTION, sheet.getServerName(), sheet.getTable().getName(), pks, tid, sqlDelete, fsm.getTableFilterParams(sheet.getServerName(), sqlDelete));
// check that 1 record is deleted
statement.setExpectedUpdateCount(1);
stats_a[0] = statement;
if (tracking) {
statement.setTrackingData(sheet.getColumnNames(), r.getRawColumnData() != null ? new Object[][] { r.getRawColumnData() } : null, null, fsm.getApplication().getUserUID(), fsm.getTrackingInfo(), fsm.getApplication().getClientID());
}
try {
Object[] results = fsm.getDataServer().performUpdates(fsm.getApplication().getClientID(), stats_a);
for (int i = 0; results != null && i < results.length; i++) {
if (results[i] instanceof ServoyException) {
throw (ServoyException) results[i];
}
}
} catch (RemoteException e) {
throw new RepositoryException(e);
}
SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> removed;
synchronized (this) {
removed = pkRowMap.remove(r.getPKHashKey());
}
fireDependingCalcs(removed, null, null);
} else {
synchronized (this) {
pkRowMap.remove(r.getPKHashKey());
}
}
fireNotifyChange(src, r, r.getPKHashKey(), null, RowEvent.DELETE);
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class RowManager method foundSetChanged.
/*
* Called from FoundsetManager GlobalFoundSetEventListener
*/
public void foundSetChanged(FoundSetEvent e) {
IFoundSet sourceFoundset = e.getSourceFoundset();
// only act on new foundsets or size changes for related foundsets
if (e.getType() == FoundSetEvent.NEW_FOUNDSET || (e.getType() == FoundSetEvent.CONTENTS_CHANGED && (e.getChangeType() == FoundSetEvent.CHANGE_INSERT || e.getChangeType() == FoundSetEvent.FOUNDSET_INVALIDATED || e.getChangeType() == FoundSetEvent.CHANGE_DELETE))) {
if (sourceFoundset instanceof RelatedFoundSet && !sourceFoundset.isInFindMode()) {
String relationName = sourceFoundset.getRelationName();
// related foundset changed
List<String> calcs = null;
// first test if there are calcs that depend on this relation, to filter out relations that are never used in calcs
synchronized (relationsUsedInCalcs) {
Set<String> calcSet = relationsUsedInCalcs.get(relationName);
if (calcSet != null) {
calcs = new ArrayList<String>(calcSet);
}
}
if (calcs != null) {
// some calcs depend on a related foundset with this name, search by whereArgs
String whereArgsHash = ((RelatedFoundSet) sourceFoundset).getWhereArgsHash();
List<CalculationDependency> calculationDependencies = new ArrayList<CalculationDependency>();
// go over each row to see if there are calcs depending on the RFS(whereArgs)
Iterator<Map.Entry<String, SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>>>> it = pkRowMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>>> entry = it.next();
String pkHash = entry.getKey();
SoftReferenceWithData<Row, Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData>> sr = entry.getValue();
synchronized (sr) {
Row row = sr.get();
if (row != null) {
Pair<Map<String, List<CalculationDependency>>, CalculationDependencyData> data = sr.getData();
if (data != null) {
CalculationDependencyData calcRowrefs = data.getRight();
if (calcRowrefs != null) {
for (String calc : calcs) {
List<RelationDependency> deps = calcRowrefs.getRelationDependencies(calc);
if (deps != null) {
for (RelationDependency dep : deps) {
if (relationName.equals(dep.relationName) && whereArgsHash.equals(dep.whereArgsHash)) {
// the calc depends on this related foundset
calculationDependencies.add(new CalculationDependency(sheet.getTable().getDataSource(), pkHash, calc));
}
}
}
}
}
}
}
}
}
if (calculationDependencies.size() > 0) {
List<RowFireNotifyChange> fires = new ArrayList<RowFireNotifyChange>();
for (CalculationDependency dep : calculationDependencies) {
fireCalculationFlagged(dep.pkHashKey, dep.calc, fires);
}
if (fires.size() > 0) {
fireRowNotifyChanges(fires);
ArrayList<String> calcColumns = new ArrayList<String>();
for (RowFireNotifyChange f : fires) {
calcColumns.add(f.name);
}
fireNotifyChange(null, null, null, calcColumns.toArray(new String[0]), RowEvent.UPDATE);
}
}
}
}
}
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class WebObjectImpl method getNewIdAndUUID.
public static Pair<Integer, UUID> getNewIdAndUUID(IPersist persist) {
UUID uuid = UUID.randomUUID();
int id;
try {
id = ((IPersistFactory) ((Solution) persist.getAncestor(IRepository.SOLUTIONS)).getRepository()).getNewElementID(uuid);
} catch (RepositoryException e) {
Debug.error(e);
id = 0;
}
return new Pair<>(Integer.valueOf(id), uuid);
}
use of com.servoy.j2db.util.Pair in project servoy-client by Servoy.
the class AbstractBaseQuery method acceptVisitor.
public static <T> T acceptVisitor(T o, IVisitor visitor) {
if (o == null) {
return null;
}
Object v = visitor.visit(o);
T o2;
if (v instanceof VisitorResult) {
o2 = (T) ((VisitorResult) v).object;
if (!((VisitorResult) v).continueTraversal) {
return o2;
}
} else {
o2 = (T) v;
if (o2 != o) {
// the visitor returned something else then the input, visting stops.
return o2;
}
}
if (o2 instanceof List) {
for (int i = 0; i < ((List) o2).size(); i++) {
((List<Object>) o2).set(i, acceptVisitor(((List) o2).get(i), visitor));
}
} else if (o2 instanceof Map) {
Iterator<Map.Entry> it = ((Map) o2).entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = it.next();
entry.setValue(acceptVisitor(entry.getValue(), visitor));
}
} else if (o2 instanceof Object[]) {
for (int i = 0; i < ((Object[]) o2).length; i++) {
((Object[]) o2)[i] = acceptVisitor(((Object[]) o2)[i], visitor);
}
} else if (o2 instanceof Pair) {
Pair pair = (Pair) o2;
pair.setLeft(acceptVisitor(pair.getLeft(), visitor));
pair.setRight(acceptVisitor(pair.getRight(), visitor));
} else if (o2 instanceof IVisitable) {
((IVisitable) o2).acceptVisitor(visitor);
}
return o2;
}
Aggregations