DbGroupProvider.java 22.8 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
11

Matt Tucker's avatar
Matt Tucker committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
package org.jivesoftware.messenger.auth.spi;

import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.database.SequenceManager;
import org.jivesoftware.util.*;
import org.jivesoftware.messenger.auth.*;
import org.jivesoftware.messenger.user.UserAlreadyExistsException;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.database.SequenceManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * Database implementation of the GroupManager interface.
 *
 * @author Iain Shigeoka
 */
public class DbGroupProvider implements GroupProvider {

    private static final String INSERT_GROUP =
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        "INSERT INTO jiveGroup " +
        "(name, description, groupID, creationDate, modificationDate) " +
        "VALUES (?, ?, ?, ?, ?)";
    private static final String LOAD_PROPERTIES =
        "SELECT name, propValue FROM jiveGroupProp WHERE groupID=?";
    private static final String LOAD_GROUP_BY_ID =
        "SELECT name, description, groupID, creationDate, modificationDate " +
        "FROM jiveGroup WHERE groupID=?";
    private static final String DELETE_PROPERTY =
        "DELETE FROM jiveGroupProp WHERE groupID=? AND name=?";
    private static final String SAVE_GROUP =
        "UPDATE jiveGroup SET name=?, description=?, creationDate=?, modificationDate=? " +
        "WHERE groupID=?";
    private static final String DELETE_GROUP_USERS =
        "DELETE FROM jiveGroupUser WHERE groupID=?";
    private static final String DELETE_GROUP =
        "DELETE FROM jiveGroup WHERE groupID=?";
    private static final String GROUP_COUNT = "SELECT count(*) FROM jiveGroup";
    private static final String UPDATE_PROPERTY =
        "UPDATE jiveGroupProp SET propValue=? WHERE name=? AND groupID=?";
    private static final String INSERT_PROPERTY =
        "INSERT INTO jiveGroupProp (groupID, name, propValue) VALUES (?, ?, ?)";
     private static final String MEMBER_TEST =
        "SELECT userID FROM jiveGroupUser " +
        "WHERE groupID=? AND userID=? AND administrator=0";
    private static final String ADMIN_TEST =
        "SELECT userID FROM jiveGroupUser " +
        "WHERE groupID=? AND userID=? AND administrator=1";
     private static final String LOAD_ADMINS =
        "SELECT userID FROM jiveGroupUser WHERE administrator=1 AND groupID=?";
    private static final String LOAD_MEMBERS =
        "SELECT userID FROM jiveGroupUser WHERE administrator=0 AND groupID=?";
    private static final String GROUP_MEMBER_COUNT =
        "SELECT count(*) FROM jiveGroupUser WHERE administrator =0";
    private static final String GROUP_ADMIN_COUNT =
        "SELECT count(*) FROM jiveGroupUser WHERE administrator =1";
    private static final String SELECT_GROUP_BY_NAME =
        "SELECT name, description, groupID, creationDate, modificationDate " +
        "FROM jiveGroup WHERE name=?";
    private static final String REMOVE_USER =
        "DELETE FROM jiveGroupUser WHERE groupID=? AND userID=?";
    private static final String UPDATE_USER =
        "UPDATE jiveGroupUser SET administrator=? WHERE  groupID=? userID=?";
    private static final String ADD_USER =
        "INSERT INTO jiveGroupUser (groupID, userID, administrator) VALUES (?, ?, ?)";
    private static final String USER_GROUPS =
        "SELECT groupID FROM jiveGroupUser WHERE userID=? AND administrator=0";
    private static final String ALL_GROUPS = "SELECT groupID FROM jiveGroup";
Matt Tucker's avatar
Matt Tucker committed
84

85 86 87
    public Group createGroup(String name) throws UnauthorizedException,
            GroupAlreadyExistsException
    {
Matt Tucker's avatar
Matt Tucker committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        long now = System.currentTimeMillis();
        Date nowDate = new Date(now);
        long id = SequenceManager.nextID(JiveConstants.GROUP);
        Group group = null;

        Connection con = null;
        PreparedStatement pstmt = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(INSERT_GROUP);
            pstmt.setString(1, name);
            pstmt.setString(2, "None");
            pstmt.setLong(3, id);
            pstmt.setString(4, StringUtils.dateToMillis(nowDate));
            pstmt.setString(5, StringUtils.dateToMillis(nowDate));
            pstmt.executeUpdate();
            group = new GroupImpl(id, name, null, nowDate, nowDate);
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
110 111 112 113
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
        }
        if (group == null) {
            throw new GroupAlreadyExistsException(name);
        }
        return group;
    }

    public Group getGroup(long groupID) throws GroupNotFoundException {
        Connection con = null;
        PreparedStatement pstmt = null;
        Group group = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(LOAD_GROUP_BY_ID);
            pstmt.setLong(1, groupID);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                group = new GroupImpl(groupID,
                        rs.getString(1),
                        rs.getString(2),
                        new java.util.Date(Long.parseLong(rs.getString(4).trim())),
                        new java.util.Date(Long.parseLong(rs.getString(5).trim())));
                // Load any extended properties.
                pstmt = con.prepareStatement(LOAD_PROPERTIES);
                pstmt.setLong(1, groupID);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    // Add in name, value as a new property.
                    group.setProperty(rs.getString(1), rs.getString(2));
                }
            }
        }
        catch (SQLException e) {
            Log.error(e);
            throw new GroupNotFoundException();
        }
        catch (NumberFormatException nfe) {
            Log.error("WARNING: There was an error parsing the dates " +
                    "returned from the database. Ensure that they're being stored " +
                    "correctly.");
            throw new GroupNotFoundException("Group with id "
                    + groupID + " could not be loaded from the database.");
        }
        catch (UnauthorizedException e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        }
        finally {
161 162 163 164
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
        }
        if (group == null) {
            throw new GroupNotFoundException("Group with ID "
                    + groupID + " not found.");
        }
        return group;
    }

    public Group getGroup(String name) throws GroupNotFoundException {
        Connection con = null;
        PreparedStatement pstmt = null;
        Group group = null;
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(SELECT_GROUP_BY_NAME);
            pstmt.setString(1, name);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
183
                group = new GroupImpl(rs.getLong(3), rs.getString(1), rs.getString(2),
Matt Tucker's avatar
Matt Tucker committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
                        new java.util.Date(Long.parseLong(rs.getString(4).trim())),
                        new java.util.Date(Long.parseLong(rs.getString(5).trim())));
                // Load any extended properties.
                pstmt = con.prepareStatement(LOAD_PROPERTIES);
                pstmt.setLong(1, group.getID());
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    // Add in name, value as a new property.
                    group.setProperty(rs.getString(1), rs.getString(2));
                }
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        catch (UnauthorizedException e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        }
        finally {
203 204 205 206
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
207 208 209 210 211 212 213 214
        }
        if (group == null) {
            throw new GroupNotFoundException("Group with name "
                    + name + " not found.");
        }
        return group;
    }

