Search in sources :

Example 11 with IServer

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);
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) ISMRelation(com.servoy.j2db.solutionmodel.ISMRelation) Relation(com.servoy.j2db.persistence.Relation) Table(com.servoy.j2db.persistence.Table) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 12 with IServer

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;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ThrowingRunnable(com.servoy.j2db.util.UIUtils.ThrowingRunnable) RemoteException(java.rmi.RemoteException) Solution(com.servoy.j2db.persistence.Solution)

Example 13 with IServer

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);
}
Also used : IServer(com.servoy.j2db.persistence.IServer) Relation(com.servoy.j2db.persistence.Relation) Table(com.servoy.j2db.persistence.Table) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Column(com.servoy.j2db.persistence.Column) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 14 with IServer

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);
}
Also used : IServer(com.servoy.j2db.persistence.IServer) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 15 with IServer

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();
}
Also used : IServer(com.servoy.j2db.persistence.IServer) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) RemoteException(java.rmi.RemoteException)

Aggregations

IServer (com.servoy.j2db.persistence.IServer)19 RepositoryException (com.servoy.j2db.persistence.RepositoryException)14 RemoteException (java.rmi.RemoteException)12 ServoyException (com.servoy.j2db.util.ServoyException)10 ITable (com.servoy.j2db.persistence.ITable)7 Table (com.servoy.j2db.persistence.Table)7 ApplicationException (com.servoy.j2db.ApplicationException)6 Column (com.servoy.j2db.persistence.Column)5 QueryTable (com.servoy.j2db.query.QueryTable)5 QueryColumn (com.servoy.j2db.query.QueryColumn)4 SQLException (java.sql.SQLException)4 IBaseColumn (com.servoy.base.persistence.IBaseColumn)3 ColumnInfo (com.servoy.j2db.persistence.ColumnInfo)3 ArrayList (java.util.ArrayList)3 BaseQueryTable (com.servoy.base.query.BaseQueryTable)2 BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)2 Relation (com.servoy.j2db.persistence.Relation)2 Solution (com.servoy.j2db.persistence.Solution)2 CompareCondition (com.servoy.j2db.query.CompareCondition)2 QueryDelete (com.servoy.j2db.query.QueryDelete)2