Skip to content

Commit

Permalink
TEIID-3030 upgrading saxon to 9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jul 22, 2014
1 parent 4f8c210 commit f0be970
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 295 deletions.
4 changes: 4 additions & 0 deletions build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
Expand Up @@ -316,6 +316,10 @@ <h2><a name="LibraryUpdates">Thirdparty Library Updates</a></h2>

The following components have been updated:

<h4>From 8.8</h4>
<ul>
<li>Saxon was upgraded from 9.2.1.5 to 9.5.1-6
</ul>
<h4>From 8.5</h4>
<ul>
<li>the engine xom and the embedded jaxen dependency were replaced with module dependencies
Expand Down
4 changes: 2 additions & 2 deletions engine/pom.xml
Expand Up @@ -106,8 +106,8 @@
</dependency>

<dependency>
<groupId>net.sourceforge.saxon</groupId>
<artifactId>saxonhe</artifactId>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
</dependency>

<dependency>
Expand Down
Expand Up @@ -70,7 +70,6 @@
import net.sf.saxon.om.Item;
import net.sf.saxon.om.Name11Checker;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.StandardNames;
import net.sf.saxon.sxpath.XPathEvaluator;
import net.sf.saxon.sxpath.XPathExpression;
import net.sf.saxon.trans.XPathException;
Expand Down Expand Up @@ -671,7 +670,7 @@ public static AtomicValue convertToAtomicValue(Object value) throws TransformerE
java.util.Date d = (java.util.Date)value;
DateTimeValue tdv = DateTimeValue.fromJavaDate(d);
if (value instanceof Date) {
value = new DateValue(tdv.getYear(), tdv.getMonth(), tdv.getDay(), tdv.getTimezoneInMinutes());
value = new DateValue(tdv.getYear(), tdv.getMonth(), tdv.getDay(), tdv.getTimezoneInMinutes(), true);
} else if (value instanceof Time) {
value = new TimeValue(tdv.getHour(), tdv.getMinute(), tdv.getSecond(), tdv.getMicrosecond(), tdv.getTimezoneInMinutes());
} else if (value instanceof Timestamp) {
Expand Down Expand Up @@ -825,7 +824,7 @@ public static String xpathValue(Object doc, String xpath) throws XPathException,
public static boolean isNull(Item i) {
if (i instanceof NodeInfo) {
NodeInfo ni = (NodeInfo)i;
return ni.getNodeKind() == net.sf.saxon.type.Type.ELEMENT && !ni.hasChildNodes() && Boolean.valueOf(ni.getAttributeValue(StandardNames.XSI_NIL));
return ni.getNodeKind() == net.sf.saxon.type.Type.ELEMENT && !ni.hasChildNodes() && Boolean.valueOf(ni.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil")); //$NON-NLS-1$
/* ideally we'd be able to check for nilled, but that doesn't work without validation
if (ni.isNilled()) {
tuple.add(null);
Expand Down
Expand Up @@ -33,19 +33,21 @@
import java.util.Map;
import java.util.TimeZone;

import net.sf.saxon.lib.ConversionRules;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.SequenceTool;
import net.sf.saxon.sxpath.XPathDynamicContext;
import net.sf.saxon.sxpath.XPathExpression;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.BuiltInAtomicType;
import net.sf.saxon.type.ConversionResult;
import net.sf.saxon.type.Converter;
import net.sf.saxon.type.ValidationException;
import net.sf.saxon.value.AtomicValue;
import net.sf.saxon.value.CalendarValue;
import net.sf.saxon.value.StringValue;
import net.sf.saxon.value.Value;

import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.common.buffer.BlockedException;
Expand Down Expand Up @@ -339,7 +341,8 @@ private Object getValue(Class<?> type,
}
BuiltInAtomicType bat = typeMapping.get(type);
if (bat != null) {
ConversionResult cr = StringValue.convertStringToBuiltInType(i.getStringValueCS(), bat, null);
AtomicValue av = new StringValue(i.getStringValueCS());
ConversionResult cr = Converter.convert(av, bat, new ConversionRules());
value = cr.asAtomic();
value = getValue((AtomicValue)value);
if (value instanceof Item) {
Expand All @@ -366,7 +369,7 @@ private Object getValue(AtomicValue value) throws XPathException {
return new Timestamp(cal.getTime().getTime());
}
}
return Value.convertToJava(value);
return SequenceTool.convertToJava(value);
}

@Override
Expand Down
Expand Up @@ -155,7 +155,7 @@ public static String translateToXMLValue(Object value, Class<?> runtimeType, Str
} catch (TransformerException e) {
throw new TransformationException(QueryPlugin.Event.TEIID30209, e, e.getMessage());
}
valueStr = new GYearMonthValue(dtv.getYear(), dtv.getMonth(), dtv.getTimezoneInMinutes()).getStringValue();
valueStr = new GYearMonthValue(dtv.getYear(), dtv.getMonth(), dtv.getTimezoneInMinutes(), true).getStringValue();
break;
default:
valueStr = defaultTranslation(value);
Expand Down
@@ -1,9 +1,9 @@
package org.teiid.query.xquery.saxon;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import net.sf.saxon.Configuration;
import net.sf.saxon.om.DocumentInfo;
Expand Down Expand Up @@ -32,10 +32,12 @@ public class DocumentWrapper extends NodeWrapper implements DocumentInfo {

protected String baseURI;

protected int documentNumber;
protected long documentNumber;

private HashMap idIndex;

private Map<String, Object> userData = new HashMap<String, Object>();

/**
* Create a Saxon wrapper for a XOM root node
*
Expand Down Expand Up @@ -86,7 +88,7 @@ public NodeInfo wrap(Node node) {

public void setConfiguration(Configuration config) {
this.config = config;
this.documentNumber = allocateDocumentNumber(config);
this.documentNumber = config.getDocumentNumberAllocator().allocateDocumentNumber();
}

/**
Expand Down Expand Up @@ -193,42 +195,6 @@ public String[] getUnparsedEntity(String name) {
return null;
}

private static final Method saxon85Method = findAllocateDocumentNumberMethod85();

// work-around for incompatibility introduced in saxon-8.5.1
private int allocateDocumentNumber(Configuration config) {
if (saxon85Method == null) {
try { // saxon >= 8.5.1
return allocateDocumentNumber851(config);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}

// saxon < 8.5.1
try {
// return config.getNamePool().allocateDocumentNumber(this);
Object result = saxon85Method.invoke(config.getNamePool(), new Object[] {this});
return ((Integer) result).intValue();
} catch (Throwable t) {
throw new RuntimeException(t);
}

}

// saxon >= 8.5.1
private int allocateDocumentNumber851(Configuration config) {
return config.getDocumentNumberAllocator().allocateDocumentNumber();
}

private static Method findAllocateDocumentNumberMethod85() {
try {
return NamePool.class.getMethod("allocateDocumentNumber", new Class[] {NodeInfo.class});
} catch (Throwable t) {
return null;
}
}

@Override
public Iterator getUnparsedEntityNames() {
return Collections.EMPTY_LIST.iterator();
Expand All @@ -253,6 +219,21 @@ public boolean isIdref() {
public boolean isNilled() {
return false;
}

@Override
public Object getUserData(String arg0) {
return this.userData.get(arg0);
}

@Override
public void setUserData(String arg0, Object arg1) {
this.userData.put(arg0, arg1);
}

@Override
public boolean isTyped() {
return false;
}

}

Expand Down

0 comments on commit f0be970

Please sign in to comment.