215
    public void updateGroup(Group group) throws UnauthorizedException, GroupNotFoundException {
Matt Tucker's avatar
Matt Tucker committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
        group.setModificationDate(new Date());
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(SAVE_GROUP);
            pstmt.setString(1, group.getName());
            pstmt.setString(2, group.getDescription());
            pstmt.setString(3, StringUtils.dateToMillis(group.getCreationDate()));
            pstmt.setString(4, StringUtils.dateToMillis(group.getModificationDate()));
            pstmt.setLong(5, group.getID());
            pstmt.executeUpdate();
        }
        catch (SQLException e) {
            Log.error(e);
            throw new GroupNotFoundException();
        }
        finally {
235 236 237 238
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
239 240 241 242 243 244 245 246 247 248 249 250 251
        }
    }

    public void deleteGroup(long groupID) throws UnauthorizedException {
        Connection con = null;
        PreparedStatement pstmt = null;
        boolean abortTransaction = false;

        try {
            con = DbConnectionManager.getTransactionConnection();
            // Remove all users in the group.
            pstmt = con.prepareStatement(DELETE_GROUP_USERS);
            pstmt.setLong(1, groupID);
Derek DeMoro's avatar
Derek DeMoro committed
252
            pstmt.executeUpdate();
Matt Tucker's avatar
Matt Tucker committed
253 254 255 256
            pstmt.close();
            // Remove the group entry.
            pstmt = con.prepareStatement(DELETE_GROUP);
            pstmt.setLong(1, groupID);
Derek DeMoro's avatar
Derek DeMoro committed
257
            pstmt.executeUpdate();
Matt Tucker's avatar
Matt Tucker committed
258 259 260 261 262 263 264
            pstmt.close();
        }
        catch (SQLException e) {
            Log.error(e);
            abortTransaction = true;
        }
        finally {
265 266
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
            DbConnectionManager.closeTransactionConnection(con, abortTransaction);
        }
        // Removing a group can change the permissions of all the users in that
        // group. Therefore, expire permissions cache.
    }

    public int getGroupCount() {
        int count = 0;
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(GROUP_COUNT);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                count = rs.getInt(1);
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
290 291 292 293
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
        }
        return count;
    }

    public LongList getGroups() {
        LongList groups = new LongList();
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(ALL_GROUPS);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                groups.add(rs.getLong(1));
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
315 316 317 318
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
        }
        return groups;
    }

    public LongList getGroups(BasicResultFilter filter) {
        LongList groups = new LongList();
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(ALL_GROUPS);
            ResultSet rs = pstmt.executeQuery();
            // Move to start of index
            for (int i = 0; i < filter.getStartIndex(); i++) {
                if (!rs.next()) {
                    break;
                }
            }
            // Now read in desired number of results
            for (int i = 0; i < filter.getNumResults(); i++) {
                if (rs.next()) {
                    groups.add(rs.getLong(1));
                }
                else {
                    break;
                }
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
352 353 354 355
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
        }
        return groups;
    }

    public LongList getGroups(long entityID) {
        Connection con = null;
        PreparedStatement pstmt = null;
        LongList groups = new LongList();
        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(USER_GROUPS);
            pstmt.setLong(1, entityID);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                groups.add(rs.getLong(1));
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
377 378 379 380
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
        }
        return groups;
    }

    public void createMember(long groupID, long entityID, boolean administrator)
            throws UserAlreadyExistsException {
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(ADD_USER);
            pstmt.setLong(1, groupID);
            pstmt.setLong(2, entityID);
            pstmt.setInt(3, administrator ? 1 : 0);
            pstmt.executeUpdate();
        }
        catch (SQLException e) {
            Log.error(e);
            throw new UserAlreadyExistsException(e);
        }
        finally {
403 404 405 406
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
        }
    }

    public void updateMember(long groupID, long entityID, boolean administrator) {
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(UPDATE_USER);
            pstmt.setInt(1, administrator ? 1 : 0);
            pstmt.setLong(2, groupID);
            pstmt.setLong(3, entityID);
            pstmt.executeUpdate();
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
426 427 428 429
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
        }
    }

    public void deleteMember(long groupID, long entityID) {
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(REMOVE_USER);
            pstmt.setLong(1, groupID);
            pstmt.setLong(2, entityID);
            pstmt.executeUpdate();
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
448 449 450 451
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
        }
    }

    public int getMemberCount(long groupID, boolean adminsOnly) {
        int count = 0;
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            if (adminsOnly) {
                pstmt = con.prepareStatement(GROUP_MEMBER_COUNT);
            }
            else {
                pstmt = con.prepareStatement(GROUP_ADMIN_COUNT);
            }
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                count = rs.getInt(1);
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
477 478 479 480
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
        }
        return count;
    }

    public LongList getMembers(long groupID, boolean adminsOnly) {
        Connection con = null;
        PreparedStatement pstmt = null;
        LongList members = new LongList();
        try {
            con = DbConnectionManager.getConnection();
            if (adminsOnly) {
                pstmt = con.prepareStatement(LOAD_MEMBERS);
            }
            else {
                pstmt = con.prepareStatement(LOAD_ADMINS);
            }
            pstmt.setLong(1, groupID);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                members.add(rs.getLong(1));
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
507 508 509 510
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
511 512 513 514
        }
        return members;
    }

