Search in sources :

Example 6 with IServer

use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.

the class FoundSetManager method getTable.

@SuppressWarnings("nls")
public ITable getTable(String dataSource) throws RepositoryException {
    if (dataSource == null) {
        return null;
    }
    if (application.getSolution() == null) {
        if (Debug.tracing()) {
            Debug.trace("Trying to get a table for a datasource: " + dataSource + " on an already closed solution", new RuntimeException());
        }
        return null;
    }
    ITable table = dataSource.startsWith(DataSourceUtils.VIEW_DATASOURCE_SCHEME_COLON) ? viewDataSources.get(dataSource) : inMemDataSources.get(dataSource);
    if (table == null) {
        // when it is a db:/server/table data source
        String[] servernameTablename = DataSourceUtilsBase.getDBServernameTablename(dataSource);
        if (servernameTablename != null && servernameTablename[0] != null) {
            try {
                IServer server = application.getSolution().getServer(servernameTablename[0]);
                if (server == null) {
                    // $NON-NLS-1$
                    throw new RepositoryException(Messages.getString("servoy.exception.serverNotFound", new Object[] { servernameTablename[0] }));
                }
                table = server.getTable(servernameTablename[1]);
            } catch (RemoteException e) {
                throw new RepositoryException(e);
            }
        } else if (getDataSourceServerName(dataSource) == IServer.INMEM_SERVER) {
            if (!inMemDataSources.containsKey(dataSource) && dataSourceExists(dataSource)) {
                try {
                    insertToDataSource(DataSourceUtils.getDataSourceTableName(dataSource), new BufferedDataSet(), null, null, true, false, IServer.INMEM_SERVER);
                } catch (Exception e) {
                    Debug.error(e);
                }
            }
            return inMemDataSources.get(dataSource);
        } else if (getDataSourceServerName(dataSource) == IServer.VIEW_SERVER) {
            Optional<ServoyJSONObject> columnDefintion;
            if (!viewDataSources.containsKey(dataSource) && (columnDefintion = getColumnDefintion(dataSource)).isPresent()) {
                Table tbl = new Table(IServer.VIEW_SERVER, DataSourceUtils.getViewDataSourceName(dataSource), true, ITable.VIEW, null, null);
                tbl.setDataSource(dataSource);
                DatabaseUtils.deserializeInMemoryTable(application.getFlattenedSolution().getPersistFactory(), tbl, columnDefintion.get());
                tbl.setExistInDB(true);
                tbl.setInitialized(true);
                viewDataSources.put(dataSource, tbl);
                try {
                    executeFoundsetTriggerReturnFirst(tbl, new Object[] { DataSourceUtils.getViewDataSourceName(dataSource) }, StaticContentSpecLoader.PROPERTY_ONFOUNDSETLOADMETHODID, false, // can't entity methods, not supported on view foundsets
                    null);
                } catch (ServoyException e) {
                    Debug.error("Error executing foundset method for datasource:  " + dataSource, e);
                }
            }
            return viewDataSources.get(dataSource);
        }
    }
    return table;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) BaseQueryTable(com.servoy.base.query.BaseQueryTable) Table(com.servoy.j2db.persistence.Table) QueryTable(com.servoy.j2db.query.QueryTable) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) MarshallException(org.jabsorb.serializer.MarshallException) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ITable(com.servoy.j2db.persistence.ITable) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) RemoteException(java.rmi.RemoteException)

Example 7 with IServer

use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.

the class JSDatabaseManager method addTableFilterParamInternal.

