This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Data Filtering on the Server Side

Documents for the development of and with JVx.

--Data Filtering on the Server Side

Postby Development@SIB » Thu Sep 16, 2010 12:16 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




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 the use of 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:

Code: Select all
/**
 * 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;
}
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation