Author: shawkins
Date: 2010-05-07 09:30:14 -0400 (Fri, 07 May 2010)
New Revision: 2102
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
Log:
TEIID-171 adding support for xmlpi and xmlcomment
Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java 2010-05-06
21:39:42 UTC (rev 2101)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java 2010-05-07
13:30:14 UTC (rev 2102)
@@ -46,7 +46,7 @@
public final class XMLType extends Streamable<SQLXML> implements SQLXML {
public enum Type {
- UNKNOWN, DOCUMENT, FRAGMENT, SIBLINGS
+ UNKNOWN, DOCUMENT, FRAGMENT, SIBLINGS, COMMENT, PI
}
private static final long serialVersionUID = -7922647237095135723L;
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java 2010-05-06
21:39:42 UTC (rev 2101)
+++
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java 2010-05-07
13:30:14 UTC (rev 2102)
@@ -139,5 +139,7 @@
public static final String XSLTRANSFORM = "xsltransform"; //$NON-NLS-1$
public static final String XMLELEMENT = "xmlelement"; //$NON-NLS-1$
public static final String XMLCONCAT = "xmlconcat"; //$NON-NLS-1$
+ public static final String XMLCOMMENT = "xmlcomment"; //$NON-NLS-1$
+ public static final String XMLPI = "xmlpi"; //$NON-NLS-1$
}
Modified:
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-05-06
21:39:42 UTC (rev 2101)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-05-07
13:30:14 UTC (rev 2102)
@@ -1998,10 +1998,36 @@
</para>
</entry>
<entry>
- <para>Name is an identifier. exp can be any type. Return value is
xml.
+ <para>Name is an identifier. Exp can be any type. Return value is
xml.
</para>
</entry>
</row>
+ <row>
+ <entry>
+ <para><code>XMLCOMMENT(comment)</code></para>
+ </entry>
+ <entry>
+ <para>Returns an xml comment.
+ </para>
+ </entry>
+ <entry>
+ <para>Comment is a string. Return value is xml.
+ </para>
+ </entry>
+ </row>
+ <row>
+ <entry>
+ <para><code>XMLPI([NAME] name [,
content])</code></para>
+ </entry>
+ <entry>
+ <para>Returns an xml processing instruction.
+ </para>
+ </entry>
+ <entry>
+ <para>Name is an identifier. Content is a string. Return value is
xml.
+ </para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
Modified:
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2010-05-06
21:39:42 UTC (rev 2101)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2010-05-07
13:30:14 UTC (rev 2102)
@@ -170,6 +170,8 @@
addXslTransformFunction();
addXmlElement();
addXmlConcat();
+ addXmlComment();
+ addXmlPi();
addSecurityFunctions();
@@ -931,6 +933,26 @@
new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xmlement_result")), true,
FunctionMethod.DETERMINISTIC ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
+ private void addXmlComment() {
+ functions.add(new FunctionMethod(SourceSystemFunctions.XMLCOMMENT,
QueryPlugin.Util.getString("SystemSource.xmlcomment_description"), XML,
XML_FUNCTION_CLASS, "xmlComment", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("value",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xmlcomment_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xmlcomment_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ private void addXmlPi() {
+ functions.add(new FunctionMethod(SourceSystemFunctions.XMLPI,
QueryPlugin.Util.getString("SystemSource.xmlpi_description"), XML,
XML_FUNCTION_CLASS, "xmlPi", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("name",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xmlpi_param1"))}, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xmlpi_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+
+ functions.add(new FunctionMethod(SourceSystemFunctions.XMLPI,
QueryPlugin.Util.getString("SystemSource.xmlpi_description"), XML,
XML_FUNCTION_CLASS, "xmlPi", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("name",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xmlpi_param1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("value",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.xmlpi_param2"))}, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.XML,
QueryPlugin.Util.getString("SystemSource.xmlpi_result")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+
private void addXmlConcat() {
functions.add(new FunctionMethod(SourceSystemFunctions.XMLCONCAT,
QueryPlugin.Util.getString("SystemSource.xmlconcat_description"), XML,
FunctionMethod.CAN_PUSHDOWN, XML_FUNCTION_CLASS, "xmlConcat", //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter[] {
Modified:
trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java 2010-05-06
21:39:42 UTC (rev 2101)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java 2010-05-07
13:30:14 UTC (rev 2102)
@@ -56,6 +56,7 @@
import com.metamatrix.api.exception.query.FunctionExecutionException;
import com.metamatrix.common.types.ClobType;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.SQLXMLImpl;
import com.metamatrix.common.types.Streamable;
import com.metamatrix.common.types.TransformationException;
import com.metamatrix.common.types.XMLTranslator;
@@ -276,6 +277,21 @@
return result;
}
+ public static XMLType xmlPi(String name) {
+ return xmlPi(name, ""); //$NON-NLS-1$
+ }
+
+ public static XMLType xmlPi(String name, String content) {
+ int start = 0;
+ char[] chars = content.toCharArray();
+ while (start < chars.length && chars[start] == ' ') {
+ start++;
+ }
+ XMLType result = new XMLType(new SQLXMLImpl("<?" + name + " " +
content.substring(start) + "?>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ result.setType(Type.PI);
+ return result;
+ }
+
static String getStringValue(Object object) throws TransformerException {
if (object instanceof Timestamp) {
try {
@@ -307,7 +323,9 @@
}
switch(xml.getType()) {
case FRAGMENT:
- case SIBLINGS: //write the value directly to the writer
+ case SIBLINGS:
+ case PI:
+ case COMMENT: //write the value directly to the writer
eventWriter.flush();
int chr = -1;
while ((chr = r.read()) != -1) {
@@ -341,6 +359,10 @@
//TODO: blob - with base64 encoding
//TODO: full clob?
}
+
+ public static XMLType xmlComment(String comment) {
+ return new XMLType(new SQLXMLImpl("<!--" + comment + "-->"));
//$NON-NLS-1$ //$NON-NLS-2$
+ }
/**
* Formats a timestamp to an xs:dateTime. This uses DATETIME_FORMAT
Modified: trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2010-05-06
21:39:42 UTC (rev 2101)
+++ trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2010-05-07
13:30:14 UTC (rev 2102)
@@ -2918,7 +2918,8 @@
(
(funcToken = <LEFT> | funcToken = <RIGHT> | funcToken = <CHAR> |
funcToken = <USER>
| funcToken = <YEAR> | funcToken = <MONTH> | funcToken
= <HOUR>
- | funcToken = <MINUTE> | funcToken = <SECOND> |
funcToken = <XMLCONCAT>)
+ | funcToken = <MINUTE> | funcToken = <SECOND> |
funcToken = <XMLCONCAT>
+ | funcToken = <XMLCOMMENT>)
<LPAREN>
[
expression = expression(info)
@@ -3002,6 +3003,26 @@
)*
<RPAREN>
)
+ | ( funcToken = <XMLPI>
+ <LPAREN>
+ (
+ LOOKAHEAD(<ID>, { "name".equalsIgnoreCase(getToken(1).image) })
<ID> expression = idExpression()
+ |
+ expression = idExpression()
+ )
+ {
+ args.add(expression);
+ expression = null;
+ }
+ [
+ <COMMA> expression = expression(info)
+ {
+ args.add(expression);
+ expression = null;
+ }
+ ]
+ <RPAREN>
+ )
|
LOOKAHEAD(<XMLFOREST>) (
expression = sqlXmlFunction(info)
Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2010-05-06
21:39:42 UTC (rev 2101)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2010-05-07
13:30:14 UTC (rev 2102)
@@ -778,8 +778,13 @@
SystemSource.xmlelement_result=XML result
SystemSource.xmlconcat_description=Concat XML types.
SystemSource.xmlconcat_param1=First element
-SystemSource.xmlconcat_param2=Other elements
+SystemSource.xmlcomment_description=Creates an XML comment.
+SystemSource.xmlconcat_param1=String comment
SystemSource.xmlconcat_result=XML result
+SystemSource.xmlpi_description=Creates an XML processing instruction.
+SystemSource.xmlpi_param1=Target
+SystemSource.xmlpi_param2=Content
+SystemSource.xmlpi_result=XML result
SystemSource.modifyTimeZone_description=Modify the time zone of this timestamp by adding
or subtracting time
SystemSource.modifyTimeZone_param1=Timestamp
SystemSource.modifyTimeZone_param2=Starting time zone
Modified:
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2010-05-06
21:39:42 UTC (rev 2101)
+++
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2010-05-07
13:30:14 UTC (rev 2102)
@@ -1380,4 +1380,14 @@
String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
assertEquals("<bar/><Catalogs
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><...
ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>",
xml);
}
+
+ @Test public void testInvokeXmlComment() throws Exception {
+ CommandContext c = new CommandContext();
+ c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+ XMLType result = (XMLType)helpInvokeMethod("xmlcomment", new Class[]
{DataTypeManager.DefaultDataClasses.STRING},
+ new Object[] {"comment"}, c);
+
+ String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
+ assertEquals("<!--comment-->", xml);
+ }
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2010-05-06
21:39:42 UTC (rev 2101)
+++
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2010-05-07
13:30:14 UTC (rev 2102)
@@ -7555,5 +7555,20 @@
helpProcess(plan, dataManager, expected);
}
+ @Test public void testXmlElementWithPi() {
+ String sql = "SELECT xmlelement(x, xmlpi(name e1, ' 1'))";
//$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList("<x><?e1 1?></x>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql),
FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
private static final boolean DEBUG = false;
}