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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations