teiid SVN: r4509 - in trunk/connectors: translator-salesforce/src/main/java/org/teiid/translator/salesforce and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-03 10:27:31 -0400 (Wed, 03 Oct 2012)
New Revision: 4509
Modified:
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java
Log:
TEIID-2177 adding olap canned queries
Modified: trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java
===================================================================
--- trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java 2012-10-03 13:10:21 UTC (rev 4508)
+++ trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java 2012-10-03 14:27:31 UTC (rev 4509)
@@ -30,7 +30,9 @@
import org.olap4j.OlapConnection;
import org.olap4j.OlapWrapper;
import org.teiid.language.Argument;
+import org.teiid.language.Call;
import org.teiid.language.Command;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.RuntimeMetadata;
@@ -52,8 +54,19 @@
@Override
public ProcedureExecution createDirectExecution(List<Argument> arguments, Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Connection connection) throws TranslatorException {
- return new OlapQueryExecution(arguments, command, unwrap(connection), executionContext, this);
+ return new OlapQueryExecution(arguments.subList(1, arguments.size()), command, unwrap(connection), executionContext, this, (String) arguments.get(0).getArgumentValue().getValue(), true);
}
+
+ @Override
+ public ProcedureExecution createProcedureExecution(Call command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Connection connection) throws TranslatorException {
+ String nativeQuery = command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ return new OlapQueryExecution(command.getArguments(), command, unwrap(connection), executionContext, this, nativeQuery, false);
+ }
+ throw new TranslatorException("Missing native-query extension metadata."); //$NON-NLS-1$
+ }
private OlapConnection unwrap(Connection conn) throws TranslatorException {
try {
Modified: trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java
===================================================================
--- trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java 2012-10-03 13:10:21 UTC (rev 4508)
+++ trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java 2012-10-03 14:27:31 UTC (rev 4509)
@@ -23,6 +23,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
@@ -36,6 +37,7 @@
import org.olap4j.metadata.Member;
import org.teiid.language.Argument;
import org.teiid.language.Command;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.translator.ExecutionContext;
@@ -57,13 +59,27 @@
private int colWidth;
private ListIterator<Position> rowPositionIterator;
private String mdxQuery;
+ private boolean returnsArray;
- public OlapQueryExecution(List<Argument> arguments, Command command, OlapConnection connection, ExecutionContext context, OlapExecutionFactory executionFactory) {
- this.mdxQuery = (String) arguments.get(0).getArgumentValue().getValue();;
+ public OlapQueryExecution(List<Argument> arguments, Command command, OlapConnection connection, ExecutionContext context, OlapExecutionFactory executionFactory, String mdxQuery, boolean returnsArray) {
+ this.mdxQuery = mdxQuery;
+ if (arguments.size() > 0 || !returnsArray) { //TODO this is a hack at backwards compatibility
+ StringBuilder buffer = new StringBuilder();
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(this.mdxQuery, arguments);
+ for (Object o : parts) {
+ if (o instanceof String) {
+ buffer.append(o);
+ } else {
+ Integer i = (Integer)o;
+ buffer.append(arguments.get(i).getArgumentValue().getValue());
+ }
+ }
+ }
this.command = command;
this.connection = connection;
this.context = context;
this.executionFactory = executionFactory;
+ this.returnsArray = returnsArray;
}
@Override
@@ -124,9 +140,12 @@
Cell cell = cellSet.getCell(colPos, rowPosition);
result[i++] = cell.getValue();
}
- ArrayList<Object[]> results = new ArrayList<Object[]>(1);
- results.add(result);
- return results;
+ if (returnsArray) {
+ ArrayList<Object[]> results = new ArrayList<Object[]>(1);
+ results.add(result);
+ return results;
+ }
+ return Arrays.asList(result);
}
@Override
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-10-03 13:10:21 UTC (rev 4508)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-10-03 14:27:31 UTC (rev 4509)
@@ -56,7 +56,6 @@
import org.teiid.translator.salesforce.execution.ProcedureExecutionParentImpl;
import org.teiid.translator.salesforce.execution.QueryExecutionImpl;
import org.teiid.translator.salesforce.execution.UpdateExecutionImpl;
-import org.teiid.translator.salesforce.execution.visitors.CriteriaVisitor;
@Translator(name="salesforce", description="A translator for Salesforce")
public class SalesForceExecutionFactory extends ExecutionFactory<ConnectionFactory, SalesforceConnection> {
@@ -117,27 +116,14 @@
Procedure metadataObject = command.getMetadataObject();
String nativeQuery = metadataObject.getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false);
if (nativeQuery != null) {
- if (nativeQuery.startsWith(DirectQueryExecution.SEARCH)) {
- StringBuilder buffer = new StringBuilder();
- List<Object> parts = SQLStringVisitor.parseNativeQueryParts(nativeQuery, command.getArguments());
- for (Object o : parts) {
- if (o instanceof String) {
- buffer.append(o);
- } else {
- Integer i = (Integer)o;
- CriteriaVisitor.appendLiteralValue(buffer, command.getArguments().get(i).getArgumentValue());
- }
- }
- nativeQuery = buffer.toString();
- }
- return new DirectQueryExecution(command.getArguments(), command, connection, metadata, executionContext, nativeQuery);
+ return new DirectQueryExecution(command.getArguments(), command, connection, metadata, executionContext, nativeQuery, false);
}
return new ProcedureExecutionParentImpl(command, connection, metadata, executionContext);
}
@Override
public ProcedureExecution createDirectExecution(List<Argument> arguments, Command command, ExecutionContext executionContext, RuntimeMetadata metadata, SalesforceConnection connection) throws TranslatorException {
- return new DirectQueryExecution(arguments.subList(1, arguments.size()), command, connection, metadata, executionContext, (String)arguments.get(0).getArgumentValue().getValue());
+ return new DirectQueryExecution(arguments.subList(1, arguments.size()), command, connection, metadata, executionContext, (String)arguments.get(0).getArgumentValue().getValue(), true);
}
@Override
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java 2012-10-03 13:10:21 UTC (rev 4508)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java 2012-10-03 14:27:31 UTC (rev 4509)
@@ -32,6 +32,7 @@
import org.teiid.language.Argument;
import org.teiid.language.Command;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ExecutionContext;
@@ -40,6 +41,7 @@
import org.teiid.translator.salesforce.SalesForcePlugin;
import org.teiid.translator.salesforce.SalesforceConnection;
import org.teiid.translator.salesforce.Util;
+import org.teiid.translator.salesforce.execution.visitors.CriteriaVisitor;
import org.w3c.dom.Element;
import com.sforce.soap.partner.QueryResult;
@@ -62,6 +64,7 @@
private int updateCount = -1;
private boolean updateQuery = false;
private String query;
+ private boolean returnsArray = true;
/**
*
@@ -72,19 +75,30 @@
* @param context
* @param query
*/
- public DirectQueryExecution(List<Argument> arguments, Command command, SalesforceConnection connection, RuntimeMetadata metadata, ExecutionContext context, String query) {
+ public DirectQueryExecution(List<Argument> arguments, Command command, SalesforceConnection connection, RuntimeMetadata metadata, ExecutionContext context, String query, boolean returnsArray) {
this.arguments = arguments;
this.command = command;
this.connection = connection;
this.metadata = metadata;
this.context = context;
this.query = query;
+ this.returnsArray = returnsArray;
}
-
+
@Override
public void execute() throws TranslatorException {
if (query.startsWith(SEARCH)) {
- doSelect(query.substring(7));
+ StringBuilder buffer = new StringBuilder();
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(query, arguments);
+ for (Object o : parts) {
+ if (o instanceof String) {
+ buffer.append(o);
+ } else {
+ Integer i = (Integer)o;
+ CriteriaVisitor.appendLiteralValue(buffer, arguments.get(i).getArgumentValue());
+ }
+ }
+ doSelect(buffer.toString().substring(7));
}
else if (query.startsWith("create;")) { //$NON-NLS-1$
doInsert(query.substring(7));
@@ -150,9 +164,12 @@
if (vals == null) {
return null;
}
- List<Object[]> row = new ArrayList<Object[]>(1);
- row.add(vals.toArray(new Object[vals.size()]));
- return row;
+ if (returnsArray) {
+ List<Object[]> row = new ArrayList<Object[]>(1);
+ row.add(vals.toArray(new Object[vals.size()]));
+ return row;
+ }
+ return vals;
}
private List<?> getRow(QueryResult result) throws TranslatorException {
12 years, 2 months
teiid SVN: r4508 - in trunk: api/src/main/java/org/teiid/metadata and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-03 09:10:21 -0400 (Wed, 03 Oct 2012)
New Revision: 4508
Modified:
trunk/api/src/main/java/org/teiid/connector/DataPlugin.java
trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
trunk/api/src/main/resources/org/teiid/connector/i18n.properties
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/Constants.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java
Log:
TEIID-2235 refining namespace support
Modified: trunk/api/src/main/java/org/teiid/connector/DataPlugin.java
===================================================================
--- trunk/api/src/main/java/org/teiid/connector/DataPlugin.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/api/src/main/java/org/teiid/connector/DataPlugin.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -46,6 +46,8 @@
TEIID60013,
TEIID60014,
TEIID60015,
- TEIID60016
+ TEIID60016,
+ TEIID60017,
+ TEIID60018
}
}
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataFactory.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -27,6 +27,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -36,9 +37,9 @@
import org.teiid.CommandContext;
import org.teiid.connector.DataPlugin;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.StringUtil;
import org.teiid.metadata.FunctionMethod.PushDown;
import org.teiid.metadata.ProcedureParameter.Type;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
@@ -49,6 +50,10 @@
* TODO: add support for unique constraints
*/
public class MetadataFactory implements Serializable {
+ private static final String TEIID_RESERVED = "teiid_"; //$NON-NLS-1$
+ private static final String TEIID_SF = "teiid_sf"; //$NON-NLS-1$
+ private static final String TEIID_RELATIONAL = "teiid_rel"; //$NON-NLS-1$
+
private static final long serialVersionUID = 8590341087771685630L;
private String vdbName;
@@ -56,7 +61,7 @@
private Map<String, Datatype> dataTypes;
private Map<String, Datatype> builtinDataTypes;
private boolean autoCorrectColumnNames = true;
- private Map<String, String> namespaces = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+ private Map<String, String> namespaces;
private String rawMetadata;
private Properties importProperties;
private Schema schema = new Schema();
@@ -64,6 +69,16 @@
private int count;
private transient Parser parser;
+ public static final String SF_URI = "{http://www.teiid.org/translator/salesforce/2012}"; //$NON-NLS-1$
+
+ public static final Map<String, String> BUILTIN_NAMESPACES;
+ static {
+ Map<String, String> map = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+ map.put(TEIID_RELATIONAL, AbstractMetadataRecord.RELATIONAL_URI.substring(1, AbstractMetadataRecord.RELATIONAL_URI.length()-1));
+ map.put(TEIID_SF, SF_URI.substring(1, SF_URI.length()-1));
+ BUILTIN_NAMESPACES = Collections.unmodifiableMap(map);
+ }
+
public MetadataFactory(String vdbName, int vdbVersion, String schemaName, Map<String, Datatype> runtimeTypes, Properties importProperties, String rawMetadata) {
this.vdbName = vdbName;
this.vdbVersion = vdbVersion;
@@ -124,9 +139,9 @@
* Add a table with the given name to the model.
* @param name
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public Table addTable(String name) throws TranslatorException {
+ public Table addTable(String name) {
Table table = new Table();
table.setTableType(Table.Type.Table);
table.setName(name);
@@ -141,14 +156,14 @@
* @param type should be one of {@link TypeFacility.RUNTIME_NAMES}
* @param table
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public Column addColumn(String name, String type, ColumnSet<?> table) throws TranslatorException {
+ public Column addColumn(String name, String type, ColumnSet<?> table) {
if (autoCorrectColumnNames) {
name.replace(AbstractMetadataRecord.NAME_DELIM_CHAR, '_');
} else if (name.indexOf(AbstractMetadataRecord.NAME_DELIM_CHAR) != -1) {
//TODO: for now this is not used
- throw new TranslatorException(DataPlugin.Event.TEIID60008, DataPlugin.Util.gs(DataPlugin.Event.TEIID60008, name));
+ throw new MetadataException(DataPlugin.Event.TEIID60008, DataPlugin.Util.gs(DataPlugin.Event.TEIID60008, name));
}
if (table.getColumnByName(name) != null) {
throw new DuplicateRecordException(DataPlugin.Event.TEIID60016, DataPlugin.Util.gs(DataPlugin.Event.TEIID60016, table.getFullName() + AbstractMetadataRecord.NAME_DELIM_CHAR + name));
@@ -164,10 +179,10 @@
}
private Datatype setColumnType(String type,
- BaseColumn column) throws TranslatorException {
+ BaseColumn column) {
Datatype datatype = dataTypes.get(type);
if (datatype == null) {
- throw new TranslatorException(DataPlugin.Event.TEIID60009, DataPlugin.Util.gs(DataPlugin.Event.TEIID60009, type));
+ throw new MetadataException(DataPlugin.Event.TEIID60009, DataPlugin.Util.gs(DataPlugin.Event.TEIID60009, type));
}
column.setDatatype(datatype, true);
return datatype;
@@ -179,9 +194,9 @@
* @param columnNames
* @param table
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public KeyRecord addPrimaryKey(String name, List<String> columnNames, Table table) throws TranslatorException {
+ public KeyRecord addPrimaryKey(String name, List<String> columnNames, Table table) {
KeyRecord primaryKey = new KeyRecord(KeyRecord.Type.Primary);
primaryKey.setParent(table);
primaryKey.setColumns(new ArrayList<Column>(columnNames.size()));
@@ -198,9 +213,9 @@
* @param columnNames
* @param table
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public KeyRecord addAccessPattern(String name, List<String> columnNames, Table table) throws TranslatorException {
+ public KeyRecord addAccessPattern(String name, List<String> columnNames, Table table) {
KeyRecord ap = new KeyRecord(KeyRecord.Type.AccessPattern);
ap.setParent(table);
ap.setColumns(new ArrayList<Column>(columnNames.size()));
@@ -218,9 +233,9 @@
* @param columnNames
* @param table
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public KeyRecord addIndex(String name, boolean nonUnique, List<String> columnNames, Table table) throws TranslatorException {
+ public KeyRecord addIndex(String name, boolean nonUnique, List<String> columnNames, Table table) {
KeyRecord index = new KeyRecord(nonUnique?KeyRecord.Type.Index:KeyRecord.Type.Unique);
index.setParent(table);
index.setColumns(new ArrayList<Column>(columnNames.size()));
@@ -243,9 +258,9 @@
* @param nonColumnExpressions a Boolean list indicating when expressions are non-column expressions
* @param table
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public KeyRecord addFunctionBasedIndex(String name, List<String> expressions, List<Boolean> nonColumnExpressions, Table table) throws TranslatorException {
+ public KeyRecord addFunctionBasedIndex(String name, List<String> expressions, List<Boolean> nonColumnExpressions, Table table) {
KeyRecord index = new KeyRecord(KeyRecord.Type.Index);
index.setParent(table);
index.setColumns(new ArrayList<Column>(expressions.size()));
@@ -291,9 +306,9 @@
* @param referenceTable - schema qualified reference table name
* @param table
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public ForeignKey addForiegnKey(String name, List<String> columnNames, String referenceTable, Table table) throws TranslatorException {
+ public ForeignKey addForiegnKey(String name, List<String> columnNames, String referenceTable, Table table) {
return addForiegnKey(name, columnNames, null, referenceTable, table);
}
@@ -307,9 +322,9 @@
* @param table
* @param addUniqueConstraint - if true, if the referenced table columns do not match with either PK, or FK then a UNIQUE index on reference table is created.
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public ForeignKey addForiegnKey(String name, List<String> columnNames, List<String> referencedColumnNames, String referenceTable, Table table) throws TranslatorException {
+ public ForeignKey addForiegnKey(String name, List<String> columnNames, List<String> referencedColumnNames, String referenceTable, Table table) {
ForeignKey foreignKey = new ForeignKey();
foreignKey.setParent(table);
foreignKey.setColumns(new ArrayList<Column>(columnNames.size()));
@@ -326,9 +341,9 @@
* Add a procedure with the given name to the model.
* @param name
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public Procedure addProcedure(String name) throws TranslatorException {
+ public Procedure addProcedure(String name) {
Procedure procedure = new Procedure();
procedure.setName(name);
setUUID(procedure);
@@ -344,9 +359,9 @@
* @param parameterType should be one of {@link ProcedureParameter.Type}
* @param procedure
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public ProcedureParameter addProcedureParameter(String name, String type, ProcedureParameter.Type parameterType, Procedure procedure) throws TranslatorException {
+ public ProcedureParameter addProcedureParameter(String name, String type, ProcedureParameter.Type parameterType, Procedure procedure) {
ProcedureParameter param = new ProcedureParameter();
param.setName(name);
setUUID(param);
@@ -371,9 +386,9 @@
* @param type should be one of {@link TypeFacility.RUNTIME_NAMES}
* @param procedure
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public Column addProcedureResultSetColumn(String name, String type, Procedure procedure) throws TranslatorException {
+ public Column addProcedureResultSetColumn(String name, String type, Procedure procedure) {
if (procedure.getResultSet() == null) {
ColumnSet<Procedure> resultSet = new ColumnSet<Procedure>();
resultSet.setParent(procedure);
@@ -395,9 +410,9 @@
* Add a function with the given name to the model.
* @param name
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public FunctionMethod addFunction(String name) throws TranslatorException {
+ public FunctionMethod addFunction(String name) {
FunctionMethod function = new FunctionMethod();
function.setName(name);
setUUID(function);
@@ -410,9 +425,9 @@
* @param name
* @param method
* @return
- * @throws TranslatorException
+ * @throws MetadataException
*/
- public FunctionMethod addFunction(String name, Method method) throws TranslatorException {
+ public FunctionMethod addFunction(String name, Method method) {
String returnType = DataTypeManager.getDataTypeName(method.getReturnType());
Class<?>[] params = method.getParameterTypes();
String[] paramTypes = new String[params.length];
@@ -456,6 +471,15 @@
}
public void addNamespace(String prefix, String uri) {
+ if (StringUtil.startsWithIgnoreCase(prefix, TEIID_RESERVED)) {
+ throw new MetadataException(DataPlugin.Event.TEIID60017, DataPlugin.Util.gs(DataPlugin.Event.TEIID60017, prefix));
+ }
+ if (uri == null || uri.indexOf('}') != -1) {
+ throw new MetadataException(DataPlugin.Event.TEIID60018, DataPlugin.Util.gs(DataPlugin.Event.TEIID60018, uri));
+ }
+ if (this.namespaces == null) {
+ this.namespaces = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
+ }
this.namespaces.put(prefix, uri);
}
@@ -540,7 +564,15 @@
return vdbVersion;
}
+ /**
+ * Get the namespace map. Will be an unmodifiable empty map if {@link #addNamespace(String, String)}
+ * has not been called successfully.
+ * @return
+ */
public Map<String, String> getNamespaces() {
+ if (this.namespaces == null) {
+ return Collections.emptyMap();
+ }
return namespaces;
}
Modified: trunk/api/src/main/resources/org/teiid/connector/i18n.properties
===================================================================
--- trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2012-10-03 13:10:21 UTC (rev 4508)
@@ -26,6 +26,8 @@
TEIID60014=Duplicate Procedure {0}
TEIID60015=Duplicate Function {0}
TEIID60016=Duplicate Column {0}
+TEIID60017=Invalid prefix {0}, teiid_ is reserved for Teiid use.
+TEIID60018=Invalid uri {0}, uris must be non null and not contain curly braces.
TEIID60009=Unknown datatype {0}
TEIID60011=No column found with name {0}
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-10-03 13:10:21 UTC (rev 4508)
@@ -61,7 +61,8 @@
to the integer suffix of the teiidCode if possible.
<li>TEIID-2226 All statements that return result sets that are executed as command statements in a procedure are validated against the expected resultset columns of the procedure.
If the statement is not intended to be returnable, WITHOUT RETURN can be added to the end of the statement.
- <li>TEIID-2235 The MetadataRepository.setNext was removed. Also if an instance of a DefaultMetadataRepository is used, it will only affect metadata already loaded in the repository chain.
+ <li>TEIID-2235 The MetadataRepository.setNext was removed. Also if an instance of a DefaultMetadataRepository is used, it will only affect metadata already loaded in the repository chain.
+ <li>TEIID-2237 teiid_ is a reserved DDL namespace prefix and the MetadataFactory class no longer throws TranslatorExceptions, instead the unchecked MetadataException is thrown.
</ul>
<h4>from 8.0</h4>
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/Constants.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/Constants.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/Constants.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -1,5 +1,7 @@
package org.teiid.translator.salesforce;
+import org.teiid.metadata.MetadataFactory;
+
public interface Constants {
public static final String PICKLIST_TYPE = "picklist"; //$NON-NLS-1$
@@ -40,14 +42,12 @@
public static final String EMAIL_TYPE = "email"; //$NON-NLS-1$
- public static final String EXTENSION_URI = "{http://www.teiid.org/translator/salesforce/2012}"; //$NON-NLS-1$
-
public static final String RESTRICTED_PICKLIST_TYPE = "restrictedpicklist"; //$NON-NLS-1$
public static final String RESTRICTED_MULTISELECT_PICKLIST_TYPE = "restrictedmultiselectpicklist"; //$NON-NLS-1$
- public static final String SUPPORTS_QUERY = EXTENSION_URI +"Supports Query";//$NON-NLS-1$
+ public static final String SUPPORTS_QUERY = MetadataFactory.SF_URI +"Supports Query";//$NON-NLS-1$
- public static final String SUPPORTS_RETRIEVE = EXTENSION_URI +"Supports Retrieve";//$NON-NLS-1$
+ public static final String SUPPORTS_RETRIEVE = MetadataFactory.SF_URI +"Supports Retrieve";//$NON-NLS-1$
}
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -29,7 +29,6 @@
import java.util.Map;
import org.teiid.language.*;
-import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.Column;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.TranslatorException;
@@ -38,7 +37,6 @@
public class SelectVisitor extends CriteriaVisitor implements IQueryProvidingVisitor {
- public static final String TEIID_NATIVE_QUERY = AbstractMetadataRecord.RELATIONAL_URI + "native-query"; //$NON-NLS-1$
public static final String AGG_PREFIX = "expr"; //$NON-NLS-1$
private Map<Integer, Expression> selectSymbolIndexToElement = new HashMap<Integer, Expression>();
private Map<String, Integer> selectSymbolNameToIndex = new HashMap<String, Integer>();
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -28,7 +28,9 @@
import java.util.Arrays;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@@ -42,6 +44,7 @@
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.metadata.FunctionMethod.Determinism;
import org.teiid.metadata.ProcedureParameter.Type;
+import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -68,7 +71,15 @@
private boolean includeProcedures = true;
private boolean includeFunctions = true;
private Pattern filter;
+ private Map<String, String> prefixMap;
+ private final static Map<String, String> BUILTIN_PREFIXES = new HashMap<String, String>();
+ static {
+ for (Map.Entry<String, String> entry : MetadataFactory.BUILTIN_NAMESPACES.entrySet()) {
+ BUILTIN_PREFIXES.put(entry.getValue(), entry.getKey());
+ }
+ }
+
public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) {
DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern);
visitor.visit(schema);
@@ -466,9 +477,31 @@
if (sb.length() != 0) {
sb.append(COMMA).append(SPACE);
}
- if (value instanceof String) {
- value = TICK + StringUtil.replaceAll((String)value, TICK, TICK + TICK) + TICK;
+ if (value != null) {
+ value = new Constant(value);
+ } else {
+ value = Constant.NULL_CONSTANT;
}
+ if (key != null && key.length() > 2 && key.charAt(0) == '{') {
+ int index = key.indexOf('}');
+ if (index > 1) {
+ String uri = key.substring(1, index);
+ key = key.substring(index + 1, key.length());
+ String prefix = BUILTIN_PREFIXES.get(uri);
+ if (prefix == null) {
+ if (prefixMap == null) {
+ prefixMap = new LinkedHashMap<String, String>();
+ } else {
+ prefix = this.prefixMap.get(uri);
+ }
+ if (prefix == null) {
+ prefix = "n"+this.prefixMap.size(); //$NON-NLS-1$
+ this.prefixMap.put(uri, prefix);
+ }
+ }
+ key = prefix + ":" + key; //$NON-NLS-1$
+ }
+ }
sb.append(SQLStringVisitor.escapeSinglePart(key)).append(SPACE).append(value);
}
@@ -644,6 +677,14 @@
}
public String toString() {
+ if (this.prefixMap != null) {
+ StringBuilder sb = new StringBuilder();
+ for (Map.Entry<String, String> entry : this.prefixMap.entrySet()) {
+ sb.append("SET NAMESPACE '").append(StringUtil.replaceAll(entry.getKey(), "'", "''")).append('\'') //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ .append(" AS " ).append(SQLStringVisitor.escapeSinglePart(entry.getValue())).append(";\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return sb.append("\n").toString() + buffer.toString(); //$NON-NLS-1$
+ }
return buffer.toString();
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -45,7 +45,6 @@
import org.teiid.metadata.Table;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.validator.ValidatorReport;
-import org.teiid.translator.TranslatorException;
public class SystemMetadata {
@@ -123,15 +122,11 @@
vdb.addModel(mmd);
InputStream is = SystemMetadata.class.getClassLoader().getResourceAsStream("org/teiid/metadata/"+name+".sql"); //$NON-NLS-1$ //$NON-NLS-2$
try {
- MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), name, typeMap, p, null) {
- @Override
- public Table addTable(String name) throws TranslatorException {
- Table t = super.addTable(name);
- t.setSystem(true);
- return t;
- }
- };
+ MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), name, typeMap, p, null);
QueryParser.getQueryParser().parseDDL(factory, new InputStreamReader(is, Charset.forName("UTF-8"))); //$NON-NLS-1$
+ for (Table t : factory.getSchema().getTables().values()) {
+ t.setSystem(true);
+ }
return factory;
} finally {
try {
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -48,7 +48,6 @@
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.translator.TranslatorException;
public class SQLParserUtil {
@@ -554,29 +553,25 @@
}
BaseColumn addProcColumn(MetadataFactory factory, Procedure proc, String name, ParsedDataType type, boolean rs) throws MetadataException {
- try {
- BaseColumn column = null;
- if (rs) {
- column = factory.addProcedureResultSetColumn(name, type.type, proc);
- } else {
- boolean added = false;
- for (ProcedureParameter pp : proc.getParameters()) {
- if (pp.getType() == Type.ReturnValue) {
- added = true;
- if (pp.getDatatype() != factory.getDataTypes().get(type.type)) {
- throw new MetadataException(QueryPlugin.Util.getString("SQLParser.proc_type_conflict", proc.getName(), pp.getDatatype(), type.type)); //$NON-NLS-1$
- }
+ BaseColumn column = null;
+ if (rs) {
+ column = factory.addProcedureResultSetColumn(name, type.type, proc);
+ } else {
+ boolean added = false;
+ for (ProcedureParameter pp : proc.getParameters()) {
+ if (pp.getType() == Type.ReturnValue) {
+ added = true;
+ if (pp.getDatatype() != factory.getDataTypes().get(type.type)) {
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.proc_type_conflict", proc.getName(), pp.getDatatype(), type.type)); //$NON-NLS-1$
}
}
- if (!added) {
- column = factory.addProcedureParameter(name, type.type, ProcedureParameter.Type.ReturnValue, proc);
- }
}
- setTypeInfo(type, column);
- return column;
- } catch (TranslatorException e){
- throw new MetadataException(e.getMessage());
- }
+ if (!added) {
+ column = factory.addProcedureParameter(name, type.type, ProcedureParameter.Type.ReturnValue, proc);
+ }
+ }
+ setTypeInfo(type, column);
+ return column;
}
void setTypeInfo(ParsedDataType type, BaseColumn column) {
@@ -595,7 +590,10 @@
int index = key.indexOf(':');
if (index > 0 && index < key.length() - 1) {
String prefix = key.substring(0, index);
- String uri = factory.getNamespaces().get(prefix);
+ String uri = MetadataFactory.BUILTIN_NAMESPACES.get(prefix);
+ if (uri == null) {
+ uri = factory.getNamespaces().get(prefix);
+ }
if (uri != null) {
key = '{' +uri + '}' + key.substring(index + 1, key.length());
}
@@ -619,12 +617,8 @@
fbi = true;
}
}
- try{
- table.addAttchment(MetadataFactory.class, factory);
- return factory.addFunctionBasedIndex(name != null?name:(SQLConstants.NonReserved.INDEX+(fbi?table.getFunctionBasedIndexes().size():table.getIndexes().size())), columnNames, nonColumnExpressions, table);
- }catch(TranslatorException e){
- throw new MetadataException(e.getMessage());
- }
+ table.addAttchment(MetadataFactory.class, factory);
+ return factory.addFunctionBasedIndex(name != null?name:(SQLConstants.NonReserved.INDEX+(fbi?table.getFunctionBasedIndexes().size():table.getIndexes().size())), columnNames, nonColumnExpressions, table);
}
static class ParsedDataType{
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2012-10-03 13:10:21 UTC (rev 4508)
@@ -4592,11 +4592,7 @@
//the below is optional beacuse to allow the designer based metadata
( procName = id(null)
{
- try {
- proc = factory.addProcedure(procName);
- } catch(TranslatorException e){
- throw new MetadataException(e);
- }
+ proc = factory.addProcedure(procName);
}
<LPAREN>
@@ -4670,18 +4666,14 @@
}
]
{
- try {
- param = factory.addProcedureParameter(name, type.type, ppType, proc);
- setTypeInfo(type, param);
- if (notNull) {
- param.setNullType(Column.NullType.No_Nulls);
- }
- if (vararg) {
- param.setVarArg(vararg);
- }
- } catch (TranslatorException e){
- throw new MetadataException(e);
+ param = factory.addProcedureParameter(name, type.type, ppType, proc);
+ setTypeInfo(type, param);
+ if (notNull) {
+ param.setNullType(Column.NullType.No_Nulls);
}
+ if (vararg) {
+ param.setVarArg(vararg);
+ }
}
[<DEFAULT_KEYWORD> defaultValue = stringVal() {param.setDefaultValue(defaultValue);}]
[optionsClause(param, factory)
@@ -4736,12 +4728,8 @@
<CREATE> (<FOREIGN> <TABLE> | [<VIRTUAL>] <VIEW> {view = true;})
tableName = id(null)
{
- try{
- table = factory.addTable(tableName);
- table.setVirtual(view);
- } catch(TranslatorException e){
- throw new MetadataException(e);
- }
+ table = factory.addTable(tableName);
+ table.setVirtual(view);
}
[<LPAREN>
createColumn(factory, table)
@@ -4801,11 +4789,7 @@
viewName = id(null)
[pkColumnNames = columnList(true, false)]
{
- try{
- return factory.addForiegnKey(name != null?name:("FK"+table.getForeignKeys().size()), columnNames, pkColumnNames, viewName, table);
- } catch (TranslatorException e){
- throw new MetadataException(e);
- }
+ return factory.addForiegnKey(name != null?name:("FK"+table.getForeignKeys().size()), columnNames, pkColumnNames, viewName, table);
}
}
@@ -4827,11 +4811,7 @@
if (table.getPrimaryKey() != null){
throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
}
- try{
- return factory.addPrimaryKey(name!=null?name:"PK", columnNames, table);
- } catch(TranslatorException e){
- throw new MetadataException(e);
- }
+ return factory.addPrimaryKey(name!=null?name:"PK", columnNames, table);
}
}
@@ -4853,15 +4833,11 @@
(( type = <UNIQUE> | type = <ACCESSPATTERN>)
columnNames = columnList(true, false)
{
- try{
- if (type.image.equalsIgnoreCase("UNIQUE")) {
- return factory.addIndex(name != null?name:("UNIQUE"+table.getUniqueKeys().size()), false, columnNames, table);
- } else if (type.image.equalsIgnoreCase("ACCESSPATTERN")) {
- return factory.addAccessPattern(name != null?name:("AP"+table.getAccessPatterns().size()), columnNames, table);
- }
- }catch(TranslatorException e){
- throw new MetadataException(e);
- }
+ if (type.image.equalsIgnoreCase("UNIQUE")) {
+ return factory.addIndex(name != null?name:("UNIQUE"+table.getUniqueKeys().size()), false, columnNames, table);
+ } else if (type.image.equalsIgnoreCase("ACCESSPATTERN")) {
+ return factory.addAccessPattern(name != null?name:("AP"+table.getAccessPatterns().size()), columnNames, table);
+ }
}) | (
type = <INDEX>
<LPAREN>
@@ -4932,14 +4908,10 @@
(
type = parseDataType()
{
- try{
- column = factory.addColumn(element, type.type, table);
- column.setUpdatable(true);
- setTypeInfo(type, column);
- columnName.add(element);
- }catch(TranslatorException e){
- throw new MetadataException(e);
- }
+ column = factory.addColumn(element, type.type, table);
+ column.setUpdatable(true);
+ setTypeInfo(type, column);
+ columnName.add(element);
}
)
[<NOT> <NULL> { column.setNullType(Column.NullType.No_Nulls); }]
@@ -4957,20 +4929,16 @@
}
]
{
- try{
- if (index){
- factory.addIndex("INDEX"+table.getIndexes().size(), true, columnName, table);
- } else if (unique){
- factory.addIndex("UNIQUE"+table.getIndexes().size(), false, columnName, table);
- } else if (pk) {
- if (table.getPrimaryKey() != null) {
- throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
- }
- factory.addPrimaryKey("PK", columnName, table);
- }
- }catch(TranslatorException e){
- throw new MetadataException(e);
- }
+ if (index){
+ factory.addIndex("INDEX"+table.getIndexes().size(), true, columnName, table);
+ } else if (unique){
+ factory.addIndex("UNIQUE"+table.getIndexes().size(), false, columnName, table);
+ } else if (pk) {
+ if (table.getPrimaryKey() != null) {
+ throw new MetadataException(QueryPlugin.Util.getString("SQLParser.pk_exists", table.getName()));
+ }
+ factory.addPrimaryKey("PK", columnName, table);
+ }
column.setAutoIncremented(autoIncrement);
}
Modified: trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
+++ trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java 2012-10-03 13:10:21 UTC (rev 4508)
@@ -29,7 +29,6 @@
import java.util.Properties;
import org.junit.Test;
-import org.teiid.api.exception.query.QueryParserException;
import org.teiid.metadata.Column;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.Schema;
@@ -48,7 +47,7 @@
" e2 string(10),\n" +
" e3 date NOT NULL,\n" +
" e4 bigdecimal(12,3),\n" +
- " e5 integer AUTO_INCREMENT OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE false),\n" +
+ " e5 integer AUTO_INCREMENT OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE FALSE),\n" +
" e6 string DEFAULT 'hello',\n" +
" PRIMARY KEY(e1),\n" +
" UNIQUE(e2),\n" +
@@ -243,7 +242,7 @@
helpTest(ddl, expected);
}
- private void helpTest(String ddl, String expected) throws QueryParserException {
+ private void helpTest(String ddl, String expected) {
Schema s = TestDDLParser.helpParse(ddl, "model").getSchema();
String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
assertEquals(expected, metadataDDL);
@@ -263,4 +262,10 @@
String expected = "CREATE VIEW G1 (\n \"a e1\" integer,\n \"a e2\" string,\n INDEX(\"a e1\", upper(\"a e2\"))\n)\nAS\nSELECT e1, e2 FROM foo.bar;";
helpTest(ddl, expected);
}
+
+ @Test public void testNamespaces() throws Exception {
+ String ddl = "set namespace 'some long thing' as x; CREATE View G1(a integer, b varchar) options (\"teiid_rel:x\" false, \"x:z\" 'stringval') AS select e1, e2 from foo.bar";
+ String expected = "SET NAMESPACE 'some long thing' AS n0;\n\nCREATE VIEW G1 (\n a integer,\n b string\n) OPTIONS (\"teiid_rel:x\" 'false', \"n0:z\" 'stringval')\nAS\nSELECT e1, e2 FROM foo.bar;";
+ helpTest(ddl, expected);
+ }
}
12 years, 2 months
teiid SVN: r4507 - in trunk: api/src/main/resources/org/teiid/connector and 9 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 22:25:48 -0400 (Tue, 02 Oct 2012)
New Revision: 4507
Modified:
trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
trunk/api/src/main/resources/org/teiid/connector/i18n.properties
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForcePlugin.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/CriteriaVisitor.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/InsertVisitor.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
trunk/connectors/translator-salesforce/src/main/resources/org/teiid/translator/salesforce/i18n.properties
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java
trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-2177 using a sf native/canned query procedure
Modified: trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -26,11 +26,15 @@
import java.util.Arrays;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.StringUtil;
+import org.teiid.jdbc.JDBCPlugin;
import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
import org.teiid.language.SQLConstants.NonReserved;
@@ -45,7 +49,8 @@
* are not reusable, and are not thread-safe.
*/
public class SQLStringVisitor extends AbstractLanguageVisitor {
-
+ public static final String TEIID_NATIVE_QUERY = AbstractMetadataRecord.RELATIONAL_URI + "native-query"; //$NON-NLS-1$
+
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$
@@ -974,4 +979,40 @@
protected boolean useSelectLimit() {
return false;
}
+
+ public static List<Object> parseNativeQueryParts(String nativeQuery, List<Argument> list) {
+ Pattern pattern = Pattern.compile("\\$+\\d+"); //$NON-NLS-1$
+ List<Object> parts = new LinkedList<Object>();
+ Matcher m = pattern.matcher(nativeQuery);
+ for (int i = 0; i < nativeQuery.length();) {
+ if (!m.find(i)) {
+ parts.add(nativeQuery.substring(i));
+ break;
+ }
+ if (m.start() != i) {
+ parts.add(nativeQuery.substring(i, m.start()));
+ }
+ String match = m.group();
+ int end = match.lastIndexOf('$');
+ if ((end&0x1) == 1) {
+ //escaped
+ parts.add(match.substring((end+1)/2));
+ } else {
+ if (end != 0) {
+ parts.add(match.substring(0, end/2));
+ }
+ int index = Integer.parseInt(match.substring(end + 1))-1;
+ if (index < 0 || index >= list.size()) {
+ throw new IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.invalid_parameter", index+1, list.size())); //$NON-NLS-1$
+ }
+ Argument arg = list.get(index);
+ if (arg.getDirection() != Direction.IN) {
+ throw new IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.not_in_parameter", index+1)); //$NON-NLS-1$
+ }
+ parts.add(index);
+ }
+ i = m.end();
+ }
+ return parts;
+ }
}
Modified: trunk/api/src/main/resources/org/teiid/connector/i18n.properties
===================================================================
--- trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/api/src/main/resources/org/teiid/connector/i18n.properties 2012-10-03 02:25:48 UTC (rev 4507)
@@ -38,3 +38,7 @@
TEIID60001=Unsupported Execution {0}
TEIID60010=No unique key defined for table {0} for columns {1}
TEIID60004=Neither class name nor default class specified to create an instance
+
+SQLConversionVisitor.invalid_parameter=Invalid parameter {0}. Must be between 1 and {1}.
+SQLConversionVisitor.not_in_parameter=Invalid parameter {0}. Native query procedures cannot use non IN parameters.
+
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -32,12 +32,9 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.teiid.language.*;
import org.teiid.language.Argument.Direction;
@@ -56,7 +53,6 @@
* to produce a SQL String. This class is expected to be subclassed.
*/
public class SQLConversionVisitor extends SQLStringVisitor{
- public static final String TEIID_NATIVE_QUERY = AbstractMetadataRecord.RELATIONAL_URI + "native-query"; //$NON-NLS-1$
public static final String TEIID_NON_PREPARED = AbstractMetadataRecord.RELATIONAL_URI + "non-prepared"; //$NON-NLS-1$
private static DecimalFormat DECIMAL_FORMAT =
@@ -182,7 +178,7 @@
if (p != null) {
String nativeQuery = p.getProperty(TEIID_NATIVE_QUERY, false);
if (nativeQuery != null) {
- List<Object> parts = parseNativeQueryParts(nativeQuery);
+ List<Object> parts = parseNativeQueryParts(nativeQuery, obj.getArguments());
this.prepared = !Boolean.valueOf(p.getProperty(TEIID_NON_PREPARED, false));
if (this.prepared) {
this.preparedValues = new ArrayList<Object>();
@@ -191,18 +187,11 @@
if (o instanceof String) {
buffer.append(o);
} else {
- Integer i = (Integer)o;
- if (i < 0 || i >= obj.getArguments().size()) {
- throw new IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.invalid_parameter", i+1, obj.getArguments().size())); //$NON-NLS-1$
- }
- if (obj.getArguments().get(i).getDirection() != Direction.IN) {
- throw new IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.not_in_parameter", i+1)); //$NON-NLS-1$
- }
if (this.prepared) {
buffer.append('?');
this.preparedValues = obj.getArguments();
} else {
- this.visit(obj.getArguments().get(i).getArgumentValue());
+ visit(obj.getArguments().get((Integer)o));
}
}
}
@@ -217,34 +206,6 @@
buffer.append(generateSqlForStoredProcedure(obj));
}
- private List<Object> parseNativeQueryParts(String nativeQuery) {
- Pattern pattern = Pattern.compile("\\$+\\d+"); //$NON-NLS-1$
- List<Object> parts = new LinkedList<Object>();
- Matcher m = pattern.matcher(nativeQuery);
- for (int i = 0; i < nativeQuery.length();) {
- if (!m.find(i)) {
- parts.add(nativeQuery.substring(i));
- break;
- }
- if (m.start() != i) {
- parts.add(nativeQuery.substring(i, m.start()));
- }
- String match = m.group();
- int end = match.lastIndexOf('$');
- if ((end&0x1) == 1) {
- //escaped
- parts.add(match.substring((end+1)/2));
- } else {
- if (end != 0) {
- parts.add(match.substring(0, end/2));
- }
- parts.add(Integer.parseInt(match.substring(end + 1))-1);
- }
- i = m.end();
- }
- return parts;
- }
-
@Override
public void visit(Parameter obj) {
buffer.append(UNDEFINED_PARAM);
@@ -434,5 +395,4 @@
super.appendBaseName(obj);
}
-
}
Modified: trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties
===================================================================
--- trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-jdbc/src/main/resources/org/teiid/translator/jdbc/i18n.properties 2012-10-03 02:25:48 UTC (rev 4507)
@@ -26,8 +26,6 @@
TEIID11004=Error executing statement(s): {0}
-SQLConversionVisitor.invalid_parameter=Invalid parameter {0}. Must be between 1 and {1}.
-SQLConversionVisitor.not_in_parameter=Invalid parameter {0}. Native query procedures cannot use non IN parameters.
TEIID11003=Not using oracle execution payload {0} as hint, since it appears to contain more than just a single comment.
TEIID11002=Failed to report the JDBC driver and connection information
TEIID11006=Teiid runtime names, which are case insensitive, for the imported metadata are not unique. If not already set, use the setting importer.useFullSchemaName to create Teiid names that include the source schema.
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -33,6 +33,7 @@
import org.teiid.language.Call;
import org.teiid.language.Command;
import org.teiid.language.QueryExpression;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.MetadataFactory;
@@ -55,10 +56,10 @@
import org.teiid.translator.salesforce.execution.ProcedureExecutionParentImpl;
import org.teiid.translator.salesforce.execution.QueryExecutionImpl;
import org.teiid.translator.salesforce.execution.UpdateExecutionImpl;
+import org.teiid.translator.salesforce.execution.visitors.CriteriaVisitor;
@Translator(name="salesforce", description="A translator for Salesforce")
public class SalesForceExecutionFactory extends ExecutionFactory<ConnectionFactory, SalesforceConnection> {
-
private static final String SALESFORCE = "salesforce"; //$NON-NLS-1$
private static final String EXCLUDES = "excludes";//$NON-NLS-1$
private static final String INCLUDES = "includes";//$NON-NLS-1$
@@ -113,12 +114,30 @@
@Override
public ProcedureExecution createProcedureExecution(Call command,ExecutionContext executionContext, RuntimeMetadata metadata, SalesforceConnection connection)
throws TranslatorException {
+ Procedure metadataObject = command.getMetadataObject();
+ String nativeQuery = metadataObject.getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ if (nativeQuery.startsWith(DirectQueryExecution.SEARCH)) {
+ StringBuilder buffer = new StringBuilder();
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(nativeQuery, command.getArguments());
+ for (Object o : parts) {
+ if (o instanceof String) {
+ buffer.append(o);
+ } else {
+ Integer i = (Integer)o;
+ CriteriaVisitor.appendLiteralValue(buffer, command.getArguments().get(i).getArgumentValue());
+ }
+ }
+ nativeQuery = buffer.toString();
+ }
+ return new DirectQueryExecution(command.getArguments(), command, connection, metadata, executionContext, nativeQuery);
+ }
return new ProcedureExecutionParentImpl(command, connection, metadata, executionContext);
}
@Override
public ProcedureExecution createDirectExecution(List<Argument> arguments, Command command, ExecutionContext executionContext, RuntimeMetadata metadata, SalesforceConnection connection) throws TranslatorException {
- return new DirectQueryExecution(arguments, command, connection, metadata, executionContext);
+ return new DirectQueryExecution(arguments.subList(1, arguments.size()), command, connection, metadata, executionContext, (String)arguments.get(0).getArgumentValue().getValue());
}
@Override
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForcePlugin.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForcePlugin.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForcePlugin.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -45,7 +45,6 @@
public static enum Event implements BundleUtil.Event{
TEIID13001,
TEIID13002,
- TEIID13003,
TEIID13004,
TEIID13005,
}
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -39,6 +39,7 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.salesforce.SalesForcePlugin;
import org.teiid.translator.salesforce.SalesforceConnection;
+import org.teiid.translator.salesforce.Util;
import org.w3c.dom.Element;
import com.sforce.soap.partner.QueryResult;
@@ -46,33 +47,43 @@
public class DirectQueryExecution implements ProcedureExecution {
- private static final String DELETE_IDS = "ids"; //$NON-NLS-1$
+ public static final String SEARCH = "search;"; //$NON-NLS-1$
private static final String ATTRIBUTES = "attributes"; //$NON-NLS-1$
private static final String TYPE = "type"; //$NON-NLS-1$
private static final String ID = "id"; //$NON-NLS-1$
- private List<Argument> arguments;
- private Command command;
+ protected List<Argument> arguments;
+ protected Command command;
private SalesforceConnection connection;
- private RuntimeMetadata metadata;
+ protected RuntimeMetadata metadata;
private ExecutionContext context;
private QueryResult results;
private List<List<Object>> currentBatch;
private int updateCount = -1;
- private boolean updateQuery = false;
+ private boolean updateQuery = false;
+ private String query;
- public DirectQueryExecution(List<Argument> arguments, Command command, SalesforceConnection connection, RuntimeMetadata metadata, ExecutionContext context) {
+ /**
+ *
+ * @param arguments parameter arguments only
+ * @param command
+ * @param connection
+ * @param metadata
+ * @param context
+ * @param query
+ */
+ public DirectQueryExecution(List<Argument> arguments, Command command, SalesforceConnection connection, RuntimeMetadata metadata, ExecutionContext context, String query) {
this.arguments = arguments;
this.command = command;
this.connection = connection;
this.metadata = metadata;
this.context = context;
+ this.query = query;
}
@Override
public void execute() throws TranslatorException {
- String query = (String)this.arguments.get(0).getArgumentValue().getValue();
- if (query.startsWith("search;")) { //$NON-NLS-1$
+ if (query.startsWith(SEARCH)) {
doSelect(query.substring(7));
}
else if (query.startsWith("create;")) { //$NON-NLS-1$
@@ -82,16 +93,21 @@
doUpdate(query.substring(7));
}
else if (query.startsWith("delete;")) { //$NON-NLS-1$
- doDelete(query.substring(7));
+ doDelete();
}
else {
throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13002));
}
-
}
- private void doDelete(String query) throws TranslatorException {
- List<String> ids = getIds(query);
+ private void doDelete() throws TranslatorException {
+ List<String> ids = new ArrayList<String>();
+ for (Argument arg : arguments) {
+ Object val = arg.getArgumentValue().getValue();
+ if (val != null) {
+ ids.add(Util.stripQutes(val.toString()));
+ }
+ }
try {
this.updateCount = this.connection.delete(ids.toArray(new String[ids.size()]));
this.updateQuery = true;
@@ -100,8 +116,8 @@
}
}
- private void doUpdate(String query) throws TranslatorException {
- DataPayload payload = buildDataPlayload(query, this.arguments);
+ private void doUpdate(String update) throws TranslatorException {
+ DataPayload payload = buildDataPlayload(update);
try {
this.updateCount = this.connection.update(Arrays.asList(payload));
this.updateQuery = true;
@@ -110,8 +126,8 @@
}
}
- private void doInsert(String query) throws TranslatorException {
- DataPayload payload = buildDataPlayload(query, this.arguments);
+ private void doInsert(String insert) throws TranslatorException {
+ DataPayload payload = buildDataPlayload(insert);
try {
this.updateCount = this.connection.create(payload);
this.updateQuery = true;
@@ -120,9 +136,9 @@
}
}
- private void doSelect(String query) throws TranslatorException {
+ private void doSelect(String select) throws TranslatorException {
try {
- this.results = this.connection.query(query, this.context.getBatchSize(), Boolean.FALSE);
+ this.results = this.connection.query(select, this.context.getBatchSize(), Boolean.FALSE);
} catch (ResourceException e) {
throw new TranslatorException(e);
}
@@ -139,12 +155,12 @@
return row;
}
- private List<Object> getRow(QueryResult result) throws TranslatorException {
+ private List<?> getRow(QueryResult result) throws TranslatorException {
// for insert/update/delete clauses
if (this.updateQuery) {
if (this.updateCount != -1) {
- List updateResult = Arrays.asList(this.updateCount);
+ List<?> updateResult = Arrays.asList(this.updateCount);
this.updateCount = -1;
return updateResult;
}
@@ -203,36 +219,9 @@
@Override
public void cancel() throws TranslatorException {
}
-
- private ArrayList<String> getIds(String query) throws TranslatorException {
- StringTokenizer st = new StringTokenizer(query, ";"); //$NON-NLS-1$
- if (!st.hasMoreTokens()) {
- throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13003));
- }
- ArrayList<String> ids = new ArrayList<String>();
-
- while(st.hasMoreElements()) {
- String var = st.nextToken();
- int index = var.indexOf('=');
- if (index == -1) {
- continue;
- }
- String key = var.substring(0, index).trim().toLowerCase();
- String value = var.substring(index+1).trim();
-
- if (key.equalsIgnoreCase(DELETE_IDS)) {
- StringTokenizer attrTokens = new StringTokenizer(value, ","); //$NON-NLS-1$
- while (attrTokens.hasMoreElements()) {
- ids.add(attrTokens.nextToken());
- }
- }
- }
- return ids;
- }
-
- private DataPayload buildDataPlayload(String query, List<Argument> arguments) throws TranslatorException {
- StringTokenizer st = new StringTokenizer(query, ";"); //$NON-NLS-1$
+ private DataPayload buildDataPlayload(String update) throws TranslatorException {
+ StringTokenizer st = new StringTokenizer(update, ";"); //$NON-NLS-1$
if (!st.hasMoreTokens()) {
throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13004));
}
@@ -254,7 +243,7 @@
if (key.equalsIgnoreCase(ATTRIBUTES)) {
StringTokenizer attrTokens = new StringTokenizer(value, ","); //$NON-NLS-1$
- int attrCount = 1;
+ int attrCount = 0;
while(attrTokens.hasMoreElements()) {
String name = attrTokens.nextToken().trim();
if (arguments.size() <= attrCount) {
@@ -262,6 +251,10 @@
}
Argument argument = arguments.get(attrCount++);
Object anObj = argument.getArgumentValue().getValue();
+ if (anObj == null) {
+ continue;
+ }
+ anObj = Util.stripQutes(anObj.toString());
QName qname = new QName(name);
@SuppressWarnings( "unchecked" )
JAXBElement jbe = new JAXBElement( qname, String.class, anObj );
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -24,6 +24,7 @@
import java.util.List;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.language.Call;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.DataNotAvailableException;
@@ -82,7 +83,7 @@
} else if(GET_DELETED.equalsIgnoreCase(name)) {
execution = new GetDeletedExecutionImpl(this);
} else {
- throw new AssertionError("Unknown procedure " + getCommand().getProcedureName() + " with name in source " + getCommand().getMetadataObject().getNameInSource()); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TeiidRuntimeException("Unknown procedure " + getCommand().getProcedureName() + " with name in source " + name); //$NON-NLS-1$ //$NON-NLS-2$
}
execution.execute(this);
}
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/CriteriaVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/CriteriaVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/CriteriaVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -308,44 +308,15 @@
} else if (expr instanceof Literal) {
Literal literal = (Literal)expr;
if (literal.getValue() == null) {
- if (raw) {
- return null;
- }
- return "NULL"; //$NON-NLS-1$
+ if (raw) {
+ return null;
+ }
+ return "NULL"; //$NON-NLS-1$
}
- if (raw) {
- return literal.getValue().toString();
- }
- if (literal.getValue().getClass().equals(Boolean.class)) {
- result.append(((Boolean)literal.getValue()).toString());
- } else if (literal.getValue().getClass().equals(java.sql.Timestamp.class)) {
- Timestamp datetime = (java.sql.Timestamp)literal.getValue();
- String value = datetime.toString();
- int fractionalPlace = value.lastIndexOf('.');
- int fractionalLength = value.length() - fractionalPlace - 1;
- if (fractionalLength > 3) {
- value = value.substring(0, fractionalPlace + 3);
- } else if (fractionalLength < 3) {
- value += "00".substring(fractionalLength - 1); //$NON-NLS-1$
- }
- result.append(value).setCharAt(result.length()-value.length()+10, 'T');
- Calendar c = TimestampWithTimezone.getCalendar();
- c.setTime(datetime);
- int minutes = (c.get(Calendar.ZONE_OFFSET) +
- c.get(Calendar.DST_OFFSET)) / 60000;
- int val = minutes/60;
- result.append(String.format("%1$+03d", val)); //$NON-NLS-1$
- result.append(':');
- val = minutes%60;
- result.append(val/10);
- result.append(val%10);
- } else if (literal.getValue().getClass().equals(java.sql.Time.class)) {
- result.append(literal.getValue()).append(".000").append(Util.getDefaultTimeZoneString()); //$NON-NLS-1$
- } else if (literal.getValue().getClass().equals(java.sql.Date.class)) {
- result.append(literal.getValue());
- } else {
- result.append(expr.toString());
- }
+ if (raw) {
+ return literal.getValue().toString();
+ }
+ appendLiteralValue(result, literal);
} else if (expr instanceof AggregateFunction) {
appendAggregateFunction(result, (AggregateFunction)expr);
} else {
@@ -353,6 +324,39 @@
}
return result.toString();
}
+
+ public static void appendLiteralValue(StringBuilder result, Literal literal) {
+ if (literal.getValue().getClass().equals(Boolean.class)) {
+ result.append(((Boolean)literal.getValue()).toString());
+ } else if (literal.getValue().getClass().equals(java.sql.Timestamp.class)) {
+ Timestamp datetime = (java.sql.Timestamp)literal.getValue();
+ String value = datetime.toString();
+ int fractionalPlace = value.lastIndexOf('.');
+ int fractionalLength = value.length() - fractionalPlace - 1;
+ if (fractionalLength > 3) {
+ value = value.substring(0, fractionalPlace + 3);
+ } else if (fractionalLength < 3) {
+ value += "00".substring(fractionalLength - 1); //$NON-NLS-1$
+ }
+ result.append(value).setCharAt(result.length()-value.length()+10, 'T');
+ Calendar c = TimestampWithTimezone.getCalendar();
+ c.setTime(datetime);
+ int minutes = (c.get(Calendar.ZONE_OFFSET) +
+ c.get(Calendar.DST_OFFSET)) / 60000;
+ int val = minutes/60;
+ result.append(String.format("%1$+03d", val)); //$NON-NLS-1$
+ result.append(':');
+ val = minutes%60;
+ result.append(val/10);
+ result.append(val%10);
+ } else if (literal.getValue().getClass().equals(java.sql.Time.class)) {
+ result.append(literal.getValue()).append(".000").append(Util.getDefaultTimeZoneString()); //$NON-NLS-1$
+ } else if (literal.getValue().getClass().equals(java.sql.Date.class)) {
+ result.append(literal.getValue());
+ } else {
+ result.append(literal.toString());
+ }
+ }
protected void appendAggregateFunction(StringBuilder result,
AggregateFunction af) {
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/InsertVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/InsertVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/InsertVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -35,6 +35,7 @@
import org.teiid.metadata.Column;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.salesforce.Util;
public class InsertVisitor extends CriteriaVisitor {
@@ -69,7 +70,7 @@
Literal literalValue = (Literal)value;
val = literalValue.getValue().toString();
if(null != val && !val.isEmpty()) {
- val = this.stripQutes(val);
+ val = Util.stripQutes(val);
}
} else {
val = value.toString();
@@ -89,13 +90,5 @@
public List<JAXBElement> getMessageElements() {
return elements;
}
-
- private String stripQutes(String id) {
- if((id.startsWith("'") && id.endsWith("'"))) {
- id = id.substring(1,id.length()-1);
- } else if ((id.startsWith("\"") && id.endsWith("\""))) {
- id = id.substring(1,id.length()-1);
- }
- return id;
- }
+
}
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/JoinQueryVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -99,29 +99,17 @@
addSelect(rightTableInJoin.getNameInSource(), subselect, false);
subselect.append(SPACE);
- String nativeQuery = this.rightTableInJoin.getProperty(TEIID_NATIVE_QUERY, false);
- if (nativeQuery != null) {
- subselect.append(nativeQuery);
- }
- else {
- subselect.append(FROM).append(SPACE);
- subselect.append(rightTableInJoin.getNameInSource()).append('s');
- }
+ subselect.append(FROM).append(SPACE);
+ subselect.append(rightTableInJoin.getNameInSource()).append('s');
subselect.append(CLOSE).append(SPACE);
select.append(subselect);
- nativeQuery = this.leftTableInJoin.getProperty(TEIID_NATIVE_QUERY, false);
- if (nativeQuery != null) {
- select.append(nativeQuery);
- }
- else {
- select.append(FROM).append(SPACE);
- select.append(leftTableInJoin.getNameInSource()).append(SPACE);
- addCriteriaString(select);
- appendGroupByHaving(select);
- select.append(limitClause);
- }
+ select.append(FROM).append(SPACE);
+ select.append(leftTableInJoin.getNameInSource()).append(SPACE);
+ addCriteriaString(select);
+ appendGroupByHaving(select);
+ select.append(limitClause);
return select.toString();
}
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/visitors/SelectVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -150,18 +150,12 @@
addSelectSymbols(result);
result.append(SPACE);
- String nativeQuery = this.table.getProperty(TEIID_NATIVE_QUERY, false);
- if (nativeQuery != null) {
- result.append(nativeQuery);
- }
- else {
- result.append(FROM).append(SPACE);
- result.append(table.getNameInSource()).append(SPACE);
- addCriteriaString(result);
- appendGroupByHaving(result);
- //result.append(orderByClause).append(SPACE);
- result.append(limitClause);
- }
+ result.append(FROM).append(SPACE);
+ result.append(table.getNameInSource()).append(SPACE);
+ addCriteriaString(result);
+ appendGroupByHaving(result);
+ //result.append(orderByClause).append(SPACE);
+ result.append(limitClause);
return result.toString();
}
Modified: trunk/connectors/translator-salesforce/src/main/resources/org/teiid/translator/salesforce/i18n.properties
===================================================================
--- trunk/connectors/translator-salesforce/src/main/resources/org/teiid/translator/salesforce/i18n.properties 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/main/resources/org/teiid/translator/salesforce/i18n.properties 2012-10-03 02:25:48 UTC (rev 4507)
@@ -39,6 +39,5 @@
TEIID13001=Unknown type returned by SalesForce: {0}
TEIID13002=Unknown request; query must start with one of [search|create|update|delete]
-TEIID13003=The query is missing "id=x,y.." values.
TEIID13004=The query is missing type, id and attribute values.
TEIID13005=The attribute count does not match with the value parameters supplied.
\ No newline at end of file
Modified: trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/TestSalesForceDirectQueryExecution.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -21,9 +21,7 @@
*/
package org.teiid.translator.salesforce.execution;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
@@ -102,7 +100,7 @@
}
- @Test public void testWithoutMarker() throws Exception {
+ @Test(expected=TranslatorException.class) public void testWithoutMarker() throws Exception {
String input = "exec native('salesforce query')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
@@ -111,16 +109,12 @@
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
- try {
- DirectQueryExecution execution = (DirectQueryExecution)TRANSLATOR.createExecution(command, ec, rm, connection);
- execution.execute();
- fail("the above should have thrown exception");
- } catch (TranslatorException e) {
- }
+ DirectQueryExecution execution = (DirectQueryExecution)TRANSLATOR.createExecution(command, ec, rm, connection);
+ execution.execute();
}
@Test public void testDelete() throws Exception {
- String input = "exec native('delete;ids=id1,id2')";
+ String input = "exec native('delete;', 'id1','id2')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
@@ -192,7 +186,7 @@
assertArrayEquals(new Object[] {23}, (Object[])execution.next().get(0));
}
- @Test public void testCreateFail() throws Exception {
+ @Test(expected=TranslatorException.class) public void testCreateFail() throws Exception {
String input = "exec native('create;id=pk;type=table;attributes=one,two,three', 'one')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
@@ -201,11 +195,7 @@
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
- try {
- DirectQueryExecution execution = (DirectQueryExecution)TRANSLATOR.createExecution(command, ec, rm, connection);
- execution.execute();
- fail("should have failed because there are not enough values");
- } catch (TranslatorException e) {
- }
+ DirectQueryExecution execution = (DirectQueryExecution)TRANSLATOR.createExecution(command, ec, rm, connection);
+ execution.execute();
}
}
Modified: trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java
===================================================================
--- trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/connectors/translator-salesforce/src/test/java/org/teiid/translator/salesforce/execution/visitors/TestVisitors.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -35,7 +35,9 @@
import org.mockito.Mockito;
import org.teiid.cdk.api.TranslationUtility;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.language.Command;
import org.teiid.language.Select;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.Column;
import org.teiid.metadata.MetadataStore;
import org.teiid.metadata.Procedure;
@@ -49,9 +51,8 @@
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.unittest.RealMetadataFactory;
+import org.teiid.translator.Execution;
import org.teiid.translator.ExecutionContext;
-import org.teiid.translator.ResultSetExecution;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.salesforce.Constants;
import org.teiid.translator.salesforce.SalesForceExecutionFactory;
@@ -115,17 +116,6 @@
obj.setNameInSource(contactNameInSource[i]);
}
- Table nativeTable = RealMetadataFactory.createPhysicalGroup("Native", salesforceModel); //$NON-NLS-1$
- nativeTable.setNameInSource("Native"); //$NON-NLS-1$
- nativeTable.setProperty("Supports Query", Boolean.TRUE.toString()); //$NON-NLS-1$
- nativeTable.setProperty(SelectVisitor.TEIID_NATIVE_QUERY, "FROM MyTable WHERE Anything='goes'");
-
- List<Column> contactCols2 = RealMetadataFactory.createElements(nativeTable, elemNames, elemTypes);
- for(int i=0; i<2; i++) {
- Column obj = contactCols2.get(i);
- obj.setNameInSource(contactNameInSource[i]);
- }
-
List<ProcedureParameter> params = new LinkedList<ProcedureParameter>();
params.add(RealMetadataFactory.createParameter("type", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
params.add(RealMetadataFactory.createParameter("start", SPParameter.IN, TypeFacility.RUNTIME_NAMES.TIMESTAMP));
@@ -133,7 +123,14 @@
Procedure getUpdated = RealMetadataFactory.createStoredProcedure("GetUpdated", salesforceModel, params);
getUpdated.setResultSet(RealMetadataFactory.createResultSet("rs", new String[] {"updated"}, new String[] {TypeFacility.RUNTIME_NAMES.STRING}));
+
+ params = new LinkedList<ProcedureParameter>();
+ params.add(RealMetadataFactory.createParameter("x", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
+ Procedure nativeProc = RealMetadataFactory.createStoredProcedure("native", salesforceModel, params);
+ nativeProc.setProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, "search;select accountname from account where accountid = $1");
+ nativeProc.setResultSet(RealMetadataFactory.createResultSet("rs", new String[] {"accountname"}, new String[] {TypeFacility.RUNTIME_NAMES.STRING}));
+
return new TransformationMetadata(null, new CompositeMetadataStore(store), null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
@@ -269,7 +266,7 @@
}
private void helpTest(String sql, String expected) throws Exception {
- Select command = (Select)translationUtility.parseCommand(sql);
+ Command command = translationUtility.parseCommand(sql);
SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
@@ -278,7 +275,7 @@
ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(Mockito.mock(QueryResult.class));
- ResultSetExecution execution = factory.createResultSetExecution(command, ec, rm, connection);
+ Execution execution = factory.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
@@ -286,15 +283,10 @@
assertEquals(expected, queryArgument.getValue().trim());
}
- @Test public void testNativeQuery() throws Exception {
- String sql = "select name, accountid From Native";
- String source = "SELECT Native.ContactName, Native.AccountId FROM MyTable WHERE Anything='goes'";
+ @Test public void testNativeProc() throws Exception {
+ String sql = "exec native('1')";
+ String source = "select accountname from account where accountid = '1'";
helpTest(sql, source);
}
- @Test public void testNativeQueryWithJoin() throws Exception {
- String sql = "select n.name, n.accountid, a.industry From Native n left outer join Account a on n.ContactID = a.id";
- String expected = "SELECT Native.ContactName, Native.AccountId, (SELECT Account.Industry FROM Accounts) FROM MyTable WHERE Anything='goes'";
- helpTest(sql, expected);
- }
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2012-10-03 02:25:48 UTC (rev 4507)
@@ -32,41 +32,9 @@
import org.junit.Test;
import org.teiid.cdk.unittest.FakeTranslationFactory;
-import org.teiid.dqp.internal.datamgr.TestAggregateImpl;
-import org.teiid.dqp.internal.datamgr.TestCompareCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestDeleteImpl;
-import org.teiid.dqp.internal.datamgr.TestElementImpl;
-import org.teiid.dqp.internal.datamgr.TestExistsCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestFunctionImpl;
-import org.teiid.dqp.internal.datamgr.TestGroupByImpl;
-import org.teiid.dqp.internal.datamgr.TestGroupImpl;
-import org.teiid.dqp.internal.datamgr.TestInCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestInsertImpl;
-import org.teiid.dqp.internal.datamgr.TestIsNullCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestJoinImpl;
-import org.teiid.dqp.internal.datamgr.TestLikeCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestLiteralImpl;
-import org.teiid.dqp.internal.datamgr.TestNotCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestOrderByImpl;
-import org.teiid.dqp.internal.datamgr.TestProcedureImpl;
-import org.teiid.dqp.internal.datamgr.TestQueryImpl;
-import org.teiid.dqp.internal.datamgr.TestScalarSubqueryImpl;
-import org.teiid.dqp.internal.datamgr.TestSearchedCaseExpressionImpl;
-import org.teiid.dqp.internal.datamgr.TestSelectSymbolImpl;
-import org.teiid.dqp.internal.datamgr.TestSetQueryImpl;
-import org.teiid.dqp.internal.datamgr.TestSubqueryCompareCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestSubqueryInCriteriaImpl;
-import org.teiid.dqp.internal.datamgr.TestUpdateImpl;
-import org.teiid.dqp.internal.datamgr.TstLanguageBridgeFactory;
-import org.teiid.language.AggregateFunction;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Command;
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.language.Insert;
-import org.teiid.language.LanguageObject;
-import org.teiid.language.Literal;
-import org.teiid.language.Select;
+import org.teiid.dqp.internal.datamgr.*;
+import org.teiid.language.*;
+import org.teiid.language.Argument.Direction;
import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.RuntimeMetadata;
@@ -439,5 +407,17 @@
Command command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql, true, true);
assertEquals("SELECT trim('x' FROM g_0.StringKey) FROM SmallA AS g_0", command.toString()); //$NON-NLS-1$
}
+
+ @Test public void testNativeParsing() throws Exception {
+ String sql = "select $1 from $2";
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(sql, Arrays.asList(new Argument(Direction.IN, null, String.class, null), new Argument(Direction.IN, null, String.class, null)));
+ assertEquals(Arrays.asList((Object)"select ", 0, " from ", 1), parts);
+ }
+
+ @Test public void testNativeParsing1() throws Exception {
+ String sql = "select $$1 from $$$2";
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(sql, Arrays.asList(new Argument(Direction.IN, null, String.class, null), new Argument(Direction.IN, null, String.class, null)));
+ assertEquals(Arrays.asList((Object)"select ", "$1", " from ", "$", 1), parts);
+ }
}
12 years, 2 months
teiid SVN: r4506 - in trunk/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/oracle and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 22:15:04 -0400 (Tue, 02 Oct 2012)
New Revision: 4506
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
Log:
TEIID-2238 fixing native-query and non-prepared handling
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-02 17:00:38 UTC (rev 4505)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2012-10-03 02:15:04 UTC (rev 4506)
@@ -198,9 +198,11 @@
if (obj.getArguments().get(i).getDirection() != Direction.IN) {
throw new IllegalArgumentException(JDBCPlugin.Util.getString("SQLConversionVisitor.not_in_parameter", i+1)); //$NON-NLS-1$
}
- buffer.append('?');
if (this.prepared) {
+ buffer.append('?');
this.preparedValues = obj.getArguments();
+ } else {
+ this.visit(obj.getArguments().get(i).getArgumentValue());
}
}
}
@@ -219,7 +221,7 @@
Pattern pattern = Pattern.compile("\\$+\\d+"); //$NON-NLS-1$
List<Object> parts = new LinkedList<Object>();
Matcher m = pattern.matcher(nativeQuery);
- for (int i = 0; i < nativeQuery.length(); i++) {
+ for (int i = 0; i < nativeQuery.length();) {
if (!m.find(i)) {
parts.add(nativeQuery.substring(i));
break;
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-02 17:00:38 UTC (rev 4505)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleTranslator.java 2012-10-03 02:15:04 UTC (rev 4506)
@@ -799,6 +799,7 @@
DataTypeManager.DefaultDataTypes.STRING,
};
RealMetadataFactory.createElements(x, elemNames, elemTypes);
+
List<Column> cols = RealMetadataFactory.createElements(table, elemNames, elemTypes);
cols.get(1).setAutoIncremented(true);
cols.get(1).setNameInSource("ID:SEQUENCE=MYSEQUENCE.nextVal"); //$NON-NLS-1$
@@ -812,6 +813,11 @@
Procedure p = RealMetadataFactory.createStoredProcedure("proc", foo, Arrays.asList(in1));
p.setResultSet(rs3);
p.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select x from y where z = $1");
+
+ p = RealMetadataFactory.createStoredProcedure("proc1", foo, Arrays.asList(RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.STRING)));
+ p.setResultSet(RealMetadataFactory.createResultSet("proc.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER })); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select $1 from y");
+ p.setProperty(SQLConversionVisitor.TEIID_NON_PREPARED, "true");
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
return new TransformationMetadata(null, store, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
@@ -920,6 +926,15 @@
helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
}
+ @Test public void testNativeQueryProcNonPrepared() throws Exception {
+ String input = "call proc1('col')"; //$NON-NLS-1$
+ String output = "select 'col' from y"; //$NON-NLS-1$
+
+ QueryMetadataInterface metadata = getOracleSpecificMetadata();
+
+ helpTestVisitor(metadata, input, EMPTY_CONTEXT, null, output);
+ }
+
@Test public void testNativeQueryProcPreparedExecution() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Command command = commandBuilder.getCommand("call proc(2)");
12 years, 2 months
teiid SVN: r4505 - trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 13:00:38 -0400 (Tue, 02 Oct 2012)
New Revision: 4505
Modified:
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
Log:
TEIID-2210 refinements to the object translator. some projection is necessary. also adding to embedded
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-10-02 16:38:13 UTC (rev 4504)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-10-02 17:00:38 UTC (rev 4505)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.language.ColumnReference;
import org.teiid.language.Command;
import org.teiid.language.Comparison;
12 years, 2 months
teiid SVN: r4504 - in trunk: build/kits/jboss-as7/modules/org/jboss/teiid/translator/object/main and 13 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 12:38:13 -0400 (Tue, 02 Oct 2012)
New Revision: 4504
Removed:
trunk/connectors/translator-jpa/src/main/resources/META-INF/MANIFEST.MF
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/util/
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
trunk/connectors/translator-object/src/test/resources/BasicSearchTest/
Modified:
trunk/build/assembly/embedded-dist.xml
trunk/build/kits/jboss-as7/modules/org/jboss/teiid/translator/object/main/module.xml
trunk/connectors/translator-jpa/pom.xml
trunk/connectors/translator-object/pom.xml
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheConnection.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
Log:
TEIID-2210 refinements to the object translator. some projection is necessary. also adding to embedded
Modified: trunk/build/assembly/embedded-dist.xml
===================================================================
--- trunk/build/assembly/embedded-dist.xml 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/build/assembly/embedded-dist.xml 2012-10-02 16:38:13 UTC (rev 4504)
@@ -89,6 +89,7 @@
<include>org.jboss.teiid.connectors:translator-olap</include>
<include>org.jboss.teiid.connectors:translator-hive</include>
<include>org.jboss.teiid.connectors:translator-jpa</include>
+ <include>org.jboss.teiid.connectors:translator-object</include>
</includes>
<binaries>
Modified: trunk/build/kits/jboss-as7/modules/org/jboss/teiid/translator/object/main/module.xml
===================================================================
--- trunk/build/kits/jboss-as7/modules/org/jboss/teiid/translator/object/main/module.xml 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/build/kits/jboss-as7/modules/org/jboss/teiid/translator/object/main/module.xml 2012-10-02 16:38:13 UTC (rev 4504)
@@ -10,6 +10,7 @@
<module name="javax.resource.api"/>
<module name="org.jboss.teiid.common-core" />
<module name="org.jboss.teiid.api" />
+ <module name="org.jboss.teiid" />
<module name="javax.persistence.api"/>
<module name="org.hibernate"/>
<module name="org.infinispan"/>
Modified: trunk/connectors/translator-jpa/pom.xml
===================================================================
--- trunk/connectors/translator-jpa/pom.xml 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-jpa/pom.xml 2012-10-02 16:38:13 UTC (rev 4504)
@@ -52,18 +52,6 @@
</dependencies>
<build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
- </archive>
- </configuration>
- </plugin>
- </plugins>
-
<outputDirectory>target/classes</outputDirectory>
<resources>
<resource>
Deleted: trunk/connectors/translator-jpa/src/main/resources/META-INF/MANIFEST.MF
===================================================================
--- trunk/connectors/translator-jpa/src/main/resources/META-INF/MANIFEST.MF 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-jpa/src/main/resources/META-INF/MANIFEST.MF 2012-10-02 16:38:13 UTC (rev 4504)
@@ -1 +0,0 @@
-Dependencies: org.hibernate,org.jboss.teiid.translator.jdbc
Modified: trunk/connectors/translator-object/pom.xml
===================================================================
--- trunk/connectors/translator-object/pom.xml 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/pom.xml 2012-10-02 16:38:13 UTC (rev 4504)
@@ -27,22 +27,28 @@
<artifactId>teiid-common-core</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- TODO: could put teiidscript in api -->
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-engine</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-client</artifactId>
<type>test-jar</type>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-metadata</artifactId>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
<artifactId>teiid-metadata</artifactId>
<type>test-jar</type>
- <scope>provided</scope>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>javax.resource</groupId>
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/ObjectExecution.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -27,10 +27,19 @@
import java.util.Iterator;
import java.util.List;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptException;
+import javax.script.SimpleScriptContext;
+
+import org.teiid.language.ColumnReference;
+import org.teiid.language.DerivedColumn;
import org.teiid.language.Select;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.query.eval.TeiidScriptEngine;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ResultSetExecution;
import org.teiid.translator.TranslatorException;
@@ -40,15 +49,32 @@
*/
public class ObjectExecution implements ResultSetExecution {
+ private static final String OBJECT_NAME = "o"; //$NON-NLS-1$
private Select query;
private ObjectConnection connection;
-
+ private ArrayList<CompiledScript> projects;
+ private ScriptContext sc = new SimpleScriptContext();
+ private static TeiidScriptEngine scriptEngine = new TeiidScriptEngine();
private Iterator<Object> resultsIt = null;
public ObjectExecution(Select query, RuntimeMetadata metadata,
- ObjectExecutionFactory factory, ObjectConnection connection) {
+ ObjectExecutionFactory factory, ObjectConnection connection) throws TranslatorException {
this.query = query;
this.connection = connection;
+ projects = new ArrayList<CompiledScript>(query.getDerivedColumns().size());
+ for (DerivedColumn dc : query.getDerivedColumns()) {
+ Column c = ((ColumnReference) dc.getExpression()).getMetadataObject();
+ String name = getNameInSourceFromColumn(c);
+ if (name.equalsIgnoreCase("this")) { //$NON-NLS-1$
+ projects.add(null);
+ } else {
+ try {
+ projects.add(scriptEngine.compile(OBJECT_NAME + "." + name)); //$NON-NLS-1$
+ } catch (ScriptException e) {
+ throw new TranslatorException(e);
+ }
+ }
+ }
}
@Override
@@ -90,8 +116,20 @@
DataNotAvailableException {
// create and return one row at a time for your resultset.
if (resultsIt.hasNext()) {
- List<Object> r = new ArrayList<Object>(1);
- r.add(resultsIt.next());
+ List<Object> r = new ArrayList<Object>(projects.size());
+ Object o = resultsIt.next();
+ sc.setAttribute(OBJECT_NAME, o, ScriptContext.ENGINE_SCOPE);
+ for (CompiledScript cs : this.projects) {
+ if (cs == null) {
+ r.add(o);
+ continue;
+ }
+ try {
+ r.add(cs.eval(sc));
+ } catch (ScriptException e) {
+ throw new TranslatorException(e);
+ }
+ }
return r;
}
return null;
@@ -107,5 +145,13 @@
@Override
public void cancel() throws TranslatorException {
}
+
+ public static String getNameInSourceFromColumn(Column c) {
+ String name = c.getNameInSource();
+ if (name == null || name.trim().isEmpty()) {
+ return c.getName();
+ }
+ return name;
+ }
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanBaseExecutionFactory.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -146,8 +146,8 @@
this.configurationFileName = configurationFileName;
}
- public BasicCache<String, Object> getCache() throws TranslatorException {
- BasicCache<String, Object> cache = null;
+ public BasicCache<Object, Object> getCache() throws TranslatorException {
+ BasicCache<Object, Object> cache = null;
BasicCacheContainer container = getCacheContainer();
if (getCacheName() != null) {
cache = container.getCache(getCacheName());
@@ -188,4 +188,9 @@
public boolean supportsOrCriteria() {
return isFullTextSearchingSupported();
}
+
+ @Override
+ public boolean supportsCompareCriteriaOrdered() {
+ return isFullTextSearchingSupported();
+ }
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/InfinispanConnectionImpl.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -95,11 +95,9 @@
return SearchByKey.performSearch(command, this);
}
- public BasicCache<String, Object> getCache()
+ public BasicCache<Object, Object> getCache()
throws TranslatorException {
return factory.getCache();
-
}
-
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/LuceneSearch.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -36,6 +36,7 @@
import org.teiid.logging.LogManager;
import org.teiid.metadata.Column;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectExecution;
import org.teiid.translator.object.ObjectPlugin;
import org.teiid.translator.object.infinispan.InfinispanConnectionImpl;
@@ -328,7 +329,7 @@
private static Query createEqualsQuery(Column column, Object value, boolean and,
boolean not, BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder) {
Query queryKey = queryBuilder.keyword()
- .onField(getNameInSourceFromColumn(column))
+ .onField(ObjectExecution.getNameInSourceFromColumn(column))
// .matching(value.toString() + "*")
.matching(value.toString()).createQuery();
@@ -346,7 +347,7 @@
BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder) {
Query queryKey = queryBuilder.range()
- .onField(getNameInSourceFromColumn(column))
+ .onField(ObjectExecution.getNameInSourceFromColumn(column))
.above(value.toString()).excludeLimit().createQuery();
junction.must(queryKey);
return queryKey;
@@ -356,7 +357,7 @@
BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder) {
Query queryKey = queryBuilder.range()
- .onField(getNameInSourceFromColumn(column))
+ .onField(ObjectExecution.getNameInSourceFromColumn(column))
.below(value.toString()).excludeLimit().createQuery();
junction.must(queryKey);
return queryKey;
@@ -365,18 +366,10 @@
private static Query createLikeQuery(Column column, String value,
BooleanJunction<BooleanJunction> junction, QueryBuilder queryBuilder) {
Query queryKey = queryBuilder.phrase()
- .onField(getNameInSourceFromColumn(column)).sentence(value)
+ .onField(ObjectExecution.getNameInSourceFromColumn(column)).sentence(value)
.createQuery();
junction.should(queryKey);
return queryKey;
}
- private static String getNameInSourceFromColumn(Column c) {
- String name = c.getNameInSource();
- if (name == null || name.trim().equals("")) { //$NON-NLS-1$
- return c.getName();
- }
- return name;
- }
-
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/infinispan/search/SearchByKey.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -34,6 +34,7 @@
import org.infinispan.client.hotrod.RemoteCache;
import org.teiid.language.Select;
import org.teiid.translator.TranslatorException;
+import org.teiid.translator.object.ObjectPlugin;
import org.teiid.translator.object.infinispan.InfinispanConnectionImpl;
import org.teiid.translator.object.search.BasicKeySearchCriteria;
import org.teiid.translator.object.search.SearchCriterion;
@@ -47,7 +48,7 @@
public static List<Object> performSearch(Select command, InfinispanConnectionImpl connection)
throws TranslatorException {
- BasicCache<String, Object> cache = connection.getCache();
+ BasicCache<Object, Object> cache = connection.getCache();
BasicKeySearchCriteria bksc = BasicKeySearchCriteria.getInstance(
connection.getFactory(), command);
@@ -55,18 +56,18 @@
}
- private static List<Object> get(SearchCriterion criterion,
- BasicCache<String, Object> cache, Class<?> rootClass)
+ public static List<Object> get(SearchCriterion criterion,
+ Map<?, ?> cache, Class<?> rootClass)
throws TranslatorException {
List<Object> results = null;
if (criterion.getOperator() == SearchCriterion.Operator.ALL) {
- Map<String, Object> map = cache;
+ Map<?, ?> map = cache;
if (cache instanceof RemoteCache<?, ?>) {
RemoteCache<?, ?> rc = (RemoteCache<?, ?>) cache;
- map = (Map<String, Object>) rc.getBulk();
+ map = (Map<Object, Object>) rc.getBulk();
}
- Set<String> keys = map.keySet();
+ Set<?> keys = map.keySet();
results = new ArrayList<Object>();
for (Iterator<?> it = keys.iterator(); it.hasNext();) {
Object v = cache.get(it.next());
@@ -87,8 +88,7 @@
Object value = criterion.getValue();
- Object v = cache.get(value instanceof String ? value : value
- .toString());
+ Object v = cache.get(value);
if (v != null) {
addValue(v, results, rootClass);
}
@@ -98,8 +98,7 @@
for (Iterator<Object> it = parms.iterator(); it.hasNext();) {
Object arg = it.next();
// the key is only supported in string format
- Object v = cache.get(arg instanceof String ? arg : arg
- .toString());
+ Object v = cache.get(arg);
if (v != null) {
addValue(v, results, rootClass);
}
@@ -111,29 +110,40 @@
}
- private static void addValue(Object value, List<Object> results, Class<?> rootNodeType) {
- if (value != null && value.getClass().equals(rootNodeType)) {
+ private static void addValue(Object value, List<Object> results, Class<?> rootNodeType) throws TranslatorException {
+ if (value == null) {
+ return;
+ }
+ if (!value.getClass().equals(rootNodeType)) {
+ // the object obtained from the cache has to be of the same root
+ // class type, otherwise, the modeling
+ // structure won't correspond correctly
+ String msg = ObjectPlugin.Util.getString(
+ "MapCacheConnection.unexpectedObjectTypeInCache",
+ new Object[] { value.getClass().getName(),
+ rootNodeType.getName() });
- if (value.getClass().isArray()) {
- List<Object> listRows = Arrays.asList((Object[]) value);
- results.addAll(listRows);
- return;
- }
+ throw new TranslatorException(msg);
+ }
+
+ if (value.getClass().isArray()) {
+ List<Object> listRows = Arrays.asList((Object[]) value);
+ results.addAll(listRows);
+ return;
+ }
- if (value instanceof Collection<?>) {
- results.addAll((Collection<?>) value);
- return;
- }
+ if (value instanceof Collection<?>) {
+ results.addAll((Collection<?>) value);
+ return;
+ }
- if (value instanceof Map<?, ?>) {
- Map<?, ?> mapRows = (Map<?, ?>) value;
- results.addAll(mapRows.values());
- return;
- }
-
- results.add(value);
+ if (value instanceof Map<?, ?>) {
+ Map<?, ?> mapRows = (Map<?, ?>) value;
+ results.addAll(mapRows.values());
+ return;
}
+ results.add(value);
}
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheConnection.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheConnection.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheConnection.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,12 +21,7 @@
*/
package org.teiid.translator.object.mapcache;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import javax.resource.ResourceException;
@@ -34,9 +29,8 @@
import org.teiid.resource.spi.BasicConnection;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.ObjectConnection;
-import org.teiid.translator.object.ObjectPlugin;
+import org.teiid.translator.object.infinispan.search.SearchByKey;
import org.teiid.translator.object.search.BasicKeySearchCriteria;
-import org.teiid.translator.object.search.SearchCriterion;
/**
* The MapCacheConnection provides simple key searches of the cache.
@@ -74,94 +68,8 @@
}
public List<Object> performSearch(Select command) throws TranslatorException {
-
visitor = BasicKeySearchCriteria.getInstance(factory,command);
-
- return get(visitor.getCriterion(), factory.getCache(), factory.getRootClass());
+ return SearchByKey.get(visitor.getCriterion(), factory.getCache(), factory.getRootClass());
}
- private List<Object> get(SearchCriterion criterion, Map<?, ?> cache,
- Class<?> rootClass) throws TranslatorException {
- List<Object> results = null;
- if (criterion.getOperator() == SearchCriterion.Operator.ALL) {
- results = new ArrayList<Object>();
- for (Iterator<?> it = cache.keySet().iterator(); it.hasNext();) {
- Object v = cache.get(it.next());
- addValue(v, results, rootClass);
-
- }
-
- return results;
- }
-
- if (criterion.getCriterion() != null) {
- results = get(criterion.getCriterion(), cache, rootClass);
- }
-
- if (results == null) {
- results = new ArrayList<Object>();
- }
-
- if (criterion.getOperator().equals(SearchCriterion.Operator.EQUALS)) {
-
- Object v = cache.get(criterion.getValue());
- if (v != null) {
- addValue(v, results, rootClass);
- }
- } else if (criterion.getOperator().equals(SearchCriterion.Operator.IN)) {
-
- List<?> parms = (List<?>) criterion.getValue();
- for (Iterator<?> it = parms.iterator(); it.hasNext();) {
- Object arg = it.next();
- Object v = cache.get(arg);
- if (v != null) {
- addValue(v, results, rootClass);
- }
- }
-
- }
-
- return results;
-
- }
-
- private void addValue(Object value, List<Object> results, Class<?> rootClass)
- throws TranslatorException {
- // can only add objects of the same root class in the cache
- if (value != null) {
- if (value.getClass().equals(rootClass)) {
-
- if (value.getClass().isArray()) {
- List<Object> listRows = Arrays.asList((Object[]) value);
- results.addAll(listRows);
- return;
- }
-
- if (value instanceof Collection) {
- results.addAll((Collection<?>) value);
- return;
- }
-
- if (value instanceof Map) {
- Map<?, ?> mapRows = (Map<?, ?>) value;
- results.addAll(mapRows.values());
- return;
- }
-
- results.add(value);
- } else {
- // the object obtained from the cache has to be of the same root
- // class type, otherwise, the modeling
- // structure won't correspond correctly
- String msg = ObjectPlugin.Util.getString(
- "MapCacheConnection.unexpectedObjectTypeInCache",
- new Object[] { value.getClass().getName(),
- rootClass.getName() });
-
- throw new TranslatorException(msg);
- }
- }
-
- }
-
}
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/mapcache/MapCacheExecutionFactory.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -66,28 +66,30 @@
}
- protected synchronized Map<?,?> getCache() throws TranslatorException {
- if (this.cache != null) return this.cache;
-
- Object object = findCacheUsingJNDIName();
-
- if (object instanceof Map<?,?>) {
-
- cache = (Map<?,?>)object;
-
- LogManager.logInfo(LogConstants.CTX_CONNECTOR, "=== Using CacheManager (obtained from JNDI ==="); //$NON-NLS-1$
+ protected Map<?,?> getCache() throws TranslatorException {
+ if (this.cache == null) {
+ synchronized (this) {
+ if (this.cache != null) {
+ return cache;
+ }
+ Object object = findCacheUsingJNDIName();
+
+ if (object instanceof Map<?,?>) {
+
+ cache = (Map<?,?>)object;
+
+ LogManager.logInfo(LogConstants.CTX_CONNECTOR, "=== Using CacheManager (obtained from JNDI ==="); //$NON-NLS-1$
- } else {
- String msg = ObjectPlugin.Util.getString(
- "MapCacheExecutionFactory.unexpectedCacheType", //$NON-NLS-1$
- new Object[] { (object == null ? "nullObject" : object.getClass().getName()), "Map" }); //$NON-NLS-1$ //$NON-NLS-2$
- throw new TranslatorException(msg);
- }
-
- return this.cache;
+ } else {
+ String msg = ObjectPlugin.Util.getString(
+ "MapCacheExecutionFactory.unexpectedCacheType", //$NON-NLS-1$
+ new Object[] { (object == null ? "nullObject" : object.getClass().getName()), "Map" }); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TranslatorException(msg);
+ }
+ }
+ }
+ return this.cache;
}
-
-
@Override
public ObjectConnection getConnection(ConnectionFactory factory,
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/BasicKeySearchCriteria.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -133,15 +133,8 @@
}
private void addSearchCriterion(SearchCriterion searchCriteria) {
- // only searching on primary key is part of the criteria sent for cache
- // lookup
- // all other criteria will be used to filter the rows
- assert (searchCriteria.getTableName() != null);
-
- assert (searchCriteria.getField() != null);
-
if (this.criterion != null) {
- throw new AssertionError("There should not be more than one predicate against the primary key"); //$NON-NLS-1$
+ throw new TeiidRuntimeException("There should not be more than one predicate against the primary key"); //$NON-NLS-1$
}
this.criterion = searchCriteria;
Modified: trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java
===================================================================
--- trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/main/java/org/teiid/translator/object/search/SearchCriterion.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -72,10 +72,6 @@
throw new AssertionError();
}
- public String getField() {
- return getNameInSourceFromColumn(this.column);
- }
-
public Object getValue() {
return value;
}
@@ -123,12 +119,4 @@
return this.isAnd;
}
- private String getNameInSourceFromColumn(Column c) {
- String name = c.getNameInSource();
- if (name == null || name.equals("")) { //$NON-NLS-1$
- return c.getName();
- }
- return name;
- }
-
}
Deleted: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BaseObjectTest.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -1,217 +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 org.teiid.translator.object;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.teiid.core.util.UnitTestUtil;
-import org.teiid.jdbc.util.ResultSetUtil;
-
-
-/**
- * Base Testing class that's extended to reuse the reading/writing/comparing expected results
- *
- */
-public abstract class BaseObjectTest {
-
- protected static boolean REPLACE_EXPECTED = false;
- protected static boolean WRITE_ACTUAL_RESULTS_TO_FILE = false;
- protected static boolean PRINT_RESULTSETS_TO_CONSOLE = false;
-
- private static final int MAX_COL_WIDTH = 65;
-
- protected static boolean print = false;
-
- public void compareResultSet(ResultSet... rs) throws IOException, SQLException {
-
- StackTraceElement ste = new Exception().getStackTrace()[1];
- String testName = ste.getMethodName();
- String className = this.getClass().getName();
- //ste.getClassName();
- className = className.substring(className.lastIndexOf('.') + 1);
- testName = className + "/" + testName; //$NON-NLS-1$
- compareResultSet(testName, rs);
- }
-
- public void compareResultSet(String testName, ResultSet... rs)
- throws FileNotFoundException, SQLException, IOException {
- FileOutputStream actualOut = null;
- BufferedReader expectedIn = null;
- PrintStream stream = null;
- try {
- if (REPLACE_EXPECTED) {
- File actual = new File(UnitTestUtil.getTestDataPath() + "/" +testName+".expected"); //$NON-NLS-1$ //$NON-NLS-2$
- actualOut = new FileOutputStream(actual);
- } else {
- if (WRITE_ACTUAL_RESULTS_TO_FILE) {
- File actual = new File(UnitTestUtil.getTestDataPath() + "/" +testName+".actual"); //$NON-NLS-1$ //$NON-NLS-2$
- if (!actual.getParentFile().exists()) {
- actual.getParentFile().mkdir();
- }
- actualOut = new FileOutputStream(actual);
-
-
- } else {
- File expected = new File(UnitTestUtil.getTestDataPath() + "/"+testName+".expected"); //$NON-NLS-1$ //$NON-NLS-2$
- expectedIn = new BufferedReader(new FileReader(expected));
- }
-
-
- }
- PrintStream defaultStream = null;
- if (PRINT_RESULTSETS_TO_CONSOLE) {
- defaultStream = new PrintStream(System.out) {
- // SYS.out should be protected from being closed.
- public void close() {}
- };
- }
- stream = ResultSetUtil.getPrintStream(actualOut, expectedIn, defaultStream);
- for (int i = 0; i < rs.length; i++) {
- ResultSetUtil.printResultSet(rs[i], MAX_COL_WIDTH, true, stream);
- }
- assertEquals("Actual data did not match expected", //$NON-NLS-1$
- Collections.EMPTY_LIST,
- ResultSetUtil.getUnequalLines(stream));
- } finally {
- if (stream != null) {
- stream.close();
- }
- if (actualOut != null) {
- actualOut.close();
- }
- if (expectedIn != null) {
- expectedIn.close();
- }
- }
- }
-
- public void compareResultSet(List<Object> rs) throws IOException, SQLException {
- StackTraceElement ste = new Exception().getStackTrace()[1];
- String testName = ste.getMethodName();
- String className = ste.getClassName();
- className = className.substring(className.lastIndexOf('.') + 1);
- testName = className + "/" + testName; //$NON-NLS-1$
- compareResultSet(testName, rs);
- }
-
-
- public void compareResultSet(String testName, List<Object> rs)
- throws FileNotFoundException, SQLException, IOException {
- FileOutputStream actualOut = null;
- BufferedReader expectedIn = null;
- PrintStream stream = null;
- try {
- if (REPLACE_EXPECTED) {
- File actual = new File(UnitTestUtil.getTestDataPath()
- + "/" + testName + ".expected"); //$NON-NLS-1$ //$NON-NLS-2$
- actualOut = new FileOutputStream(actual);
- } else {
- if (WRITE_ACTUAL_RESULTS_TO_FILE) {
- File actual = new File(UnitTestUtil.getTestDataPath()
- + "/" + testName + ".actual"); //$NON-NLS-1$ //$NON-NLS-2$
- if (!actual.getParentFile().exists()) {
- actual.getParentFile().mkdir();
- }
- actualOut = new FileOutputStream(actual);
-
-// ObjectOutput oo = null;
-// oo = new ObjectOutputStream(actualOut);
-
- for (int i = 0; i < rs.size(); i++) {
- List<Object> r = (List) rs.get(i);
- actualOut.write( new String("ROW_" + i).getBytes());
- for (Iterator it=r.iterator(); it.hasNext();) {
- Object o = it.next();
- actualOut.write( o.toString().getBytes());
- actualOut.write( new String("\t").getBytes());
- }
- //ExternalizeUtil.writeList(oo, rs[i]);
- }
-
- return;
-
-
- } else {
- File expected = new File(UnitTestUtil.getTestDataPath()
- + "/" + testName + ".expected"); //$NON-NLS-1$ //$NON-NLS-2$
- expectedIn = new BufferedReader(new FileReader(expected));
- }
-
- }
- PrintStream defaultStream = null;
- if (PRINT_RESULTSETS_TO_CONSOLE) {
- defaultStream = new PrintStream(System.out) {
- // SYS.out should be protected from being closed.
- public void close() {
- }
- };
- }
- stream = ResultSetUtil.getPrintStream(actualOut, expectedIn,
- defaultStream);
-// for (int i = 0; i < rs.length; i++) {
-// ResultSetUtil.printResultSet(rs[i], MAX_COL_WIDTH, true, stream);
-// }
- assertEquals(
- "Actual data did not match expected", //$NON-NLS-1$
- Collections.EMPTY_LIST,
- ResultSetUtil.getUnequalLines(stream));
- } finally {
- if (stream != null) {
- stream.close();
- }
- if (actualOut != null) {
- actualOut.close();
- }
- if (expectedIn != null) {
- expectedIn.close();
- }
- }
- }
-
- protected void printRow(int rownum, List<?> row) {
- if (!print) return;
- if (row == null) {
- System.out.println("Row " + rownum + " is null");
- return;
- }
- int i = 0;
- for(Object o:row) {
- System.out.println("Row " + rownum + " Col " + i + " - " + o.toString());
- ++i;
- }
-
- }
-
-}
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/BasicSearchTest.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,6 +21,9 @@
*/
package org.teiid.translator.object;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
@@ -33,71 +36,59 @@
* @author vhalbert
*
*/
-
-@SuppressWarnings("nls")
-public abstract class BasicSearchTest extends BaseObjectTest {
+public abstract class BasicSearchTest {
@Test public void testQueryGetAllTrades() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select * From Trade_Object.Trade as T"); //$NON-NLS-1$
- List<Object> rows = performTest(command, TradesCacheSource.NUMTRADES);
+ performTest(command, TradesCacheSource.NUMTRADES);
- compareResultSet(rows);
-
}
- @Test public void testQueryGetAllTradesAndLegs() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T, Trade_Object.Leg as L Where T.TradeId = L.TradeId"); //$NON-NLS-1$
+ @Test public void testTradeProjection() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId From Trade_Object.Trade as T"); //$NON-NLS-1$
- List<Object> rows = performTest(command, TradesCacheSource.NUMTRADES);
+ performTest(command, TradesCacheSource.NUMTRADES);
- compareResultSet(rows);
-
}
- @Test public void testQueryGetAllTradesLegsAndTransactions() throws Exception {
-
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName, L.Name as LegName, " +
- " N.LineItem " +
- " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction as N " +
- " Where T.TradeId = L.TradeId and L.LegId = N.LegId "); //$NON-NLS-1$
-
- List<Object> rows = performTest(command, TradesCacheSource.NUMTRADES);
-
- compareResultSet(rows);
-
- }
-
-
@Test public void testQueryGetOneTrade() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId = '1'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 1);
+ performTest(command, 1);
- compareResultSet(rows);
+ }
+
+ @Test public void testQueryInCriteria() throws Exception {
+ Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId in ('1', '3')"); //$NON-NLS-1$
+
+ performTest(command, 2);
}
- @Test public void testQueryGetOneTradeAndLegs() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T, Trade_Object.Leg as L Where T.TradeId = L.TradeId and T.TradeId = '1'"); //$NON-NLS-1$
+ protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+
+ ObjectExecution exec = createExecution(command);
- List<Object> rows = performTest(command, 1);
+ exec.execute();
- compareResultSet(rows);
+ List<Object> rows = new ArrayList<Object>();
- }
+ int cnt = 0;
+ List<Object> row = exec.next();
-
- @Test public void testQueryInCriteria() throws Exception {
- Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId in ('1', '3')"); //$NON-NLS-1$
-
- List<Object> rows = performTest(command, 2);
+ while (row != null) {
+ rows.add(row);
+ ++cnt;
+ row = exec.next();
+ }
- compareResultSet(rows);
+ assertEquals("Did not get expected number of rows", rowcnt, cnt); //$NON-NLS-1$
- }
-
- protected abstract List<Object> performTest(Select command, int rowcnt) throws Exception;
+ exec.close();
+ return rows;
+ }
+ protected abstract ObjectExecution createExecution(Select command) throws Exception;
-}
+}
\ No newline at end of file
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/TestObjectExecution.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,9 +21,9 @@
*/
package org.teiid.translator.object;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
import java.util.List;
@@ -64,23 +64,9 @@
@Test public void testQueryRootObject() throws Exception {
- execute( createExecution("select * From Trade_Object.Trade"), 3, 1);
+ execute( createExecution("select * From Trade_Object.Trade"), 3, 4);
}
- @Test public void testQueryIncludeLegs() throws Exception {
- execute( createExecution("select T.TradeId, T.Name as TradeName, L.Name as LegName From Trade_Object.Trade as T, Trade_Object.Leg as L Where T.TradeId = L.TradeId"),
- 3, 1);
-
- }
-
- @Test public void testQueryGetAllTransactions() throws Exception {
- execute( createExecution("select T.TradeId, T.Name as TradeName, L.Name as LegName, " +
- " N.LineItem " +
- " From Trade_Object.Trade as T, Trade_Object.Leg as L, Trade_Object.Transaction N " +
- " Where T.TradeId = L.TradeId and L.LegId = N.LegId"),3, 1);
- }
-
-
@Test public void testAtomicSelects() throws Exception {
Thread[] threads = new Thread[20];
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanConfigFileKeySearch.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,18 +21,14 @@
*/
package org.teiid.translator.object.infinispan;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.*;
-import java.util.ArrayList;
-import java.util.List;
-
import org.junit.BeforeClass;
import org.teiid.language.Select;
import org.teiid.translator.ExecutionContext;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.BasicSearchTest;
import org.teiid.translator.object.ObjectExecution;
-import org.teiid.translator.object.infinispan.search.SearchByKey;
import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
@@ -63,31 +59,10 @@
}
-
@Override
- protected List<Object> performTest(Select command, int rowcnt) throws Exception {
-
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
-
- exec.execute();
-
- List<Object> rows = new ArrayList<Object>();
-
- int cnt = 0;
- List<Object> row = exec.next();
-
- while (row != null) {
- rows.add(row);
- ++cnt;
- row = exec.next();
- }
-
- assertEquals("Did not get expected number of rows", rowcnt, cnt); //$NON-NLS-1$
-
- exec.close();
- return rows;
+ protected ObjectExecution createExecution(Select command) throws TranslatorException {
+ return (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
}
-
}
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiILuceneSearch.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,12 +21,8 @@
*/
package org.teiid.translator.object.infinispan;
-import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
-import java.util.ArrayList;
-import java.util.List;
-
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.Before;
@@ -78,98 +74,55 @@
}
@Override
- protected List<Object> performTest(Select command, int rowcnt) throws Exception {
-
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
-
- exec.execute();
-
- List<Object> rows = new ArrayList<Object>();
-
- int cnt = 0;
- List<Object> row = exec.next();
-
- while (row != null) {
- rows.add(row);
- ++cnt;
- row = exec.next();
- }
-
- assertEquals("Did not get expected number of rows", rowcnt, cnt); //$NON-NLS-1$
-
- exec.close();
- return rows;
+ protected ObjectExecution createExecution(Select command) throws TranslatorException {
+ return (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
}
@Test public void testQueryLikeCriteria1() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name From Trade_Object.Trade as T WHERE T.Name like 'TradeName%'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 3);
-
- compareResultSet(rows);
-
+ performTest(command, 3);
}
@Test public void testQueryLikeCriteria2() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name From Trade_Object.Trade as T WHERE T.Name like 'TradeName 2%'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 1);
-
- compareResultSet(rows);
-
+ performTest(command, 1);
}
@Test public void testQueryCompareEQBoolean() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name, T.Settled From Trade_Object.Trade as T WHERE T.Settled = 'false'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 2);
-
- compareResultSet(rows);
-
+ performTest(command, 2);
}
@Test public void testQueryCompareNEBoolean() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name, T.Settled From Trade_Object.Trade as T WHERE T.Settled <> 'false'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 1);
-
- compareResultSet(rows);
-
+ performTest(command, 1);
}
@Test public void testQueryRangeBetween() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId > '1' and T.TradeId < '3'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 1);
-
- compareResultSet(rows);
-
+ performTest(command, 1);
}
@Test public void testQueryRangeAbove() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId > '1'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 2);
-
- compareResultSet(rows);
-
+ performTest(command, 2);
}
@Test public void testQueryRangeBelow() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId < '2'"); //$NON-NLS-1$
- List<Object> rows = performTest(command, 1);
-
- compareResultSet(rows);
-
+ performTest(command, 1);
}
@Test public void testQueryAnd() throws Exception {
Select command = (Select)VDBUtility.TRANSLATION_UTILITY.parseCommand("select T.TradeId, T.Name as TradeName From Trade_Object.Trade as T WHERE T.TradeId > '1' and T.Settled = 'false' "); //$NON-NLS-1$
- List<Object> rows = performTest(command, 1);
-
- compareResultSet(rows);
-
+ performTest(command, 1);
}
}
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanJndiKeySearch.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,12 +21,8 @@
*/
package org.teiid.translator.object.infinispan;
-import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
-import java.util.ArrayList;
-import java.util.List;
-
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.Before;
@@ -72,33 +68,11 @@
factory.setCacheName(TradesCacheSource.TRADES_CACHE_NAME);
factory.setRootClassName(TradesCacheSource.TRADE_CLASS_NAME);
factory.start();
-
-
}
-
- @Override
- protected List<Object> performTest(Select command, int rowcnt) throws Exception {
-
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
-
- exec.execute();
-
- List<Object> rows = new ArrayList<Object>();
-
- int cnt = 0;
- List<Object> row = exec.next();
- while (row != null) {
- rows.add(row);
- ++cnt;
- row = exec.next();
- }
-
- assertEquals("Did not get expected number of rows", rowcnt, cnt); //$NON-NLS-1$
-
- exec.close();
- return rows;
+ @Override
+ protected ObjectExecution createExecution(Select command) throws TranslatorException {
+ return (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
}
-
}
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/infinispan/TestInfinispanRemoteJndiKeySearch.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,15 +21,10 @@
*/
package org.teiid.translator.object.infinispan;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.naming.Context;
import org.infinispan.client.hotrod.RemoteCacheManager;
@@ -88,36 +83,18 @@
public static void closeConnection() throws Exception {
RemoteInfinispanTestHelper.releaseServer();
}
-
-
- @Override
- protected List<Object> performTest(Select command, int rowcnt) throws Exception {
+
+ @Override
+ protected ObjectExecution createExecution(Select command)
+ throws Exception {
when(jndi.lookup(JNDI_NAME)).thenReturn(container);
Object t = RemoteInfinispanTestHelper.getCacheManager().getCache(TradesCacheSource.TRADES_CACHE_NAME).get("1");
assertNotNull(t);
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
-
- exec.execute();
-
- List<Object> rows = new ArrayList<Object>();
-
- int cnt = 0;
- List<Object> row = exec.next();
-
- while (row != null) {
- rows.add(row);
- ++cnt;
- row = exec.next();
- }
-
- assertEquals("Did not get expected number of rows", rowcnt, cnt); //$NON-NLS-1$
-
- exec.close();
- return rows;
- }
+ return (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
+ }
}
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/mapcache/TestMapCacheKeySearch.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -21,14 +21,10 @@
*/
package org.teiid.translator.object.mapcache;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
-import java.util.ArrayList;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -46,7 +42,6 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.object.BasicSearchTest;
import org.teiid.translator.object.ObjectExecution;
-import org.teiid.translator.object.ObjectExecutionFactory;
import org.teiid.translator.object.util.TradesCacheSource;
import org.teiid.translator.object.util.VDBUtility;
@@ -96,27 +91,8 @@
}
@Override
- protected List<Object> performTest(Select command, int rowcnt) throws Exception {
-
- ObjectExecution exec = (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
-
- exec.execute();
-
- List<Object> rows = new ArrayList<Object>();
-
- int cnt = 0;
- List<Object> row = exec.next();
-
- while (row != null) {
- rows.add(row);
- ++cnt;
- row = exec.next();
- }
-
- assertEquals("Did not get expected number of rows", rowcnt, cnt); //$NON-NLS-1$
-
- exec.close();
- return rows;
+ protected ObjectExecution createExecution(Select command) throws TranslatorException {
+ return (ObjectExecution) factory.createExecution(command, context, VDBUtility.RUNTIME_METADATA, null);
}
@Test public void testGetMetadata() throws Exception {
Modified: trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java
===================================================================
--- trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java 2012-10-02 15:05:22 UTC (rev 4503)
+++ trunk/connectors/translator-object/src/test/java/org/teiid/translator/object/search/TestBasicKeySearchCriteria.java 2012-10-02 16:38:13 UTC (rev 4504)
@@ -138,7 +138,6 @@
if (criteria.getOperator() != SearchCriterion.Operator.ALL) {
assertNotNull(criteria.getColumn());
- assertNotNull(criteria.getField());
assertNotNull(criteria.getOperator());
assertNotNull(criteria.getTableName());
assertNotNull(criteria.getRuntimeType());
12 years, 2 months
teiid SVN: r4503 - in trunk: common-core/src/main/java/org/teiid/core/util and 3 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 11:05:22 -0400 (Tue, 02 Oct 2012)
New Revision: 4503
Modified:
trunk/api/src/main/java/org/teiid/metadata/Column.java
trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
Log:
TEIID-2236 fix for searchable parsing
Modified: trunk/api/src/main/java/org/teiid/metadata/Column.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Column.java 2012-10-02 14:09:05 UTC (rev 4502)
+++ trunk/api/src/main/java/org/teiid/metadata/Column.java 2012-10-02 15:05:22 UTC (rev 4503)
@@ -113,6 +113,10 @@
}
return searchType;
}
+
+ public boolean isSearchTypeSet() {
+ return searchType != null;
+ }
public String getFormat() {
return format;
Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2012-10-02 14:09:05 UTC (rev 4502)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2012-10-02 15:05:22 UTC (rev 4503)
@@ -998,4 +998,18 @@
return true;
}
+ public static <T extends Enum<T>> T caseInsensitiveValueOf(Class<T> enumType, String name) {
+ try {
+ return Enum.valueOf(enumType, name);
+ } catch (IllegalArgumentException e) {
+ T[] vals = enumType.getEnumConstants();
+ for (T t : vals) {
+ if (name.equalsIgnoreCase(t.name())) {
+ return t;
+ }
+ }
+ throw e;
+ }
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-10-02 14:09:05 UTC (rev 4502)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-10-02 15:05:22 UTC (rev 4503)
@@ -419,7 +419,7 @@
}
// by default the search type is default data type search, so avoid it.
- if (column.getSearchType() != null && !column.getSearchType().equals(column.getDatatype().getSearchType())) {
+ if (column.getSearchType() != null && (!column.getSearchType().equals(column.getDatatype().getSearchType()) || column.isSearchTypeSet())) {
addOption(options, SEARCHABLE, column.getSearchType().name());
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-10-02 14:09:05 UTC (rev 4502)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-10-02 15:05:22 UTC (rev 4503)
@@ -367,7 +367,7 @@
v = props.remove(DDLConstants.SEARCHABLE);
if (v != null) {
- c.setSearchType(SearchType.valueOf(v.toUpperCase()));
+ c.setSearchType(StringUtil.caseInsensitiveValueOf(SearchType.class, v));
}
v = props.remove(DDLConstants.MIN_VALUE);
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-10-02 14:09:05 UTC (rev 4502)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-10-02 15:05:22 UTC (rev 4503)
@@ -31,6 +31,7 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.metadata.*;
import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.Column.SearchType;
import org.teiid.query.metadata.MetadataValidator;
import org.teiid.query.metadata.SystemMetadata;
import org.teiid.query.validator.ValidatorReport;
@@ -48,7 +49,7 @@
"e1 integer primary key,\n" +
"e2 varchar(10) unique,\n" +
"e3 date not null unique,\n" +
- "e4 decimal(12,3),\n" +
+ "e4 decimal(12,3) options (searchable 'unsearchable'),\n" +
"e5 integer auto_increment INDEX OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE 'NO'),\n" +
"e6 varchar index default 'hello')\n" +
"OPTIONS (CARDINALITY 12, UUID 'uuid2', UPDATABLE 'true', FOO 'BAR', ANNOTATION 'Test Table')";
@@ -101,6 +102,7 @@
assertEquals(false, e4.isAutoIncremented());
assertEquals(12, e4.getPrecision());
assertEquals(3, e4.getScale());
+ assertEquals(SearchType.Unsearchable, e4.getSearchType());
assertEquals("e5", e5.getName());
assertEquals("int", e5.getDatatype().getName());
12 years, 2 months
teiid SVN: r4502 - trunk/build/kits/jboss-as7/docs/teiid.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2012-10-02 10:09:05 -0400 (Tue, 02 Oct 2012)
New Revision: 4502
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
Log:
TEIID-2177, TEIID-2176
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-10-02 13:06:35 UTC (rev 4501)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-10-02 14:09:05 UTC (rev 4502)
@@ -39,6 +39,7 @@
<li>TEIID-2086 <b>Transactional results caching</b> - the result set cache is now transactional by default.
<li>TEIID-2210 <b>Object Translator</b> - the translator-object can support Infinispan Cache and other Map type caches. See OBJECTTABLE for executing queries against this translator.
<li>TEIID-1386 <b>Procedure exception handling</b> - the Teiid procedure language now supports exception handling and emitting SQLWarnings. See the Reference for syntax and usage.
+ <li>TEIID-2176,TEIID-2177 <b>Native Query Support</b> - JDBC, LDAP, SalesForce, JPA, OLAP translators now support execution of native queries directly against the source either through "native-query" extension metadata property or native procedure defined by their translator.
</ul>
<h2><a name="Compatibility">Compatibility Issues</a></h2>
12 years, 2 months
teiid SVN: r4501 - trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 09:06:35 -0400 (Tue, 02 Oct 2012)
New Revision: 4501
Modified:
trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java
Log:
TEIID-2176 refinements to jpa native query support
Modified: trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java
===================================================================
--- trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java 2012-10-02 12:52:37 UTC (rev 4500)
+++ trunk/connectors/translator-jpa/src/main/java/org/teiid/translator/jpa/JPQLDirectQueryExecution.java 2012-10-02 13:06:35 UTC (rev 4501)
@@ -25,7 +25,6 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import javax.persistence.EntityManager;
import javax.persistence.Query;
@@ -41,7 +40,7 @@
import org.teiid.translator.TranslatorException;
public class JPQLDirectQueryExecution extends JPQLBaseExecution implements ProcedureExecution{
- private Iterator resultsIterator;
+ private Iterator<?> resultsIterator;
private List<Argument> arguments;
private int updateCount = -1;
private boolean updateQuery;
@@ -55,22 +54,17 @@
@Override
public void execute() throws TranslatorException {
String query = (String)arguments.get(0).getArgumentValue().getValue();
- String firstToken = null;
-
- StringTokenizer st = new StringTokenizer(query, ";"); //$NON-NLS-1$
- if (st.hasMoreTokens()) {
- firstToken = st.nextToken();
- if (!firstToken.equalsIgnoreCase("search") && !firstToken.equalsIgnoreCase("create") && !firstToken.equalsIgnoreCase("update") && !firstToken.equalsIgnoreCase("delete")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
- }
+ if (query.length() < 7) {
+ throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
-
+ String firstToken = query.substring(0, 6);
+
String jpql = query.substring(7);
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "JPA Source-Query:", jpql); //$NON-NLS-1$
if (firstToken.equalsIgnoreCase("search")) { // //$NON-NLS-1$
Query queryCommand = this.enityManager.createQuery(jpql);
- List results = queryCommand.getResultList();
+ List<?> results = queryCommand.getResultList();
this.resultsIterator = results.iterator();
}
else if (firstToken.equalsIgnoreCase("create")) { // //$NON-NLS-1$
@@ -83,6 +77,8 @@
Query queryCmd = this.enityManager.createQuery(jpql);
this.updateCount = queryCmd.executeUpdate();
this.updateQuery = true;
+ } else {
+ throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
}
12 years, 2 months
teiid SVN: r4500 - in trunk: jboss-integration/src/main/java/org/teiid/jboss and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-10-02 08:52:37 -0400 (Tue, 02 Oct 2012)
New Revision: 4500
Modified:
trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
Log:
TEIID-2235 fixing synchronization and adding a release note
Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-10-02 12:26:48 UTC (rev 4499)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html 2012-10-02 12:52:37 UTC (rev 4500)
@@ -60,6 +60,7 @@
to the integer suffix of the teiidCode if possible.
<li>TEIID-2226 All statements that return result sets that are executed as command statements in a procedure are validated against the expected resultset columns of the procedure.
If the statement is not intended to be returnable, WITHOUT RETURN can be added to the end of the statement.
+ <li>TEIID-2235 The MetadataRepository.setNext was removed. Also if an instance of a DefaultMetadataRepository is used, it will only affect metadata already loaded in the repository chain.
</ul>
<h4>from 8.0</h4>
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-10-02 12:26:48 UTC (rev 4499)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-10-02 12:52:37 UTC (rev 4500)
@@ -476,31 +476,26 @@
if (repo != null) {
return repo;
}
- synchronized (this) {
- final Module module;
- ClassLoader moduleLoader = this.vdb.getAttachment(ClassLoader.class);
- if (moduleLoader == null) {
- moduleLoader = this.getClass().getClassLoader();
+ final Module module;
+ ClassLoader moduleLoader = this.getClass().getClassLoader();
+ ModuleLoader ml = Module.getCallerModuleLoader();
+ if (repoType != null && ml != null) {
+ try {
+ module = ml.loadModule(ModuleIdentifier.create(repoType));
+ moduleLoader = module.getClassLoader();
+ } catch (ModuleLoadException e) {
+ throw new VirtualDatabaseException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50057, repoType));
}
- ModuleLoader ml = Module.getCallerModuleLoader();
- if (repoType != null && ml != null) {
- try {
- module = ml.loadModule(ModuleIdentifier.create(repoType));
- moduleLoader = module.getClassLoader();
- } catch (ModuleLoadException e) {
- throw new VirtualDatabaseException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50057, repoType));
- }
- }
-
- final ServiceLoader<MetadataRepository> serviceLoader = ServiceLoader.load(MetadataRepository.class, moduleLoader);
- if (serviceLoader != null) {
- for (MetadataRepository loader:serviceLoader) {
- this.addMetadataRepository(repoType, loader);
- return loader;
- }
- }
- return null;
- }
+ }
+
+ final ServiceLoader<MetadataRepository> serviceLoader = ServiceLoader.load(MetadataRepository.class, moduleLoader);
+ if (serviceLoader != null) {
+ for (MetadataRepository loader:serviceLoader) {
+ MetadataRepository old = this.repositories.putIfAbsent(repoType, loader);
+ return old!=null?old:loader;
+ }
+ }
+ return null;
}
}
Modified: trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-10-02 12:26:48 UTC (rev 4499)
+++ trunk/runtime/src/main/java/org/teiid/runtime/AbstractVDBDeployer.java 2012-10-02 12:52:37 UTC (rev 4500)
@@ -55,7 +55,7 @@
public abstract class AbstractVDBDeployer {
- private Map<String, MetadataRepository<?, ?>> repositories = new ConcurrentSkipListMap<String, MetadataRepository<?, ?>>(String.CASE_INSENSITIVE_ORDER);
+ protected ConcurrentSkipListMap<String, MetadataRepository<?, ?>> repositories = new ConcurrentSkipListMap<String, MetadataRepository<?, ?>>(String.CASE_INSENSITIVE_ORDER);
public AbstractVDBDeployer() {
repositories.put("ddl", new DDLMetadataRepository()); //$NON-NLS-1$
12 years, 2 months