Package com.cosmo.data

Examples of com.cosmo.data.DataAgent


    * @throws OrmDriverException
    */
   private static OrmDriver loadDriver(String dataSourceId, Workspace workspace) throws OrmDriverException
   {
      OrmDriver provider;
      DataAgent conn = null;

      try
      {
         // Genera la conexi�n
         conn = DataFactory.getInstance(workspace, dataSourceId);

         // Invoca el constructor del driver
         Class<?> cls = Class.forName(conn.getCompatibleOrmDriver());
         Constructor<?> cons = cls.getConstructor(DataAgent.class);
         provider = (OrmDriver) cons.newInstance(conn);

         return provider;
      }
      catch (NoSuchMethodException ex)
      {
         throw new OrmDriverException("CORM driver loader: NoSuchMethodException: " + (conn != null ? conn.getCompatibleOrmDriver() : "[unknown ORM driver]"), ex);
      }
      catch (InvocationTargetException ex)
      {
         throw new OrmDriverException("CORM driver loader: InvocationTargetException: " + (conn != null ? conn.getCompatibleOrmDriver() : "[unknown ORM driver]"), ex);
      }
      catch (ClassNotFoundException ex)
      {
         throw new OrmDriverException("CORM driver loader: ClassNotFoundException: " + (conn != null ? conn.getCompatibleOrmDriver() : "[unknown ORM driver]"), ex);
      }
      catch (InstantiationException ex)
      {
         throw new OrmDriverException("CORM driver loader: InstantiationException: " + (conn != null ? conn.getCompatibleOrmDriver() : "[unknown ORM driver]"), ex);
      }
      catch (IllegalAccessException ex)
      {
         throw new OrmDriverException("CORM driver loader: IllegalAccessException: " + (conn != null ? conn.getCompatibleOrmDriver() : "[unknown ORM driver]"), ex);
      }
      catch (DataException ex)
      {
         throw new OrmDriverException("CORM driver loader: " + (conn != null ? conn.getCompatibleOrmDriver() : "[unknown ORM driver]"), ex);
      }
   }
View Full Code Here


    * @throws AuthorizationException
    */
   public ArrayList<Role> getRoles() throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;
      ArrayList<Role> roles = new ArrayList<Role>();

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Obtiene la lista de roles
         sql = "SELECT * " +
               "FROM " + TABLE_ROLES + " " +
               "ORDER BY roleid";
         ResultSet rs = conn.executeSql(sql);
         while (rs.next())
         {
            roles.add(readRole(rs));
         }
      }
View Full Code Here

    * @throws AuthorizationException
    */
   public ArrayList<Role> getRolesByUser(String login) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;
      ArrayList<Role> roles = new ArrayList<Role>();

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Obtiene la lista de roles del usuario
         sql = "SELECT * " +
               "FROM     " + TABLE_ROLES + " Inner Join " + TABLE_USER_ROLES + " On (" + TABLE_ROLES + ".roleid=" + TABLE_USER_ROLES + ".roleid) " +
               "WHERE    " + TABLE_USER_ROLES + ".usrlogin='" + DataAgent.sqlFormatTextValue(login) + "' " +
               "ORDER BY " + TABLE_ROLES + ".roleid";
         ResultSet rs = conn.executeSql(sql);
         while (rs.next())
         {
            roles.add(readRole(rs));
         }
      }
View Full Code Here

    * @throws AuthorizationException
    */
   public void addRole(Role role) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Agrega el nuevo rol
         sql = "INSERT INTO " + TABLE_ROLES + " (roleid, roledescription, roleappid, rolesu) " +
               "VALUES ('" + DataAgent.sqlFormatTextValue(role.getId()) + "', " +
                       "'" + DataAgent.sqlFormatTextValue(role.getDescription()) + "', " +
                       "'" + DataAgent.sqlFormatTextValue(role.getApplicationId()) + "', " +
                             (role.isSuperUser() ? "true" : "false") + ")";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthorizationException
    */
   public void deleteRole(String roleId) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Elimina las asociaciones con actividades
         sql = "DELETE FROM " + TABLE_ROLE_ACTIVITIES + " " +
               "WHERE roleid='" + DataAgent.sqlFormatTextValue(roleId) + "'";
         conn.execute(sql);

         // Elimina las asociaciones con usuarios
         sql = "DELETE FROM " + TABLE_USER_ROLES + " " +
               "WHERE roleid='" + DataAgent.sqlFormatTextValue(roleId) + "'";
         conn.execute(sql);

         // Elimina el rol
         sql = "DELETE FROM " + TABLE_ROLES + " " +
               "WHERE roleid='" + DataAgent.sqlFormatTextValue(roleId) + "'";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthorizationException
    */
   public void updateRole(Role role) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Agrega el nuevo rol
         sql = "UPDATE " + TABLE_ROLES + " " +
               "SET roledescription = '" + DataAgent.sqlFormatTextValue(role.getDescription()) + "', " +
               "    roleappid       = '" + DataAgent.sqlFormatTextValue(role.getApplicationId()) + "', " +
               "    rolesu          =  " + (role.isSuperUser() ? "true" : "false") + " " +
               "WHERE roleid = '" + DataAgent.sqlFormatTextValue(role.getId()) + "'";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

    * @throws AuthorizationException
    */
   public ArrayList<Activity> getActivities() throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;
      ArrayList<Activity> activities = new ArrayList<Activity>();

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Obtiene la lista de actividades
         sql = "SELECT * " +
               "FROM " + TABLE_ACTIVITIES + " " +
               "ORDER BY actid";
         ResultSet rs = conn.executeSql(sql);
         while (rs.next())
         {
            activities.add(readActivity(rs));
         }
      }
