Author: shawkins
Date: 2010-10-05 12:09:40 -0400 (Tue, 05 Oct 2010)
New Revision: 2626
Added:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/IdentifierFunctionModifier.java
branches/7.1.x/connectors/translator-jdbc/src/main/resources/JCRFunctions.xmi
Removed:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeSQLVisitor.java
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeUtil.java
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/PathFunctionModifier.java
branches/7.1.x/connectors/translator-jdbc/src/test/resources/ModeShape.vdb
Modified:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeExecutionFactory.java
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TranslationHelper.java
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/modeshape/TestModeShapeSqlTranslator.java
branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
Log:
TEIID-1106 updating support for modeshape's modified jcr2 sql over jdbc
Modified:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -563,7 +563,7 @@
* @param modifier
*/
public void registerFunctionModifier(String name, FunctionModifier modifier) {
- this.functionModifiers.put(name, modifier);
+ this.functionModifiers.put(name.toLowerCase(), modifier);
}
/**
Copied:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/IdentifierFunctionModifier.java
(from rev 2611,
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/PathFunctionModifier.java)
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/IdentifierFunctionModifier.java
(rev 0)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/IdentifierFunctionModifier.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -0,0 +1,94 @@
+/*
+ * 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.jdbc.modeshape;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.teiid.language.ColumnReference;
+import org.teiid.language.Expression;
+import org.teiid.language.Function;
+import org.teiid.language.NamedTable;
+import org.teiid.language.SQLConstants;
+import org.teiid.metadata.Column;
+import org.teiid.translator.jdbc.FunctionModifier;
+
+
+/**
+ * Function to translate ColumnReferences to selector names
+ * @since 7.1
+ */
+public class IdentifierFunctionModifier extends FunctionModifier {
+
+ public List<?> translate(Function function) {
+
+ List<Object> objs = new ArrayList<Object>();
+
+ List<Expression> parms = function.getParameters();
+
+ objs.add(function.getName().substring(function.getName().indexOf('_') + 1));
+ objs.add(SQLConstants.Tokens.LPAREN);
+
+ for (Iterator<Expression> iter = parms.iterator(); iter.hasNext();)
+ {
+ Expression expr = iter.next();
+ if (expr instanceof ColumnReference) {
+ boolean dotAll = false;
+ boolean useSelector = false;
+ ColumnReference cr = (ColumnReference)expr;
+ Column c = cr.getMetadataObject();
+ if (c != null) {
+ if
("\"mode:properties\"".equalsIgnoreCase(c.getNameInSource())) {
//$NON-NLS-1$
+ dotAll = true;
+ useSelector = true;
+ } else if
("\"mode:path\"".equalsIgnoreCase(c.getNameInSource())) {
//$NON-NLS-1$
+ useSelector = true;
+ }
+ }
+ if (useSelector) {
+ NamedTable nt = ((ColumnReference)expr).getTable();
+ if (nt.getCorrelationName() != null) {
+ objs.add(nt.getCorrelationName());
+ } else {
+ objs.add(nt);
+ }
+ } else {
+ objs.add(expr);
+ }
+ if (dotAll) {
+ objs.add(".*"); //$NON-NLS-1$
+ }
+ } else {
+ objs.add(expr);
+ }
+ if (iter.hasNext()) {
+ objs.add(", "); //$NON-NLS-1$
+ }
+ }
+
+ objs.add(SQLConstants.Tokens.RPAREN);
+ return objs;
+ }
+
+}
Property changes on:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/IdentifierFunctionModifier.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeExecutionFactory.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeExecutionFactory.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeExecutionFactory.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -29,174 +29,219 @@
import java.util.Arrays;
import java.util.List;
-import org.teiid.language.ColumnReference;
-import org.teiid.language.Expression;
+import org.teiid.language.Comparison;
import org.teiid.language.Function;
import org.teiid.language.LanguageObject;
import org.teiid.language.Literal;
-import org.teiid.language.NamedTable;
+import org.teiid.language.Not;
+import org.teiid.language.Comparison.Operator;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.jdbc.ConvertModifier;
-import org.teiid.translator.jdbc.FunctionModifier;
+import org.teiid.translator.TypeFacility;
+import org.teiid.translator.jdbc.AliasModifier;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
-import org.teiid.translator.jdbc.SQLConversionVisitor;
-
-
/**
* Translator class for accessing the ModeShape JCR repository.
*/
-@Translator(name="modeshape", description="A translator for open source
Modeshape JCA repository")
+@Translator(name="modeshape", description="A translator for the open
source Modeshape JCR Repository")
public class ModeShapeExecutionFactory extends JDBCExecutionFactory {
public ModeShapeExecutionFactory() {
setDatabaseVersion("2.0"); //$NON-NLS-1$
+ setUseBindVariables(false);
}
@Override
public void start() throws TranslatorException {
super.start();
- registerFunctionModifier("PATH", new PathFunctionModifier());
-
- //add in type conversion
- ConvertModifier convertModifier = new ConvertModifier();
-
+ registerFunctionModifier(SourceSystemFunctions.UCASE, new
AliasModifier("UpperCase")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.LCASE,new
AliasModifier("LowerCase")); //$NON-NLS-1$
- convertModifier.addTypeMapping("boolean", FunctionModifier.BOOLEAN);
//$NON-NLS-1$
- convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE,
FunctionModifier.SHORT); //$NON-NLS-1$
- convertModifier.addTypeMapping("integer", FunctionModifier.INTEGER);
//$NON-NLS-1$
- convertModifier.addTypeMapping("bigint", FunctionModifier.LONG);
//$NON-NLS-1$
- convertModifier.addTypeMapping("real", FunctionModifier.FLOAT);
//$NON-NLS-1$
- convertModifier.addTypeMapping("float8", FunctionModifier.DOUBLE);
//$NON-NLS-1$
- convertModifier.addTypeMapping("numeric(38)",
FunctionModifier.BIGINTEGER); //$NON-NLS-1$
- convertModifier.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL);
//$NON-NLS-1$
- convertModifier.addTypeMapping("char(1)", FunctionModifier.CHAR);
//$NON-NLS-1$
- convertModifier.addTypeMapping("varchar(4000)", FunctionModifier.STRING);
//$NON-NLS-1$
- convertModifier.addTypeMapping("date", FunctionModifier.DATE);
//$NON-NLS-1$
- convertModifier.addTypeMapping("time", FunctionModifier.TIME);
//$NON-NLS-1$
- convertModifier.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
//$NON-NLS-1$
- convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.TIMESTAMP, new
FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList(function.getParameters().get(0), " + TIMESTAMP
'1970-01-01'"); //$NON-NLS-1$
- }
- });
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.TIME, new
FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- return Arrays.asList("cast(date_trunc('second', ",
function.getParameters().get(0), ") AS time)"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- });
- convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new
ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD"));
//$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new
ConvertModifier.FormatModifier("to_char", "HH24:MI:SS"));
//$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new
ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD
HH24:MI:SS.UF")); //$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new
FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- Expression stringValue = function.getParameters().get(0);
- return Arrays.asList("CASE WHEN ", stringValue, " THEN 'true'
WHEN not(", stringValue, ") THEN 'false' END"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- }
- });
- convertModifier.addSourceConversion(new FunctionModifier() {
- @Override
- public List<?> translate(Function function) {
- ((Literal)function.getParameters().get(1)).setValue("integer");
//$NON-NLS-1$
- return null;
- }
- }, FunctionModifier.BOOLEAN);
-
- registerFunctionModifier(SourceSystemFunctions.CONVERT, convertModifier);
-
-
- LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Started"); //$NON-NLS-1$
-
+ registerFunctionModifier("JCR_ISCHILDNODE", new
IdentifierFunctionModifier()); //$NON-NLS-1$
+ registerFunctionModifier("JCR_ISDESCENDANTNODE", new
IdentifierFunctionModifier()); //$NON-NLS-1$
+ registerFunctionModifier("JCR_ISSAMENODE", new IdentifierFunctionModifier());
//$NON-NLS-1$
+ registerFunctionModifier("JCR_REFERENCE", new IdentifierFunctionModifier());
//$NON-NLS-1$
+ registerFunctionModifier("JCR_CONTAINS", new IdentifierFunctionModifier());
//$NON-NLS-1$
+
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "ModeShape Translator
Started"); //$NON-NLS-1$
}
- /**
- * Create the {@link SQLConversionVisitor} that will perform translation. Typical
custom
- * JDBC connectors will not need to create custom conversion visitors, rather
implementors
- * should override existing {@link JDBCExecutionFactory} methods.
- * @return the {@link SQLConversionVisitor}
- */
- public SQLConversionVisitor getSQLConversionVisitor() {
- return new ModeShapeSQLVisitor(this);
- }
-
-
- @Override
- public List<?> translate(LanguageObject obj, ExecutionContext context) {
- if (obj instanceof NamedTable) {
- NamedTable nt = (NamedTable) obj;
- List<String> ntlist = new ArrayList<String>(1);
- ntlist.add(ModeShapeUtil.createJCRName(nt.getMetadataObject().getNameInSource()));
- return ntlist;
- } else if (obj instanceof ColumnReference) {
- ColumnReference elem = (ColumnReference) obj;
-
- String nameInSource = "NoNameInSource";
- if (elem.getMetadataObject() != null) {
- nameInSource = elem.getMetadataObject().getNameInSource();
-
- List<String> ntlist = new ArrayList<String>(1);
- ntlist.add(ModeShapeUtil.createJCRName(nameInSource));
-
- return ntlist;
- }
- }
-
- return super.translate(obj, context);
- }
-
-
- @Override
- public String translateLiteralBoolean(Boolean booleanValue) {
- if(booleanValue.booleanValue()) {
- return "TRUE"; //$NON-NLS-1$
- }
- return "FALSE"; //$NON-NLS-1$
- }
-
@Override
public String translateLiteralDate(Date dateValue) {
- return "DATE '" + formatDateValue(dateValue) + "'";
//$NON-NLS-1$//$NON-NLS-2$
+ return "CAST('" + formatDateValue(dateValue) + "' AS
DATE)"; //$NON-NLS-1$//$NON-NLS-2$
}
@Override
public String translateLiteralTime(Time timeValue) {
- return "TIME '" + formatDateValue(timeValue) + "'";
//$NON-NLS-1$//$NON-NLS-2$
+ return "CAST('" + formatDateValue(timeValue) + "' AS
DATE)"; //$NON-NLS-1$//$NON-NLS-2$
}
@Override
public String translateLiteralTimestamp(Timestamp timestampValue) {
- return "TIMESTAMP '" + formatDateValue(timestampValue) +
"'"; //$NON-NLS-1$//$NON-NLS-2$
+ return "CAST('" + formatDateValue(timestampValue) + "' AS
DATE)"; //$NON-NLS-1$//$NON-NLS-2$
}
@Override
- public int getTimestampNanoPrecision() {
- return 6;
+ public String translateLiteralBoolean(Boolean booleanValue) {
+ return "CAST('" + booleanValue.toString() + "' AS
BOOLEAN)"; //$NON-NLS-1$//$NON-NLS-2$
}
@Override
public List<String> getSupportedFunctions() {
List<String> supportedFunctions = new ArrayList<String>();
supportedFunctions.addAll(super.getSupportedFunctions());
- supportedFunctions.add("PATH"); //$NON-NLS-1$
- supportedFunctions.add("NAME"); //$NON-NLS-1$
- supportedFunctions.add("ISCHILDNODE"); //$NON-NLS-1$
-
+ supportedFunctions.add(SourceSystemFunctions.UCASE);
+ supportedFunctions.add(SourceSystemFunctions.LCASE);
+ supportedFunctions.add(SourceSystemFunctions.LENGTH);
+ supportedFunctions.add("JCR_ISCHILDNODE"); //$NON-NLS-1$
+ supportedFunctions.add("JCR_ISDESCENDANTNODE"); //$NON-NLS-1$
+ supportedFunctions.add("JCR_ISSAMENODE"); //$NON-NLS-1$
+ supportedFunctions.add("JCR_REFERENCE"); //$NON-NLS-1$
+ supportedFunctions.add("JCR_CONTAINS"); //$NON-NLS-1$
return supportedFunctions;
-
}
+
+ @Override
+ public List<?> translate(LanguageObject obj, ExecutionContext context) {
+ if (obj instanceof Comparison) {
+ Comparison compare = (Comparison)obj;
+ if (compare.getLeftExpression().getType() == TypeFacility.RUNTIME_TYPES.BOOLEAN
+ && compare.getLeftExpression() instanceof Function
+ && compare.getRightExpression() instanceof Literal) {
+ boolean isTrue =
Boolean.TRUE.equals(((Literal)compare.getRightExpression()).getValue());
+ if ((isTrue && compare.getOperator() == Operator.EQ) || (!isTrue
&& compare.getOperator() == Operator.NE)) {
+ return Arrays.asList(compare.getLeftExpression());
+ }
+ if ((!isTrue && compare.getOperator() == Operator.EQ) || (isTrue
&& compare.getOperator() == Operator.NE)) {
+ return Arrays.asList("NOT ", compare.getLeftExpression());
//$NON-NLS-1$
+ }
+ }
+ } else if (obj instanceof Not) {
+ Not not = (Not)obj;
+ return Arrays.asList("NOT ", not.getCriteria()); //$NON-NLS-1$
+ }
+ return super.translate(obj, context);
+ }
@Override
public boolean useBindVariables() {
return false;
}
+ @Override
+ public boolean supportsAggregatesAvg() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAggregatesCountStar() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAggregatesCount() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAggregatesMax() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAggregatesMin() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsAggregatesSum() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsGroupBy() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsHaving() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSelectExpression() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCaseExpressions() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsCorrelatedSubqueries() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsExistsCriteria() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsInCriteriaSubquery() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsInlineViews() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsOrderByNullOrdering() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsQuantifiedCompareCriteriaAll() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsQuantifiedCompareCriteriaSome() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsScalarSubqueries() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsSearchedCaseExpressions() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsExcept() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsIntersect() {
+ return true;
+ }
+
}
Deleted:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeSQLVisitor.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeSQLVisitor.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeSQLVisitor.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -1,95 +0,0 @@
-package org.teiid.translator.jdbc.modeshape;
-
-import static org.teiid.language.SQLConstants.Reserved.BY;
-import static org.teiid.language.SQLConstants.Reserved.ORDER;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.teiid.language.ColumnReference;
-import org.teiid.language.DerivedColumn;
-import org.teiid.language.Expression;
-import org.teiid.language.OrderBy;
-import org.teiid.language.Select;
-import org.teiid.language.SortSpecification;
-import org.teiid.language.SQLConstants.Tokens;
-import org.teiid.metadata.Column;
-import org.teiid.translator.jdbc.JDBCExecutionFactory;
-import org.teiid.translator.jdbc.SQLConversionVisitor;
-
-public class ModeShapeSQLVisitor extends SQLConversionVisitor {
-
- private Map<String, Column> columnMap = new HashMap<String, Column>();
- private Map<String, Column> aliasMap = new HashMap<String, Column>();
-
- public ModeShapeSQLVisitor(JDBCExecutionFactory ef) {
- super(ef);
-
- }
-
- public void visit(Select query) {
-
- // if the query has an order by, then
- // need to cache the columns so that the
- // order by column name can be replaced by its
- // correlating select column that has the nameInSource
- if (query.getOrderBy() == null) {
- super.visit(query);
- return;
- }
-
- List<DerivedColumn> selectSymbols = query.getDerivedColumns();
- Iterator<DerivedColumn> symbolIter = selectSymbols.iterator();
- while (symbolIter.hasNext()) {
- DerivedColumn symbol = symbolIter.next();
- Expression expression = symbol.getExpression();
-
- if (symbol.getAlias() != null) {
-
- }
- // cache the columns so that order by
- if (expression instanceof ColumnReference) {
- ColumnReference colRef = (ColumnReference) expression;
- if (colRef.getMetadataObject() != null) {
- Column element = colRef.getMetadataObject();
- if (symbol.getAlias() != null) {
- aliasMap.put(symbol.getAlias(), element);
- }
- columnMap.put(element.getName(), element);
- }
- }
- }
-
- super.visit(query);
- }
-
- public void visit(OrderBy obj) {
- buffer.append(ORDER)
- .append(Tokens.SPACE)
- .append(BY)
- .append(Tokens.SPACE);
-
- List<SortSpecification> specs = obj.getSortSpecifications();
- for (SortSpecification spec : specs) {
- String specName = spec.getExpression().toString();
- Column col = null;
-
- col = aliasMap.get(specName);
- if (col == null) {
- col = columnMap.get(specName);
- }
- if (col != null) {
- buffer.append(ModeShapeUtil.createJCRName(col.getNameInSource()))
- .append(" ")
- .append(spec.getOrdering().toString());
-
- } else {
- buffer.append(obj.getSortSpecifications());
- }
- }
-
- }
-
-}
Deleted:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeUtil.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeUtil.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/ModeShapeUtil.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -1,27 +0,0 @@
-package org.teiid.translator.jdbc.modeshape;
-
-public class ModeShapeUtil {
-
- public static final String createJCRName(String name) {
- return "[" + ModeShapeUtil.trimTics(name) + "]";
- }
-
- /**
- * Because the Teiid Designer Import from JDBC adds tic's to a nameInSource that has
special characters,
- * they have to be removed when building the sql syntax
- * @param name
- * @return
- */
- public static final String trimTics(String name) {
- String rtn = name;
- if (rtn.startsWith("'")) {
- rtn = rtn.substring(1);
- }
-
- if (rtn.endsWith("'")) {
- rtn = rtn.substring(0, rtn.indexOf("'"));
- }
- return rtn;
- }
-
-}
Deleted:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/PathFunctionModifier.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/PathFunctionModifier.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/modeshape/PathFunctionModifier.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -1,58 +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.jdbc.modeshape;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.teiid.language.Expression;
-import org.teiid.language.Function;
-import org.teiid.translator.jdbc.FunctionModifier;
-
-
-/**
- * Function to translate the PATH function
- * @since 7.1
- */
-public class PathFunctionModifier extends FunctionModifier {
-
- public PathFunctionModifier() {
- super();
- }
-
- public List<?> translate(Function function) {
- List<Object> objs = new ArrayList<Object>();
-
- List<Expression> parms = function.getParameters();
-
- for (Expression s : parms)
- {
- String v = s.toString();
- v.replace('\'', ' ');
- objs.add(v);
- }
-
- return objs;
- }
-
-}
Added: branches/7.1.x/connectors/translator-jdbc/src/main/resources/JCRFunctions.xmi
===================================================================
--- branches/7.1.x/connectors/translator-jdbc/src/main/resources/JCRFunctions.xmi
(rev 0)
+++
branches/7.1.x/connectors/translator-jdbc/src/main/resources/JCRFunctions.xmi 2010-10-05
16:09:40 UTC (rev 2626)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="ASCII"?>
+<xmi:XMI xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:diagram="http://www.metamatrix.com/metamodels/Diagram"
xmlns:mmcore="http://www.metamatrix.com/metamodels/Core"
xmlns:mmfunction="http://www.metamatrix.com/metamodels/MetaMatrixFun...
+ <mmcore:ModelAnnotation
xmi:uuid="mmuuid:ab62e724-42e6-4dc3-a79b-b232e388b2a4"
primaryMetamodelUri="http://www.metamatrix.com/metamodels/MetaMatrix...
modelType="FUNCTION" ProducerName="Teiid Designer"
ProducerVersion="7.1.0.v20100829-1858-H223-M2"/>
+ <diagram:DiagramContainer
xmi:uuid="mmuuid:e34ae0e1-b34f-4889-9a64-3bdcc9d82411">
+ <diagram xmi:uuid="mmuuid:f4269ae0-b411-4b34-b051-5186948278af"
type="packageDiagramType"
target="mmuuid/ab62e724-42e6-4dc3-a79b-b232e388b2a4">
+ <diagramEntity xmi:uuid="mmuuid:056149af-ef62-4a02-9497-430ec4748dc5"
name="JCR_ISCHILDNODE"
modelObject="mmuuid/ecf2b4a4-40fe-4cab-b84a-93a26c0560c7"
xPosition="20" yPosition="20"/>
+ <diagramEntity xmi:uuid="mmuuid:540e49b4-9034-4de6-bcb6-8c30f2bc6fd6"
name="JCR_ISDESCENDANTNODE"
modelObject="mmuuid/6387763f-0397-4abc-a2ca-46c9c0f793bd"
xPosition="40" yPosition="30"/>
+ <diagramEntity xmi:uuid="mmuuid:87c6912c-78eb-4e60-a0b5-1b0cb0c2a368"
name="JCR_ISSAMENODE"
modelObject="mmuuid/4ecc9ba6-a383-4196-a261-1860cc3ee88c"
xPosition="60" yPosition="40"/>
+ <diagramEntity xmi:uuid="mmuuid:12901a36-f796-4ed1-8dba-68a4493abffb"
name="JCR_CONTAINS"
modelObject="mmuuid/a84444b6-79b4-45bc-97bf-745503dabc03"
xPosition="80" yPosition="50"/>
+ <diagramEntity xmi:uuid="mmuuid:e3725579-e657-455f-845b-ddd1c5690ff8"
name="JCR_REFERENCE"
modelObject="mmuuid/c562c350-eaf8-4992-a9c0-5450ef188761"
xPosition="100" yPosition="60"/>
+ </diagram>
+ </diagram:DiagramContainer>
+ <mmcore:AnnotationContainer
xmi:uuid="mmuuid:c3c82dbf-1339-4354-b23d-7135aa430b21"/>
+ <mmfunction:ScalarFunction
xmi:uuid="mmuuid:ecf2b4a4-40fe-4cab-b84a-93a26c0560c7"
name="JCR_ISCHILDNODE" category="JCR"
pushDown="REQUIRED">
+ <inputParameters xmi:uuid="mmuuid:23fd3fce-de13-4b11-957d-a44c2ac6da43"
name="path" type="string"/>
+ <inputParameters xmi:uuid="mmuuid:68bafab4-98f7-472d-81cb-38e6bf2aa096"
name="path" type="string"/>
+ <returnParameter xmi:uuid="mmuuid:151394ed-8654-4e9a-a081-f3bf02b71b2d"
type="boolean"/>
+ </mmfunction:ScalarFunction>
+ <mmfunction:ScalarFunction
xmi:uuid="mmuuid:6387763f-0397-4abc-a2ca-46c9c0f793bd"
name="JCR_ISDESCENDANTNODE" category="JCR"
pushDown="REQUIRED">
+ <inputParameters xmi:uuid="mmuuid:c3a1f10b-58a5-4c5b-a94f-bac009b31284"
name="path" type="string"/>
+ <inputParameters xmi:uuid="mmuuid:403500a9-f48b-4603-8d92-2011944baa9d"
name="path" type="string"/>
+ <returnParameter xmi:uuid="mmuuid:ae90df19-106a-481d-b905-68a9c2493316"
type="boolean"/>
+ </mmfunction:ScalarFunction>
+ <mmfunction:ScalarFunction
xmi:uuid="mmuuid:4ecc9ba6-a383-4196-a261-1860cc3ee88c"
name="JCR_ISSAMENODE" category="JCR"
pushDown="REQUIRED">
+ <inputParameters xmi:uuid="mmuuid:94a8a68c-4744-4cdb-9ad8-23417e5aff56"
name="path" type="string"/>
+ <inputParameters xmi:uuid="mmuuid:004473ae-2199-43d0-b4bd-fd996fa18b7b"
name="path" type="string"/>
+ <returnParameter xmi:uuid="mmuuid:8ab20d78-fd6a-400a-9e03-70be996b4cc6"
type="boolean"/>
+ </mmfunction:ScalarFunction>
+ <mmfunction:ScalarFunction
xmi:uuid="mmuuid:a84444b6-79b4-45bc-97bf-745503dabc03"
name="JCR_CONTAINS" category="JCR" pushDown="REQUIRED">
+ <inputParameters xmi:uuid="mmuuid:ae2e922c-bd03-4f02-9e23-2f50fc88c497"
name="selectorOrProperty" type="string"/>
+ <inputParameters xmi:uuid="mmuuid:10e90221-2ffc-4145-ae3b-494384b823d3"
name="searchExpr" type="string"/>
+ <returnParameter xmi:uuid="mmuuid:dab3ded9-9fbf-458f-ade5-4e77b010022b"
type="boolean"/>
+ </mmfunction:ScalarFunction>
+ <mmfunction:ScalarFunction
xmi:uuid="mmuuid:c562c350-eaf8-4992-a9c0-5450ef188761"
name="JCR_REFERENCE" category="JCR" pushDown="REQUIRED">
+ <inputParameters xmi:uuid="mmuuid:aa8e27e8-3fc9-46b9-9c1a-c407af6ee5a6"
name="selectorOrProperty" type="string"/>
+ <returnParameter xmi:uuid="mmuuid:d9de7a7d-a84e-4775-9931-5516f4a1a940"
type="string"/>
+ </mmfunction:ScalarFunction>
+</xmi:XMI>
Property changes on:
branches/7.1.x/connectors/translator-jdbc/src/main/resources/JCRFunctions.xmi
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TranslationHelper.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TranslationHelper.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TranslationHelper.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -51,7 +51,7 @@
return helpTranslate(vdbFileName, null, sql);
}
- public static Command helpTranslate(String vdbFileName, String udf, String sql) {
+ public static TranslationUtility getTranslationUtility(String vdbFileName, String
udf) {
TranslationUtility util = null;
if (PARTS_VDB.equals(vdbFileName)) {
util = new TranslationUtility(TranslationHelper.class.getResource(vdbFileName));
@@ -62,16 +62,24 @@
}
if (udf != null) {
- try {
- Collection <FunctionMethod> methods =
FunctionMetadataReader.loadFunctionMethods(TranslationHelper.class.getResource(udf).openStream());
- util.setUDF(methods);
- } catch (IOException e) {
- throw new TeiidRuntimeException("failed to load UDF"); //$NON-NLS-1$
- } catch (JAXBException e) {
- throw new TeiidRuntimeException("failed to load UDF"); //$NON-NLS-1$
- }
+ loadUDFs(udf, util);
}
- return util.parseCommand(sql);
+ return util;
+ }
+
+ public static void loadUDFs(String udf, TranslationUtility util) {
+ try {
+ Collection <FunctionMethod> methods =
FunctionMetadataReader.loadFunctionMethods(TranslationHelper.class.getResource(udf).openStream());
+ util.setUDF(methods);
+ } catch (IOException e) {
+ throw new TeiidRuntimeException("failed to load UDF"); //$NON-NLS-1$
+ } catch (JAXBException e) {
+ throw new TeiidRuntimeException("failed to load UDF"); //$NON-NLS-1$
+ }
+ }
+
+ public static Command helpTranslate(String vdbFileName, String udf, String sql) {
+ return getTranslationUtility(vdbFileName, udf).parseCommand(sql);
}
public static void helpTestVisitor(String vdb, String input, String expectedOutput,
JDBCExecutionFactory translator) throws TranslatorException {
Modified:
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/modeshape/TestModeShapeSqlTranslator.java
===================================================================
---
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/modeshape/TestModeShapeSqlTranslator.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/modeshape/TestModeShapeSqlTranslator.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -22,18 +22,21 @@
package org.teiid.translator.jdbc.modeshape;
-import static org.junit.Assert.assertEquals;
+import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Mockito;
import org.teiid.cdk.api.TranslationUtility;
-import org.teiid.core.util.UnitTestUtil;
import org.teiid.language.Command;
-import org.teiid.language.LanguageFactory;
-import org.teiid.translator.ExecutionContext;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.metadata.Schema;
+import org.teiid.metadata.Table;
+import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.unittest.RealMetadataFactory;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.jdbc.TranslatedCommand;
+import org.teiid.translator.TypeFacility;
+import org.teiid.translator.jdbc.TranslationHelper;
/**
*/
@@ -41,67 +44,66 @@
public class TestModeShapeSqlTranslator {
private static ModeShapeExecutionFactory TRANSLATOR;
+ private static TranslationUtility UTIL;
+ private static String UDF = "/JCRFunctions.xmi"; //$NON-NLS-1$;
- private static String MODESHAPE_VDB = (UnitTestUtil.getTestDataPath() != null ?
UnitTestUtil
- .getTestDataPath()
- : "src/test/resources")
- + "/ModeShape.vdb";
-
-
@BeforeClass
public static void setUp() throws TranslatorException {
TRANSLATOR = new ModeShapeExecutionFactory();
TRANSLATOR.setUseBindVariables(false);
TRANSLATOR.start();
-
+ UTIL = new TranslationUtility(getMetadata());
+ TranslationHelper.loadUDFs(UDF, UTIL);
}
+
+ public static TransformationMetadata getMetadata() {
+ MetadataStore store = new MetadataStore();
+ Schema modeshape = RealMetadataFactory.createPhysicalModel("modeshape",
store);
+ Table nt_base = RealMetadataFactory.createPhysicalGroup("nt_base",
modeshape);
+ nt_base.setNameInSource("\"nt:base\"");
+ List<Column> cols = RealMetadataFactory.createElements(nt_base, new String[] {
"mode_path",
+ "mode_properties", "jcr_primaryType", "prop" }, new
String[] {
+ TypeFacility.RUNTIME_NAMES.STRING,
+ TypeFacility.RUNTIME_NAMES.STRING,
+ TypeFacility.RUNTIME_NAMES.STRING,
+ TypeFacility.RUNTIME_NAMES.STRING });
+ cols.get(0).setNameInSource("\"mode:path\"");
+ cols.get(1).setNameInSource("\"mode:properties\"");
+ cols.get(2).setNameInSource("\"jcr:primaryType\"");
+ return RealMetadataFactory.createTransformationMetadata(store,
"modeshape");
+ }
- public void helpTestVisitor(TranslationUtility util, String input,
- String expectedOutput) throws TranslatorException {
- // Convert from sql to objects
- Command obj = util.parseCommand(input);
-
- TranslatedCommand tc = new TranslatedCommand(Mockito
- .mock(ExecutionContext.class), TRANSLATOR);
- tc.translateCommand(obj);
- assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
+ public void helpTestVisitor(String input, String expectedOutput) throws
TranslatorException {
+ Command obj = UTIL.parseCommand(input, true, true);
+ TranslationHelper.helpTestVisitor(expectedOutput, TRANSLATOR, obj);
}
@Test
public void testSelectAllFromBase() throws Exception {
String input = "select * from nt_base"; //$NON-NLS-1$
- String output = "SELECT [jcr:primaryType] FROM [nt:base]"; //$NON-NLS-1$
+ String output = "SELECT g_0.\"mode:path\",
g_0.\"mode:properties\", g_0.\"jcr:primaryType\", g_0.prop FROM
\"nt:base\" AS g_0"; //$NON-NLS-1$
- helpTestVisitor(new TranslationUtility(MODESHAPE_VDB), input, output);
+ helpTestVisitor(input, output);
}
@Test
- public void testSelectColumnFromBase() throws Exception {
- String input = "select jcr_primaryType from nt_base"; //$NON-NLS-1$
- String output = "SELECT [jcr:primaryType] FROM [nt:base]"; //$NON-NLS-1$
+ public void testPredicate() throws Exception {
- helpTestVisitor(new TranslationUtility(MODESHAPE_VDB), input, output);
+ String input = "SELECT x.jcr_primaryType from nt_base inner join nt_base as x on
jcr_issamenode(nt_base.mode_path, x.mode_path) = true where
jcr_isdescendantnode(nt_base.mode_path, 'x/y/z') = true and
jcr_reference(nt_base.mode_properties) = 'x'"; //$NON-NLS-1$
+ String output = "SELECT g_1.\"jcr:primaryType\" FROM
\"nt:base\" AS g_0 INNER JOIN \"nt:base\" AS g_1 ON issamenode(g_0,
g_1) WHERE isdescendantnode(g_0, 'x/y/z') AND reference(g_0.*) =
'x'"; //$NON-NLS-1$
- }
+ helpTestVisitor(input, output);
- @Test
- public void testWhereClause() throws Exception {
-
- String input = "SELECT jcr_primaryType from nt_base WHERE jcr_primaryType =
'relational:column'"; //$NON-NLS-1$
- String output = "SELECT [jcr:primaryType] FROM [nt:base] WHERE [jcr:primaryType] =
'relational:column'"; //$NON-NLS-1$
-
- helpTestVisitor(new TranslationUtility(MODESHAPE_VDB), input, output);
-
}
@Test
public void testOrderBy() throws Exception {
String input = "SELECT jcr_primaryType from nt_base ORDER BY
jcr_primaryType"; //$NON-NLS-1$
- String output = "SELECT [jcr:primaryType] FROM [nt:base] ORDER BY
[jcr:primaryType] ASC"; //$NON-NLS-1$
+ String output = "SELECT g_0.\"jcr:primaryType\" AS c_0 FROM
\"nt:base\" AS g_0 ORDER BY c_0"; //$NON-NLS-1$
- helpTestVisitor(new TranslationUtility(MODESHAPE_VDB), input, output);
+ helpTestVisitor(input, output);
}
@@ -109,12 +111,10 @@
public void testUsingLike() throws Exception {
String input = "SELECT jcr_primaryType from nt_base WHERE jcr_primaryType LIKE
'%relational%'"; //$NON-NLS-1$
- String output = "SELECT [jcr:primaryType] FROM [nt:base] WHERE [jcr:primaryType]
LIKE '%relational%'"; //$NON-NLS-1$
+ String output = "SELECT g_0.\"jcr:primaryType\" FROM
\"nt:base\" AS g_0 WHERE g_0.\"jcr:primaryType\" LIKE
'%relational%'"; //$NON-NLS-1$
- helpTestVisitor(new TranslationUtility(MODESHAPE_VDB), input, output);
+ helpTestVisitor(input, output);
}
-
-
}
Deleted: branches/7.1.x/connectors/translator-jdbc/src/test/resources/ModeShape.vdb
===================================================================
(Binary files differ)
Modified:
branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java
===================================================================
---
branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-10-04
21:04:24 UTC (rev 2625)
+++
branches/7.1.x/engine/src/test/java/org/teiid/query/unittest/RealMetadataFactory.java 2010-10-05
16:09:40 UTC (rev 2626)
@@ -260,7 +260,7 @@
return createTransformationMetadata(metadataStore, "bqt");
}
- private static TransformationMetadata createTransformationMetadata(
+ public static TransformationMetadata createTransformationMetadata(
MetadataStore metadataStore, String vdbName) {
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
VDBMetaData vdbMetaData = new VDBMetaData();