Author: shawkins
Date: 2010-03-22 21:59:46 -0400 (Mon, 22 Mar 2010)
New Revision: 1989
Added:
trunk/client/src/test/java/org/teiid/client/plan/
trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToClobTransform.java
Removed:
trunk/client/src/test/java/org/teiid/client/plan/
trunk/engine/src/main/java/org/teiid/adminapi/
Modified:
trunk/client/src/test/java/org/teiid/client/plan/TestTextOutputVisitor.java
trunk/client/src/test/java/org/teiid/client/plan/TestXMLOutputVisitor.java
trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java
trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java
trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
trunk/common-core/src/main/java/com/metamatrix/common/types/InputStreamFactory.java
trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java
trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java
trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java
trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml
Log:
TEIID-1024 adding support for the conversion between clob and sqlxml
Copied: trunk/client/src/test/java/org/teiid/client/plan (from rev 1986,
trunk/client/src/test/java/org/teiid/jdbc/plan)
Modified: trunk/client/src/test/java/org/teiid/client/plan/TestTextOutputVisitor.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/plan/TestTextOutputVisitor.java 2010-03-22
21:01:44 UTC (rev 1986)
+++ trunk/client/src/test/java/org/teiid/client/plan/TestTextOutputVisitor.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package org.teiid.jdbc.plan;
+package org.teiid.client.plan;
import java.util.ArrayList;
import java.util.Arrays;
Modified: trunk/client/src/test/java/org/teiid/client/plan/TestXMLOutputVisitor.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/plan/TestXMLOutputVisitor.java 2010-03-22
21:01:44 UTC (rev 1986)
+++ trunk/client/src/test/java/org/teiid/client/plan/TestXMLOutputVisitor.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package org.teiid.jdbc.plan;
+package org.teiid.client.plan;
import org.teiid.client.plan.DefaultDisplayHelper;
import org.teiid.client.plan.XMLOutputVisitor;
Added: trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java
(rev 0)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -0,0 +1,57 @@
+package com.metamatrix.common.types;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.sql.SQLException;
+
+public class BaseLob {
+
+ private InputStreamFactory streamFactory;
+
+ protected BaseLob(InputStreamFactory streamFactory) {
+ this.streamFactory = streamFactory;
+ }
+
+ public InputStreamFactory getStreamFactory() throws SQLException {
+ if (this.streamFactory == null) {
+ throw new SQLException("Already freed"); //$NON-NLS-1$
+ }
+ return streamFactory;
+ }
+
+ public void free() throws SQLException {
+ if (this.streamFactory != null) {
+ try {
+ this.streamFactory.free();
+ this.streamFactory = null;
+ } catch (IOException e) {
+ SQLException ex = new SQLException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+ }
+
+ public Reader getCharacterStream() throws SQLException {
+ try {
+ return new InputStreamReader(this.getStreamFactory().getInputStream(),
this.getStreamFactory().getEncoding());
+ } catch (IOException e) {
+ SQLException ex = new SQLException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+
+ public InputStream getBinaryStream() throws SQLException {
+ try {
+ return this.getStreamFactory().getInputStream();
+ } catch (IOException e) {
+ SQLException ex = new SQLException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+
+}
Property changes on:
trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java 2010-03-22
21:50:36 UTC (rev 1988)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -41,34 +41,17 @@
* of the blob data. Connectors can use this object when dealing with large
* objects.
*/
-public class BlobImpl implements Blob, StreamProvider {
-
- private InputStreamFactory streamFactory;
+public class BlobImpl extends BaseLob implements Blob, StreamProvider {
/**
* Creates a MMBlob object with the <code>valueID</code>.
* @param valueID reference to value chunk in data source.
*/
public BlobImpl(InputStreamFactory streamFactory) {
- this.streamFactory = streamFactory;
+ super(streamFactory);
}
/**
- * Retrieves the <code>BLOB</code> designated by this
- * <code>Blob</code> instance as a stream.
- * @return a stream containing the whole or part of the <code>BLOB</code>
data
- * @exception SQLException if there is an error accessing the
- * <code>BLOB</code>
- */
- public InputStream getBinaryStream() throws SQLException {
- try {
- return streamFactory.getInputStream();
- } catch (IOException e) {
- throw new SQLException(e);
- }
- }
-
- /**
* Returns as an array of bytes, part or all of the <code>BLOB</code>
* value that this <code>Blob</code> object designates. The byte
* array contains up to <code>length</code> consecutive bytes
@@ -122,14 +105,14 @@
* @return length of the <code>BLOB</code> in bytes
*/
public long length() throws SQLException{
- if (streamFactory.getLength() == -1) {
+ if (getStreamFactory().getLength() == -1) {
InputStream is = new BufferedInputStream(getBinaryStream());
try {
long length = 0;
while (is.read() != -1) {
length++;
}
- streamFactory.setLength(length);
+ getStreamFactory().setLength(length);
} catch (IOException e) {
throw new SQLException(e);
} finally {
@@ -139,7 +122,7 @@
}
}
}
- return streamFactory.getLength();
+ return getStreamFactory().getLength();
}
/**
@@ -187,10 +170,6 @@
return position(new SerialBlob(pattern), start);
}
- public void free() throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
public InputStream getBinaryStream(long arg0, long arg1)
throws SQLException {
throw SqlUtil.createFeatureNotSupportedException();
Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java 2010-03-22
21:50:36 UTC (rev 1988)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -25,7 +25,6 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
@@ -45,7 +44,7 @@
* of the Clob data. Connectors can use this object when dealing with large
* objects.
*/
-public class ClobImpl implements Clob {
+public class ClobImpl extends BaseLob implements Clob {
private final static class ClobStreamProvider implements
LobSearchUtil.StreamProvider {
@@ -66,7 +65,6 @@
}
}
- private final InputStreamFactory streamFactory;
private long len;
/**
@@ -76,7 +74,7 @@
* @param length
*/
public ClobImpl(InputStreamFactory streamFactory, long length) {
- this.streamFactory = streamFactory;
+ super(streamFactory);
this.len = length;
}
@@ -92,21 +90,6 @@
}
/**
- * Gets the <code>CLOB</code> value designated by this
<code>Clob</code>
- * object as a Unicode stream.
- * @return a Unicode stream containing the <code>CLOB</code> data
- * @exception SQLException if there is an error accessing the
- * <code>CLOB</code> value
- */
- public Reader getCharacterStream() throws SQLException {
- try {
- return new InputStreamReader(this.streamFactory.getInputStream(),
this.streamFactory.getEncoding());
- } catch (IOException e) {
- throw new SQLException(e);
- }
- }
-
- /**
* Returns a copy of the specified substring
* in the <code>CLOB</code> value
* designated by this <code>Clob</code> object.
@@ -214,10 +197,6 @@
return position(new SerialClob(searchstr.toCharArray()), start);
}
- public void free() throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
public Reader getCharacterStream(long arg0, long arg1) throws SQLException {
throw SqlUtil.createFeatureNotSupportedException();
}
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-03-22
21:50:36 UTC (rev 1988)
+++
trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -50,6 +50,8 @@
import com.metamatrix.common.types.basic.AnyToObjectTransform;
import com.metamatrix.common.types.basic.AnyToStringTransform;
import com.metamatrix.common.types.basic.BooleanToNumberTransform;
+import com.metamatrix.common.types.basic.ClobToSQLXMLTransform;
+import com.metamatrix.common.types.basic.ClobToStringTransform;
import com.metamatrix.common.types.basic.FixedNumberToBigDecimalTransform;
import com.metamatrix.common.types.basic.FixedNumberToBigIntegerTransform;
import com.metamatrix.common.types.basic.FloatingNumberToBigDecimalTransform;
@@ -63,6 +65,7 @@
import com.metamatrix.common.types.basic.NumberToLongTransform;
import com.metamatrix.common.types.basic.NumberToShortTransform;
import com.metamatrix.common.types.basic.ObjectToAnyTransform;
+import com.metamatrix.common.types.basic.SQLXMLToClobTransform;
import com.metamatrix.common.util.PropertiesUtils;
import com.metamatrix.core.CorePlugin;
import com.metamatrix.core.ErrorMessageKeys;
@@ -583,26 +586,6 @@
* set is always installed but may be overridden.
*/
static void loadBasicTransforms() {
- DataTypeManager.addTransform(new NumberToBooleanTransform(BigDecimal.valueOf(0)));
- DataTypeManager.addTransform(new
NumberToByteTransform(DefaultDataClasses.BIG_DECIMAL));
- DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.BIG_DECIMAL,
true));
- DataTypeManager.addTransform(new
NumberToIntegerTransform(DefaultDataClasses.BIG_DECIMAL, true));
- DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.BIG_DECIMAL,
true, false));
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.BigDecimalToBigIntegerTransform());
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.BIG_DECIMAL,
true, false));
- DataTypeManager.addTransform(new
NumberToDoubleTransform(DefaultDataClasses.BIG_DECIMAL, true, false));
- DataTypeManager.addTransform(new
AnyToStringTransform(DefaultDataClasses.BIG_DECIMAL));
-
- DataTypeManager.addTransform(new NumberToBooleanTransform(BigInteger.valueOf(0)));
- DataTypeManager.addTransform(new
NumberToByteTransform(DefaultDataClasses.BIG_INTEGER));
- DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.BIG_INTEGER,
true));
- DataTypeManager.addTransform(new
NumberToIntegerTransform(DefaultDataClasses.BIG_INTEGER, true));
- DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.BIG_INTEGER,
true, false));
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.BIG_INTEGER,
true, false));
- DataTypeManager.addTransform(new
NumberToDoubleTransform(DefaultDataClasses.BIG_INTEGER, true, false));
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.BigIntegerToBigDecimalTransform());
- DataTypeManager.addTransform(new
AnyToStringTransform(DefaultDataClasses.BIG_INTEGER));
-
DataTypeManager.addTransform(new BooleanToNumberTransform(Byte.valueOf((byte)1),
Byte.valueOf((byte)0)));
DataTypeManager.addTransform(new BooleanToNumberTransform(Short.valueOf((short)1),
Short.valueOf((short)0)));
DataTypeManager.addTransform(new BooleanToNumberTransform(Integer.valueOf(1),
Integer.valueOf(0)));
@@ -624,32 +607,17 @@
DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.BYTE));
DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.CHAR));
-
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.ClobToStringTransform());
-
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.DateToTimestampTransform());
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.DATE));
-
- DataTypeManager.addTransform(new NumberToBooleanTransform(Double.valueOf(0)));
- DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.DOUBLE));
- DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.DOUBLE,
true));
- DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.DOUBLE,
true));
- DataTypeManager.addTransform(new NumberToLongTransform( DefaultDataClasses.DOUBLE,
false, true)); //lossy, but not narrowing
- DataTypeManager.addTransform(new
FloatingNumberToBigIntegerTransform(DefaultDataClasses.DOUBLE));
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.DOUBLE,
true, false));
- DataTypeManager.addTransform(new
FloatingNumberToBigDecimalTransform(DefaultDataClasses.DOUBLE));
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.DOUBLE));
-
- DataTypeManager.addTransform(new NumberToBooleanTransform(Float.valueOf(0)));
- DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.FLOAT));
- DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.FLOAT,
true));
- DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.FLOAT,
true));
- DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.FLOAT, false,
true)); //lossy, but not narrowing
- DataTypeManager.addTransform(new
FloatingNumberToBigIntegerTransform(DefaultDataClasses.FLOAT));
- DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.FLOAT,
false, false));
- DataTypeManager.addTransform(new
FloatingNumberToBigDecimalTransform(DefaultDataClasses.FLOAT));
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.FLOAT));
-
+
+ DataTypeManager.addTransform(new NumberToBooleanTransform(Short.valueOf((short)0)));
+ DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.SHORT));
+ DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.SHORT,
false));
+ DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.SHORT, false,
false));
+ DataTypeManager.addTransform(new
FixedNumberToBigIntegerTransform(DefaultDataClasses.SHORT));
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.SHORT,
false, false));
+ DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.SHORT,
false, false));
+ DataTypeManager.addTransform(new
FixedNumberToBigDecimalTransform(DefaultDataClasses.SHORT));
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.SHORT));
+
DataTypeManager.addTransform(new NumberToBooleanTransform(Integer.valueOf(0)));
DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.INTEGER));
DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.INTEGER,
true));
@@ -669,17 +637,57 @@
DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.LONG,
false, true)); //lossy, but not narrowing
DataTypeManager.addTransform(new
FixedNumberToBigDecimalTransform(DefaultDataClasses.LONG));
DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.LONG));
-
- DataTypeManager.addTransform(new NumberToBooleanTransform(Short.valueOf((short)0)));
- DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.SHORT));
- DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.SHORT,
false));
- DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.SHORT, false,
false));
- DataTypeManager.addTransform(new
FixedNumberToBigIntegerTransform(DefaultDataClasses.SHORT));
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.SHORT,
false, false));
- DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.SHORT,
false, false));
- DataTypeManager.addTransform(new
FixedNumberToBigDecimalTransform(DefaultDataClasses.SHORT));
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.SHORT));
+ DataTypeManager.addTransform(new NumberToBooleanTransform(BigInteger.valueOf(0)));
+ DataTypeManager.addTransform(new
NumberToByteTransform(DefaultDataClasses.BIG_INTEGER));
+ DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.BIG_INTEGER,
true));
+ DataTypeManager.addTransform(new
NumberToIntegerTransform(DefaultDataClasses.BIG_INTEGER, true));
+ DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.BIG_INTEGER,
true, false));
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.BIG_INTEGER,
true, false));
+ DataTypeManager.addTransform(new
NumberToDoubleTransform(DefaultDataClasses.BIG_INTEGER, true, false));
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.BigIntegerToBigDecimalTransform());
+ DataTypeManager.addTransform(new
AnyToStringTransform(DefaultDataClasses.BIG_INTEGER));
+
+ DataTypeManager.addTransform(new NumberToBooleanTransform(BigDecimal.valueOf(0)));
+ DataTypeManager.addTransform(new
NumberToByteTransform(DefaultDataClasses.BIG_DECIMAL));
+ DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.BIG_DECIMAL,
true));
+ DataTypeManager.addTransform(new
NumberToIntegerTransform(DefaultDataClasses.BIG_DECIMAL, true));
+ DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.BIG_DECIMAL,
true, false));
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.BigDecimalToBigIntegerTransform());
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.BIG_DECIMAL,
true, false));
+ DataTypeManager.addTransform(new
NumberToDoubleTransform(DefaultDataClasses.BIG_DECIMAL, true, false));
+ DataTypeManager.addTransform(new
AnyToStringTransform(DefaultDataClasses.BIG_DECIMAL));
+
+ DataTypeManager.addTransform(new NumberToBooleanTransform(Float.valueOf(0)));
+ DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.FLOAT));
+ DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.FLOAT,
true));
+ DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.FLOAT,
true));
+ DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.FLOAT, false,
true)); //lossy, but not narrowing
+ DataTypeManager.addTransform(new
FloatingNumberToBigIntegerTransform(DefaultDataClasses.FLOAT));
+ DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.FLOAT,
false, false));
+ DataTypeManager.addTransform(new
FloatingNumberToBigDecimalTransform(DefaultDataClasses.FLOAT));
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.FLOAT));
+
+ DataTypeManager.addTransform(new NumberToBooleanTransform(Double.valueOf(0)));
+ DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.DOUBLE));
+ DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.DOUBLE,
true));
+ DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.DOUBLE,
true));
+ DataTypeManager.addTransform(new NumberToLongTransform( DefaultDataClasses.DOUBLE,
false, true)); //lossy, but not narrowing
+ DataTypeManager.addTransform(new
FloatingNumberToBigIntegerTransform(DefaultDataClasses.DOUBLE));
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.DOUBLE,
true, false));
+ DataTypeManager.addTransform(new
FloatingNumberToBigDecimalTransform(DefaultDataClasses.DOUBLE));
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.DOUBLE));
+
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.DateToTimestampTransform());
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.DATE));
+
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.TimeToTimestampTransform());
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.TIME));
+
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.TimestampToTimeTransform());
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.TimestampToDateTransform());
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.TIMESTAMP));
+
DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.StringToBooleanTransform());
DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.StringToByteTransform());
DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.StringToShortTransform());
@@ -696,15 +704,12 @@
DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.StringToClobTransform());
DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.StringToSQLXMLTransform());
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.SQLXMLToStringTransform());
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.ClobToStringTransform());
+ DataTypeManager.addTransform(new ClobToSQLXMLTransform());
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.TimestampToTimeTransform());
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.TimestampToDateTransform());
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.TIMESTAMP));
+ DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.SQLXMLToStringTransform());
+ DataTypeManager.addTransform(new SQLXMLToClobTransform());
- DataTypeManager.addTransform(new
com.metamatrix.common.types.basic.TimeToTimestampTransform());
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.TIME));
-
for (Class<?> type : getAllDataTypeClasses()) {
if (type != DefaultDataClasses.OBJECT) {
DataTypeManager.addTransform(new AnyToObjectTransform(type));
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/types/InputStreamFactory.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/types/InputStreamFactory.java 2010-03-22
21:50:36 UTC (rev 1988)
+++
trunk/common-core/src/main/java/com/metamatrix/common/types/InputStreamFactory.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -28,6 +28,7 @@
import javax.xml.transform.Source;
+//TODO: add support for Readers
public abstract class InputStreamFactory implements Source {
private String encoding;
Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java 2010-03-22
21:50:36 UTC (rev 1988)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -25,11 +25,9 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.sql.SQLException;
import java.sql.SQLXML;
@@ -38,44 +36,33 @@
import javax.xml.transform.stream.StreamSource;
import com.metamatrix.common.util.SqlUtil;
-import com.metamatrix.core.MetaMatrixRuntimeException;
import com.metamatrix.core.util.ObjectConverterUtil;
/**
* Default SQLXML impl
*/
-public class SQLXMLImpl implements SQLXML {
+public class SQLXMLImpl extends BaseLob implements SQLXML {
- private InputStreamFactory streamFactory;
-
/**
* Constructs a SQLXML from bytes that are already encoded in {@link
Streamable#ENCODING}
* @param bytes
*/
public SQLXMLImpl(final byte[] bytes) {
- setStreamFactory(bytes);
- }
-
- private void setStreamFactory(final byte[] bytes) {
- this.streamFactory = new InputStreamFactory(Streamable.ENCODING) {
+ super(new InputStreamFactory(Streamable.ENCODING) {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(bytes);
}
- };
+ });
}
public SQLXMLImpl(final String str) {
- try {
- setStreamFactory(str.getBytes(Streamable.ENCODING));
- } catch (UnsupportedEncodingException e) {
- throw new MetaMatrixRuntimeException(e);
- }
+ this(str.getBytes(Charset.forName(Streamable.ENCODING)));
}
public SQLXMLImpl(InputStreamFactory factory) {
- this.streamFactory = factory;
+ super(factory);
}
@SuppressWarnings("unchecked")
@@ -86,35 +73,9 @@
throw new SQLException("Unsupported source type " + sourceClass);
//$NON-NLS-1$
}
- public Reader getCharacterStream() throws SQLException {
- if (this.streamFactory == null) {
- throw new SQLException("SQLXML already freed"); //$NON-NLS-1$
- }
- try {
- return new InputStreamReader(this.streamFactory.getInputStream(),
this.streamFactory.getEncoding());
- } catch (IOException e) {
- SQLException ex = new SQLException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
- }
-
- public InputStream getBinaryStream() throws SQLException {
- if (this.streamFactory == null) {
- throw new SQLException("SQLXML already freed"); //$NON-NLS-1$
- }
- try {
- return this.streamFactory.getInputStream();
- } catch (IOException e) {
- SQLException ex = new SQLException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
- }
-
public String getString() throws SQLException {
try {
- return new String(ObjectConverterUtil.convertToByteArray(getBinaryStream()),
this.streamFactory.getEncoding());
+ return new String(ObjectConverterUtil.convertToByteArray(getBinaryStream()),
this.getStreamFactory().getEncoding());
} catch (IOException e) {
SQLException ex = new SQLException(e.getMessage());
ex.initCause(e);
@@ -142,19 +103,6 @@
}
}
- public void free() throws SQLException {
- if (this.streamFactory != null) {
- try {
- this.streamFactory.free();
- this.streamFactory = null;
- } catch (IOException e) {
- SQLException ex = new SQLException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
- }
- }
-
public <T extends Result> T setResult(Class<T> resultClass)
throws SQLException {
throw SqlUtil.createFeatureNotSupportedException();
Modified: trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java 2010-03-22
21:50:36 UTC (rev 1988)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -23,7 +23,6 @@
package com.metamatrix.common.types;
import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.util.HashCodeUtil;
/**
* This interface represents the transformation from one data type to
@@ -55,7 +54,7 @@
* Type of the incoming value.
* @return Source type
*/
- public abstract Class getSourceType();
+ public abstract Class<?> getSourceType();
/**
* Name of the source type.
@@ -69,7 +68,7 @@
* Type of the outgoing value.
* @return Target type
*/
- public abstract Class getTargetType();
+ public abstract Class<?> getTargetType();
/**
* Name of the target type.
@@ -107,33 +106,6 @@
return getDisplayName();
}
- /**
- * Override Object.hashCode() to build a hash based on types.
- * @return Hash code
- */
- public int hashCode() {
- return HashCodeUtil.hashCode( getSourceTypeName().hashCode(),
getTargetTypeName().hashCode() );
- }
-
- /**
- * Override Object.equals() to build an equals based on src and tgt types.
- * @param obj Other object
- * @return True if obj==this
- */
- public boolean equals(Object obj) {
- if(this == obj) {
- return true;
- }
-
- if(! this.getClass().isInstance(obj)) {
- return false;
- }
-
- Transform other = (Transform) obj;
- return other.getSourceType() == this.getSourceType() &&
- other.getTargetType() == this.getTargetType();
- }
-
protected void checkValueRange(Object value, Number min, Number max)
throws TransformationException {
if (((Comparable)value).compareTo(DataTypeManager.transformValue(min, getSourceType()))
< 0 || ((Comparable)value).compareTo(DataTypeManager.transformValue(max,
getSourceType())) > 0) {
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java 2010-03-22
21:50:36 UTC (rev 1988)
+++
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -22,22 +22,35 @@
package com.metamatrix.common.types.basic;
-import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
import java.sql.SQLException;
+import com.metamatrix.common.types.ClobImpl;
import com.metamatrix.common.types.ClobType;
import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.InputStreamFactory;
+import com.metamatrix.common.types.SQLXMLImpl;
+import com.metamatrix.common.types.Streamable;
+import com.metamatrix.common.types.Transform;
import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
+import com.metamatrix.common.types.XMLType;
+import com.metamatrix.common.util.ReaderInputStream;
import com.metamatrix.core.CorePlugin;
-public class ClobToSQLXMLTransform extends AnyToStringTransform {
+public class ClobToSQLXMLTransform extends Transform {
- public ClobToSQLXMLTransform() {
- super(DefaultDataClasses.CLOB);
+ @Override
+ public Class<?> getSourceType() {
+ return DataTypeManager.DefaultDataClasses.CLOB;
}
+ @Override
+ public Class<?> getTargetType() {
+ return DataTypeManager.DefaultDataClasses.XML;
+ }
+
/**
* This method transforms a value of the source type into a value
* of the target type.
@@ -47,24 +60,26 @@
* the transformation fails
*/
public Object transformDirect(Object value) throws TransformationException {
- ClobType source = (ClobType)value;
+ final ClobType source = (ClobType)value;
try {
- BufferedReader reader = new BufferedReader (source.getCharacterStream());
- StringBuffer contents = new StringBuffer();
-
- int chr = reader.read();
- while (chr != -1 && contents.length() <
DataTypeManager.MAX_STRING_LENGTH) {
- contents.append((char)chr);
- chr = reader.read();
- }
- reader.close();
- return contents.toString();
-
+ StringToSQLXMLTransform.isXml(source.getCharacterStream());
+ if (source.getReference() instanceof ClobImpl) {
+ ClobImpl clob = (ClobImpl)source.getReference();
+ return new XMLType(new SQLXMLImpl(clob.getStreamFactory()));
+ }
+ return new XMLType(new SQLXMLImpl(new InputStreamFactory(Streamable.ENCODING)
{
+ @Override
+ public InputStream getInputStream() throws IOException {
+ try {
+ return new ReaderInputStream(source.getCharacterStream(),
Charset.forName(Streamable.ENCODING));
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+ }));
} catch (SQLException e) {
throw new TransformationException(e,
CorePlugin.Util.getString("failed_convert", new Object[]
{getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$
- } catch(IOException e) {
- throw new TransformationException(e,
CorePlugin.Util.getString("failed_convert", new Object[]
{getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$
}
}
Added:
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToClobTransform.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToClobTransform.java
(rev 0)
+++
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToClobTransform.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -0,0 +1,91 @@
+/*
+ * 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 com.metamatrix.common.types.basic;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.sql.SQLException;
+
+import com.metamatrix.common.types.ClobImpl;
+import com.metamatrix.common.types.ClobType;
+import com.metamatrix.common.types.DataTypeManager;
+import com.metamatrix.common.types.InputStreamFactory;
+import com.metamatrix.common.types.SQLXMLImpl;
+import com.metamatrix.common.types.Streamable;
+import com.metamatrix.common.types.Transform;
+import com.metamatrix.common.types.TransformationException;
+import com.metamatrix.common.types.XMLType;
+import com.metamatrix.common.util.ReaderInputStream;
+import com.metamatrix.core.CorePlugin;
+
+public class SQLXMLToClobTransform extends Transform {
+
+ @Override
+ public Class<?> getSourceType() {
+ return DataTypeManager.DefaultDataClasses.XML;
+ }
+
+ @Override
+ public Class<?> getTargetType() {
+ return DataTypeManager.DefaultDataClasses.CLOB;
+ }
+
+ /**
+ * This method transforms a value of the source type into a value
+ * of the target type.
+ * @param value Incoming value of source type
+ * @return Outgoing value of target type
+ * @throws TransformationException if value is an incorrect input type or
+ * the transformation fails
+ */
+ public Object transformDirect(Object value) throws TransformationException {
+ final XMLType source = (XMLType)value;
+
+ try {
+ if (source.getReference() instanceof SQLXMLImpl) {
+ SQLXMLImpl xml = (SQLXMLImpl)source.getReference();
+ return new ClobType(new ClobImpl(xml.getStreamFactory(), -1));
+ }
+ return new ClobType(new ClobImpl(new InputStreamFactory(Streamable.ENCODING)
{
+ @Override
+ public InputStream getInputStream() throws IOException {
+ try {
+ return new ReaderInputStream(source.getCharacterStream(),
Charset.forName(Streamable.ENCODING));
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+ }, -1));
+ } catch (SQLException e) {
+ throw new TransformationException(e,
CorePlugin.Util.getString("failed_convert", new Object[]
{getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @see com.metamatrix.common.types.Transform#isExplicit()
+ */
+ public boolean isExplicit() {
+ return true;
+ }
+}
Property changes on:
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToClobTransform.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java
===================================================================
---
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java 2010-03-22
21:50:36 UTC (rev 1988)
+++
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -22,17 +22,18 @@
package com.metamatrix.common.types.basic;
+import java.io.IOException;
+import java.io.Reader;
import java.io.StringReader;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.dom.DOMSource;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
-import org.w3c.dom.Document;
import org.xml.sax.InputSource;
+import org.xml.sax.helpers.DefaultHandler;
+import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.SQLXMLImpl;
-import com.metamatrix.common.types.StandardXMLTranslator;
import com.metamatrix.common.types.Transform;
import com.metamatrix.common.types.TransformationException;
import com.metamatrix.common.types.XMLType;
@@ -49,16 +50,24 @@
* the transformation fails
*/
public Object transformDirect(Object value) throws TransformationException {
- String xml = (String)value;
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ String xml = (String)value;
+ Reader reader = new StringReader(xml);
+ isXml(reader);
+ return new XMLType(new SQLXMLImpl(xml));
+ }
+
+ static void isXml(Reader reader) throws TransformationException {
+ SAXParserFactory spf = SAXParserFactory.newInstance();
try{
- DocumentBuilder parser = factory.newDocumentBuilder();
- Document doc = parser.parse(new InputSource(new StringReader(xml)));
- StandardXMLTranslator sxt = new StandardXMLTranslator(new DOMSource(doc),
null);
- return new XMLType(new SQLXMLImpl(sxt.getString()));
- }
- catch (Exception e){
+ SAXParser sp = spf.newSAXParser();
+ sp.parse(new InputSource(reader), new DefaultHandler());
+ } catch (Exception e){
throw new TransformationException(e,
CorePlugin.Util.getString("invalid_string")); //$NON-NLS-1$
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ }
}
}
@@ -66,16 +75,16 @@
* Type of the incoming value.
* @return Source type
*/
- public Class getSourceType() {
- return String.class;
+ public Class<?> getSourceType() {
+ return DataTypeManager.DefaultDataClasses.STRING;
}
/**
* Type of the outgoing value.
* @return Target type
*/
- public Class getTargetType() {
- return XMLType.class;
+ public Class<?> getTargetType() {
+ return DataTypeManager.DefaultDataClasses.XML;
}
@Override
Modified:
trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java
===================================================================
---
trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java 2010-03-22
21:50:36 UTC (rev 1988)
+++
trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java 2010-03-23
01:59:46 UTC (rev 1989)
@@ -161,7 +161,7 @@
assertEquals(DataTypeManager.DefaultDataClasses.DATE, t.getTargetType());
t = DataTypeManager.getTransform(DataTypeManager.DefaultDataTypes.TIME,
DataTypeManager.DefaultDataTypes.TIMESTAMP);
-
+
assertEquals(DataTypeManager.DefaultDataClasses.TIMESTAMP, t.getTargetType());
}
@@ -216,5 +216,10 @@
DataTypeManager.DefaultDataTypes.STRING,
DataTypeManager.DefaultDataTypes.OBJECT),
DataTypeManager.getImplicitConversions(DataTypeManager.DefaultDataTypes.INTEGER));
}
+
+ @SuppressWarnings("unchecked")
+ @Test(expected=TransformationException.class) public void testStringToXML() throws
Exception {
+ DataTypeManager.transformValue("hello",
DataTypeManager.DefaultDataClasses.XML); //$NON-NLS-1$
+ }
}
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml 2010-03-22
21:50:36 UTC (rev 1988)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/datatypes.xml 2010-03-23
01:59:46 UTC (rev 1989)
@@ -342,12 +342,12 @@
<row>
<entry>clob</entry>
<entry></entry>
- <entry>string</entry>
+ <entry>string, xml</entry>
</row>
<row>
<entry>xml</entry>
<entry></entry>
- <entry>string</entry>
+ <entry>string, clob</entry>
</row>
</tbody>
</tgroup>