Author: rareddy
Date: 2009-12-14 20:04:57 -0500 (Mon, 14 Dec 2009)
New Revision: 1666
Added:
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextManagedConnectionFactory.java
branches/JCA/connectors/connector-text/src/main/rar/
branches/JCA/connectors/connector-text/src/main/rar/META-INF/
branches/JCA/connectors/connector-text/src/main/rar/META-INF/ra.xml
Removed:
branches/JCA/connectors/connector-text/src/assembly/
branches/JCA/connectors/connector-text/src/main/resources/connector-text.xml
Modified:
branches/JCA/build/assembly/jboss-container/connectors.xml
branches/JCA/connectors/connector-text/pom.xml
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/StringToDateTranslator.java
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnection.java
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnector.java
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextSynchExecution.java
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnection.java
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java
branches/JCA/connectors/pom.xml
Log:
TEIID-861: Converted Text Converter to JCA Connector
Modified: branches/JCA/build/assembly/jboss-container/connectors.xml
===================================================================
--- branches/JCA/build/assembly/jboss-container/connectors.xml 2009-12-14 22:41:13 UTC
(rev 1665)
+++ branches/JCA/build/assembly/jboss-container/connectors.xml 2009-12-15 01:04:57 UTC
(rev 1666)
@@ -17,6 +17,8 @@
<includes>
<include>org.jboss.teiid.connectors:connector-jdbc:rar</include>
<include>org.jboss.teiid.connectors:connector-loopback</include>
+ <include>org.jboss.teiid.connectors:connector-text</include>
+
</includes>
<binaries>
Modified: branches/JCA/connectors/connector-text/pom.xml
===================================================================
--- branches/JCA/connectors/connector-text/pom.xml 2009-12-14 22:41:13 UTC (rev 1665)
+++ branches/JCA/connectors/connector-text/pom.xml 2009-12-15 01:04:57 UTC (rev 1666)
@@ -20,107 +20,29 @@
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-common-core</artifactId>
<scope>provided</scope>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>javax.resource</groupId>
+ <artifactId>connector-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
- <!-- This build portion is identical for all the connectors that are deployed; so
when making changes make sure
- it applies to all the connectors. This below block computes the classpath, writes to
classpath.properties; it replaces
- classpath in the xml file, then bundles current project and its dependencies and xml
file in a zip for deployment-->
+
<build>
<plugins>
- <!-- build class path -->
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
+ <artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
- <id>build-classpath</id>
- <phase>generate-sources</phase>
+ <id>build_jar</id>
+ <phase>process-classes</phase>
<goals>
- <goal>build-classpath</goal>
+ <goal>jar</goal>
</goals>
- <configuration>
- <fileSeparator>:</fileSeparator>
- <pathSeparator>;</pathSeparator>
- <prefix>extensionjar</prefix>
- <excludeTransitive>false</excludeTransitive>
- <includeScope>runtime</includeScope>
- <excludeTypes>pom</excludeTypes>
-
<outputFile>target/classpath.properties</outputFile>
- <regenerateFile>true</regenerateFile>
- <outputFilterFile>true</outputFilterFile>
- </configuration>
</execution>
</executions>
</plugin>
-
- <!-- bundles all its dependencies in a single zip file -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <excludeTransitive>false</excludeTransitive>
- <includeScope>runtime</includeScope>
- <excludeTypes>pom</excludeTypes>
-
<outputDirectory>target/dependency</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-2</version>
- <configuration>
- <descriptors>
- <descriptor>src/assembly/bundle.xml</descriptor>
- </descriptors>
- <outputDirectory>target/distribution</outputDirectory>
- <workDirectory>target/assembly/work</workDirectory>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
- <!-- replaces the classpath tokens in the xml file -->
- <filters>
- <filter>target/classpath.properties</filter>
- </filters>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/*.xml</include>
- </includes>
- </resource>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>false</filtering>
- <excludes>
- <exclude>**/*.xml</exclude>
- </excludes>
- </resource>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>false</filtering>
- <excludes>
- <exclude>**/*.xml</exclude>
- </excludes>
- </resource>
- </resources>
-
- </build>
+ </build>
+
</project>
\ No newline at end of file
Modified:
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/StringToDateTranslator.java
===================================================================
---
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/StringToDateTranslator.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/StringToDateTranslator.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -22,12 +22,14 @@
package com.metamatrix.connector.text;
-import java.util.*;
-import java.text.*;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
-import org.teiid.connector.api.ConnectorLogger;
-
/**
* <p>This is a helper class for TextTranslators that can be used to translate
* any String that is a representation of a date to a java.util.Date object.
@@ -44,6 +46,8 @@
*/
public class StringToDateTranslator {
+ TextManagedConnectionFactory config;
+
/**
* The SimpleDateFormat objects that are used to translate dates for this
* connector.
@@ -62,8 +66,6 @@
*/
private boolean hasFormatters=false;
- private ConnectorLogger logger;
-
/**
* <p>This class is created by passing it a properties object that contains at
least
* one property. The value of this property is a String that can be a delimited list
of
@@ -91,16 +93,12 @@
* PropertyValue: Delimiter for value of TextPropertyNames.DATE_RESULT_FORMATS
* </pre>
*/
- public StringToDateTranslator(Properties props, ConnectorLogger logger) {
-
- if (props==null) {
- return;
- }
+ public StringToDateTranslator(TextManagedConnectionFactory config) {
+ this.config = config;
+
+ String dateFormats = config.getDateResultFormats();
+ String dateFormatsDelimiter = config.getDateResultFormatsDelimiter();
- this.logger = logger;
-
- String dateFormats = props.getProperty(TextPropertyNames.DATE_RESULT_FORMATS);
- String dateFormatsDelimiter =
props.getProperty(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER);
if (!(dateFormatsDelimiter == null || dateFormatsDelimiter.trim().length() == 0))
{
if (!(dateFormats == null || dateFormats.trim().length() == 0)) {
createSimpleDateFormats(dateFormats, dateFormatsDelimiter);
@@ -202,7 +200,7 @@
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
- logger.logTrace("Creating simple Date format for formatting String:
" +token); //$NON-NLS-1$
+ this.config.getLogger().logTrace("Creating simple Date format for
formatting String: " +token); //$NON-NLS-1$
dateFormatStrings.add(token);
SimpleDateFormat formatter = new SimpleDateFormat(token.trim());
@@ -220,7 +218,7 @@
private void createSimpleDateFormat(String dateFormats) {
simpleDateFormats = new ArrayList();
dateFormatStrings = new ArrayList();
- logger.logTrace("Creating simple Date format for formatting String: "
+dateFormats); //$NON-NLS-1$
+ this.config.getLogger().logTrace("Creating simple Date format for formatting
String: " +dateFormats); //$NON-NLS-1$
SimpleDateFormat formatter = new SimpleDateFormat(dateFormats);
dateFormatStrings.add(dateFormats);
Modified:
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnection.java
===================================================================
---
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnection.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnection.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -22,49 +22,78 @@
package com.metamatrix.connector.text;
-import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
-import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.api.MetadataProvider;
import org.teiid.connector.api.ResultSetExecution;
+import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.basic.BasicConnection;
import org.teiid.connector.language.IQuery;
import org.teiid.connector.language.IQueryCommand;
+import org.teiid.connector.metadata.runtime.Column;
+import org.teiid.connector.metadata.runtime.MetadataFactory;
import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+import org.teiid.connector.metadata.runtime.Table;
/**
* Implementation of Connection interface for text connection.
*/
-public class TextConnection extends BasicConnection {
+public class TextConnection extends BasicConnection implements MetadataProvider {
// metadata props -- Map<groupName --> Map<propName, propValue>
- Map metadataProps = new HashMap();
+ Map <String, Properties> metadataProps;
// connector props
- ConnectorEnvironment env;
+ private TextManagedConnectionFactory config;
/**
* Constructor.
* @param env
*/
- TextConnection(ConnectorEnvironment env, Map metadataProps) throws ConnectorException
{
- this.env = env;
+ TextConnection(TextManagedConnectionFactory env, Map metadataProps) {
+ this.config = env;
this.metadataProps = metadataProps;
}
@Override
- public ResultSetExecution createResultSetExecution(IQueryCommand command,
- ExecutionContext executionContext, RuntimeMetadata metadata)
+ public ResultSetExecution createResultSetExecution(IQueryCommand command,
ExecutionContext executionContext, RuntimeMetadata metadata)
throws ConnectorException {
- return new TextSynchExecution((IQuery)command, this, metadata);
+ return new TextSynchExecution(this.config, (IQuery)command, this.metadataProps);
}
@Override
public void close() {
metadataProps = null;
- env.getLogger().logDetail("Text Connection is successfully closed.");
//$NON-NLS-1$
}
+
+ @Override
+ public void getConnectorMetadata(MetadataFactory metadataFactory) throws
ConnectorException {
+ for (Map.Entry<String, Properties> entry : this.metadataProps.entrySet()) {
+ Properties p = entry.getValue();
+ String columns = p.getProperty(TextPropertyNames.COLUMNS);
+ if (columns == null) {
+ continue;
+ }
+ String types = p.getProperty(TextPropertyNames.TYPES);
+ String[] columnNames = columns.trim().split(","); //$NON-NLS-1$
+ String[] typeNames = null;
+ if (types != null) {
+ typeNames = types.trim().split(","); //$NON-NLS-1$
+ if (typeNames.length != columnNames.length) {
+ throw new
ConnectorException(TextPlugin.Util.getString("TextConnector.column_mismatch",
entry.getKey())); //$NON-NLS-1$
+ }
+ }
+ Table table =
metadataFactory.addTable(entry.getKey().substring(entry.getKey().indexOf('.') +
1));
+ for (int i = 0; i < columnNames.length; i++) {
+ String type = typeNames ==
null?TypeFacility.RUNTIME_NAMES.STRING:typeNames[i].trim().toLowerCase();
+ Column column = metadataFactory.addColumn(columnNames[i].trim(), type, table);
+ column.setNameInSource(String.valueOf(i));
+ column.setNativeType(TypeFacility.RUNTIME_NAMES.STRING);
+ }
+ }
+ }
}
Modified:
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnector.java
===================================================================
---
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnector.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextConnector.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -35,71 +35,48 @@
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.api.MetadataProvider;
-import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.basic.BasicConnector;
-import org.teiid.connector.metadata.runtime.Column;
-import org.teiid.connector.metadata.runtime.MetadataFactory;
-import org.teiid.connector.metadata.runtime.Table;
/**
* Implementation of text connector.
*/
-public class TextConnector extends BasicConnector implements MetadataProvider {
+public class TextConnector extends BasicConnector {
- private ConnectorLogger logger;
- private ConnectorEnvironment env;
+ private TextManagedConnectionFactory config;
private int srcFiles = 0;
private int srcFileErrs = 0;
private Map<String, Properties> metadataProps = new HashMap<String,
Properties>();
private String parentDirectory;
- /**
- * Initialization with environment.
- */
- @Override
- public void start(ConnectorEnvironment environment) throws ConnectorException {
- logger = environment.getLogger();
- this.env = environment;
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+
+ this.config = (TextManagedConnectionFactory)env;
initMetaDataProps();
+
// test connection
- TextConnection test = new TextConnection(this.env, metadataProps);
+ TextConnection test = new TextConnection(this.config, metadataProps);
test.close();
-
- // logging
- logger = environment.getLogger();
- logger.logInfo("Text Connector is started."); //$NON-NLS-1$
}
- public void stop() {
- logger.logInfo("Text Connector is stoped."); //$NON-NLS-1$
- }
- /*
- * @see
com.metamatrix.data.Connector#getConnection(com.metamatrix.data.SecurityContext)
- */
- public Connection getConnection(ExecutionContext context) throws ConnectorException
{
- return new TextConnection(this.env, metadataProps);
+ public Connection getConnection() throws ConnectorException {
+ return new TextConnection(this.config, metadataProps);
}
private void initMetaDataProps() throws ConnectorException {
- Properties connectorProps = env.getProperties();
- String descriptor =
connectorProps.getProperty(TextPropertyNames.DESCRIPTOR_FILE);
- boolean partialStartupAllowed = getPartialStartupAllowedValue(connectorProps);
reinitFileCounts();
try {
- readDescriptor(descriptor,partialStartupAllowed);
+
readDescriptor(this.config.getDescriptorFile(),this.config.isPartialStartupAllowed());
reinitFileCounts();
} catch (ConnectorException ce) {
// If partial startup is not allowed, throw the exception
- if(!partialStartupAllowed ) {
+ if(!this.config.isPartialStartupAllowed() ) {
reinitFileCounts();
throw ce;
// If partial startup is allowed, only throw exception if no files connected
@@ -109,12 +86,8 @@
}
}
}
+
- private boolean getPartialStartupAllowedValue(Properties connectorProps) {
- String partialAllowedStr =
connectorProps.getProperty(TextPropertyNames.PARTIAL_STARTUP_ALLOWED,"true");
//$NON-NLS-1$
- return Boolean.valueOf(partialAllowedStr).booleanValue();
- }
-
private void reinitFileCounts() {
this.srcFiles=0;
this.srcFileErrs=0;
@@ -138,7 +111,7 @@
BufferedReader br = null;
try {
br = getReader(descriptorFile);
- logger.logInfo("Reading descriptor file: " + descriptorFile);
//$NON-NLS-1$
+ this.config.getLogger().logInfo("Reading descriptor file: " +
descriptorFile); //$NON-NLS-1$
String line = null;
// Walk through records, finding matches
@@ -170,14 +143,14 @@
if(connExcep!=null) throw connExcep;
} catch (IOException e) {
-
logger.logError(TextPlugin.Util.getString("TextConnection.Error_while_reading_text_file__{0}_1",
new Object[] {e.getMessage()}), e); //$NON-NLS-1$
+
this.config.getLogger().logError(TextPlugin.Util.getString("TextConnection.Error_while_reading_text_file__{0}_1",
new Object[] {e.getMessage()}), e); //$NON-NLS-1$
throw new ConnectorException(e,
TextPlugin.Util.getString("TextConnection.Error_trying_to_establish_connection_5"));
//$NON-NLS-1$
} finally {
if (br != null) {
try {br.close();} catch (Exception ee) {}
}
}
- logger.logDetail("Successfully read metadata information from the descriptor
file " + descriptorFile); //$NON-NLS-1$
+ this.config.getLogger().logDetail("Successfully read metadata information
from the descriptor file " + descriptorFile); //$NON-NLS-1$
}
/**
@@ -261,7 +234,6 @@
metadataProps.put(groupName, props);
}
} catch (Exception e) {
-
logger.logError(TextPlugin.Util.getString("TextConnection.Error_parsing_property_string_{0}_5",
new Object[] {propStr}), e); //$NON-NLS-1$
throw new
ConnectorException(TextPlugin.Util.getString("TextConnection.Error_parsing_property_string_{0}__{1}_6",
new Object[] {propStr, e.getMessage()})); //$NON-NLS-1$
}
@@ -353,35 +325,7 @@
return br;
}
- public ConnectorCapabilities getCapabilities() {
- return TextCapabilities.INSTANCE;
- }
- @Override
- public void getConnectorMetadata(MetadataFactory metadataFactory) throws
ConnectorException {
- for (Map.Entry<String, Properties> entry : this.metadataProps.entrySet()) {
- Properties p = entry.getValue();
- String columns = p.getProperty(TextPropertyNames.COLUMNS);
- if (columns == null) {
- continue;
- }
- String types = p.getProperty(TextPropertyNames.TYPES);
- String[] columnNames = columns.trim().split(","); //$NON-NLS-1$
- String[] typeNames = null;
- if (types != null) {
- typeNames = types.trim().split(","); //$NON-NLS-1$
- if (typeNames.length != columnNames.length) {
- throw new
ConnectorException(TextPlugin.Util.getString("TextConnector.column_mismatch",
entry.getKey())); //$NON-NLS-1$
- }
- }
- Table table =
metadataFactory.addTable(entry.getKey().substring(entry.getKey().indexOf('.') +
1));
- for (int i = 0; i < columnNames.length; i++) {
- String type = typeNames ==
null?TypeFacility.RUNTIME_NAMES.STRING:typeNames[i].trim().toLowerCase();
- Column column = metadataFactory.addColumn(columnNames[i].trim(), type, table);
- column.setNameInSource(String.valueOf(i));
- column.setNativeType(TypeFacility.RUNTIME_NAMES.STRING);
- }
- }
- }
+
}
Added:
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextManagedConnectionFactory.java
===================================================================
---
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextManagedConnectionFactory.java
(rev 0)
+++
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextManagedConnectionFactory.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -0,0 +1,76 @@
+/*
+ * 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.text;
+
+import org.teiid.connector.basic.BasicManagedConnectionFactory;
+
+public class TextManagedConnectionFactory extends BasicManagedConnectionFactory{
+
+ private static final long serialVersionUID = -1495488034205703625L;
+
+ private String descriptorFile;
+ private boolean partialStartupAllowed = true;
+ private boolean enforceColumnCount = false;
+ private String dateResultFormatsDelimiter;
+ private String dateResultFormats;
+
+ public String getDescriptorFile() {
+ return descriptorFile;
+ }
+
+ public void setDescriptorFile(String descriptorFile) {
+ this.descriptorFile = descriptorFile;
+ }
+
+ public boolean isPartialStartupAllowed() {
+ return partialStartupAllowed;
+ }
+
+ public void setPartialStartupAllowed(Boolean partialStartupAllowed) {
+ this.partialStartupAllowed = partialStartupAllowed.booleanValue();
+ }
+
+ public boolean isEnforceColumnCount() {
+ return enforceColumnCount;
+ }
+
+ public void setEnforceColumnCount(Boolean enforceColumnCount) {
+ this.enforceColumnCount = enforceColumnCount.booleanValue();
+ }
+
+ public String getDateResultFormatsDelimiter() {
+ return dateResultFormatsDelimiter;
+ }
+
+ public void setDateResultFormatsDelimiter(String dateResultFormatsDelimiter) {
+ this.dateResultFormatsDelimiter = dateResultFormatsDelimiter;
+ }
+
+ public String getDateResultFormats() {
+ return dateResultFormats;
+ }
+
+ public void setDateResultFormats(String dateResultFormats) {
+ this.dateResultFormats = dateResultFormats;
+ }
+
+}
Modified:
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextSynchExecution.java
===================================================================
---
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextSynchExecution.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/main/java/com/metamatrix/connector/text/TextSynchExecution.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -40,7 +40,6 @@
import java.util.Properties;
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.api.TypeFacility;
@@ -53,7 +52,6 @@
import org.teiid.connector.language.ISelectSymbol;
import org.teiid.connector.metadata.runtime.Element;
import org.teiid.connector.metadata.runtime.Group;
-import org.teiid.connector.metadata.runtime.RuntimeMetadata;
import com.metamatrix.core.util.StringUtil;
@@ -65,16 +63,11 @@
// Command to be executed
private IQuery cmd;
- private TextConnection txtConn;
-
// metadata properties
private Map metadataProps;
- private ConnectorLogger logger;
+ private TextManagedConnectionFactory config;
- // runtime metadata
- private RuntimeMetadata rm;
-
// metadata properties for a given group
private Properties groupProps = null;
@@ -101,7 +94,6 @@
// the number of modeled columsn should match the
// number of colums parsed from the file
private int numModeledColumns = 0;
- private boolean useModeledColumnCntedit=false;
// If a header row is to be used, this is where the
// column names will be saved
@@ -119,11 +111,9 @@
* @param cmd
* @param txtConn
*/
- public TextSynchExecution(IQuery query, TextConnection txtConn, RuntimeMetadata
metadata) {
- this.txtConn = txtConn;
- this.rm = metadata;
- this.logger = this.txtConn.env.getLogger();
- this.metadataProps = this.txtConn.metadataProps;
+ public TextSynchExecution(TextManagedConnectionFactory config, IQuery query, Map
<String, Properties> metaProps) {
+ this.config = config;
+ this.metadataProps = metaProps;
this.cmd = query;
}
@@ -195,7 +185,7 @@
Object[] params = new Object[] { line };
String msg =
TextPlugin.Util.getString("TextSynchExecution.Text_has_no_determined_ending_qualifier",
params); //$NON-NLS-1$
- logger.logError(msg);
+ this.config.getLogger().logError(msg);
throw new ConnectorException( msg);
}
@@ -212,11 +202,8 @@
++rowsProduced;
// Save selected columns into query results
- if (this.useModeledColumnCntedit && record.size() != numModeledColumns)
{
- Object[] params = new Object[] { new Integer(numModeledColumns), new
Integer(record.size()) };
- String msg =
TextPlugin.Util.getString("TextSynchExecution.Input_column_cnt_incorrect",
params); //$NON-NLS-1$
- logger.logError(msg);
- throw new ConnectorException( msg);
+ if (this.config.isEnforceColumnCount() && record.size() !=
numModeledColumns) {
+ throw new
ConnectorException(TextPlugin.Util.getString("TextSynchExecution.Input_column_cnt_incorrect",
new Object[] { new Integer(numModeledColumns), new Integer(record.size()) }));
}
return getRow(record, cols, types);
@@ -224,9 +211,7 @@
} catch(ConnectorException ce) {
throw ce;
} catch(Throwable e) {
- Object[] params = new Object[] { location, e.getMessage() };
-
logger.logError(TextPlugin.Util.getString("TextSynchExecution.Error_reading_text_file",
params), e); //$NON-NLS-1$
- throw new ConnectorException(e, "Error while reading text file:
"+location); //$NON-NLS-1$
+ throw new ConnectorException(e,
TextPlugin.Util.getString("TextSynchExecution.Error_reading_text_file", new
Object[] { location, e.getMessage() })); //$NON-NLS-1$
}
}
@@ -277,7 +262,7 @@
Object[] params = new Object[] { TextPropertyNames.HEADER_ROW, new
Integer(headerRowNum), new Integer(numTop) };
String msg =
TextPlugin.Util.getString("TextSynchExecution.Property_contains_an_invalid_value_Using_value",
params); //$NON-NLS-1$
// TODO: We should include the group name in the log message.
- logger.logWarning(msg);
+ this.config.getLogger().logWarning(msg);
headerRowNum = numTop;
}
@@ -309,7 +294,6 @@
else {
Object[] params = new Object[] { line };
String msg =
TextPlugin.Util.getString("TextSynchExecution.Text_has_no_determined_ending_qualifier",
params); //$NON-NLS-1$
- logger.logError(msg);
throw new ConnectorException(msg);
}
}
@@ -329,9 +313,7 @@
} else if (numTop >= lineNum) continue;
}
} catch (Throwable e) {
- Object[] params = new Object[] { location, e.getMessage() };
- logger.logError(TextPlugin.Util.getString("TextSynchExecution.Error_reading_text_file",
params), e); //$NON-NLS-1$
- throw new ConnectorException(e, "Error while reading text file: " +
location); //$NON-NLS-1$
+ throw new ConnectorException(e,
TextPlugin.Util.getString("TextSynchExecution.Error_reading_text_file", new
Object[] { location, e.getMessage() })); //$NON-NLS-1$
}
}
@@ -362,7 +344,7 @@
}
}
readerQueue.clear();
- logger.logInfo("TextSynchExecution is successfully closed.");
//$NON-NLS-1$
+ this.config.getLogger().logInfo("TextSynchExecution is successfully
closed."); //$NON-NLS-1$
}
public void cancel() {
@@ -436,12 +418,6 @@
* @return Object
*/
protected Object submitRequest(Object req) {
- Properties connprops = txtConn.env.getProperties();
-
- String cnt_edit = (String)
connprops.get(TextPropertyNames.COLUMN_CNT_MUST_MATCH_MODEL);
- if (cnt_edit != null &&
cnt_edit.equalsIgnoreCase(Boolean.TRUE.toString())) {
- this.useModeledColumnCntedit = true;
- }
return metadataProps;
}
@@ -466,10 +442,9 @@
String groupName = group.getFullName();
Map metadataMap = (Map) response;
- Properties connProps = this.txtConn.env.getProperties();
- if(connProps.get(TextPropertyNames.DATE_RESULT_FORMATS) != null) {
- stringToDateTranslator = new StringToDateTranslator(connProps, logger);
+ if(this.config.getDateResultFormats() != null) {
+ stringToDateTranslator = new StringToDateTranslator(this.config);
}
groupProps = (Properties) metadataMap.get(groupName.toUpperCase());
@@ -559,13 +534,13 @@
BufferedReader r = new BufferedReader(inSR);
//new FileReader(datafile));
- logger.logInfo("Reading file: " + fileName); //$NON-NLS-1$
+ this.config.getLogger().logInfo("Reading file: " + fileName);
//$NON-NLS-1$
readerQueue.add(r);
}
- private void addReader(String fileName, InputStreamReader inSr) throws IOException {
+ private void addReader(String fileName, InputStreamReader inSr) {
BufferedReader r = new BufferedReader(inSr);
- logger.logInfo("Reading URL: " + fileName); //$NON-NLS-1$
+ this.config.getLogger().logInfo("Reading URL: " + fileName);
//$NON-NLS-1$
readerQueue.add(r);
}
@@ -602,7 +577,7 @@
* @param symbol Input ISelectSymbol
* @return Element returned metadata runtime Element
*/
- private Element getElementFromSymbol(ISelectSymbol symbol) throws ConnectorException
{
+ private Element getElementFromSymbol(ISelectSymbol symbol) {
IElement expr = (IElement) symbol.getExpression();
return expr.getMetadataObject();
}
@@ -740,8 +715,6 @@
if(charIndex < totalChars && line.charAt(charIndex) !=
delimChar) {
Object[] params = new Object[] { ""+(columns.size()+1),
line }; //$NON-NLS-1$
String msg =
TextPlugin.Util.getString("TextSynchExecution.Text_file_must_have_delimiter",
params);//$NON-NLS-1$
-// Object[] params = new Object[] { location, e.getMessage() };
- logger.logError(msg);
// changed to Connectorexception so that the exception is thrown to the user
// and becomes known a problem, rather than just
// keeping it internally to the server
Added: branches/JCA/connectors/connector-text/src/main/rar/META-INF/ra.xml
===================================================================
--- branches/JCA/connectors/connector-text/src/main/rar/META-INF/ra.xml
(rev 0)
+++ branches/JCA/connectors/connector-text/src/main/rar/META-INF/ra.xml 2009-12-15
01:04:57 UTC (rev 1666)
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<connector
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
+ version="1.5">
+
+ <vendor-name>Red Hat Middleware LLC</vendor-name>
+ <eis-type>Teiid JDBC Connector</eis-type>
+ <resourceadapter-version>1.0</resourceadapter-version>
+ <license>
+ <description>
+ JBoss, Home of Professional Open Source.
+ Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ as indicated by the @author tags. See the copyright.txt file in the
+ distribution for a full listing of individual contributors.
+
+ This 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 software 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 software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ </description>
+ <license-required>true</license-required>
+ </license>
+ <resourceadapter>
+
<resourceadapter-class>org.teiid.connector.basic.BasicResourceAdapter</resourceadapter-class>
+
+ <outbound-resourceadapter>
+ <connection-definition>
+
<managedconnectionfactory-class>com.metamatrix.connector.text.TextManagedConnectionFactory</managedconnectionfactory-class>
+
+ <config-property>
+ <description>Connector Class</description>
+ <config-property-name>ConnectorClass</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+
<config-property-value>TextConnector.java.TextConnector</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Connector Capabilities</description>
+ <description>The class to use to provide the Connector
Capabilities</description>
+
<config-property-name>CapabilitiesClass</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+
<config-property-value>com.metamatrix.connector.text.TextCapabilities</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Is Immutable</description>
+ <description>Is Immutable, True if the source never
changes.</description>
+ <config-property-name>Immutable</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>true</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Is XA Capable</description>
+ <description>True, if this connector supports XA
Transactions</description>
+ <config-property-name>XaCapable</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>false</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Exception on Exceeding Max Rows</description>
+ <description>Indicates if an Exception should be thrown if the
specified value for Maximum Result Rows is exceeded; else no exception and no more than
the maximum will be returned</description>
+
<config-property-name>ExceptionOnMaxRows</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>true</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Maximum Result Rows</description>
+ <description>Maximum Result Rows allowed</description>
+ <config-property-name>MaxResultRows</config-property-name>
+
<config-property-type>java.lang.Integer</config-property-type>
+ <config-property-value>10000</config-property-value>
+ </config-property>
+
+ <!-- Text Connector Specific properties -->
+
+ <config-property>
+ <description>Text File Descriptor</description>
+ <config-property-name>DescriptorFile</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+
+ <config-property>
+ <description>Partial Startup Allowed</description>
+
<config-property-name>PartialStartupAllowed</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>true</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Enforce Column Count</description>
+ <description>This forces the number of columns in text file to match
what was modeled</description>
+
<config-property-name>EnforceColumnCount</config-property-name>
+
<config-property-type>java.lang.Boolean</config-property-type>
+ <config-property-value>false</config-property-value>
+ </config-property>
+
+ <config-property>
+ <description>Date Result Formats Delimiter</description>
+
<config-property-name>DateResultFormatsDelimiter</config-property-name>
+ <config-property-type>java.lang.String</config-property-type>
+ </config-property>
+
+ <config-property>
+ <description>Date Result Formats</description>
+
<config-property-name>DateResultFormats</config-property-name>
+
<config-property-type>java.lang.String</config-property-type>
+ </config-property>
+
+
+
<connectionfactory-interface>org.teiid.connector.api.Connector</connectionfactory-interface>
+
<connectionfactory-impl-class>org.teiid.connector.basic.WrappedConnector</connectionfactory-impl-class>
+
<connection-interface>org.teiid.connector.api.Connection</connection-interface>
+
<connection-impl-class>org.teiid.connector.basic.WrappedConnection</connection-impl-class>
+
+ </connection-definition>
+
+ <transaction-support>NoTransaction</transaction-support>
+
+ <authentication-mechanism>
+
<authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
+
<credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
+ </authentication-mechanism>
+ <reauthentication-support>false</reauthentication-support>
+ </outbound-resourceadapter>
+ </resourceadapter>
+</connector>
Deleted: branches/JCA/connectors/connector-text/src/main/resources/connector-text.xml
===================================================================
---
branches/JCA/connectors/connector-text/src/main/resources/connector-text.xml 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/main/resources/connector-text.xml 2009-12-15
01:04:57 UTC (rev 1666)
@@ -1,12 +0,0 @@
- <ComponentType Name="Text File Connector"
ComponentTypeCode="2" Deployable="true" Deprecated="false"
Monitorable="false" SuperComponentType="Connector"
ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup"
LastChangedDate="2008-10-31T10:26:19.945-06:00"
CreatedBy="ConfigurationStartup"
CreationDate="2008-10-31T10:26:19.945-06:00">
- <PropertyDefinition Name="ConnectorTypeClassPath"
DisplayName="Connector Type Class Path" ShortDescription="Connector Type
classpath (defined by system, do not modify)"
DefaultValue="extensionjar:connector_patch.jar;extensionjar:${project.artifactId}-${project.version}.jar;${classpath}"
IsModifiable="false" />
- <PropertyDefinition Name="PartialStartupAllowed"
DisplayName="Partial Startup Allowed" ShortDescription=""
DefaultValue="true" IsRequired="true" PropertyType="Boolean"
IsExpert="true" />
- <PropertyDefinition Name="Standard" DisplayName="Standard
Type" ShortDescription="Standard Built-in Connector Type"
DefaultValue="true" PropertyType="Boolean" IsExpert="true"
IsModifiable="false" />
- <PropertyDefinition Name="DescriptorFile" DisplayName="Text
File Descriptor" ShortDescription="" IsRequired="true" />
- <PropertyDefinition Name="ConnectorClass"
DisplayName="Connector Class" ShortDescription=""
DefaultValue="com.metamatrix.connector.text.TextConnector"
IsRequired="true" IsExpert="true" />
- <PropertyDefinition Name="EnforceColumnCount"
DisplayName="Enforce Column Count" ShortDescription="This forces the number
of columns in text file to match what was modeled" DefaultValue="false"
PropertyType="Boolean" />
- <PropertyDefinition Name="DateResultFormatsDelimiter"
DisplayName="Date Result Formats Delimiter" ShortDescription=""
IsExpert="true" />
- <PropertyDefinition Name="DateResultFormats"
DisplayName="Date Result Formats" ShortDescription=""
IsExpert="true" />
- <PropertyDefinition Name="Immutable" DisplayName="Is
Immutable" ShortDescription="True if the source never changes."
DefaultValue="true" IsRequired="true" PropertyType="Boolean"
IsExpert="true" />
- </ComponentType>
-
\ No newline at end of file
Modified:
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnection.java
===================================================================
---
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnection.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnection.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -25,12 +25,12 @@
import java.util.Map;
import java.util.Properties;
-import org.teiid.connector.api.ConnectorEnvironment;
+import junit.framework.TestCase;
+
+import org.mockito.Mockito;
import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ConnectorLogger;
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.core.util.UnitTestUtil;
/**
@@ -49,11 +49,15 @@
String descFile = UnitTestUtil.getTestDataPath() +
"/EmployeeTestDataSalary.txt"; //$NON-NLS-1$
props.put(TextPropertyNames.DESCRIPTOR_FILE, descFile);
- ConnectorEnvironment env = EnvironmentUtility.createEnvironment(props, false);
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descFile);
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+
TextConnector txr = new TextConnector();
- txr.start(env);
- TextConnection conn = (TextConnection)txr.getConnection(null);
+ txr.initialize(config);
+ TextConnection conn = (TextConnection)txr.getConnection();
+
Map actualProps = conn.metadataProps;
assertNotNull(actualProps);
}
@@ -65,11 +69,13 @@
Properties props = new Properties();
String descFile = UnitTestUtil.getTestDataPath() +
"/testDescriptorDelimited.txt"; //$NON-NLS-1$
- props.put(TextPropertyNames.DESCRIPTOR_FILE, descFile);
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descFile);
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+ Mockito.stub(config.isPartialStartupAllowed()).toReturn(true);
- ConnectorEnvironment env = EnvironmentUtility.createEnvironment(props, false);
TextConnector txr = new TextConnector();
- txr.start(env);
+ txr.initialize(config);
}
/**
@@ -79,13 +85,14 @@
Properties props = new Properties();
String descFile = UnitTestUtil.getTestDataPath() +
"/testDescriptorDelimited.txt"; //$NON-NLS-1$
- props.put(TextPropertyNames.DESCRIPTOR_FILE, descFile);
- props.put(TextPropertyNames.PARTIAL_STARTUP_ALLOWED, "false");
//$NON-NLS-1$
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descFile);
+ Mockito.stub(config.isPartialStartupAllowed()).toReturn(false);
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
- ConnectorEnvironment env = EnvironmentUtility.createEnvironment(props, false);
TextConnector txr = new TextConnector();
try {
- txr.start(env);
+ txr.initialize(config);
fail("expected exception"); //$NON-NLS-1$
} catch (ConnectorException e) {
String m1 = "Error parsing property string text.library2.location";
//$NON-NLS-1$
@@ -106,12 +113,13 @@
Properties props = new Properties();
String descFile = UnitTestUtil.getTestDataPath() +
"/testDescriptorDelimited.txt"; //$NON-NLS-1$
- props.put(TextPropertyNames.DESCRIPTOR_FILE, descFile);
- props.put(TextPropertyNames.PARTIAL_STARTUP_ALLOWED, "true");
//$NON-NLS-1$
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descFile);
+ Mockito.stub(config.isPartialStartupAllowed()).toReturn(true);
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
- ConnectorEnvironment env = EnvironmentUtility.createEnvironment(props, false);
TextConnector txr = new TextConnector();
- txr.start(env);
+ txr.initialize(config);
}
}
Modified:
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java
===================================================================
---
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/TestTextConnector.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -22,20 +22,21 @@
package com.metamatrix.connector.text;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.Test;
-import org.teiid.connector.api.ConnectorEnvironment;
+import org.mockito.Mockito;
+import org.teiid.connector.api.ConnectorLogger;
+import org.teiid.connector.api.MetadataProvider;
import org.teiid.connector.metadata.runtime.Datatype;
import org.teiid.connector.metadata.runtime.MetadataFactory;
-import org.teiid.connector.metadata.runtime.Schema;
import org.teiid.connector.metadata.runtime.Table;
-import com.metamatrix.cdk.api.EnvironmentUtility;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.core.util.UnitTestUtil;
@@ -48,16 +49,20 @@
Properties props = new Properties();
props.put(TextPropertyNames.DESCRIPTOR_FILE, descFile);
- ConnectorEnvironment env = EnvironmentUtility.createEnvironment(props, false);
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descFile);
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+ Mockito.stub(config.isPartialStartupAllowed()).toReturn(true);
+
TextConnector connector = new TextConnector();
- connector.start(env);
+ connector.initialize(config);
return connector;
}
// descriptor and data file both are files
@Test public void testGetConnection() throws Exception{
TextConnector connector = helpSetUp(DESC_FILE);
- TextConnection conn = (TextConnection) connector.getConnection(null);
+ TextConnection conn = (TextConnection) connector.getConnection();
assertNotNull(conn);
}
@@ -68,8 +73,11 @@
datatypes.put(DataTypeManager.DefaultDataTypes.BIG_INTEGER, new Datatype());
datatypes.put(DataTypeManager.DefaultDataTypes.INTEGER, new Datatype());
datatypes.put(DataTypeManager.DefaultDataTypes.TIMESTAMP, new Datatype());
+
MetadataFactory metadata = new MetadataFactory("SummitData", datatypes,
new Properties()); //$NON-NLS-1$
- connector.getConnectorMetadata(metadata);
+
+ ((MetadataProvider)connector.getConnection()).getConnectorMetadata(metadata);
+
assertEquals(0,
metadata.getMetadataStore().getSchemas().values().iterator().next().getProcedures().size());
Table group =
metadata.getMetadataStore().getSchemas().values().iterator().next().getTables().get("summitdata");
//$NON-NLS-1$
assertEquals("SUMMITDATA", group.getName()); //$NON-NLS-1$
Modified:
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java
===================================================================
---
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java 2009-12-14
22:41:13 UTC (rev 1665)
+++
branches/JCA/connectors/connector-text/src/test/java/com/metamatrix/connector/text/Util.java 2009-12-15
01:04:57 UTC (rev 1666)
@@ -23,12 +23,13 @@
package com.metamatrix.connector.text;
import java.io.File;
-import java.io.FileInputStream;
import java.util.List;
-import java.util.Properties;
import junit.framework.Assert;
+import org.mockito.Mockito;
+import org.teiid.connector.api.ConnectorLogger;
+
import com.metamatrix.cdk.api.ConnectorHost;
import com.metamatrix.cdk.unittest.FakeTranslationFactory;
import com.metamatrix.core.util.UnitTestUtil;
@@ -37,24 +38,31 @@
static void helpTestExecution(String vdb, String descriptorFile, String sql, int
maxBatchSize, int expectedRowCount) throws Exception {
descriptorFile = UnitTestUtil.getTestDataPath() + File.separator + descriptorFile;
- Properties connProps = new Properties();
- connProps.load(new FileInputStream(descriptorFile));
- connProps.put(TextPropertyNames.DESCRIPTOR_FILE, descriptorFile);
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS,
"yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy"); //$NON-NLS-1$
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER, ",");
//$NON-NLS-1$
- ConnectorHost host = new ConnectorHost(new TextConnector(), connProps,
UnitTestUtil.getTestDataPath() + File.separator + vdb, false);
+
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descriptorFile);
+ Mockito.stub(config.isPartialStartupAllowed()).toReturn(true);
+
Mockito.stub(config.getDateResultFormats()).toReturn("yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy");
+ Mockito.stub(config.getDateResultFormatsDelimiter()).toReturn(",");
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+
+ ConnectorHost host = new ConnectorHost(new TextConnector(), config,
UnitTestUtil.getTestDataPath() + File.separator + vdb);
List results = host.executeCommand(sql);
Assert.assertEquals("Total row count doesn't match expected size. ",
expectedRowCount, results.size()); //$NON-NLS-1$
}
public static ConnectorHost getConnectorHostWithFakeMetadata(String descriptorFile)
throws Exception {
- Properties connProps = new Properties();
- connProps.load(new FileInputStream(descriptorFile));
- connProps.put(TextPropertyNames.DESCRIPTOR_FILE, descriptorFile);
- connProps.put(TextPropertyNames.COLUMN_CNT_MUST_MATCH_MODEL, "true");
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS,
"yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy"); //$NON-NLS-1$
- connProps.put(TextPropertyNames.DATE_RESULT_FORMATS_DELIMITER, ",");
//$NON-NLS-1$
- ConnectorHost host = new ConnectorHost(new TextConnector(), connProps,
FakeTranslationFactory.getInstance().getTextTranslationUtility(), false);
+ TextManagedConnectionFactory config =
Mockito.mock(TextManagedConnectionFactory.class);
+ Mockito.stub(config.getDescriptorFile()).toReturn(descriptorFile);
+ Mockito.stub(config.isPartialStartupAllowed()).toReturn(true);
+
Mockito.stub(config.getDateResultFormats()).toReturn("yyyy-MM-dd,hh:mm:ss,hh:mm,dd/mm/yyyy");
+ Mockito.stub(config.getDateResultFormatsDelimiter()).toReturn(",");
+ Mockito.stub(config.isEnforceColumnCount()).toReturn(true);
+
+ Mockito.stub(config.getLogger()).toReturn(Mockito.mock(ConnectorLogger.class));
+
+
+ ConnectorHost host = new ConnectorHost(new TextConnector(), config,
FakeTranslationFactory.getInstance().getTextTranslationUtility());
return host;
}
Modified: branches/JCA/connectors/pom.xml
===================================================================
--- branches/JCA/connectors/pom.xml 2009-12-14 22:41:13 UTC (rev 1665)
+++ branches/JCA/connectors/pom.xml 2009-12-15 01:04:57 UTC (rev 1666)
@@ -83,8 +83,9 @@
<modules>
<module>connector-jdbc</module>
<module>connector-loopback</module>
+ <module>connector-text</module>
<!--
- <module>connector-text</module>
+
<module>connector-xml</module>
<module>sandbox</module>
<module>connector-salesforce</module>