Author: shawkins
Date: 2009-12-01 12:48:54 -0500 (Tue, 01 Dec 2009)
New Revision: 1609
Removed:
trunk/common-internal/src/main/java/com/metamatrix/api/core/message/
trunk/common-internal/src/main/java/com/metamatrix/api/core/xmi/
trunk/common-internal/src/main/java/com/metamatrix/common/tree/
trunk/common-internal/src/test/java/com/metamatrix/common/tree/
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigObjectsNotResolvableException.java
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java
trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java
Log:
TEIID-891 adding correction for unsigned types
Modified:
trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigObjectsNotResolvableException.java
===================================================================
---
trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigObjectsNotResolvableException.java 2009-11-30
20:16:38 UTC (rev 1608)
+++
trunk/common-internal/src/main/java/com/metamatrix/common/config/util/ConfigObjectsNotResolvableException.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -22,10 +22,6 @@
package com.metamatrix.common.config.util;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
import com.metamatrix.api.exception.MetaMatrixException;
public class ConfigObjectsNotResolvableException extends MetaMatrixException{
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java 2009-11-30
20:16:38 UTC (rev 1608)
+++
trunk/connector-api/src/main/java/org/teiid/connector/metadata/runtime/MetadataFactory.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -97,7 +97,10 @@
* @return
* @throws ConnectorException
*/
- public Column addColumn(String name, String type, ColumnSet table) throws
ConnectorException {
+ public Column addColumn(String name, String type, ColumnSet<?> table) throws
ConnectorException {
+ if (name.indexOf(AbstractMetadataRecord.NAME_DELIM_CHAR) != -1) {
+ throw new
ConnectorException(DataPlugin.Util.getString("MetadataFactory.invalid_name",
name)); //$NON-NLS-1$
+ }
Column column = new Column();
column.setName(name);
table.getColumns().add(column);
@@ -134,7 +137,7 @@
* @return
* @throws ConnectorException
*/
- public ColumnSet addPrimaryKey(String name, List<String> columnNames, Table table)
throws ConnectorException {
+ public KeyRecord addPrimaryKey(String name, List<String> columnNames, Table table)
throws ConnectorException {
KeyRecord primaryKey = new KeyRecord(KeyRecord.Type.Primary);
primaryKey.setParent(table);
primaryKey.setColumns(new ArrayList<Column>(columnNames.size()));
@@ -265,7 +268,7 @@
}
private void assignColumns(List<String> columnNames, Table table,
- ColumnSet columns) throws ConnectorException {
+ ColumnSet<?> columns) throws ConnectorException {
for (String columnName : columnNames) {
boolean match = false;
for (Column column : table.getColumns()) {
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2009-11-30
20:16:38 UTC (rev 1608)
+++
trunk/connector-api/src/main/java/org/teiid/connector/visitor/util/SQLStringVisitor.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -87,8 +87,6 @@
private Set<String> infixFunctions = new
HashSet<String>(Arrays.asList("%", "+", "-",
"*", "+", "/", "||", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
"&", "|", "^", "#")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- private static final String ESCAPED_QUOTE = "''"; //$NON-NLS-1$
-
protected static final String UNDEFINED = "<undefined>";
//$NON-NLS-1$
protected static final String UNDEFINED_PARAM = "?"; //$NON-NLS-1$
@@ -160,8 +158,8 @@
* @param str the input string
* @return a SQL-safe string
*/
- protected String escapeString(String str) {
- return StringUtil.replaceAll(str, QUOTE, ESCAPED_QUOTE);
+ protected String escapeString(String str, String quote) {
+ return StringUtil.replaceAll(str, quote, quote + quote);
}
public String toString() {
@@ -735,7 +733,7 @@
.append("'}"); //$NON-NLS-1$
} else {
buffer.append(QUOTE)
- .append(escapeString(val))
+ .append(escapeString(val, QUOTE))
.append(QUOTE);
}
}
Modified: trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties
===================================================================
--- trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties 2009-11-30
20:16:38 UTC (rev 1608)
+++ trunk/connector-api/src/main/resources/org/teiid/connector/i18n.properties 2009-12-01
17:48:54 UTC (rev 1609)
@@ -65,4 +65,5 @@
MetadataFactory.unknown_datatype=Unknown datatype {0}
MetadataFactory.no_column_found=No column found with name {0}
-MetadataFactory.duplicate_name="Non-uniquely named record detected
''{0}''
\ No newline at end of file
+MetadataFactory.duplicate_name="Non-uniquely named record detected
''{0}''
+MetadataFactory.invalid_name=Invalid column name ''{0}'', cannot contain
the . character.
\ No newline at end of file
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java 2009-11-30
20:16:38 UTC (rev 1608)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/JDBCMetdataProcessor.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -26,9 +26,12 @@
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import org.teiid.connector.api.ConnectorException;
@@ -76,8 +79,11 @@
private boolean importIndexes = true;
private boolean importApproximateIndexes = true;
private boolean importProcedures = true;
+ private boolean widenUnsingedTypes;
+ //TODO add an option to not fully qualify name in source
private ConnectorLogger logger;
+ private Set<String> unsignedTypes = new HashSet<String>();
public JDBCMetdataProcessor(ConnectorLogger logger) {
this.logger = logger;
@@ -87,6 +93,17 @@
throws SQLException, ConnectorException {
DatabaseMetaData metadata = conn.getMetaData();
+ if (widenUnsingedTypes) {
+ ResultSet rs = metadata.getTableTypes();
+ while (rs.next()) {
+ String name = rs.getString(1);
+ boolean unsigned = rs.getBoolean(10);
+ if (unsigned) {
+ unsignedTypes.add(name);
+ }
+ }
+ }
+
Map<String, TableInfo> tableMap = getTables(metadataFactory, metadata);
if (importKeys) {
@@ -121,6 +138,8 @@
String columnName = columns.getString(4);
short columnType = columns.getShort(5);
int sqlType = columns.getInt(6);
+ String typeName = columns.getString(7);
+ sqlType = checkForUnsigned(sqlType, typeName);
if (columnType == DatabaseMetaData.procedureColumnUnknown) {
continue; //there's a good chance this won't work
}
@@ -128,7 +147,7 @@
if (columnType == DatabaseMetaData.procedureColumnResult) {
Column column = metadataFactory.addProcedureResultSetColumn(columnName,
TypeFacility.getDataTypeNameFromSQLType(sqlType), procedure);
record = column;
- column.setNativeType(columns.getString(7));
+ column.setNativeType(typeName);
} else {
record = metadataFactory.addProcedureParameter(columnName,
TypeFacility.getDataTypeNameFromSQLType(sqlType), Type.values()[columnType], procedure);
}
@@ -142,6 +161,23 @@
}
procedures.close();
}
+
+ private int checkForUnsigned(int sqlType, String typeName) {
+ if (widenUnsingedTypes && unsignedTypes.contains(typeName)) {
+ switch (sqlType) {
+ case Types.TINYINT:
+ sqlType = Types.SMALLINT;
+ break;
+ case Types.SMALLINT:
+ sqlType = Types.INTEGER;
+ break;
+ case Types.INTEGER:
+ sqlType = Types.BIGINT;
+ break;
+ }
+ }
+ return sqlType;
+ }
private Map<String, TableInfo> getTables(MetadataFactory metadataFactory,
DatabaseMetaData metadata) throws SQLException, ConnectorException {
@@ -183,6 +219,8 @@
}
String columnName = columns.getString(4);
int type = columns.getInt(5);
+ String typeName = columns.getString(6);
+ type = checkForUnsigned(type, typeName);
//note that the resultset is already ordered by position, so we can rely on just
adding columns in order
Column column = metadataFactory.addColumn(columnName,
TypeFacility.getDataTypeNameFromSQLType(type), tableInfo.table);
column.setNativeType(columns.getString(6));
@@ -363,5 +401,9 @@
public void setImportApproximateIndexes(boolean importApproximateIndexes) {
this.importApproximateIndexes = importApproximateIndexes;
}
-
+
+ public void setWidenUnsingedTypes(boolean widenUnsingedTypes) {
+ this.widenUnsingedTypes = widenUnsingedTypes;
+ }
+
}
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-11-30
20:16:38 UTC (rev 1608)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/translator/SQLConversionVisitor.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -173,9 +173,9 @@
} else {
// If obj is string, toSting() will not create a new String
// object, it returns it self, so new object creation.
- valuesbuffer.append("'") //$NON-NLS-1$
- .append(escapeString(obj.toString()))
- .append("'"); //$NON-NLS-1$
+ valuesbuffer.append(QUOTE)
+ .append(escapeString(obj.toString(), QUOTE))
+ .append(QUOTE);
}
}
}
Modified: trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java 2009-11-30
20:16:38 UTC (rev 1608)
+++ trunk/engine/src/main/java/org/teiid/metadata/CompositeMetadataStore.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -27,7 +27,6 @@
import java.util.LinkedList;
import java.util.List;
-import org.teiid.connector.metadata.runtime.Column;
import org.teiid.connector.metadata.runtime.MetadataStore;
import org.teiid.connector.metadata.runtime.ProcedureRecordImpl;
import org.teiid.connector.metadata.runtime.Schema;
@@ -128,23 +127,8 @@
}
/*
- * The next methods are hold overs from XML/UUID resolving and will perform poorly
+ * The next method is a hold over from XML/UUID resolving and will perform poorly
*/
-
- public Column findElement(String fullName) throws QueryMetadataException {
- int columnIndex = fullName.lastIndexOf(TransformationMetadata.DELIMITER_STRING);
- if (columnIndex == -1) {
- throw new QueryMetadataException(fullName+TransformationMetadata.NOT_EXISTS_MESSAGE);
- }
- Table table = findGroup(fullName.substring(0, columnIndex));
- String shortElementName = fullName.substring(columnIndex + 1);
- for (Column column : table.getColumns()) {
- if (column.getName().equalsIgnoreCase(shortElementName)) {
- return column;
- }
- }
- throw new
QueryMetadataException(fullName+TransformationMetadata.NOT_EXISTS_MESSAGE);
- }
public Collection<Table> getXMLTempGroups(Table tableRecord) {
ArrayList<Table> results = new ArrayList<Table>();
Modified: trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java 2009-11-30
20:16:38 UTC (rev 1608)
+++ trunk/engine/src/main/java/org/teiid/metadata/TransformationMetadata.java 2009-12-01
17:48:54 UTC (rev 1609)
@@ -117,7 +117,18 @@
* @see
com.metamatrix.query.metadata.QueryMetadataInterface#getElementID(java.lang.String)
*/
public Object getElementID(final String elementName) throws
MetaMatrixComponentException, QueryMetadataException {
- return getMetadataStore().findElement(elementName.toLowerCase());
+ int columnIndex = elementName.lastIndexOf(TransformationMetadata.DELIMITER_STRING);
+ if (columnIndex == -1) {
+ throw new
QueryMetadataException(elementName+TransformationMetadata.NOT_EXISTS_MESSAGE);
+ }
+ Table table = this.store.findGroup(elementName.substring(0, columnIndex));
+ String shortElementName = elementName.substring(columnIndex + 1);
+ for (Column column : (List<Column>)getElementIDsInGroupID(table)) {
+ if (column.getName().equalsIgnoreCase(shortElementName)) {
+ return column;
+ }
+ }
+ throw new
QueryMetadataException(elementName+TransformationMetadata.NOT_EXISTS_MESSAGE);
}
/* (non-Javadoc)