Documentation

(jvx:server:storage)

Data Filtering on the Server Side

Translations of this page:

Usually the data for the client UI is limited on the server side, so that the client only receives data it needs. One efficient way to limit data is to use views in the respective database. This method, however, leaves us dependent on the database, and not all databases offer this feature.

The Restrict Condition exists to restrict data database-independently. It is one or more conditions that result in the restriction of data before it is transmitted to the client.

Example

Our application only shows data for the registered user; data for other users is not transmitted.

This is done as follows:

/**
 * Returns the user DBStorage.
 * 
 * @return the user DBStorage.
 * @throws Exception if the user DBStorage couldn't be initialized.
 */
public DBStorage getUserData() throws Exception
{
    DBStorage userData = (DBStorage)get("userDefaults");
 
    if (userDefaults == null)
    {
        userData = new DBStorage();
        userData.setDBAccess(getDBAccess());
        userData.setWritebackTable("USERS");
        userData.setRestrictCondition(new Equals("ID", getUserId()));
        userData.open();
 
        put("userDefaults", userDefaults);
    }
 
    return userDefaults;
}
 
/**
 * Gets the ID of the current logged on user.
 * 
 * @return the ID of the current logged on user.
 */
public Object getUserId()
{
    return get("userId");
}
 
/**
 * Creates a new database access object.
 * 
 * @return the new database access object
 * @throws Exception if the connection can not be opened
 */
public DBAccess getDBAccess() throws Exception
{   
   //configure DBAccess
   DBAccess dba = (DBAccess)get("dBAccess");
 
   if (dba == null)
   {
       dba = DBAccess.get...
 
       DBStorage dbsUser = new DBStorage();
       dbsUser.setDBAccess(dba);
       dbsUser.setFromClause("USERS");
       dbsUser.open();
 
       ISession session = SessionContext.getCurrentSession();
 
       IBean bnUser = dbsUser.fetchBean(new Equals("USERNAME", session.getUserName()));
 
       Object userId = bnUser.get(DBObjects.getColumnName(session.getConfig(), 
                                                          "USERS", "ID"));
 
       put("userId", userId);
       put("dBAccess", dba);
   }
 
   return dba;
}
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information