Ejemplo n.º 1
0
 @Override
 public void updateGroup(
     DeviceGroup deviceGroup, String oldGroupName, String oldOwner, int tenantId)
     throws GroupManagementDAOException {
   PreparedStatement stmt = null;
   try {
     Connection conn = GroupManagementDAOFactory.getConnection();
     String sql =
         "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, DATE_OF_LAST_UPDATE = ?, OWNER = ? "
             + "WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?";
     stmt = conn.prepareStatement(sql);
     stmt.setString(1, deviceGroup.getDescription());
     stmt.setString(2, deviceGroup.getName());
     stmt.setLong(3, deviceGroup.getDateOfLastUpdate());
     stmt.setString(4, deviceGroup.getOwner());
     stmt.setString(5, oldGroupName);
     stmt.setString(6, oldOwner);
     stmt.setInt(7, tenantId);
     stmt.executeUpdate();
   } catch (SQLException e) {
     throw new GroupManagementDAOException(
         "Error occurred while updating deviceGroup '" + deviceGroup.getName() + "'", e);
   } finally {
     GroupManagementDAOUtil.cleanupResources(stmt, null);
   }
 }
Ejemplo n.º 2
0
 @Override
 public int addGroup(DeviceGroup deviceGroup, int tenantId) throws GroupManagementDAOException {
   PreparedStatement stmt = null;
   ResultSet rs;
   int groupId = -1;
   try {
     Connection conn = GroupManagementDAOFactory.getConnection();
     String sql =
         "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, "
             + "OWNER, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?)";
     stmt = conn.prepareStatement(sql, new String[] {"ID"});
     stmt.setString(1, deviceGroup.getDescription());
     stmt.setString(2, deviceGroup.getName());
     stmt.setLong(3, new Date().getTime());
     stmt.setLong(4, new Date().getTime());
     stmt.setString(5, deviceGroup.getOwner());
     stmt.setInt(6, tenantId);
     stmt.executeUpdate();
     rs = stmt.getGeneratedKeys();
     if (rs.next()) {
       groupId = rs.getInt(1);
     }
     return groupId;
   } catch (SQLException e) {
     throw new GroupManagementDAOException(
         "Error occurred while adding deviceGroup '" + deviceGroup.getName() + "'", e);
   } finally {
     GroupManagementDAOUtil.cleanupResources(stmt, null);
   }
 }