Revision: 5578
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5578&view=rev
Author: manningr
Date: 2010-04-17 15:02:39 +0000 (Sat, 17 Apr 2010)
Log Message:
-----------
Maven archetype project for the Example plugin. Plugin writers can use this archetype to create a new maven project to start writing their plugin as follows:
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=net.sf.squirrel-sql -DarchetypeArtifactId=squirrelsql-plugin-archetype -DarchetypeVersion=3.1.0-SNAPSHOT -DgroupId=com.myco -DartifactId=CoolPlugin -Dpackage=net.sourceforge.squirrel_sql.plugins.example
Added Paths:
-----------
trunk/mavenize/squirrelsql-plugin-archetype/
trunk/mavenize/squirrelsql-plugin-archetype/pom.xml
trunk/mavenize/squirrelsql-plugin-archetype/src/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/java/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/META-INF/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExamplePlugin.java
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/resources/
trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/resources/example.properties
Added: trunk/mavenize/squirrelsql-plugin-archetype/pom.xml
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/pom.xml (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/pom.xml 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,10 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrelsql-plugin-archetype</artifactId>
+ <packaging>jar</packaging>
+ <version>3.1.0-SNAPSHOT</version>
+ <name>squirrelsql-plugin-archetype</name>
+ <url>http://maven.apache.org</url>
+</project>
Added: trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/META-INF/maven/archetype.xml 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,12 @@
+<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
+ <id>squirrelsql-plugin-archetype</id>
+ <sources>
+ <source>src/main/java/ExamplePlugin.java</source>
+ <source>src/main/java/ScriptDB2ProcedureAction.java</source>
+ <source>src/main/java/ScriptDB2ViewAction.java</source>
+ </sources>
+ <resources>
+ <resource>src/main/resources/example.properties</resource>
+ </resources>
+</archetype>
Added: trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/pom.xml 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,16 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrelsql-plugins-parent-pom</artifactId>
+ <version>3.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+ <packaging>jar</packaging>
+
+</project>
Added: trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExamplePlugin.java
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExamplePlugin.java (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ExamplePlugin.java 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,160 @@
+package net.sourceforge.squirrel_sql.plugins.example;
+
+import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
+import net.sourceforge.squirrel_sql.client.plugin.PluginException;
+import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
+import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallback;
+import net.sourceforge.squirrel_sql.client.plugin.PluginSessionCallbackAdaptor;
+import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
+import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
+
+/**
+ * The Example plugin class.
+ */
+public class ExamplePlugin extends DefaultSessionPlugin
+{
+ private PluginResources _resources;
+
+ /**
+ * Return the internal name of this plugin.
+ *
+ * @return the internal name of this plugin.
+ */
+ public String getInternalName()
+ {
+ return "example";
+ }
+
+ /**
+ * Return the descriptive name of this plugin.
+ *
+ * @return the descriptive name of this plugin.
+ */
+ public String getDescriptiveName()
+ {
+ return "Example Plugin";
+ }
+
+ /**
+ * Returns the current version of this plugin.
+ *
+ * @return the current version of this plugin.
+ */
+ public String getVersion()
+ {
+ return "0.01";
+ }
+
+ /**
+ * Returns the authors name.
+ *
+ * @return the authors name.
+ */
+ public String getAuthor()
+ {
+ return "Gerd Wagner";
+ }
+
+ /**
+ * Returns the name of the change log for the plugin. This should
+ * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
+ * directory.
+ *
+ * @return the changelog file name or <TT>null</TT> if plugin doesn't have
+ * a change log.
+ */
+ public String getChangeLogFileName()
+ {
+ return "changes.txt";
+ }
+
+ /**
+ * Returns the name of the Help file for the plugin. This should
+ * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
+ * directory.
+ *
+ * @return the Help file name or <TT>null</TT> if plugin doesn't have
+ * a help file.
+ */
+ public String getHelpFileName()
+ {
+ return "readme.txt";
+ }
+
+ /**
+ * Returns the name of the Licence file for the plugin. This should
+ * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
+ * directory.
+ *
+ * @return the Licence file name or <TT>null</TT> if plugin doesn't have
+ * a licence file.
+ */
+ public String getLicenceFileName()
+ {
+ return "licence.txt";
+ }
+
+ /**
+ * @return Comma separated list of contributors.
+ */
+ public String getContributors()
+ {
+ return "";
+ }
+
+ /**
+ * Create preferences panel for the Global Preferences dialog.
+ *
+ * @return Preferences panel.
+ */
+ public IGlobalPreferencesPanel[] getGlobalPreferencePanels()
+ {
+ return new IGlobalPreferencesPanel[0];
+ }
+
+ /**
+ * Initialize this plugin.
+ */
+ public synchronized void initialize() throws PluginException
+ {
+ _resources = new PluginResources("net.sourceforge.squirrel_sql.plugins.example.example", this);
+ }
+
+
+ /**
+ * Called when a session started. Add commands to popup menu
+ * in object tree.
+ *
+ * @param session The session that is starting.
+ *
+ * @return An implementation of PluginSessionCallback or null to indicate
+ * the plugin does not work with this session
+ */
+ public PluginSessionCallback sessionStarted(ISession session)
+ {
+ try
+ {
+ String driverName = session.getSQLConnection().getConnection().getMetaData().getDriverName();
+ if(false == driverName.toUpperCase().startsWith("IBM DB2 JDBC"))
+ {
+ // Plugin knows only how to script Views and Stored Procedures on DB2.
+ // So if it's not a DB2 Session we tell SQuirreL the Plugin should not be used.
+ return null;
+ }
+
+ // Add context menu items to the object tree's view and procedure nodes.
+ IObjectTreeAPI otApi = session.getSessionInternalFrame().getObjectTreeAPI();
+ otApi.addToPopup(DatabaseObjectType.VIEW, new ScriptDB2ViewAction(getApplication(), _resources, session));
+ otApi.addToPopup(DatabaseObjectType.PROCEDURE, new ScriptDB2ProcedureAction(getApplication(), _resources, session));
+
+ return new PluginSessionCallbackAdaptor(this);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ProcedureAction.java 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,82 @@
+package net.sourceforge.squirrel_sql.plugins.example;
+
+import java.awt.event.ActionEvent;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.IProcedureInfo;
+import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
+import net.sourceforge.squirrel_sql.fw.util.Resources;
+
+public class ScriptDB2ProcedureAction extends SquirrelAction {
+ private static final long serialVersionUID = 1L;
+
+ transient private ISession _session;
+
+ // /////////////////////////////////////////////////////////
+ // IBM DB 2 specific code to read procedure definitions.
+ private static final String SQL =
+ "SELECT TEXT " +
+ "FROM SYSIBM.SYSPROCEDURES " +
+ "WHERE PROCNAME = ? ";
+
+ public ScriptDB2ProcedureAction(IApplication app, Resources rsrc,
+ ISession session) {
+ super(app, rsrc);
+ _session = session;
+ }
+
+ public void actionPerformed(ActionEvent evt) {
+ PreparedStatement stat = null;
+ ResultSet res = null;
+ try {
+
+ IDatabaseObjectInfo[] dbObjs = _session.getSessionInternalFrame()
+ .getObjectTreeAPI().getSelectedDatabaseObjects();
+
+ stat = _session.getSQLConnection().prepareStatement(SQL);
+
+ StringBuffer script = new StringBuffer();
+ for (int i = 0; i < dbObjs.length; i++) {
+ IProcedureInfo pi = (IProcedureInfo) dbObjs[i];
+ stat.setString(1, pi.getSimpleName());
+ res = stat.executeQuery();
+ res.next();
+ res.getString("TEXT");
+
+ script.append(res.getString("TEXT"));
+ script.append(getStatementSeparator());
+ res.close();
+ }
+ stat.close();
+
+ SessionInternalFrame sessMainFrm = _session
+ .getSessionInternalFrame();
+ sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());
+ sessMainFrm.getSessionPanel().selectMainTab(
+ ISession.IMainPanelTabIndexes.SQL_TAB);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ SQLUtilities.closeResultSet(res);
+ SQLUtilities.closeStatement(stat);
+ }
+ }
+
+ private String getStatementSeparator() {
+ String statementSeparator = _session.getQueryTokenizer()
+ .getSQLStatementSeparator();
+
+ if (1 < statementSeparator.length()) {
+ statementSeparator = "\n" + statementSeparator + "\n";
+ }
+
+ return statementSeparator;
+ }
+
+}
Added: trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/java/ScriptDB2ViewAction.java 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,85 @@
+package net.sourceforge.squirrel_sql.plugins.example;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.SquirrelAction;
+import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.util.Resources;
+
+import java.awt.event.ActionEvent;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+public class ScriptDB2ViewAction extends SquirrelAction
+{
+ private static final long serialVersionUID = 1L;
+
+ private ISession _session;
+
+
+ public ScriptDB2ViewAction(IApplication app, Resources rsrc, ISession session)
+ {
+ super(app, rsrc);
+ _session = session;
+ }
+
+
+ public void actionPerformed(ActionEvent evt)
+ {
+ try
+ {
+ Statement stat = _session.getSQLConnection().createStatement();
+
+ SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame();
+ IDatabaseObjectInfo[] dbObjs = sessMainFrm.getObjectTreeAPI().getSelectedDatabaseObjects();
+
+
+ StringBuffer script = new StringBuffer();
+ for (int i = 0; i < dbObjs.length; i++)
+ {
+ ITableInfo ti = (ITableInfo) dbObjs[i];
+
+ ///////////////////////////////////////////////////////////
+ // IBM DB 2 specific code to read view definitions.
+ String sql =
+ "SELECT TEXT " +
+ "FROM SYSIBM.SYSVIEWS " +
+ "WHERE NAME = '" + ti.getSimpleName() + "'";
+
+ ResultSet res = stat.executeQuery(sql);
+ res.next();
+
+ script.append(res.getString("TEXT"));
+ script.append(getStatementSeparator());
+ res.close();
+ //
+ ///////////////////////////////////////////////////////////
+ }
+
+ stat.close();
+
+ sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());
+ sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String getStatementSeparator()
+ {
+ String statementSeparator = _session.getQueryTokenizer().getSQLStatementSeparator();
+
+ if (1 < statementSeparator.length())
+ {
+ statementSeparator = "\n" + statementSeparator + "\n";
+ }
+
+ return statementSeparator;
+ }
+
+
+}
Added: trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/resources/example.properties
===================================================================
--- trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/resources/example.properties (rev 0)
+++ trunk/mavenize/squirrelsql-plugin-archetype/src/main/resources/archetype-resources/src/main/resources/example.properties 2010-04-17 15:02:39 UTC (rev 5578)
@@ -0,0 +1,18 @@
+
+########
+# Path to images. Should be terminated with a forward slash.
+########
+path.images=/net/sourceforge/squirrel_sql/plugins/example/images/
+
+
+########
+# Configuration information for Actions.
+########
+action.net.sourceforge.squirrel_sql.plugins.example.ScriptDB2ViewAction.image=
+action.net.sourceforge.squirrel_sql.plugins.example.ScriptDB2ViewAction.name=(DB2) Script view
+action.net.sourceforge.squirrel_sql.plugins.example.ScriptDB2ViewAction.tooltip=(DB2) Script view
+
+action.net.sourceforge.squirrel_sql.plugins.example.ScriptDB2ProcedureAction.image=
+action.net.sourceforge.squirrel_sql.plugins.example.ScriptDB2ProcedureAction.name=(DB2) Script procedure
+action.net.sourceforge.squirrel_sql.plugins.example.ScriptDB2ProcedureAction.tooltip=(DB2) Script procedure
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|