use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.
the class JSSolutionModel method getRelations.
/**
* @clonedesc getRelations(String)
* @sampleas getRelations(String)
* @param servername the specified name of the server for the specified table
* @param tablename the specified name of the table
*
* @return an array of all relations (all elements in the array are of type JSRelation)
*/
@JSFunction
public JSRelation[] getRelations(String servername, String tablename) {
FlattenedSolution fs = application.getFlattenedSolution();
try {
Table primaryTable = null;
if (servername != null && tablename != null) {
IServer primaryServer = fs.getSolution().getServer(servername);
if (primaryServer == null)
throw new RuntimeException("can't list relations, primary server not found: " + servername);
primaryTable = (Table) primaryServer.getTable(tablename);
if (primaryTable == null)
throw new RuntimeException("can't list relations, primary table not found: " + tablename);
}
List<JSRelation> relations = new ArrayList<JSRelation>();
Iterator<Relation> iterator = fs.getRelations(primaryTable, true, true);
while (iterator.hasNext()) {
Relation relation = iterator.next();
if (((primaryTable == null) == relation.isGlobal()) && !relation.isInternal()) {
relations.add(new JSRelation(relation, application, false));
}
}
return relations.toArray(new JSRelation[relations.size()]);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.
the class RemoteActiveSolutionHandler method loadActiveSolutions.
@Override
public Solution[] loadActiveSolutions(final RootObjectMetaData[] solutionDefs) throws RepositoryException, RemoteException {
final int[] sol_ids = new int[solutionDefs.length];
for (int i = 0; i < sol_ids.length; i++) {
sol_ids[i] = solutionDefs[i].getRootObjectId();
}
final Solution[] retval = new Solution[solutionDefs.length];
ThrowingRunnable<RepositoryException, RemoteException> r = new ThrowingRunnable<RepositoryException, RemoteException>() {
@Override
public void run() {
try {
long[] asus = getApplicationServer().getActiveRootObjectsLastModified(sol_ids);
ConcurrentMap<String, IServer> sps = getRepository().getServerProxies(solutionDefs);
for (int i = 0; i < solutionDefs.length; i++) {
Solution s = loadCachedSolution(solutionDefs[i], asus[i], sps);
if (s == null) {
// do full load
s = loadSolution(solutionDefs[i]);
}
if (s != null) {
if (s.getRepository() == null) {
// transient
s.setRepository(getRepository());
}
loadedActiveSolutionUpdateSequences.put(new Integer(s.getSolutionID()), new Long(asus[i]));
s.setServerProxies(sps);
}
retval[i] = s;
}
} catch (RepositoryException eo) {
e1 = eo;
} catch (RemoteException et) {
e2 = et;
}
}
};
UIUtils.runWhileDispatchingEvents(r, getServiceProvider());
return retval;
}
use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.
the class FoundsetTest method setupData.
@Override
protected void setupData() throws ServoyException {
BufferedDataSet ds = new BufferedDataSet(new String[] { "pk", "test1", "test2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
ds.addRow(new Object[] { Integer.valueOf(1), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(2), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(3), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(4), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(5), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(6), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(7), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(8), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(9), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(10), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(11), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(12), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(13), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(14), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(15), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(16), "value3", "value4" });
ds.addRow(new Object[] { Integer.valueOf(17), "value1", "value2" });
ds.addRow(new Object[] { Integer.valueOf(18), "value3", "value4" });
client.getFoundSetManager().insertToDataSource("test", ds, null, new WrappedObjectReference<String[]>(new String[] { "pk" }), true, false);
BufferedDataSet separateDSs = new BufferedDataSet(new String[] { "pk", "test1", "test2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
for (int i = 0; i < 943; i++) {
separateDSs.addRow(new Object[] { Integer.valueOf(i), "value" + i + "0", "value" + i + "1" });
}
client.getFoundSetManager().insertToDataSource("testseparatefoundset", separateDSs, null, new WrappedObjectReference<String[]>(new String[] { "pk" }), true, false);
BufferedDataSet relatedDS = new BufferedDataSet(new String[] { "relatedtestpk", "testpk", "relatedtest1", "relatedtest2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
relatedDS.addRow(new Object[] { Integer.valueOf(1), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
relatedDS.addRow(new Object[] { Integer.valueOf(2), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
relatedDS.addRow(new Object[] { Integer.valueOf(3), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
relatedDS.addRow(new Object[] { Integer.valueOf(4), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
relatedDS.addRow(new Object[] { Integer.valueOf(5), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
relatedDS.addRow(new Object[] { Integer.valueOf(6), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
relatedDS.addRow(new Object[] { Integer.valueOf(7), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
relatedDS.addRow(new Object[] { Integer.valueOf(8), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
relatedDS.addRow(new Object[] { Integer.valueOf(9), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
relatedDS.addRow(new Object[] { Integer.valueOf(10), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
relatedDS.addRow(new Object[] { Integer.valueOf(11), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
relatedDS.addRow(new Object[] { Integer.valueOf(12), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
relatedDS.addRow(new Object[] { Integer.valueOf(13), Integer.valueOf(1), "relatedvalue111", "relatedvalue112" });
relatedDS.addRow(new Object[] { Integer.valueOf(14), Integer.valueOf(1), "relatedvalue121", "relatedvalue122" });
relatedDS.addRow(new Object[] { Integer.valueOf(15), Integer.valueOf(1), "relatedvalue131", "relatedvalue132" });
relatedDS.addRow(new Object[] { Integer.valueOf(16), Integer.valueOf(2), "relatedvalue241", "relatedvalue242" });
client.getFoundSetManager().insertToDataSource("relatedtest", relatedDS, null, new WrappedObjectReference<String[]>(new String[] { "relatedtestpk" }), true, false);
ConcurrentHashMap<String, IServer> serverProxies = new ConcurrentHashMap<String, IServer>();
serverProxies.put("_sv_inmem", DUMMY_ISERVER);
solution.setServerProxies(serverProxies);
Relation relation = solution.createNewRelation(validator, "test_to_relatedtest", "mem:test", "mem:relatedtest", LEFT_OUTER_JOIN);
Column primaryColumn = ((Table) client.getFoundSetManager().getTable(relation.getPrimaryDataSource())).getColumn("pk");
Column foreignColumn = ((Table) client.getFoundSetManager().getTable(relation.getForeignDataSource())).getColumn("testpk");
relation.createNewRelationItem(client.getFoundSetManager(), primaryColumn, IBaseSQLCondition.EQUALS_OPERATOR, foreignColumn);
}
use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.
the class ValuelistPropTest method setupData.
@Override
protected void setupData() throws ServoyException {
BufferedDataSet ds = new BufferedDataSet(new String[] { "pk", "test1", "test2" }, new int[] { IColumnTypes.INTEGER, IColumnTypes.TEXT, IColumnTypes.TEXT });
ds.addRow(new Object[] { Integer.valueOf(1), "value1", "valueA" });
ds.addRow(new Object[] { Integer.valueOf(2), "value2", "valueB" });
ds.addRow(new Object[] { Integer.valueOf(3), "value3", "valueC" });
ds.addRow(new Object[] { Integer.valueOf(4), "value4", "valueD" });
ds.addRow(new Object[] { Integer.valueOf(5), "value5", "valueE" });
ds.addRow(new Object[] { Integer.valueOf(6), "value6", "valueF" });
ds.addRow(new Object[] { Integer.valueOf(7), "value7", "valueG" });
ds.addRow(new Object[] { Integer.valueOf(8), "value8", "valueH" });
ds.addRow(new Object[] { Integer.valueOf(9), "value9", "valueI" });
ds.addRow(new Object[] { Integer.valueOf(10), "value10", "valueJ" });
ds.addRow(new Object[] { Integer.valueOf(11), "value11", "valueK" });
ds.addRow(new Object[] { Integer.valueOf(12), "value12", "valueL" });
ds.addRow(new Object[] { Integer.valueOf(13), "value13", "valueM" });
ds.addRow(new Object[] { Integer.valueOf(14), "value14", "valueN" });
ds.addRow(new Object[] { Integer.valueOf(15), "value15", "valueO" });
ds.addRow(new Object[] { Integer.valueOf(16), "value16", "valueP" });
ds.addRow(new Object[] { Integer.valueOf(17), "value17", "valueQ" });
ds.addRow(new Object[] { Integer.valueOf(18), "value18", "valueR" });
client.getFoundSetManager().insertToDataSource("test", ds, null, new WrappedObjectReference<String[]>(new String[] { "pk" }), true, false);
ConcurrentHashMap<String, IServer> serverProxies = new ConcurrentHashMap<String, IServer>();
serverProxies.put("_sv_inmem", DUMMY_ISERVER);
solution.setServerProxies(serverProxies);
}
use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.
the class FoundSetManager method resolveDataSource.
/**
* Find the data source of the table with given sql name in same server as serverDataSource
*/
public String resolveDataSource(String serverDataSource, String tableSQLName) {
ITable serverTable = null;
try {
serverTable = getTable(serverDataSource);
} catch (RepositoryException e) {
Debug.error(e);
}
if (serverTable == null) {
return null;
}
ITable table = null;
try {
IServer server = application.getSolution().getServer(serverTable.getServerName());
if (server != null) {
table = server.getTableBySqlname(tableSQLName);
}
} catch (RepositoryException e) {
Debug.error(e);
} catch (RemoteException e) {
Debug.error(e);
}
if (table == null) {
return null;
}
return table.getDataSource();
}
Aggregations