01: package org.jsqltool.gui.tableplugins.constraints;
02:
03: import javax.swing.*;
04: import javax.swing.table.*;
05: import java.util.Vector;
06: import org.jsqltool.conn.DbConnectionUtil;
07:
08: /**
09: * <p>Title: JSqlTool Project</p>
10: * <p>Description: Constraints panel customized for Oracle database.
11: * </p>
12: * <p>Copyright: Copyright (C) 2006 Mauro Carniel</p>
13: *
14: * <p> This file is part of JSqlTool project.
15: * This library is free software; you can redistribute it and/or
16: * modify it under the terms of the (LGPL) Lesser General Public
17: * License as published by the Free Software Foundation;
18: *
19: * GNU LESSER GENERAL PUBLIC LICENSE
20: * Version 2.1, February 1999
21: *
22: * This library is distributed in the hope that it will be useful,
23: * but WITHOUT ANY WARRANTY; without even the implied warranty of
24: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25: * Library General Public License for more details.
26: *
27: * You should have received a copy of the GNU Library General Public
28: * License along with this library; if not, write to the Free
29: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30: *
31: * The author may be contacted at:
32: * maurocarniel@tin.it</p>
33: *
34: * @author Mauro Carniel
35: * @version 1.0
36: */
37: public class OracleConstraints implements Constraints {
38:
39: private DbConnectionUtil dbConnUtil = null;
40:
41: public OracleConstraints(DbConnectionUtil dbConnUtil) {
42: this .dbConnUtil = dbConnUtil;
43: }
44:
45: public boolean enableConstraint(String tableName,
46: Object constraintId) {
47: return dbConnUtil.executeStmt("ALTER TABLE " + tableName
48: + " ENABLE CONSTRAINT " + ((Object[]) constraintId)[0],
49: new Vector()) > 0;
50: }
51:
52: public boolean disableConstraint(String tableName,
53: Object constraintId) {
54: return dbConnUtil.executeStmt(
55: "ALTER TABLE " + tableName + " DISABLE CONSTRAINT "
56: + ((Object[]) constraintId)[0], new Vector()) > 0;
57: }
58:
59: public boolean dropConstraint(String tableName, Object constraintId) {
60: return dbConnUtil.executeStmt("ALTER TABLE " + tableName
61: + " DROP CONSTRAINT " + ((Object[]) constraintId)[0],
62: new Vector()) > 0;
63: }
64:
65: public String getQueryConstraints(String tableName) {
66: if (tableName.indexOf(".") > -1)
67: tableName = tableName.substring(tableName.indexOf(".") + 1);
68: // return "select * from all_constraints where table_name='"+tableName+"'";
69: return "SELECT a1.constraint_name NAME, "
70: + "DECODE (a1.constraint_type, "
71: + " 'C', 'Check', "
72: + " 'P', 'Primary Key', "
73: + " 'R', 'Referential Integrity', "
74: + " 'U', 'Unique Key', "
75: + " 'V', 'Check Option on a view' "
76: + " ) TYPE, "
77: + "a1.r_constraint_name rname, INITCAP (a1.status) status, "
78: + "INITCAP (a1.delete_rule) delete_rule, c1.column_name, c1.POSITION, "
79: + "r_constraint_name, r_owner, a1.search_condition constext, "
80: + "INITCAP (a1.DEFERRABLE) DEFERRABLE, INITCAP (a1.DEFERRED) DEFERRED "
81: + "FROM user_cons_columns c1, user_constraints a1 "
82: + "WHERE c1.table_name = a1.table_name "
83: + "AND c1.constraint_name = a1.constraint_name "
84: + "AND c1.owner = a1.owner " + "AND a1.table_name = '"
85: + tableName + "'";
86: }
87:
88: }
|