Author: rareddy
Date: 2009-09-29 13:30:43 -0400 (Tue, 29 Sep 2009)
New Revision: 1491
Added:
branches/JCA/
branches/JCA/connectors/sandbox/connector-exec/pom.xml
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java
Removed:
branches/JCA/connectors/sandbox/connector-exec/pom.xml
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java
Log:
TEIID-833 Related changes
Copied: branches/JCA (from rev 1472, trunk)
Deleted: branches/JCA/connectors/sandbox/connector-exec/pom.xml
===================================================================
--- trunk/connectors/sandbox/connector-exec/pom.xml 2009-09-23 20:35:59 UTC (rev 1472)
+++ branches/JCA/connectors/sandbox/connector-exec/pom.xml 2009-09-29 17:30:43 UTC (rev
1491)
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <parent>
- <artifactId>sandbox</artifactId>
- <groupId>org.jboss.teiid.connectors</groupId>
- <version>6.3.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>connector-exec</artifactId>
- <groupId>org.jboss.teiid.connectors.sandbox</groupId>
- <name>Exec Connector</name>
- <description>This connector executes Admin API calls and System.exec calls
through the connector using SQL representation</description>
- <dependencies>
- <dependency>
- <groupId>org.jboss.teiid</groupId>
- <artifactId>teiid-connector-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.teiid</groupId>
- <artifactId>teiid-common-core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>ant</groupId>
- <artifactId>ant</artifactId>
- <version>1.6.5</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.teiid</groupId>
- <artifactId>teiid-common-internal</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.teiid</groupId>
- <artifactId>teiid-server</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
Copied: branches/JCA/connectors/sandbox/connector-exec/pom.xml (from rev 1473,
trunk/connectors/sandbox/connector-exec/pom.xml)
===================================================================
--- branches/JCA/connectors/sandbox/connector-exec/pom.xml (rev
0)
+++ branches/JCA/connectors/sandbox/connector-exec/pom.xml 2009-09-29 17:30:43 UTC (rev
1491)
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <parent>
+ <artifactId>sandbox</artifactId>
+ <groupId>org.jboss.teiid.connectors</groupId>
+ <version>6.3.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>connector-exec</artifactId>
+ <groupId>org.jboss.teiid.connectors.sandbox</groupId>
+ <name>Exec Connector</name>
+ <description>This connector executes Admin API calls and System.exec calls
through the connector using SQL representation</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-connector-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-internal</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Deleted:
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java
===================================================================
---
trunk/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java 2009-09-23
20:35:59 UTC (rev 1472)
+++
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java 2009-09-29
17:30:43 UTC (rev 1491)
@@ -1,348 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.exec;
-
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Location;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.ExecTask;
-import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
-import org.apache.tools.ant.taskdefs.PumpStreamHandler;
-import org.apache.tools.ant.types.Commandline.Argument;
-import org.teiid.connector.api.ConnectorEnvironment;
-import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.ConnectorLogger;
-import org.teiid.connector.api.DataNotAvailableException;
-import org.teiid.connector.api.ResultSetExecution;
-import org.teiid.connector.basic.BasicExecution;
-import org.teiid.connector.language.IQuery;
-import org.teiid.connector.metadata.runtime.RuntimeMetadata;
-
-import com.metamatrix.common.config.CurrentConfiguration;
-import com.metamatrix.common.config.api.Host;
-import com.metamatrix.common.util.CommonPropertyNames;
-import com.metamatrix.common.util.OSPlatformUtil;
-import com.metamatrix.core.util.Assertion;
-import com.metamatrix.core.util.StringUtil;
-import com.metamatrix.core.util.TempDirectory;
-
-/**
- * Represents the execution of a command.
- */
-public class ExecAntExecution extends BasicExecution implements ResultSetExecution {
-
- private static final Random random = new Random(System.currentTimeMillis());
-
- private static String INSTALL_DIR = ".";//$NON-NLS-1$
-
- private static final String WIN_EXEC = "win.executable"; //$NON-NLS-1$
- private static final String UNIX_EXEC = "unix.executable"; //$NON-NLS-1$
-
- private static final String DEFAUTL_WIN_EXEC = "cmd.exe"; //$NON-NLS-1$
- private static final String DEFAUTL_UNIX_EXEC = "/bin/sh"; //$NON-NLS-1$
-
- // Connector resources
- private ConnectorEnvironment env;
- private List responses = new ArrayList();
- private String execcommand;
- private boolean isWin = false;
-
- // Execution state
- int[] neededColumns;
- int returnIndex = 0;
-
- private Process p = null;
-
- private List exclusionList;
- private IQuery query;
-
- public ExecAntExecution(IQuery query, ConnectorEnvironment env, RuntimeMetadata
metadata, ConnectorLogger logger, List exclusionThese) {
- this.env = env;
- this.query = query;
- if (exclusionThese != null)
- exclusionList = exclusionThese;
- else
- exclusionList = Collections.EMPTY_LIST;
- Properties props = env.getProperties();
-
- if (OSPlatformUtil.isWindows()) {
- execcommand = props.getProperty(WIN_EXEC, DEFAUTL_WIN_EXEC);
- Assertion.isNotNull(execcommand, WIN_EXEC+ " property was not defined for os
type"); //$NON-NLS-1$
- isWin = true;
-
- } else {
- execcommand = props.getProperty(UNIX_EXEC, DEFAUTL_UNIX_EXEC);
- Assertion.isNotNull(execcommand, UNIX_EXEC + " property was not defined for os
type"); //$NON-NLS-1$
- }
- }
-
- /*
- * @see
com.metamatrix.data.SynchQueryExecution#execute(com.metamatrix.data.language.IQuery,
- * int)
- */
- public void execute()
- throws ConnectorException {
-
- env.getLogger().logTrace("Exec executing command: " + query); //$NON-NLS-1$
- org.teiid.connector.language.ICriteria crit = query.getWhere();
- if (crit == null)
- throw new ConnectorException(ExecPlugin.Util
- .getString("ExecExecution.Must_have_criteria")); //$NON-NLS-1$
- Map whereVariables = ExecVisitor.getWhereClauseMap(crit);
- if (whereVariables.isEmpty())
- throw new ConnectorException(ExecPlugin.Util
- .getString("ExecExecution.Must_have_criteria")); //$NON-NLS-1$
-
- String command = ""; //$NON-NLS-1$
- int i = 2;
- for (Iterator it = whereVariables.keySet().iterator(); it.hasNext();) {
- String whereKey = (String) it.next();
- String v = ((String) whereVariables.get(whereKey)).trim();
- isValid(v);
- command += v;
- i++;
- }
- try {
- execute(command);
- } catch (Exception e) {
- env.getLogger().logError("Execution Error", e); //$NON-NLS-1$
- throw new ConnectorException(e);
- }
- }
-
- private boolean isValid(String command) throws ConnectorException {
- boolean isvalid = true;
- List tokens = StringUtil.getTokens(command.toLowerCase(), " ");
//$NON-NLS-1$
- for (Iterator it = tokens.iterator(); it.hasNext();) {
- String v = (String) it.next();
- if (exclusionList.contains(v))
- throw new ConnectorException(ExecPlugin.Util.getString(
- "ExecExecution.Execution_of_statement_not_allowed", v));//$NON-NLS-1$
- }
-
- return isvalid;
- }
-
- protected void execute(String command) throws Exception {
-
- ExecuteMMTask task = createClass();
-
- env.getLogger().logTrace(
- "Exec: " + execcommand + " command: " + command); //$NON-NLS-1$
//$NON-NLS-2$
-
- Project p = new Project();
- p.init();
- p.setBasedir(INSTALL_DIR);
- p.setCoreLoader(this.getClass().getClassLoader());
-
- task.setProject(p);
-
- task.setDir(new File((INSTALL_DIR)));
-
- task.setLogError(true);
-
- task.setFailonerror(false);
-
- task.setTaskType("MMExecutionTask"); //$NON-NLS-1$
- task.setTaskName("ExecAntExecution"); //$NON-NLS-1$
- task.setExecutable(execcommand);
-
- Argument a = task.createArg();
-
- if (isWin) {
- // do not set for unix
- task.setVMLauncher(true);
-
- a.setValue("/c"); //$NON-NLS-1$
- a = task.createArg();
- }
- a.setLine(command);
- // a.setValue(command);
- a.setProject(p);
-
- task.setAppend(true);
- task.setLocation(Location.UNKNOWN_LOCATION);
-
- task.execute();
- task.addToRows(responses);
-
- }
-
- private ExecuteMMTask createClass() {
-
- ExecuteMMTask rep = new ExecuteMMTask();
-
- return rep;
- }
-
- @Override
- public List next() throws ConnectorException, DataNotAvailableException {
- if (returnIndex < responses.size()) {
- return (List)responses.get(returnIndex++);
- }
-
- return null;
- }
-
- /**
- * @param row
- * @param neededColumns
- */
- static List projectRow(List row, int[] neededColumns) {
- List output = new ArrayList(neededColumns.length);
-
- for (int i = 0; i < neededColumns.length; i++) {
- output.add(row.get(neededColumns[i]));
- }
-
- return output;
- }
-
- /*
- * @see com.metamatrix.data.Execution#close()
- */
- public void close() throws ConnectorException {
- // nothing to do
-
- exclusionList = null;
- responses = null;
-
- if (p != null) {
- try {
- p.destroy();
- } catch (Exception e) {
-
- } finally {
- p = null;
-
- }
- }
-
- }
-
- /*
- * @see com.metamatrix.data.Execution#cancel()
- */
- public void cancel() throws ConnectorException {
- this.close();
-
- }
-
- final class ExecuteMMTask extends ExecTask {
- protected ByteArrayOutputStream os = null;
- protected ByteArrayOutputStream erros = null;
- protected ByteArrayInputStream in = null;
- protected BufferedOutputStream bos = null;
- protected BufferedOutputStream bose = null;
-
- public ExecuteMMTask() {
- }
-
- /**
- * Create the StreamHandler to use with our Execute instance.
- *
- * @return the execute stream handler to manage the input, output and
- * error streams.
- *
- * @throws BuildException
- * if the execute stream handler cannot be created.
- */
- public synchronized ExecuteStreamHandler createHandler()
- throws BuildException {
- super.createHandler();
-
- os = new ByteArrayOutputStream();
- bos = new BufferedOutputStream(os);
-
- erros = new ByteArrayOutputStream();
- bose = new BufferedOutputStream(erros);
-
- in = new ByteArrayInputStream(new byte[] { ' ' });
-
- return new PumpStreamHandler(bos, bose);
- }
-
- public void addToRows(List responseRows) throws Exception {
-
- try {
- bos.flush();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(os
- .toByteArray());
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(bais));
- String oneline;
- while ((oneline = reader.readLine()) != null) {
- List row = new ArrayList(1);
- row.add(oneline);
- responseRows.add(row);
- }
- reader.close();
-
- boolean first = true;
- bose.flush();
- ByteArrayInputStream baise = new ByteArrayInputStream(erros
- .toByteArray());
- BufferedReader ereader = new BufferedReader(
- new InputStreamReader(baise));
- while ((oneline = ereader.readLine()) != null) {
- if (first) {
- env.getLogger().logError("Error Message:"); //$NON-NLS-1$
- first = false;
- }
- List row = new ArrayList(1);
- row.add(oneline);
- responseRows.add(row);
- env.getLogger().logError(oneline);
- }
- ereader.close();
- } finally {
- if (os != null) {
- os.close();
- os = null;
- }
-
- if (erros != null) {
- erros.close();
- erros = null;
- }
- }
- }
-
- }
-
-}
Copied:
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java
(from rev 1473,
trunk/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java)
===================================================================
---
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecAntExecution.java 2009-09-29
17:30:43 UTC (rev 1491)
@@ -0,0 +1,344 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.connector.exec;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Random;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.types.Commandline.Argument;
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ConnectorLogger;
+import org.teiid.connector.api.DataNotAvailableException;
+import org.teiid.connector.api.ResultSetExecution;
+import org.teiid.connector.basic.BasicExecution;
+import org.teiid.connector.language.IQuery;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+
+import com.metamatrix.common.util.OSPlatformUtil;
+import com.metamatrix.core.util.Assertion;
+import com.metamatrix.core.util.StringUtil;
+
+/**
+ * Represents the execution of a command.
+ */
+public class ExecAntExecution extends BasicExecution implements ResultSetExecution {
+
+ private static final Random random = new Random(System.currentTimeMillis());
+
+ private static String INSTALL_DIR = ".";//$NON-NLS-1$
+
+ private static final String WIN_EXEC = "win.executable"; //$NON-NLS-1$
+ private static final String UNIX_EXEC = "unix.executable"; //$NON-NLS-1$
+
+ private static final String DEFAUTL_WIN_EXEC = "cmd.exe"; //$NON-NLS-1$
+ private static final String DEFAUTL_UNIX_EXEC = "/bin/sh"; //$NON-NLS-1$
+
+ // Connector resources
+ private ConnectorEnvironment env;
+ private List responses = new ArrayList();
+ private String execcommand;
+ private boolean isWin = false;
+
+ // Execution state
+ int[] neededColumns;
+ int returnIndex = 0;
+
+ private Process p = null;
+
+ private List exclusionList;
+ private IQuery query;
+
+ public ExecAntExecution(IQuery query, ConnectorEnvironment env, RuntimeMetadata
metadata, ConnectorLogger logger, List exclusionThese) {
+ this.env = env;
+ this.query = query;
+ if (exclusionThese != null)
+ exclusionList = exclusionThese;
+ else
+ exclusionList = Collections.EMPTY_LIST;
+ Properties props = env.getProperties();
+
+ if (OSPlatformUtil.isWindows()) {
+ execcommand = props.getProperty(WIN_EXEC, DEFAUTL_WIN_EXEC);
+ Assertion.isNotNull(execcommand, WIN_EXEC+ " property was not defined for os
type"); //$NON-NLS-1$
+ isWin = true;
+
+ } else {
+ execcommand = props.getProperty(UNIX_EXEC, DEFAUTL_UNIX_EXEC);
+ Assertion.isNotNull(execcommand, UNIX_EXEC + " property was not defined for os
type"); //$NON-NLS-1$
+ }
+ }
+
+ /*
+ * @see
com.metamatrix.data.SynchQueryExecution#execute(com.metamatrix.data.language.IQuery,
+ * int)
+ */
+ public void execute()
+ throws ConnectorException {
+
+ env.getLogger().logTrace("Exec executing command: " + query); //$NON-NLS-1$
+ org.teiid.connector.language.ICriteria crit = query.getWhere();
+ if (crit == null)
+ throw new ConnectorException(ExecPlugin.Util
+ .getString("ExecExecution.Must_have_criteria")); //$NON-NLS-1$
+ Map whereVariables = ExecVisitor.getWhereClauseMap(crit);
+ if (whereVariables.isEmpty())
+ throw new ConnectorException(ExecPlugin.Util
+ .getString("ExecExecution.Must_have_criteria")); //$NON-NLS-1$
+
+ String command = ""; //$NON-NLS-1$
+ int i = 2;
+ for (Iterator it = whereVariables.keySet().iterator(); it.hasNext();) {
+ String whereKey = (String) it.next();
+ String v = ((String) whereVariables.get(whereKey)).trim();
+ isValid(v);
+ command += v;
+ i++;
+ }
+ try {
+ execute(command);
+ } catch (Exception e) {
+ env.getLogger().logError("Execution Error", e); //$NON-NLS-1$
+ throw new ConnectorException(e);
+ }
+ }
+
+ private boolean isValid(String command) throws ConnectorException {
+ boolean isvalid = true;
+ List tokens = StringUtil.getTokens(command.toLowerCase(), " ");
//$NON-NLS-1$
+ for (Iterator it = tokens.iterator(); it.hasNext();) {
+ String v = (String) it.next();
+ if (exclusionList.contains(v))
+ throw new ConnectorException(ExecPlugin.Util.getString(
+ "ExecExecution.Execution_of_statement_not_allowed", v));//$NON-NLS-1$
+ }
+
+ return isvalid;
+ }
+
+ protected void execute(String command) throws Exception {
+
+ ExecuteMMTask task = createClass();
+
+ env.getLogger().logTrace(
+ "Exec: " + execcommand + " command: " + command); //$NON-NLS-1$
//$NON-NLS-2$
+
+ Project p = new Project();
+ p.init();
+ p.setBasedir(INSTALL_DIR);
+ p.setCoreLoader(this.getClass().getClassLoader());
+
+ task.setProject(p);
+
+ task.setDir(new File((INSTALL_DIR)));
+
+ task.setLogError(true);
+
+ task.setFailonerror(false);
+
+ task.setTaskType("MMExecutionTask"); //$NON-NLS-1$
+ task.setTaskName("ExecAntExecution"); //$NON-NLS-1$
+ task.setExecutable(execcommand);
+
+ Argument a = task.createArg();
+
+ if (isWin) {
+ // do not set for unix
+ task.setVMLauncher(true);
+
+ a.setValue("/c"); //$NON-NLS-1$
+ a = task.createArg();
+ }
+ a.setLine(command);
+ // a.setValue(command);
+ a.setProject(p);
+
+ task.setAppend(true);
+ task.setLocation(Location.UNKNOWN_LOCATION);
+
+ task.execute();
+ task.addToRows(responses);
+
+ }
+
+ private ExecuteMMTask createClass() {
+
+ ExecuteMMTask rep = new ExecuteMMTask();
+
+ return rep;
+ }
+
+ @Override
+ public List next() throws ConnectorException, DataNotAvailableException {
+ if (returnIndex < responses.size()) {
+ return (List)responses.get(returnIndex++);
+ }
+
+ return null;
+ }
+
+ /**
+ * @param row
+ * @param neededColumns
+ */
+ static List projectRow(List row, int[] neededColumns) {
+ List output = new ArrayList(neededColumns.length);
+
+ for (int i = 0; i < neededColumns.length; i++) {
+ output.add(row.get(neededColumns[i]));
+ }
+
+ return output;
+ }
+
+ /*
+ * @see com.metamatrix.data.Execution#close()
+ */
+ public void close() throws ConnectorException {
+ // nothing to do
+
+ exclusionList = null;
+ responses = null;
+
+ if (p != null) {
+ try {
+ p.destroy();
+ } catch (Exception e) {
+
+ } finally {
+ p = null;
+
+ }
+ }
+
+ }
+
+ /*
+ * @see com.metamatrix.data.Execution#cancel()
+ */
+ public void cancel() throws ConnectorException {
+ this.close();
+
+ }
+
+ final class ExecuteMMTask extends ExecTask {
+ protected ByteArrayOutputStream os = null;
+ protected ByteArrayOutputStream erros = null;
+ protected ByteArrayInputStream in = null;
+ protected BufferedOutputStream bos = null;
+ protected BufferedOutputStream bose = null;
+
+ public ExecuteMMTask() {
+ }
+
+ /**
+ * Create the StreamHandler to use with our Execute instance.
+ *
+ * @return the execute stream handler to manage the input, output and
+ * error streams.
+ *
+ * @throws BuildException
+ * if the execute stream handler cannot be created.
+ */
+ public synchronized ExecuteStreamHandler createHandler()
+ throws BuildException {
+ super.createHandler();
+
+ os = new ByteArrayOutputStream();
+ bos = new BufferedOutputStream(os);
+
+ erros = new ByteArrayOutputStream();
+ bose = new BufferedOutputStream(erros);
+
+ in = new ByteArrayInputStream(new byte[] { ' ' });
+
+ return new PumpStreamHandler(bos, bose);
+ }
+
+ public void addToRows(List responseRows) throws Exception {
+
+ try {
+ bos.flush();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(os
+ .toByteArray());
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(bais));
+ String oneline;
+ while ((oneline = reader.readLine()) != null) {
+ List row = new ArrayList(1);
+ row.add(oneline);
+ responseRows.add(row);
+ }
+ reader.close();
+
+ boolean first = true;
+ bose.flush();
+ ByteArrayInputStream baise = new ByteArrayInputStream(erros
+ .toByteArray());
+ BufferedReader ereader = new BufferedReader(
+ new InputStreamReader(baise));
+ while ((oneline = ereader.readLine()) != null) {
+ if (first) {
+ env.getLogger().logError("Error Message:"); //$NON-NLS-1$
+ first = false;
+ }
+ List row = new ArrayList(1);
+ row.add(oneline);
+ responseRows.add(row);
+ env.getLogger().logError(oneline);
+ }
+ ereader.close();
+ } finally {
+ if (os != null) {
+ os.close();
+ os = null;
+ }
+
+ if (erros != null) {
+ erros.close();
+ erros = null;
+ }
+ }
+ }
+
+ }
+
+}
Deleted:
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java
===================================================================
---
trunk/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java 2009-09-23
20:35:59 UTC (rev 1472)
+++
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java 2009-09-29
17:30:43 UTC (rev 1491)
@@ -1,136 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.exec;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.teiid.connector.api.Connection;
-import org.teiid.connector.api.ConnectorCapabilities;
-import org.teiid.connector.api.ConnectorEnvironment;
-import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.ConnectorLogger;
-import org.teiid.connector.api.ExecutionContext;
-import org.teiid.connector.basic.BasicConnector;
-
-import com.metamatrix.api.exception.MetaMatrixComponentException;
-import com.metamatrix.common.extensionmodule.ExtensionModuleManager;
-import com.metamatrix.common.extensionmodule.exception.ExtensionModuleNotFoundException;
-import com.metamatrix.core.util.ObjectConverterUtil;
-
-/**
- * Implementation of text connector.
- */
-public class ExecConnector extends BasicConnector {
-
- private ConnectorLogger logger;
- private ConnectorEnvironment env;
- private boolean start = false;
- private List exclusionList= Collections.EMPTY_LIST;
- private String exclusionFile;
-
- /**
- * Initialization with environment.
- */
- @Override
- public void start( ConnectorEnvironment environment ) throws ConnectorException {
- logger = environment.getLogger();
- this.env = environment;
-
- exclusionFile =
environment.getProperties().getProperty("exclusionFile"); //$NON-NLS-1$
- if(exclusionFile != null && exclusionFile.trim().length() > 0)
- {
- loadExclusionFile(exclusionFile);
- }
-
- // logging
- logger = environment.getLogger();
- start = true;
- logger.logInfo("Exec Connector is started."); //$NON-NLS-1$
- }
-
- public void stop() {
- if(!start){
- return;
- }
-
- start = false;
- logger.logInfo("Exec Connector is stoped."); //$NON-NLS-1$
- }
-
- @Override
- public ConnectorCapabilities getCapabilities() {
- return new ExecCapabilities();
- }
-
- /*
- * @see
com.metamatrix.data.Connector#getConnection(com.metamatrix.data.SecurityContext)
- */
- public Connection getConnection(ExecutionContext context) throws ConnectorException
{
- return new ExecConnection(this.env, exclusionList);
- }
-
- protected void loadExclusionFile(String file)
- throws ConnectorException
-{
- try
- {
- if (!ExtensionModuleManager.getInstance().isSourceInUse(file)) {
- return;
- }
- byte data[] = ExtensionModuleManager.getInstance().getSource(file);
- java.io.InputStream is = ObjectConverterUtil.convertToInputStream(data);
- Properties props = new Properties();
- props.load(is);
- exclusionList = new ArrayList(props.size());
- String key;
- for(Iterator it = props.keySet().iterator(); it.hasNext();
exclusionList.add(((String)props.get(key)).trim().toLowerCase()))
- {
- key = (String)it.next();
- logger.logInfo("Exec Connector - exclude: " +
props.get(key));//$NON-NLS-1$
- }
-
- }
- catch(IOException err)
- {
- throw new ConnectorException(err,
ExecPlugin.Util.getString("ExecConnector.Error_loading_exclusion_properties",
file)); //$NON-NLS-1$
- }
- catch(ExtensionModuleNotFoundException err)
- {
- throw new
ConnectorException(ExecPlugin.Util.getString("ExecConnector.Exclusion_file_not_found",
file)); //$NON-NLS-1$
- }
- catch(MetaMatrixComponentException err1)
- {
- throw new ConnectorException(err1,
ExecPlugin.Util.getString("ExecConnector.Unable_to_load_extension_module",
file)); //$NON-NLS-1$
- }
-}
-
- protected void setExclusionList(List list) {
- this.exclusionList = new ArrayList(list);
- }
-
-
-}
Copied:
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java
(from rev 1473,
trunk/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java)
===================================================================
---
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-exec/src/main/java/com/metamatrix/connector/exec/ExecConnector.java 2009-09-29
17:30:43 UTC (rev 1491)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.connector.exec;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.teiid.connector.api.Connection;
+import org.teiid.connector.api.ConnectorCapabilities;
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ConnectorLogger;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.basic.BasicConnector;
+
+/**
+ * Implementation of text connector.
+ */
+public class ExecConnector extends BasicConnector {
+
+ private ConnectorLogger logger;
+ private ConnectorEnvironment env;
+ private boolean start = false;
+ private List exclusionList= Collections.EMPTY_LIST;
+ private String exclusionFile;
+
+ /**
+ * Initialization with environment.
+ */
+ @Override
+ public void start( ConnectorEnvironment environment ) throws ConnectorException {
+ logger = environment.getLogger();
+ this.env = environment;
+
+ exclusionFile =
environment.getProperties().getProperty("exclusionFile"); //$NON-NLS-1$
+ if(exclusionFile != null && exclusionFile.trim().length() > 0)
+ {
+ loadExclusionFile(exclusionFile);
+ }
+
+ // logging
+ logger = environment.getLogger();
+ start = true;
+ logger.logInfo("Exec Connector is started."); //$NON-NLS-1$
+ }
+
+ public void stop() {
+ if(!start){
+ return;
+ }
+
+ start = false;
+ logger.logInfo("Exec Connector is stoped."); //$NON-NLS-1$
+ }
+
+ @Override
+ public ConnectorCapabilities getCapabilities() {
+ return new ExecCapabilities();
+ }
+
+ /*
+ * @see
com.metamatrix.data.Connector#getConnection(com.metamatrix.data.SecurityContext)
+ */
+ public Connection getConnection(ExecutionContext context) throws ConnectorException
{
+ return new ExecConnection(this.env, exclusionList);
+ }
+
+ protected void loadExclusionFile(String file) throws ConnectorException {
+ try {
+ Properties props = new Properties();
+ props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(file));
+ exclusionList = new ArrayList(props.size());
+ String key;
+ for (Iterator it = props.keySet().iterator(); it.hasNext();
exclusionList.add(((String) props.get(key)).trim().toLowerCase())) {
+ key = (String) it.next();
+ logger.logInfo("Exec Connector - exclude: " +
props.get(key));//$NON-NLS-1$
+ }
+
+ } catch (IOException err) {
+ throw new ConnectorException(err,
ExecPlugin.Util.getString("ExecConnector.Error_loading_exclusion_properties",
file)); //$NON-NLS-1$
+ }
+ }
+
+ protected void setExclusionList(List list) {
+ this.exclusionList = new ArrayList(list);
+ }
+}
Deleted:
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java
===================================================================
---
trunk/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java 2009-09-23
20:35:59 UTC (rev 1472)
+++
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java 2009-09-29
17:30:43 UTC (rev 1491)
@@ -1,69 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.connector.exec;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import org.teiid.connector.api.ConnectorException;
-
-
-/**
- * Implmentation of text connector.
- */
-public class FakeExecConnector extends ExecConnector {
-
-
-
-
- protected void loadExclusionFile(String file)
- throws ConnectorException
-{
- try
- {
- FileInputStream is = new FileInputStream(file);
-//
-// byte data[] = ExtensionModuleManager.getInstance().getSource(file);
-// java.io.InputStream is = ObjectConverterUtil.convertToInputStream(data);
- Properties props = new Properties();
- props.load(is);
- List exclusionList = new ArrayList(props.size());
- String key;
- for(Iterator it = props.keySet().iterator(); it.hasNext();
exclusionList.add(((String)props.get(key)).trim().toLowerCase()))
- {
- key = (String)it.next();
- }
- this.setExclusionList(exclusionList);
-
- }
- catch(IOException err)
- {
- throw new ConnectorException(err,
ExecPlugin.Util.getString("ExecConnector.Error_loading_exclusion_properties",
file)); //$NON-NLS-1$
- }
-}
-
-
-}
Copied:
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java
(from rev 1473,
trunk/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java)
===================================================================
---
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java
(rev 0)
+++
branches/JCA/connectors/sandbox/connector-exec/src/test/java/com/metamatrix/connector/exec/FakeExecConnector.java 2009-09-29
17:30:43 UTC (rev 1491)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.connector.exec;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.teiid.connector.api.ConnectorException;
+
+
+
+public class FakeExecConnector extends ExecConnector {
+
+ protected void loadExclusionFile(String file) throws ConnectorException {
+ try {
+ FileInputStream is = new FileInputStream(file);
+ //
+ Properties props = new Properties();
+ props.load(is);
+ List exclusionList = new ArrayList(props.size());
+ String key;
+ for (Iterator it = props.keySet().iterator(); it.hasNext();
exclusionList.add(((String) props.get(key)).trim().toLowerCase())) {
+ key = (String) it.next();
+ }
+ this.setExclusionList(exclusionList);
+
+ } catch (IOException err) {
+ throw new ConnectorException(err,
ExecPlugin.Util.getString("ExecConnector.Error_loading_exclusion_properties",
file)); //$NON-NLS-1$
+ }
+ }
+
+
+}