Revision: 5803
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5803&view=rev
Author: manningr
Date: 2010-08-21 14:17:41 +0000 (Sat, 21 Aug 2010)
Log Message:
-----------
Patch 2991451 submitted by developer Bogdan Paulon (bpaulon). It adds a constraints node below Oracle tables.
Modified Paths:
--------------
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/IObjectTypes.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/OraclePlugin.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/TableExpander.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/AbstractConstraintSource.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/CKConstraintSource.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintColumnInfo.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintInfo.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintSourceBuilder.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/FKConstraintSource.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/PKConstraintSource.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/UQConstraintSource.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentExpander.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentInfo.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintColumnInfoTab.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintDetailsTab.java
trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintSourceTab.java
Modified: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/IObjectTypes.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/IObjectTypes.java 2010-08-21 12:29:59 UTC (rev 5802)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/IObjectTypes.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -36,6 +36,7 @@
DatabaseObjectType TRIGGER_PARENT = DatabaseObjectType.createNewDatabaseObjectType("Triggers");
DatabaseObjectType TYPE_PARENT = DatabaseObjectType.createNewDatabaseObjectType("Types");
DatabaseObjectType USER_PARENT = DatabaseObjectType.createNewDatabaseObjectType("Users");
+ DatabaseObjectType CONSTRAINT_PARENT = DatabaseObjectType.createNewDatabaseObjectType("Constraints");
DatabaseObjectType CONSUMER_GROUP = DatabaseObjectType.createNewDatabaseObjectType("Consumer Group");
DatabaseObjectType INSTANCE = DatabaseObjectType.createNewDatabaseObjectType("Instance");
@@ -43,4 +44,5 @@
DatabaseObjectType PACKAGE = DatabaseObjectType.createNewDatabaseObjectType("Package");
DatabaseObjectType SESSION = DatabaseObjectType.createNewDatabaseObjectType("Session");
DatabaseObjectType TYPE = DatabaseObjectType.createNewDatabaseObjectType("Type");
+ DatabaseObjectType CONSTRAINT = DatabaseObjectType.createNewDatabaseObjectType("Constraint");
}
Modified: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/OraclePlugin.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/OraclePlugin.java 2010-08-21 12:29:59 UTC (rev 5802)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/OraclePlugin.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -77,6 +77,7 @@
import net.sourceforge.squirrel_sql.plugins.oracle.SGAtrace.NewSGATraceWorksheetAction;
import net.sourceforge.squirrel_sql.plugins.oracle.dboutput.NewDBOutputWorksheetAction;
import net.sourceforge.squirrel_sql.plugins.oracle.exception.OracleExceptionFormatter;
+import net.sourceforge.squirrel_sql.plugins.oracle.expander.ConstraintParentExpander;
import net.sourceforge.squirrel_sql.plugins.oracle.expander.DefaultDatabaseExpander;
import net.sourceforge.squirrel_sql.plugins.oracle.expander.InstanceParentExpander;
import net.sourceforge.squirrel_sql.plugins.oracle.expander.OracleTableParentExpander;
@@ -93,6 +94,9 @@
import net.sourceforge.squirrel_sql.plugins.oracle.prefs.OraclePreferenceBean;
import net.sourceforge.squirrel_sql.plugins.oracle.sessioninfo.NewSessionInfoWorksheetAction;
import net.sourceforge.squirrel_sql.plugins.oracle.sqlloader.control.GenerateControlFileAction;
+import net.sourceforge.squirrel_sql.plugins.oracle.tab.ConstraintColumnInfoTab;
+import net.sourceforge.squirrel_sql.plugins.oracle.tab.ConstraintDetailsTab;
+import net.sourceforge.squirrel_sql.plugins.oracle.tab.ConstraintSourceTab;
import net.sourceforge.squirrel_sql.plugins.oracle.tab.IndexColumnInfoTab;
import net.sourceforge.squirrel_sql.plugins.oracle.tab.IndexDetailsTab;
import net.sourceforge.squirrel_sql.plugins.oracle.tab.InstanceDetailsTab;
@@ -790,7 +794,8 @@
addDetailTab(objTree, DatabaseObjectType.TRIGGER, new DatabaseObjectInfoTab());
addDetailTab(objTree, IObjectTypes.TRIGGER_PARENT, new DatabaseObjectInfoTab());
addDetailTab(objTree, IObjectTypes.TYPE, new DatabaseObjectInfoTab());
-
+ addDetailTab(objTree, IObjectTypes.CONSTRAINT, new DatabaseObjectInfoTab());
+
// Expanders.
addExpander(objTree, DatabaseObjectType.SCHEMA, new SchemaExpander());
addExpander(objTree, DatabaseObjectType.TABLE, new TableExpander());
@@ -799,6 +804,7 @@
addExpander(objTree, IObjectTypes.SESSION_PARENT, new SessionParentExpander());
addExpander(objTree, IObjectTypes.INSTANCE_PARENT, new InstanceParentExpander());
addExpander(objTree, IObjectTypes.TRIGGER_PARENT, new TriggerParentExpander());
+ addExpander(objTree, IObjectTypes.CONSTRAINT_PARENT, new ConstraintParentExpander());
addDetailTab(objTree, DatabaseObjectType.PROCEDURE, new ObjectSourceTab(
"PROCEDURE", "Show stored procedure source"));
@@ -810,6 +816,7 @@
"PACKAGE BODY", "Body", "Show package body"));
addDetailTab(objTree, IObjectTypes.TYPE, new ObjectSourceTab(
"TYPE", "Specification", "Show type specification"));
+
addDetailTab(objTree, IObjectTypes.TYPE, new ObjectSourceTab("TYPE BODY", "Body", "Show type body"));
addDetailTab(objTree, IObjectTypes.INSTANCE, new InstanceDetailsTab());
addDetailTab(objTree, DatabaseObjectType.SEQUENCE, new SequenceDetailsTab());
@@ -819,7 +826,10 @@
addDetailTab(objTree, DatabaseObjectType.TRIGGER, new TriggerSourceTab());
addDetailTab(objTree, DatabaseObjectType.TRIGGER, new TriggerColumnInfoTab());
addDetailTab(objTree, DatabaseObjectType.USER, new UserDetailsTab(session));
-
+ addDetailTab(objTree, IObjectTypes.CONSTRAINT, new ConstraintDetailsTab());
+ addDetailTab(objTree, IObjectTypes.CONSTRAINT, new ConstraintColumnInfoTab());
+ addDetailTab(objTree, IObjectTypes.CONSTRAINT, new ConstraintSourceTab());
+
addDetailTab(objTree, DatabaseObjectType.VIEW, new ViewSourceTab());
addDetailTab(objTree, DatabaseObjectType.TABLE, new SnapshotSourceTab());
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/AbstractConstraintSource.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/AbstractConstraintSource.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/AbstractConstraintSource.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
+
+/**
+ * Base class that constructs the SQL source for the constraints
+ * @author bpaulon
+ */
+public abstract class AbstractConstraintSource {
+
+ String dropStmt;
+ String addStmt;
+ String constraintClause;
+ List<ConstraintColumnInfo> columns;
+
+ ConstraintInfo ci;
+ ISession session;
+
+ public AbstractConstraintSource(ISession session, ConstraintInfo ci) {
+ if (session == null) {
+ throw new IllegalStateException("Null ISession");
+ }
+ if (ci == null) {
+ throw new IllegalStateException("Null ConstraintInfo");
+ }
+
+ this.session = session;
+ this.ci = ci;
+ }
+
+ private final String SQL_COLUMNS = "select "
+ + " owner, constraint_name, table_name, column_name, position"
+ + " from all_cons_columns "
+ + " where owner = ? and constraint_name = ? "
+ + " order by position";
+
+ public void buildDropStatement() {
+ dropStmt = "ALTER TABLE " + ci.getOwner() + "." + ci.getTableName()
+ + "\n DROP CONSTRAINT " + ci.getConstraintName();
+ }
+
+ public void buildAddStatement() {
+ addStmt = "ALTER TABLE " + ci.getOwner() + "." + ci.getTableName()
+ + " ADD";
+ }
+
+ protected String columnNamesAsCSV(List<ConstraintColumnInfo> cols) {
+ StringBuffer ret = new StringBuffer();
+ boolean first = true;
+ for (ConstraintColumnInfo column : cols) {
+ if (!first) {
+ ret.append(", ");
+ } else {
+ first = false;
+ }
+ ret.append(column.getColumnName());
+ }
+ return ret.toString();
+ }
+
+ public void readConstraintColumnNames() throws SQLException {
+ columns = readConstraintColumns(ci.getOwner(),
+ ci.getConstraintName());
+ }
+
+ protected List<ConstraintColumnInfo> readConstraintColumns(String schema,
+ String constraintName)
+ throws SQLException {
+ List<ConstraintColumnInfo> columns = null;
+
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+
+ try {
+ pstmt = session.getSQLConnection().prepareStatement(SQL_COLUMNS);
+ pstmt.setString(1, schema);
+ pstmt.setString(2, constraintName);
+
+ columns = new ArrayList<ConstraintColumnInfo>();
+ rs = pstmt.executeQuery();
+ while (rs.next()) {
+ columns.add(new ConstraintColumnInfo(rs.getString(1),
+ rs.getString(2),
+ rs.getString(3),
+ rs.getString(4),
+ rs.getInt(5))
+ );
+ }
+ } finally {
+ SQLUtilities.closeResultSet(rs, true);
+ }
+
+ return columns;
+ }
+
+ public abstract void buildConstraintClause() throws Exception ;
+
+ public String getSource() {
+ return dropStmt + ";\n\n" + addStmt + " (\n" + constraintClause + ");";
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/CKConstraintSource.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/CKConstraintSource.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/CKConstraintSource.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+import java.sql.SQLException;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+
+/**
+ * Class that creates the SQL source for a check constraint.
+ *
+ * @author bpaulon
+ */
+public class CKConstraintSource extends AbstractConstraintSource {
+
+ private AbstractConstraintSource cs;
+
+ /*
+ * Creates the SQL for the not null constraint
+ * The not null constraint is used to specify that a column may never
+ * contain a NULL value.
+ */
+ private class NotNullCKConstraintSource extends AbstractConstraintSource {
+
+ public NotNullCKConstraintSource(ISession session, ConstraintInfo ci) {
+ super(session, ci);
+ }
+
+ @Override
+ public void buildDropStatement() {
+ // ALTER TABLE <SCHEMA>.<CONSTRAINT_NAME> MODIFY NULL
+ //
+ // The check constraint defined on a table must refer to only columns
+ // in that table. It can not refer to columns in other tables.
+ dropStmt = "ALTER TABLE " + ci.getOwner() + "." + ci.getTableName()
+ + "\n MODIFY "
+ + CKConstraintSource.this.columns.get(0).getColumnName()
+ + " NULL";
+ }
+
+ @Override
+ public void buildAddStatement() {
+ // ALTER TABLE <SCHEMA>.<CONSTRAINT_NAME> MODIFY NOT NULL
+ addStmt = "ALTER TABLE " + ci.getOwner() + "." + ci.getTableName()
+ + "\n MODIFY "
+ + CKConstraintSource.this.columns.get(0).getColumnName()
+ + " NOT NULL";
+ }
+
+ @Override
+ public void buildConstraintClause() {
+ // NOP
+ }
+
+ @Override
+ public String getSource() {
+ return dropStmt + ";\n\n" + addStmt + ";";
+ }
+ }
+
+ public CKConstraintSource(ISession session, ConstraintInfo ci) {
+ super(session, ci);
+ }
+
+ public CKConstraintSource(ISession session, ConstraintInfo ci,
+ AbstractConstraintSource cs) {
+ super(session, ci);
+ this.cs = cs;
+ }
+
+ @Override
+ public void readConstraintColumnNames() throws SQLException {
+ super.readConstraintColumnNames();
+
+ if ("GENERATED NAME".equals(ci.getGenerated()) && isNotNullConstraint()) {
+ // use a NOT NULL policy
+ cs = new NotNullCKConstraintSource(session, ci);
+ } else {
+ // use a CHECK policy
+ cs = new AbstractConstraintSource(session, ci) {
+
+ @Override
+ public void buildConstraintClause() {
+ constraintClause = "CONSTRAINT " + ci.getConstraintName()
+ + "\n CHECK ( " + ci.getSearchCondition() + " )";
+ }
+ };
+ }
+ }
+
+ @Override
+ public void buildDropStatement() {
+ cs.buildDropStatement();
+ }
+
+ @Override
+ public void buildAddStatement() {
+ cs.buildAddStatement();
+ }
+
+ @Override
+ public void buildConstraintClause() throws Exception {
+ cs.buildConstraintClause();
+ }
+
+ @Override
+ public String getSource() {
+ return cs.getSource();
+ }
+
+ private boolean isNotNullConstraint() {
+ String expectedSearchCondition = "\""
+ + columns.get(0).getColumnName()
+ + "\""
+ + " IS NOT NULL";
+ if (expectedSearchCondition.equals(ci.getSearchCondition())) {
+ return true;
+ }
+ return false;
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintColumnInfo.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintColumnInfo.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintColumnInfo.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+/**
+ * Java bean containing connection constraint column information.
+ *
+ * @author bpaulon
+ */
+public class ConstraintColumnInfo {
+ private String owner;
+ private String constraintName;
+ private String tableName;
+ private String columnName;
+ private int position;
+
+ public ConstraintColumnInfo(String owner,
+ String constraintName,
+ String tableName,
+ String columnName,
+ int position)
+ {
+ this.owner = owner;
+ this.constraintName = constraintName;
+ this.tableName = tableName;
+ this.columnName = columnName;
+ this.position = position;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+ public String getConstraintName() {
+ return constraintName;
+ }
+ public String getTableName() {
+ return tableName;
+ }
+ public String getColumnName() {
+ return columnName;
+ }
+ public int getPosition() {
+ return position;
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintInfo.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintInfo.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintInfo.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+/**
+ * Java bean containing connection constraint information.
+ *
+ * @author bpaulon
+ */
+public class ConstraintInfo {
+ public static enum ConstraintType {
+ P, //primary key
+ U, //unique
+ R, //reference
+ C //check
+ }
+
+ private String owner;
+ private String constraintName;
+ private ConstraintType constraintType;
+ private String tableName;
+ private String searchCondition;
+ private String rOwner;
+ private String rConstraintName;
+ private String deleteRule;
+ private String generated;
+
+ public ConstraintInfo(String owner,
+ String constraintName,
+ ConstraintType constraintType,
+ String tableName,
+ String searchCondition,
+ String rOwner,
+ String rConstraintName,
+ String deleteRule,
+ String generated) {
+
+ this.owner = owner;
+ this.constraintName = constraintName;
+ this.constraintType = constraintType;
+ this.tableName = tableName;
+ this.searchCondition = searchCondition;
+ this.rOwner = rOwner;
+ this.rConstraintName = rConstraintName;
+ this.deleteRule = deleteRule;
+ this.generated = generated;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public String getConstraintName() {
+ return constraintName;
+ }
+
+ public ConstraintType getConstraintType() {
+ return constraintType;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public String getSearchCondition() {
+ return searchCondition;
+ }
+
+ public String getROwner() {
+ return rOwner;
+ }
+
+ public String getRConstraintName() {
+ return rConstraintName;
+ }
+
+ public String getDeleteRule() {
+ return deleteRule;
+ }
+
+ public String getGenerated() {
+ return generated;
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintSourceBuilder.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintSourceBuilder.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/ConstraintSourceBuilder.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+/**
+ * Create a source of type @link AbstractConstraintSource
+ * and calls the necessary steps to construct the SQL source
+ * (see @link buildConstraintSource)
+ *
+ * @author bpaulon
+ */
+import java.sql.SQLException;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.plugins.oracle.constraint.ConstraintInfo.ConstraintType;
+
+public class ConstraintSourceBuilder {
+
+ AbstractConstraintSource constraintSource;
+ ISession session;
+
+ public ConstraintSourceBuilder (ISession session) {
+ this.session = session;
+ }
+
+ public String getConstraintSource() {
+ if(constraintSource != null) {
+ return constraintSource.getSource();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Does not handle the following oracle constraints
+ * - Read Only Constraint - Type O
+ * Read Only on a view
+ * - Check Option - Type V
+ * Specify WITH CHECK OPTION to indicate that Oracle prohibits
+ * any changes to the table or view that would produce rows that
+ * are not included in the subquery
+ * @param ci - constraint info java bean
+ * @throws SQLException
+ */
+ public void buildConstraintSource(ConstraintInfo ci)
+ throws Exception {
+
+ if (ci.getConstraintType() == ConstraintType.P) {
+ this.constraintSource = new PKConstraintSource(session, ci);
+ } else if (ci.getConstraintType() == ConstraintType.C) {
+ this.constraintSource = new CKConstraintSource(session, ci);
+ } else if (ci.getConstraintType() == ConstraintType.R) {
+ this.constraintSource = new FKConstraintSource(session, ci);
+ } else if (ci.getConstraintType() == ConstraintType.U) {
+ this.constraintSource = new UQConstraintSource(session, ci);
+ }
+
+ constraintSource.readConstraintColumnNames();
+ constraintSource.buildDropStatement();
+ constraintSource.buildAddStatement();
+ constraintSource.buildConstraintClause();
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/FKConstraintSource.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/FKConstraintSource.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/FKConstraintSource.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+import java.util.List;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+
+/**
+ * Class that creates the SQL source for a foreign key constraint.
+ *
+ * @author bpaulon
+ */
+public class FKConstraintSource extends AbstractConstraintSource {
+
+ public FKConstraintSource(ISession session, ConstraintInfo ci) {
+ super(session, ci);
+ }
+
+ private String createReferencesClause() throws Exception {
+ List<ConstraintColumnInfo> cols = readConstraintColumns(ci.getROwner(),
+ ci.getRConstraintName());
+ String colsString = columnNamesAsCSV(cols);
+
+ // all columns belong to the same table
+ String clause = "REFERENCES " + ci.getROwner() + "."
+ + cols.get(0).getTableName()
+ + " ( " + colsString + " )";
+ return clause;
+ }
+
+ protected String buildDeleteClause() {
+ String clause = null;
+ if (!"NO ACTION".equals(ci.getDeleteRule())) {
+ clause = "ON DELETE " + ci.getDeleteRule();
+ }
+ return clause;
+ }
+
+ @Override
+ public void buildConstraintClause() throws Exception {
+ // CONSTRAINT <CONSTRAINT_NAME>
+ // FOREIGN KEY (<COLUMN_01>, <COLUMN_02>)
+ // REFERENCES GENESI_TO.BERSAGLI (<RCOLUMN_01>,<RCOLUMN_02>)
+ // ON DELETE <DELETE_RULE>);
+
+ constraintClause = "CONSTRAINT " + ci.getConstraintName()
+ + " FOREIGN KEY ( " + columnNamesAsCSV(columns) + " ) \n";
+ constraintClause += createReferencesClause();
+
+ String deleteClause = buildDeleteClause();
+ if(deleteClause != null) {
+ constraintClause += " \n " + buildDeleteClause();
+ }
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/PKConstraintSource.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/PKConstraintSource.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/PKConstraintSource.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+
+/**
+ * Class that creates the SQL source for a primary key constraint.
+ *
+ * @author bpaulon
+ */
+public class PKConstraintSource extends AbstractConstraintSource {
+
+ public PKConstraintSource(ISession session, ConstraintInfo ci) {
+ super(session, ci);
+ }
+
+ @Override
+ public void buildConstraintClause() throws Exception {
+ // CONSTRAINT + <CONSTRAINT_NAME>
+ // PRIMARY KEY
+ // (COLUMN1, COLUMN2, COLUMN3);
+
+ constraintClause = "CONSTRAINT " + ci.getConstraintName()
+ + " PRIMARY KEY ( " + columnNamesAsCSV(columns) + " )";
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/UQConstraintSource.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/UQConstraintSource.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/constraint/UQConstraintSource.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.constraint;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+
+/**
+ * Constructs the SQL source for a unique constraint.
+ * Unique constraint is used to ensure that all column values
+ * within a table never contain a duplicate entry.
+ *
+ * @author bpaulon
+ */
+public class UQConstraintSource extends AbstractConstraintSource {
+
+ public UQConstraintSource(ISession session, ConstraintInfo ci) {
+ super(session, ci);
+ }
+
+ @Override
+ public void buildConstraintClause() throws Exception {
+ // CONSTRAINT <CONSTRAINT_NAME>
+ // UNIQUE (<COLUMN_01>, <COLUMN_02>, <COLUMN_03>)
+ constraintClause = "CONSTRAINT " + ci.getConstraintName()
+ + " UNIQUE ( " + columnNamesAsCSV(columns) + " ) \n";
+ }
+}
\ No newline at end of file
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentExpander.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentExpander.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentExpander.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.expander;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.INodeExpander;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.ObjectTreeNode;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.plugins.oracle.IObjectTypes;
+
+/**
+ * This class handles the expanding of the Constraint node. It will
+ * show all the constraints for selected table.
+ *
+ * @author bpaulon
+ */
+public class ConstraintParentExpander implements INodeExpander {
+
+ private static String SQL = "select constraint_name"
+ + " from all_constraints"
+ + " where owner = ?"
+ + " and table_name = ?"
+ + " order by constraint_name asc";
+
+ public ConstraintParentExpander() {
+ super();
+ }
+
+ public List<ObjectTreeNode> createChildren(ISession session, ObjectTreeNode parentNode)
+ throws SQLException {
+
+ final List<ObjectTreeNode> childNodes = new ArrayList<ObjectTreeNode>();
+ final IDatabaseObjectInfo parentDbinfo = parentNode.getDatabaseObjectInfo();
+ final ISQLConnection conn = session.getSQLConnection();
+ final SQLDatabaseMetaData md = session.getSQLConnection().getSQLMetaData();
+ final IDatabaseObjectInfo tableInfo = ((ConstraintParentInfo)parentDbinfo).getTableInfo();
+ final String schemaName = parentDbinfo.getSchemaName();
+ final PreparedStatement pstmt = conn.prepareStatement(SQL);
+
+ try {
+ pstmt.setString(1, tableInfo.getSchemaName());
+ pstmt.setString(2, tableInfo.getSimpleName());
+ ResultSet rs = pstmt.executeQuery();
+ try {
+ while (rs.next()) {
+ DatabaseObjectInfo doi = new DatabaseObjectInfo(null,
+ schemaName,
+ rs.getString(1),
+ IObjectTypes.CONSTRAINT,
+ md);
+ childNodes.add(new ObjectTreeNode(session, doi));
+ }
+ } finally {
+ rs.close();
+ }
+ } finally {
+ pstmt.close();
+ }
+
+ return childNodes;
+ }
+}
\ No newline at end of file
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentInfo.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentInfo.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/ConstraintParentInfo.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.expander;
+
+/**
+ * Stores information about an Oracle Constraint parent
+ *
+ * @author bpaulon
+ */
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.plugins.oracle.IObjectTypes;
+
+public class ConstraintParentInfo extends DatabaseObjectInfo
+{
+ private static final long serialVersionUID = 1L;
+
+ private final IDatabaseObjectInfo _tableInfo;
+
+ public ConstraintParentInfo(IDatabaseObjectInfo tableInfo, String schema,
+ SQLDatabaseMetaData md)
+ {
+ super(null, schema, "CONSTRAINT", IObjectTypes.CONSTRAINT_PARENT, md);
+ _tableInfo = tableInfo;
+ }
+
+ public IDatabaseObjectInfo getTableInfo()
+ {
+ return _tableInfo;
+ }
+}
Modified: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/TableExpander.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/TableExpander.java 2010-08-21 12:29:59 UTC (rev 5802)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/expander/TableExpander.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -61,9 +61,16 @@
IDatabaseObjectInfo dbinfo = new TriggerParentInfo(parentDbinfo,
schemaName, md);
+
ObjectTreeNode child = new ObjectTreeNode(session, dbinfo);
childNodes.add(child);
-
+
+ IDatabaseObjectInfo cstrinfo = new ConstraintParentInfo(parentDbinfo,
+ schemaName, md);
+
+ child = new ObjectTreeNode(session, cstrinfo);
+ childNodes.add(child);
+
return childNodes;
}
}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintColumnInfoTab.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintColumnInfoTab.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintColumnInfoTab.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.tab;
+
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+
+/**
+ * This tab displays the column information for the constraint
+ *
+ * @author bpaulon
+ */
+public class ConstraintColumnInfoTab extends BasePreparedStatementTab {
+
+ private static final StringManager s_stringMgr = StringManagerFactory
+ .getStringManager(ConstraintDetailsTab.class);
+
+ private interface i18n {
+ // i18n[oracle.constraintColumns=Columns]
+ String TITLE = s_stringMgr.getString("oracle.constraintColumns");
+ // i18n[oracle.displayConstraintColumns=Display constraint column
+ // information]
+ String HINT = s_stringMgr.getString("oracle.displayConstraintColumns");
+ }
+
+ /*
+ * SQL that retrieves the information from view ALL_CONS_COLUMNS -
+ * ALL_CONS_COLUMNS describes only those columns accessible to current user
+ * that are specified in constraints.
+ */
+ private static String SQL = "select column_name, position"
+ + " from sys.all_cons_columns where owner = ?"
+ + " and constraint_name = ?";
+
+ public ConstraintColumnInfoTab() {
+ super(i18n.TITLE, i18n.HINT);
+ }
+
+ @Override
+ protected PreparedStatement createStatement() throws SQLException {
+ ISession session = getSession();
+ PreparedStatement pstmt = session.getSQLConnection().prepareStatement(
+ SQL);
+ IDatabaseObjectInfo doi = getDatabaseObjectInfo();
+ pstmt.setString(1, doi.getSchemaName());
+ pstmt.setString(2, doi.getSimpleName());
+ return pstmt;
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintDetailsTab.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintDetailsTab.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintDetailsTab.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.tab;
+
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BasePreparedStatementTab;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+
+/**
+ * This tab displays the details for the constraint
+ *
+ * @author bpaulon
+ */
+public class ConstraintDetailsTab extends BasePreparedStatementTab {
+
+ private static final StringManager s_stringMgr = StringManagerFactory
+ .getStringManager(ConstraintDetailsTab.class);
+
+ private interface i18n {
+ // i18n[oracle.constraintDetails=Details]
+ String TITLE = s_stringMgr.getString("oracle.constraintDetails");
+ // i18n[oracle.displayConstraintDetails=Display constraint details]
+ String HINT = s_stringMgr.getString("oracle.displayConstraintDetails");
+ }
+
+ /*
+ * SQL that retrieves the information from ALL_CONSTRAINTS - ALL_CONSTRAINTS
+ * describes constraint definitions on tables accessible to the current
+ * user.
+ */
+ private static String SQL = "select"
+ + " c.owner, c.constraint_name, c.constraint_type,"
+ + " c.table_name, c.search_condition, c.r_owner,"
+ + " c.r_constraint_name, c.delete_rule,"
+ + " c.status, c.deferrable, c.deferred,"
+ + " c.validated, c.generated, c.bad,"
+ + " c.rely, c.last_change, c.index_owner,"
+ + " c.index_name, c.invalid, c.view_related"
+ + " from sys.all_constraints c " + " where c.owner = ?"
+ + " and c.constraint_name = ?";
+
+ public ConstraintDetailsTab() {
+ super(i18n.TITLE, i18n.HINT, true);
+ }
+
+ protected PreparedStatement createStatement() throws SQLException {
+ ISession session = getSession();
+ PreparedStatement pstmt = session.getSQLConnection().prepareStatement(
+ SQL);
+ IDatabaseObjectInfo doi = getDatabaseObjectInfo();
+ pstmt.setString(1, doi.getSchemaName());
+ pstmt.setString(2, doi.getSimpleName());
+ return pstmt;
+ }
+}
Added: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintSourceTab.java
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintSourceTab.java (rev 0)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/ConstraintSourceTab.java 2010-08-21 14:17:41 UTC (rev 5803)
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2010 Bogdan Cristian Paulon
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.plugins.oracle.tab;
+
+import java.awt.BorderLayout;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javax.swing.JTextArea;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BaseSourcePanel;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.objecttree.tabs.BaseSourceTab;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import net.sourceforge.squirrel_sql.plugins.oracle.constraint.ConstraintInfo;
+import net.sourceforge.squirrel_sql.plugins.oracle.constraint.ConstraintSourceBuilder;
+
+/**
+ * This tab displays the source for the constraint
+ *
+ * @author bpaulon
+ */
+public class ConstraintSourceTab extends BaseSourceTab {
+
+ /** Internationalized strings for this class. */
+ private static final StringManager s_stringMgr = StringManagerFactory
+ .getStringManager(TriggerSourceTab.class);
+
+ /** Logger for this class. */
+ private final static ILogger s_log = LoggerController
+ .createLogger(BaseSourceTab.class);
+
+ /**
+ * SQL that retrieves the data we need to build the source for this
+ * constraint
+ */
+ private static String SQL = "select owner, constraint_name,"
+ + " constraint_type, table_name, search_condition, r_owner,"
+ + " r_constraint_name, delete_rule, generated"
+ + " from all_constraints"
+ + " where owner = ? and constraint_name = ?";
+
+ public ConstraintSourceTab() {
+ // i18n[oracle.showConstraintSource=Show constraint source]
+ super(s_stringMgr.getString("oracle.showConstraintSource"));
+ super.setSourcePanel(new ConstraintSourcePanel());
+ }
+
+ @Override
+ protected PreparedStatement createStatement() throws SQLException {
+ final ISession session = getSession();
+ final IDatabaseObjectInfo doi = getDatabaseObjectInfo();
+
+ ISQLConnection conn = session.getSQLConnection();
+ PreparedStatement pstmt = conn.prepareStatement(SQL);
+ pstmt.setString(1, doi.getSchemaName());
+ pstmt.setString(2, doi.getSimpleName());
+ return pstmt;
+ }
+
+ /**
+ * The panel that displays the source code for the constraint
+ */
+ private final class ConstraintSourcePanel extends BaseSourcePanel {
+ private static final long serialVersionUID = 1L;
+
+ private JTextArea textArea;
+
+ ConstraintSourcePanel() {
+ super(new BorderLayout());
+ textArea = new JTextArea();
+ textArea.setEditable(false);
+ add(textArea, BorderLayout.CENTER);
+ }
+
+ public void load(ISession session, PreparedStatement stmt) {
+ // always wrap on word boundaries
+ textArea.setWrapStyleWord(true);
+ ConstraintSourceBuilder csb = new ConstraintSourceBuilder(session);
+
+ ResultSet rs = null;
+ try {
+ rs = stmt.executeQuery();
+
+ if (rs.next()) {
+ ConstraintInfo ci = new ConstraintInfo(
+ rs.getString(1),
+ rs.getString(2),
+ ConstraintInfo.ConstraintType
+ .valueOf(rs.getString(3)),
+ rs.getString(4),
+ rs.getString(5),
+ rs.getString(6),
+ rs.getString(7),
+ rs.getString(8),
+ rs.getString(9));
+
+ csb.buildConstraintSource(ci);
+
+ if (csb.getConstraintSource() != null) {
+ textArea.setText(csb.getConstraintSource());
+ } else {
+ textArea.setText("Source NOT available");
+ }
+ }
+ } catch (Exception ex) {
+ if (s_log.isDebugEnabled()) {
+ s_log.debug("Unexpected exception while formatting "
+ + "object source code", ex);
+ }
+ session.showErrorMessage(ex);
+ } finally {
+ SQLUtilities.closeResultSet(rs, true);
+ }
+ }
+ }
+}
Modified: trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/I18NStrings.properties
===================================================================
--- trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/I18NStrings.properties 2010-08-21 12:29:59 UTC (rev 5802)
+++ trunk/sql12/plugins/oracle/src/net/sourceforge/squirrel_sql/plugins/oracle/tab/I18NStrings.properties 2010-08-21 14:17:41 UTC (rev 5803)
@@ -1,32 +1,32 @@
-oracle.options=Options
+oracle.columns=Columns
+oracle.constraintColumns=Columns
+oracle.constraintDetails=Details
+oracle.details=Details
+oracle.displayColumns=Display index column information
+oracle.displayConstraintColumns=Display constraint column information
+oracle.displayConstraintDetails=Display constraint details
+oracle.displayDetails=Display index details
+oracle.displayLobDetails=Display lob details
oracle.displayOptions=Display database options
-oracle.userDetails=Details
+oracle.diplayScriptDetails=Display script details
+oracle.displaysSequenceDetails=Display sequence details
+oracle.displaySessionDetails=Display session details
+oracle.displaySessionStatistics=Display database session statistics
+oracle.displaySnapshotDetails=Display materialized view details
+oracle.displaySnstanceDetails=Display instance details
+oracle.displayTriggerColumns=Display trigger column information
+oracle.displayTriggerDetails=Display trigger details
oracle.displayUserDetails=Display User details
oracle.instanceDetails=Details
+oracle.lobDetails=Details
+oracle.options=Options
+oracle.sequenceDetails=Details
+oracle.sessionDetails=Details
oracle.sessionStatistics=Session Statistics
-oracle.displaySessionStatistics=Display database session statistics
+oracle.showConstraintSource=Show constraint source
oracle.showTriggerSource=Show trigger source
oracle.triggerColumns=Columns
-oracle.displayTriggerColumns=Display trigger column information
-oracle.sessionDetails=Details
-oracle.displaySessionDetails=Display session details
-oracle.details=Details
-oracle.displayDetails=Display index details
-oracle.sequenceDetails=Details
-oracle.displaysSequenceDetails=Display sequence details
oracle.triggerDetails=Details
-oracle.displayTriggerDetails=Display trigger details
-oracle.lobDetails=Details
-oracle.displayLobDetails=Display lob details
-oracle.diplayScriptDetails=Display script details
-oracle.displaySnapshotDetails=Display materialized view details
-oracle.columns=Columns
-oracle.displayColumns=Display index column information
+oracle.userDetails=Details
-#
-#Missing/changed properties generated by I18n Plugin on Sat Oct 29 21:10:25 CEST 2005
-#
-
-# A T T E N T I O N: REPLACES SAME KEY ABOVE
-oracle.displaySnstanceDetails=Display instance details
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|