01: /*
02: * JDBCMySQLUserDAO.java
03: *
04: * Created on 28 de marzo de 2005, 13:46
05: */
06:
07: package org.manentia.kasai.authobject;
08:
09: import java.sql.Connection;
10: import java.sql.SQLException;
11:
12: import org.apache.commons.lang.StringUtils;
13: import org.manentia.kasai.AuthObject;
14: import org.manentia.kasai.Constants;
15: import org.manentia.kasai.exceptions.DataAccessException;
16: import org.manentia.kasai.exceptions.DoesntExistsException;
17:
18: import com.manentia.commons.log.Log;
19: import com.manentia.commons.persistence.DBUtil;
20:
21: /**
22: *
23: * @author rzuasti
24: */
25: public class JDBCMySQLAuthObjectDAO extends JDBCANSISQLAuthObjectDAO {
26:
27: /** Creates a new instance of JDBCMySQLUserDAO */
28: public JDBCMySQLAuthObjectDAO() {
29: }
30:
31: public void copyPermissionsFromObject(String sourceObject,
32: String destinationObject) throws DoesntExistsException,
33: DataAccessException {
34:
35: Connection con = null;
36: String sql;
37:
38: try {
39: if ((StringUtils.isNotEmpty(sourceObject))
40: && (StringUtils.isNotEmpty(destinationObject))) {
41: if (this .read(sourceObject) == null) {
42: Log.write("Source object doesn't exist", Log.WARN,
43: "copyPermissionsFromObject",
44: JDBCMySQLAuthObjectDAO.class);
45:
46: throw new DoesntExistsException(AuthObject.class
47: .getName()
48: + ".objectDoesntExist");
49: }
50:
51: if (this .read(destinationObject) == null) {
52: Log.write("Destination object doesn't exist",
53: Log.WARN, "copyPermissionsFromObject",
54: JDBCMySQLAuthObjectDAO.class);
55:
56: throw new DoesntExistsException(AuthObject.class
57: .getName()
58: + ".objectDoesntExist");
59: }
60:
61: con = DBUtil.getConnection(Constants.DATABASE_SOURCE,
62: Constants.CONFIG_PROPERTY_FILE);
63:
64: sql = "REPLACE INTO kasai_objects_users_roles (id_object,id_user,id_role) SELECT '"
65: + destinationObject
66: + "',id_user,id_role FROM kasai_objects_users_roles WHERE id_object='"
67: + sourceObject + "'";
68: con.createStatement().executeUpdate(sql);
69:
70: sql = "REPLACE INTO kasai_objects_groups_roles (id_object,id_group,id_role) SELECT '"
71: + destinationObject
72: + "',id_group,id_role FROM kasai_objects_groups_roles WHERE id_object='"
73: + sourceObject + "'";
74: con.createStatement().executeUpdate(sql);
75:
76: }
77: } catch (SQLException sqle) {
78: Log.write("SQL Error", sqle, Log.ERROR,
79: "copyPermissionsFromObject",
80: JDBCMySQLAuthObjectDAO.class);
81:
82: throw new DataAccessException(sqle);
83: } finally {
84: try {
85: con.close();
86: } catch (Exception e) {
87: }
88: }
89: }
90: }
|