View Full Code Here

    * @throws AuthorizationException
    */
   public ArrayList<Activity> getActivitiesByRole(String roleId) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;
      ArrayList<Activity> activities = new ArrayList<Activity>();

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Obtiene la lista de actividades del rol especificado
         sql = "SELECT   " + TABLE_ACTIVITIES + ".* " +
               "FROM     " + TABLE_ROLES + " Inner Join " + TABLE_ROLE_ACTIVITIES + " On (" + TABLE_ROLES + ".roleid=" + TABLE_ROLE_ACTIVITIES + ".roleid) " +
               "                             Inner Join " + TABLE_ACTIVITIES + " On (" + TABLE_ROLE_ACTIVITIES + ".actid=" + TABLE_ACTIVITIES + ".actid) " +
               "WHERE    " + TABLE_ROLES + ".roleid = '" + DataAgent.sqlFormatTextValue(roleId) + "' " +
               "ORDER BY " + TABLE_ACTIVITIES + ".actid";
         ResultSet rs = conn.executeSql(sql);
         while (rs.next())
         {
            activities.add(readActivity(rs));
         }
      }
View Full Code Here

    * @throws AuthorizationException
    */
   public ArrayList<Permission> getActivitiesByUser(String login) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;
      ArrayList<Permission> permissions = new ArrayList<Permission>();

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Obtiene la lista de actividades del usuario
         sql = "SELECT   " + TABLE_ACTIVITIES + ".*, " + TABLE_ROLE_ACTIVITIES + ".isgranted " +
               "FROM     " + TABLE_USER_ROLES + " Inner Join " + TABLE_ROLES + "           On (" + TABLE_ROLES + ".roleid = " + TABLE_USER_ROLES + ".roleid) " +
               "                                  Inner Join " + TABLE_ROLE_ACTIVITIES + " On (" + TABLE_ROLES + ".roleid = " + TABLE_ROLE_ACTIVITIES + ".roleid) " +
               "                                  Inner Join " + TABLE_ACTIVITIES + "      On (" + TABLE_ROLE_ACTIVITIES + ".actid = " + TABLE_ACTIVITIES + ".actid) " +
               "WHERE    " + TABLE_USER_ROLES + ".usrlogin = '" + DataAgent.sqlFormatTextValue(login) + "' " +
               "ORDER BY " + TABLE_ROLE_ACTIVITIES + ".actid";

         ResultSet rs = conn.executeSql(sql);
         while (rs.next())
         {
            permissions.add(new Permission(readActivity(rs), true));
         }
      }
View Full Code Here

    * @throws AuthorizationException
    */
   public void addActivity(Activity activity) throws AuthorizationException
   {
      String sql;
      DataAgent conn = null;

      try
      {
         // Obtiene la conexi�n
         conn = DataFactory.getInstance(workspace);

         // Agrega la nueva actividad
         sql = "INSERT INTO " + TABLE_ACTIVITIES + " (actid, actdescription, actdefaultgrant, actenabled) " +
               "VALUES ('" + DataAgent.sqlFormatTextValue(activity.getId()) + "', " +
                       "'" + DataAgent.sqlFormatTextValue(activity.getDescription()) + "', " +
                             (activity.isGrantedByDefault() ? "true" : "false") + ", " +
                             (activity.isEnabled() ? "true" : "false") + ")";
         conn.execute(sql);
      }
      catch (Exception ex)
      {
         throw new AuthorizationException(ex.getMessage(), ex);
      }
      finally
      {
         if (conn != null)
         {
            conn.disconnect();
         }
      }
   }
View Full Code Here

TOP

Related Classes of com.cosmo.data.DataAgent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.