515
    public LongList getMembers(long groupID, BasicResultFilter filter, boolean adminsOnly) {
Matt Tucker's avatar
Matt Tucker committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
        Connection con = null;
        PreparedStatement pstmt = null;
        LongList members = new LongList();
        try {
            con = DbConnectionManager.getConnection();
            if (adminsOnly) {
                pstmt = con.prepareStatement(LOAD_MEMBERS);
            }
            else {
                pstmt = con.prepareStatement(LOAD_ADMINS);
            }
            pstmt.setLong(1, groupID);
            ResultSet rs = pstmt.executeQuery();
            // Move to start of index
            for (int i = 0; i < filter.getStartIndex(); i++) {
                if (!rs.next()) {
                    break;
                }
            }
            // Now read in desired number of results
            for (int i = 0; i < filter.getNumResults(); i++) {
                if (rs.next()) {
                    members.add(rs.getLong(1));
                }
                else {
                    break;
                }
            }
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
549 550 551 552
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
        }
        return members;
    }

    public boolean isMember(long groupID, long entityID, boolean adminsOnly) {
        boolean member = false;
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            if (adminsOnly) {
                pstmt = con.prepareStatement(ADMIN_TEST);
            }
            else {
                pstmt = con.prepareStatement(MEMBER_TEST);
            }
            pstmt.setLong(1, groupID);
            pstmt.setLong(2, entityID);
            ResultSet rs = pstmt.executeQuery();
            // If there is a result, then the user is a member of the group.
            member = rs.next();
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
580 581 582 583
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
        }
        return member;
    }

    public void createProperty(long groupID, String name, String value) {
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(INSERT_PROPERTY);
            pstmt.setLong(1, groupID);
            pstmt.setString(2, name);
            pstmt.setString(3, value);
            pstmt.executeUpdate();
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
604 605 606 607
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
        }
    }

    public void updateProperty(long groupID, String name, String value) {
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(UPDATE_PROPERTY);
            pstmt.setString(1, value);
            pstmt.setString(2, name);
            pstmt.setLong(3, groupID);
            pstmt.executeUpdate();
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
627 628 629 630
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
631 632 633 634 635 636 637 638 639 640 641 642
        }
    }

    public void deleteProperty(long groupID, String name) {
        Connection con = null;
        PreparedStatement pstmt = null;

        try {
            con = DbConnectionManager.getConnection();
            pstmt = con.prepareStatement(DELETE_PROPERTY);
            pstmt.setLong(1, groupID);
            pstmt.setString(2, name);
Derek DeMoro's avatar
Derek DeMoro committed
643
            pstmt.executeUpdate();
Matt Tucker's avatar
Matt Tucker committed
644 645 646 647 648
        }
        catch (SQLException e) {
            Log.error(e);
        }
        finally {
649 650 651 652
            try { if (pstmt != null) pstmt.close(); }
            catch (Exception e) { Log.error(e); }
            try { if (con != null) con.close(); }
            catch (Exception e) { Log.error(e); }
Matt Tucker's avatar
Matt Tucker committed
653 654
        }
    }
655
}