private boolean addTableFilterParamInternal(String serverName, String tableName, String dataprovider, String operator, Object value, String filterName) throws ServoyException {
    checkAuthorized();
    try {
        if (value instanceof Wrapper) {
            value = ((Wrapper) value).unwrap();
        }
        IServer server = application.getSolution().getServer(serverName);
        if (server == null) {
            application.reportJSError("Table filter not applied to unknown server '" + serverName + "', tableName = '" + tableName + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "', value = '" + value + "', filterName = '" + filterName + "'", null);
            return false;
        }
        ITable table = null;
        if (tableName != null) {
            table = server.getTable(tableName);
            if (table == null) {
                application.reportJSError("Table filter not applied to unknown table: serverName = '" + serverName + "', tableName = '" + tableName + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "', value = '" + value + "', filterName = '" + filterName + "'", null);
                return false;
            }
        }
        // else table remains null: apply to all tables with that column
        DataproviderTableFilterdefinition dataproviderTableFilterdefinition = application.getFoundSetManager().createDataproviderTableFilterdefinition(table, dataprovider, operator, value);
        if (dataproviderTableFilterdefinition == null) {
            application.reportJSError("Table filter not created, column not found in table or operator invalid, filterName = '" + filterName + "', serverName = '" + serverName + "', table = '" + table + "', dataprovider = '" + dataprovider + "', operator = '" + operator + "'", null);
            return false;
        }
        return (((FoundSetManager) application.getFoundSetManager()).addTableFilterParam(filterName, serverName, table, dataproviderTableFilterdefinition));
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return false;
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) IServer(com.servoy.j2db.persistence.IServer) ITable(com.servoy.j2db.persistence.ITable) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) SQLException(java.sql.SQLException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 8 with IServer

use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.

the class RemoteActiveSolutionHandler method loadLoginSolutionAndModules.

@Override
public Solution[] loadLoginSolutionAndModules(final SolutionMetaData mainSolutionDef) throws RepositoryException, RemoteException {
    final SolutionMetaData[] loginSolutionDefinitions = getApplicationServer().getLoginSolutionDefinitions(mainSolutionDef);
    if (loginSolutionDefinitions == null) {
        throw new RepositoryException("Could not load login solution");
    }
    final Solution[] solutions = new Solution[loginSolutionDefinitions.length];
    if (loginSolutionDefinitions.length > 0) {
        ThrowingRunnable<RepositoryException, RemoteException> r = new ThrowingRunnable<RepositoryException, RemoteException>() {

            @Override
            public void run() {
                try {
                    int[] sol_ids = new int[loginSolutionDefinitions.length];
                    for (int i = 0; i < sol_ids.length; i++) {
                        sol_ids[i] = loginSolutionDefinitions[i].getRootObjectId();
                    }
                    long[] asus = getApplicationServer().getActiveRootObjectsLastModified(sol_ids);
                    ConcurrentMap<String, IServer> sps = getRepository().getServerProxies(loginSolutionDefinitions);
                    for (int i = 0; i < loginSolutionDefinitions.length; i++) {
                        Solution s = loadCachedSolution(loginSolutionDefinitions[i], asus[i], sps);
                        if (s == null) {
                            // do full load
                            s = getApplicationServer().getLoginSolution(mainSolutionDef, loginSolutionDefinitions[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);
                        }
                        solutions[i] = s;
                    }
                } catch (RepositoryException eo) {
                    e1 = eo;
                } catch (RemoteException et) {
                    e2 = et;
                }
            }
        };
        UIUtils.runWhileDispatchingEvents(r, getServiceProvider());
    }
    return solutions;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) ThrowingRunnable(com.servoy.j2db.util.UIUtils.ThrowingRunnable) RemoteException(java.rmi.RemoteException) Solution(com.servoy.j2db.persistence.Solution)

Example 9 with IServer

use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.

the class JSDataSource method getTable.

/**
 * Get the table of a datasource.
 *
 * @return JSTable table
 */
@JSFunction
public JSTable getTable() {
    try {
        ITable table = application.getFoundSetManager().getTable(datasource);
        IServer server = application.getSolution().getServer(table.getServerName());
        if (server != null) {
            return new JSTable(table, server);
        }
    } catch (RepositoryException e) {
        Debug.log(e);
    }
    return null;
}
Also used : IServer(com.servoy.j2db.persistence.IServer) JSTable(com.servoy.j2db.dataprocessing.JSTable) ITable(com.servoy.j2db.persistence.ITable) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 10 with IServer

use of com.servoy.j2db.persistence.IServer in project servoy-client by Servoy.

the class JSSecurity method js_setSecuritySettings.

/**
 * Sets the security settings; the entries contained in the given dataset will override those contained in the current security settings.
 *
 * NOTE: The security.getElementUUIDs and security.setSecuritySettings functions can be used to define custom security that overrides Servoy security.
 * For additional information see the function security.getElementUUIDs.
 *
 * @sample
 * var colNames = new Array();
 * colNames[0] = 'uuid';
 * colNames[1] = 'flags';
 * var dataset = databaseManager.createEmptyDataSet(0,colNames);
 *
 * var row = new Array();
 * row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
 * row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
 * dataset.addRow(row);//setting element security
 *
 * row = new Array();
 * row[0] = 'example_data.orders';
 * row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
 * dataset.addRow(row);//setting table security
 *
 * security.setSecuritySettings(dataset);//to be called in solution startup method
 *
 * @param dataset the dataset with security settings
 */
public // uuid/server.tablename , integer(flags)
void js_setSecuritySettings(// uuid/server.tablename , integer(flags)
Object dataset) {
    if (dataset instanceof JSDataSet) {
        dataset = ((JSDataSet) dataset).getDataSet();
    }
    if (dataset instanceof IDataSet) {
        application.getFoundSetManager().getEditRecordList().clearSecuritySettings();
        Map<Object, Integer> sp = new HashMap<Object, Integer>();
        IDataSet ds = (IDataSet) dataset;
        if (ds.getColumnCount() < 2)
            return;
        for (int i = 0; i < ds.getRowCount(); i++) {
            Object[] row = ds.getRow(i);
            if (row[0] != null && row[1] != null) {
                Integer val = new Integer(Utils.getAsInteger(row[1]));
                try {
                    boolean matched = false;
                    if (row[0] instanceof UUID) {
                        sp.put(row[0], val);
                        matched = true;
                    } else if (row[0].toString().indexOf('-') > 0) {
                        UUID uuid = UUID.fromString(row[0].toString());
                        sp.put(uuid, val);
                        matched = true;
                    } else {
                        String datasource = row[0].toString();
                        if (datasource.indexOf('.') != -1) {
                            String[] server_table = datasource.split("\\.");
                            if (server_table.length == 2) {
                                IServer server = application.getSolution().getServer(server_table[0]);
                                if (server != null) {
                                    ITable table = server.getTable(server_table[1]);
                                    if (table != null) {
                                        Iterator<String> it = table.getRowIdentColumnNames();
                                        if (it.hasNext()) {
                                            sp.put(Utils.getDotQualitfied(table.getServerName(), table.getName(), it.next()), val);
                                            matched = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!matched) {
                        Debug.error("security.setSecuritySettings: could not apply security settings for '" + row[0] + "'");
                    }
                } catch (Exception e) {
                    Debug.error(e);
                }
            }
        }
        application.getFlattenedSolution().overrideSecurityAccess(sp);
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) HashMap(java.util.HashMap) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) ServoyException(com.servoy.j2db.util.ServoyException) ApplicationException(com.servoy.j2db.ApplicationException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) UUID(com.servoy.j2db.util.UUID)

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