[teiid-commits] teiid SVN: r2115 - in trunk/common-core/src: main/java/com/metamatrix/api and 37 other directories.
teiid-commits at lists.jboss.org
teiid-commits at lists.jboss.org
Tue May 11 17:39:14 EDT 2010
Author: shawkins
Date: 2010-05-11 17:39:07 -0400 (Tue, 11 May 2010)
New Revision: 2115
Added:
trunk/common-core/src/main/java/org/
trunk/common-core/src/main/java/org/teiid/
trunk/common-core/src/main/java/org/teiid/core/
trunk/common-core/src/main/java/org/teiid/core/BundleUtil.java
trunk/common-core/src/main/java/org/teiid/core/ComponentNotFoundException.java
trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java
trunk/common-core/src/main/java/org/teiid/core/CorePlugin.java
trunk/common-core/src/main/java/org/teiid/core/ErrorMessageKeys.java
trunk/common-core/src/main/java/org/teiid/core/TeiidComponentException.java
trunk/common-core/src/main/java/org/teiid/core/TeiidException.java
trunk/common-core/src/main/java/org/teiid/core/TeiidProcessingException.java
trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java
trunk/common-core/src/main/java/org/teiid/core/crypto/
trunk/common-core/src/main/java/org/teiid/core/id/
trunk/common-core/src/main/java/org/teiid/core/types/
trunk/common-core/src/main/java/org/teiid/core/types/BaseLob.java
trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/BlobType.java
trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java
trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java
trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java
trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java
trunk/common-core/src/main/java/org/teiid/core/types/LobSearchUtil.java
trunk/common-core/src/main/java/org/teiid/core/types/NullType.java
trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/Sequencable.java
trunk/common-core/src/main/java/org/teiid/core/types/SourceTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/StandardXMLTranslator.java
trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java
trunk/common-core/src/main/java/org/teiid/core/types/Transform.java
trunk/common-core/src/main/java/org/teiid/core/types/TransformationException.java
trunk/common-core/src/main/java/org/teiid/core/types/XMLTranslator.java
trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/
trunk/common-core/src/main/java/org/teiid/core/util/
trunk/common-core/src/main/java/org/teiid/core/util/ApplicationInfo.java
trunk/common-core/src/main/java/org/teiid/core/util/ExceptionUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/PasswordMaskUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java
trunk/common-core/src/main/java/org/teiid/core/util/ReaderInputStream.java
trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/TimestampWithTimezone.java
trunk/common-core/src/main/resources/org/
trunk/common-core/src/main/resources/org/teiid/
trunk/common-core/src/main/resources/org/teiid/core/crypto/
trunk/common-core/src/main/resources/org/teiid/core/crypto/dh.properties
trunk/common-core/src/main/resources/org/teiid/core/util/
trunk/common-core/src/main/resources/org/teiid/core/util/application.properties
trunk/common-core/src/test/java/org/
trunk/common-core/src/test/java/org/teiid/
trunk/common-core/src/test/java/org/teiid/api/
trunk/common-core/src/test/java/org/teiid/api/exception/
trunk/common-core/src/test/java/org/teiid/common/
trunk/common-core/src/test/java/org/teiid/common/util/
trunk/common-core/src/test/java/org/teiid/core/
trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixException.java
trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
trunk/common-core/src/test/java/org/teiid/core/crypto/
trunk/common-core/src/test/java/org/teiid/core/id/
trunk/common-core/src/test/java/org/teiid/core/types/
trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java
trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java
trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java
trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java
trunk/common-core/src/test/java/org/teiid/core/types/TestXMLStreamSourceTranslator.java
trunk/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java
trunk/common-core/src/test/java/org/teiid/core/types/basic/
trunk/common-core/src/test/java/org/teiid/core/util/
trunk/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java
trunk/common-core/src/test/java/org/teiid/core/util/TestPropertiesUtils.java
trunk/common-core/src/test/java/org/teiid/core/util/TestReaderInputStream.java
trunk/common-core/src/test/java/org/teiid/core/util/TestSqlUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java
trunk/common-core/src/test/java/org/teiid/query/
trunk/common-core/src/test/java/org/teiid/query/unittest/
Removed:
trunk/common-core/src/main/java/com/metamatrix/api/exception/
trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java
trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java
trunk/common-core/src/main/java/com/metamatrix/common/types/BlobType.java
trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java
trunk/common-core/src/main/java/com/metamatrix/common/types/ClobType.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/JDBCSQLTypeInfo.java
trunk/common-core/src/main/java/com/metamatrix/common/types/LobSearchUtil.java
trunk/common-core/src/main/java/com/metamatrix/common/types/NullType.java
trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java
trunk/common-core/src/main/java/com/metamatrix/common/types/Sequencable.java
trunk/common-core/src/main/java/com/metamatrix/common/types/SourceTransform.java
trunk/common-core/src/main/java/com/metamatrix/common/types/StandardXMLTranslator.java
trunk/common-core/src/main/java/com/metamatrix/common/types/Streamable.java
trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java
trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java
trunk/common-core/src/main/java/com/metamatrix/common/types/XMLTranslator.java
trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java
trunk/common-core/src/main/java/com/metamatrix/common/types/basic/
trunk/common-core/src/main/java/com/metamatrix/common/util/ApplicationInfo.java
trunk/common-core/src/main/java/com/metamatrix/common/util/PasswordMaskUtil.java
trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
trunk/common-core/src/main/java/com/metamatrix/common/util/ReaderInputStream.java
trunk/common-core/src/main/java/com/metamatrix/common/util/SqlUtil.java
trunk/common-core/src/main/java/com/metamatrix/common/util/TimestampWithTimezone.java
trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/
trunk/common-core/src/main/java/com/metamatrix/core/BundleUtil.java
trunk/common-core/src/main/java/com/metamatrix/core/CoreConstants.java
trunk/common-core/src/main/java/com/metamatrix/core/CorePlugin.java
trunk/common-core/src/main/java/com/metamatrix/core/ErrorMessageKeys.java
trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java
trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java
trunk/common-core/src/main/java/com/metamatrix/core/id/
trunk/common-core/src/main/java/com/metamatrix/core/util/
trunk/common-core/src/main/java/com/metamatrix/core/vdb/
trunk/common-core/src/main/java/org/teiid/core/util/MetaMatrixExceptionUtil.java
trunk/common-core/src/main/resources/com/
trunk/common-core/src/main/resources/org/metamatrix/
trunk/common-core/src/main/resources/org/teiid/common/util/
trunk/common-core/src/test/java/com/metamatrix/api/exception/
trunk/common-core/src/test/java/com/metamatrix/common/types/TestBlobValue.java
trunk/common-core/src/test/java/com/metamatrix/common/types/TestClobValue.java
trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java
trunk/common-core/src/test/java/com/metamatrix/common/types/TestSQLXMLImpl.java
trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLStreamSourceTranslator.java
trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLValue.java
trunk/common-core/src/test/java/com/metamatrix/common/types/basic/
trunk/common-core/src/test/java/com/metamatrix/common/util/FakeInputStream.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestReaderInputStream.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestSqlUtil.java
trunk/common-core/src/test/java/com/metamatrix/common/util/TestTimestampWithTimezone.java
trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/
trunk/common-core/src/test/java/com/metamatrix/core/id/
trunk/common-core/src/test/java/com/metamatrix/core/util/
trunk/common-core/src/test/java/com/metamatrix/query/unittest/
trunk/common-core/src/test/java/org/teiid/api/exception/TestExceptionHolder.java
trunk/common-core/src/test/java/org/teiid/api/exception/TestMetaMatrixException.java
trunk/common-core/src/test/java/org/teiid/api/exception/TestMetaMatrixRuntimeException.java
trunk/common-core/src/test/resources/test.jar
Modified:
trunk/common-core/src/main/java/org/teiid/core/crypto/BasicCryptor.java
trunk/common-core/src/main/java/org/teiid/core/crypto/CryptoException.java
trunk/common-core/src/main/java/org/teiid/core/crypto/Cryptor.java
trunk/common-core/src/main/java/org/teiid/core/crypto/DhKeyGenerator.java
trunk/common-core/src/main/java/org/teiid/core/crypto/NullCryptor.java
trunk/common-core/src/main/java/org/teiid/core/crypto/SymmetricCryptor.java
trunk/common-core/src/main/java/org/teiid/core/id/IDGenerator.java
trunk/common-core/src/main/java/org/teiid/core/id/IntegerID.java
trunk/common-core/src/main/java/org/teiid/core/id/IntegerIDFactory.java
trunk/common-core/src/main/java/org/teiid/core/id/InvalidIDException.java
trunk/common-core/src/main/java/org/teiid/core/id/LongID.java
trunk/common-core/src/main/java/org/teiid/core/id/LongIDFactory.java
trunk/common-core/src/main/java/org/teiid/core/id/ObjectID.java
trunk/common-core/src/main/java/org/teiid/core/id/ObjectIDFactory.java
trunk/common-core/src/main/java/org/teiid/core/id/ParsedObjectID.java
trunk/common-core/src/main/java/org/teiid/core/id/StringID.java
trunk/common-core/src/main/java/org/teiid/core/id/StringIDFactory.java
trunk/common-core/src/main/java/org/teiid/core/id/UUID.java
trunk/common-core/src/main/java/org/teiid/core/id/UUIDFactory.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToStringTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/BigDecimalToBigIntegerTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/BigIntegerToBigDecimalTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/BooleanToNumberTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/ClobToSQLXMLTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/ClobToStringTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/DateToTimestampTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/FixedNumberToBigDecimalTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/FixedNumberToBigIntegerTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/FloatingNumberToBigDecimalTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/FloatingNumberToBigIntegerTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NullToAnyTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToBooleanTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToByteTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToDoubleTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToFloatTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToIntegerTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToLongTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToShortTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/ObjectToAnyTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/SQLXMLToClobTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/SQLXMLToStringTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBigDecimalTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBigIntegerTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBooleanTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToByteTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToCharacterTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToClobTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToDateTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToDoubleTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToFloatTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToIntegerTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToLongTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToShortTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToTimeTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToTimestampTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/TimeToTimestampTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/TimestampToDateTransform.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/TimestampToTimeTransform.java
trunk/common-core/src/main/java/org/teiid/core/util/AccessibleByteArrayOutputStream.java
trunk/common-core/src/main/java/org/teiid/core/util/ArgCheck.java
trunk/common-core/src/main/java/org/teiid/core/util/Assertion.java
trunk/common-core/src/main/java/org/teiid/core/util/Base64.java
trunk/common-core/src/main/java/org/teiid/core/util/EquivalenceUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java
trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/LRUCache.java
trunk/common-core/src/main/java/org/teiid/core/util/MixinProxy.java
trunk/common-core/src/main/java/org/teiid/core/util/NamedThreadFactory.java
trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java
trunk/common-core/src/main/java/org/teiid/core/util/ObjectInputStreamWithClassloader.java
trunk/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java
trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
trunk/common-core/src/test/java/org/teiid/core/crypto/TestDhKeyGenerator.java
trunk/common-core/src/test/java/org/teiid/core/crypto/TestEncryptDecrypt.java
trunk/common-core/src/test/java/org/teiid/core/id/TestIDGenerator.java
trunk/common-core/src/test/java/org/teiid/core/id/TestParsedObjectID.java
trunk/common-core/src/test/java/org/teiid/core/id/TestParsingObjectIDs.java
trunk/common-core/src/test/java/org/teiid/core/id/TestUUID.java
trunk/common-core/src/test/java/org/teiid/core/id/TestUUIDFactory.java
trunk/common-core/src/test/java/org/teiid/core/id/TestUUIDFactoryWithoutCreation.java
trunk/common-core/src/test/java/org/teiid/core/types/basic/TestStringToXmlTransform.java
trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java
trunk/common-core/src/test/java/org/teiid/core/util/SimpleMock.java
trunk/common-core/src/test/java/org/teiid/core/util/TestAssertion.java
trunk/common-core/src/test/java/org/teiid/core/util/TestEquivalenceUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestExternalizeUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java
trunk/common-core/src/test/java/org/teiid/core/util/TestMetaMatrixExceptionUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java
trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
trunk/common-core/src/test/java/org/teiid/query/unittest/TimestampUtil.java
Log:
TEIID-918 changing package to org.teiid and removing metamatrix from class names
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,81 +0,0 @@
-package com.metamatrix.common.types;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Reader;
-import java.sql.SQLException;
-
-import com.metamatrix.common.types.InputStreamFactory.StreamFactoryReference;
-
-public class BaseLob implements Externalizable, StreamFactoryReference {
-
- private static final long serialVersionUID = -1586959324208959519L;
- private InputStreamFactory streamFactory;
-
- public BaseLob() {
-
- }
-
- protected BaseLob(InputStreamFactory streamFactory) {
- this.streamFactory = streamFactory;
- }
-
- public void setStreamFactory(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 this.getStreamFactory().getCharacterStream();
- } 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;
- }
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- streamFactory = (InputStreamFactory)in.readObject();
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(streamFactory);
- }
-
-}
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,210 +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 com.metamatrix.common.types;
-
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.Blob;
-import java.sql.SQLException;
-
-import javax.sql.rowset.serial.SerialBlob;
-
-import com.metamatrix.common.types.LobSearchUtil.StreamProvider;
-import com.metamatrix.common.util.SqlUtil;
-import com.metamatrix.core.CorePlugin;
-
-/**
- * This object holds a chunk of binary data and implements the JDBC Blob interface.
- * It presents a streaming interface and provides a way to access partial
- * of the blob data. Connectors can use this object when dealing with large
- * objects.
- */
-public class BlobImpl extends BaseLob implements Blob, StreamProvider {
-
- public BlobImpl() {
-
- }
-
- /**
- * Creates a MMBlob object with the <code>valueID</code>.
- * @param valueID reference to value chunk in data source.
- */
- public BlobImpl(InputStreamFactory streamFactory) {
- super(streamFactory);
- }
-
- /**
- * 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
- * starting at position <code>pos</code>.
- * @param pos the ordinal position of the first byte in the
- * <code>BLOB</code> value to be extracted; the first byte is at
- * position 1
- * @param length the number of consecutive bytes to be copied
- * @return a byte array containing up to <code>length</code>
- * consecutive bytes from the <code>BLOB</code> value designated
- * by this <code>Blob</code> object, starting with the
- * byte at position <code>pos</code>
- * @exception SQLException if there is an error accessing the
- * <code>BLOB</code>
- */
- public byte[] getBytes(long pos, int length) throws SQLException {
- if (pos < 1) {
- Object[] params = new Object[] {new Long(pos)};
- throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.0", params)); //$NON-NLS-1$
- }
- else if (pos > length()) {
- return null;
- }
- pos = pos - 1;
-
- if (length < 0) {
- Object[] params = new Object[] {new Integer( length)};
- throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.3", params)); //$NON-NLS-1$
- }
- else if (pos + length > length()) {
- length = (int)(length() - pos);
- }
- byte[] dataCopy = new byte[length];
- InputStream in = getBinaryStream();
- try {
- try {
- in.skip(pos);
- in.read(dataCopy);
- } finally {
- in.close();
- }
- } catch (IOException e) {
- throw new SQLException(e);
- }
- return dataCopy;
- }
-
- /**
- * Returns the number of bytes in the <code>BLOB</code> value
- * designated by this <code>Blob</code> object.
- * @return length of the <code>BLOB</code> in bytes
- */
- public long length() throws SQLException{
- if (getStreamFactory().getLength() == -1) {
- InputStream is = new BufferedInputStream(getBinaryStream());
- try {
- long length = 0;
- while (is.read() != -1) {
- length++;
- }
- getStreamFactory().setLength(length);
- } catch (IOException e) {
- throw new SQLException(e);
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- }
- return getStreamFactory().getLength();
- }
-
- /**
- * Determines the byte position in the <code>BLOB</code> value
- * designated by this <code>Blob</code> object at which
- * <code>pattern</code> begins. The search begins at position
- * <code>start</code>.
- * @param pattern the <code>Blob</code> object designating
- * the <code>BLOB</code> value for which to search
- * @param start the position in the <code>BLOB</code> value
- * at which to begin searching; the first position is 1
- * @return the position at which the pattern begins, else -1
- * @exception SQLException if there is an error accessing the
- * <code>BLOB</code>
- */
- public long position(final Blob pattern, long start) throws SQLException {
- if (pattern == null) {
- return -1;
- }
-
- return LobSearchUtil.position(new LobSearchUtil.StreamProvider() {
- public InputStream getBinaryStream() throws SQLException {
- return pattern.getBinaryStream();
- }
- }, pattern.length(), this, this.length(), start, 1);
- }
-
- /**
- * Determines the byte position at which the specified byte
- * <code>pattern</code> begins within the <code>BLOB</code>
- * value that this <code>Blob</code> object represents. The
- * search for <code>pattern</code> begins at position
- * <code>start</code>.
- * @param pattern the byte array for which to search
- * @param start the position at which to begin searching; the
- * first position is 1
- * @return the position at which the pattern appears, else -1
- * @exception SQLException if there is an error accessing the
- * <code>BLOB</code>
- */
- public long position(byte[] pattern, long start) throws SQLException {
- if (pattern == null) {
- return -1;
- }
- return position(new SerialBlob(pattern), start);
- }
-
- public InputStream getBinaryStream(long arg0, long arg1)
- throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
-
- /**
- * @see java.sql.Blob#setBytes(long, byte[])
- */
- public int setBytes(long pos, byte[] bytes) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- /**
- * @see java.sql.Blob#setBytes(long, byte[], int, int)
- */
- public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- /**
- * @see java.sql.Blob#setBinaryStream(long)
- */
- public OutputStream setBinaryStream(long pos) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- /**
- * @see java.sql.Blob#truncate(long)
- */
- public void truncate(long len) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/BlobType.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/BlobType.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/BlobType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,152 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.Blob;
-import java.sql.SQLException;
-
-import javax.sql.rowset.serial.SerialBlob;
-
-import com.metamatrix.core.MetaMatrixRuntimeException;
-
-/**
- * Represent a value of type "blob", which can be streamable from client
- */
-public final class BlobType extends Streamable<Blob> implements Blob {
-
- private static final long serialVersionUID = 1294191629070433450L;
-
- public BlobType() {
- }
-
- public BlobType(Blob blob) {
- super(blob);
- }
-
- /**
- * @see java.sql.Blob#getBinaryStream()
- */
- public InputStream getBinaryStream() throws SQLException {
- return this.reference.getBinaryStream();
- }
-
- /**
- * @see java.sql.Blob#getBytes(long, int)
- */
- public byte[] getBytes(long pos, int length) throws SQLException {
- return this.reference.getBytes(pos, length);
- }
-
- /**
- * @see java.sql.Blob#length()
- */
- public long length() throws SQLException {
- //caching the length
- if (this.length != -1) {
- return this.length;
- }
- // if did not find before then do it again.
- this.length = this.reference.length();
- return length;
- }
-
- /**
- * @see java.sql.Blob#position(java.sql.Blob, long)
- */
- public long position(Blob pattern, long start) throws SQLException {
- return this.reference.position(pattern, start);
- }
-
- /**
- * @see java.sql.Blob#position(byte[], long)
- */
- public long position(byte[] pattern, long start) throws SQLException {
- return this.reference.position(pattern, start);
- }
-
- /**
- * @see java.sql.Blob#setBinaryStream(long)
- */
- public OutputStream setBinaryStream(long pos) throws SQLException {
- return this.reference.setBinaryStream(pos);
- }
-
- /**
- * @see java.sql.Blob#setBytes(long, byte[], int, int)
- * @since 4.3
- */
- public int setBytes(long pos,
- byte[] bytes,
- int offset,
- int len) throws SQLException {
- return this.reference.setBytes(pos, bytes, offset, len);
- }
-
- /**
- * @see java.sql.Blob#setBytes(long, byte[])
- */
- public int setBytes(long pos, byte[] bytes) throws SQLException {
- return this.reference.setBytes(pos, bytes);
- }
-
- /**
- * @see java.sql.Blob#truncate(long)
- */
- public void truncate(long len) throws SQLException {
- this.reference.truncate(len);
- }
-
- //## JDBC4.0-begin ##
- public void free() throws SQLException {
- this.reference.free();
- }
-
- public InputStream getBinaryStream(long pos, long length)
- throws SQLException {
- return this.reference.getBinaryStream(pos, length);
- }
- //## JDBC4.0-end ##
-
- public static SerialBlob createBlob(byte[] bytes) {
- if (bytes == null) {
- return null;
- }
- try {
- return new SerialBlob(bytes);
- } catch (SQLException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
-
- private void writeObject(java.io.ObjectOutputStream out) throws IOException {
- try {
- length();
- } catch (SQLException e) {
- }
- out.defaultWriteObject();
- }
-
-}
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,229 +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 com.metamatrix.common.types;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.sql.Clob;
-import java.sql.SQLException;
-
-import javax.sql.rowset.serial.SerialClob;
-
-import com.metamatrix.common.util.ReaderInputStream;
-import com.metamatrix.common.util.SqlUtil;
-import com.metamatrix.core.CorePlugin;
-
-/**
- * This object holds a chunk of char data and implements the JDBC Clob interface.
- * This object presents a streaming interface and provides a way to access partial
- * of the Clob data. Connectors can use this object when dealing with large
- * objects.
- */
-public class ClobImpl extends BaseLob implements Clob {
-
- private final static class ClobStreamProvider implements
- LobSearchUtil.StreamProvider {
- private final Clob searchstr;
-
- private ClobStreamProvider(Clob searchstr) {
- this.searchstr = searchstr;
- }
-
- public InputStream getBinaryStream() throws SQLException {
- ReaderInputStream ris = new ReaderInputStream(searchstr.getCharacterStream(), Charset.forName("UTF-16")); //$NON-NLS-1$
- try {
- ris.skip(2);
- return ris;
- } catch (IOException e) {
- throw new SQLException(e);
- }
- }
- }
-
- private long len = -1;
-
- public ClobImpl() {
-
- }
-
- /**
- * Creates a new ClobImpl. Note that the length is not taken from the {@link InputStreamFactory} since
- * it refers to bytes and not chars.
- * @param streamFactory
- * @param length
- */
- public ClobImpl(InputStreamFactory streamFactory, long length) {
- super(streamFactory);
- this.len = length;
- }
-
- /**
- * Gets the <code>CLOB</code> value designated by this <code>Clob</code>
- * object as a stream of Ascii bytes.
- * @return an ascii stream containing the <code>CLOB</code> data
- * @exception SQLException if there is an error accessing the
- * <code>CLOB</code> value
- */
- public InputStream getAsciiStream() throws SQLException {
- return new ReaderInputStream(getCharacterStream(), Charset.forName("US-ASCII")); //$NON-NLS-1$
- }
-
- /**
- * Returns a copy of the specified substring
- * in the <code>CLOB</code> value
- * designated by this <code>Clob</code> object.
- * The substring begins at position
- * <code>pos</code> and has up to <code>length</code> consecutive
- * characters.
- * @param pos the first character of the substring to be extracted.
- * The first character is at position 1.
- * @param length the number of consecutive characters to be copied
- * @return a <code>String</code> that is the specified substring in
- * the <code>CLOB</code> value designated by this <code>Clob</code> object
- * @exception SQLException if there is an error accessing the <code>CLOB</code>
- */
- public String getSubString(long pos, int length) throws SQLException {
- if (pos < 1) {
- Object[] params = new Object[] {new Long(pos)};
- throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.0", params)); //$NON-NLS-1$
- } else if (pos > length()) {
- return null;
- }
- pos = pos - 1;
- if (length < 0) {
- Object[] params = new Object[] {new Integer( length)};
- throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.1", params)); //$NON-NLS-1$
- } else if ((pos+length) > length()) {
- length = (int)(length()-pos);
- }
- char[] dataCopy = new char[length];
- Reader in = getCharacterStream();
- try {
- try {
- in.skip(pos);
- in.read(dataCopy);
- } finally {
- in.close();
- }
- } catch (IOException e) {
- throw new SQLException(e);
- }
- return new String(dataCopy);
- }
-
- /**
- * Returns the number of characters in the <code>CLOB</code> value
- * designated by this <code>Clob</code> object.
- * @return length of the <code>CLOB</code> in characters
- */
- public long length() throws SQLException {
- if (len == -1) {
- long length = 0;
- Reader r = new BufferedReader(getCharacterStream());
- try {
- while (r.read() != -1) {
- length++;
- }
- } catch (IOException e) {
- throw new SQLException(e);
- } finally {
- try {
- r.close();
- } catch (IOException e) {
- }
- }
- this.len = length;
- }
- return len;
- }
-
- /**
- * Determines the character position at which the specified
- * <code>Clob</code> object <code>searchstr</code> appears in this
- * <code>Clob</code> object. The search begins at position
- * <code>start</code>.
- * @param searchstr the <code>Clob</code> object for which to search
- * @param start the position at which to begin searching; the first
- * position is 1
- * @return the position at which the <code>Clob</code> object appears,
- * else -1; the first position is 1
- */
- public long position(final Clob searchstr, long start) throws SQLException {
- if (searchstr == null) {
- return -1;
- }
-
- return LobSearchUtil.position(new ClobStreamProvider(searchstr), searchstr.length(), new ClobStreamProvider(this), this.length(), start, 2);
- }
-
- /**
- * Determines the character position at which the specified substring
- * <code>searchstr</code> appears in the SQL <code>CLOB</code> value
- * represented by this <code>Clob</code> object. The search
- * begins at position <code>start</code>.
- * @param searchstr the substring for which to search
- * @param start the position at which to begin searching; the first position
- * is 1
- * @return the position at which the substring appears, else -1; the first
- * position is 1
- * @exception SQLException if there is an error accessing the
- * <code>CLOB</code> value
- */
- public long position(String searchstr, long start) throws SQLException {
- if (searchstr == null) {
- return -1;
- }
- return position(new SerialClob(searchstr.toCharArray()), start);
- }
-
- public Reader getCharacterStream(long arg0, long arg1) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public OutputStream setAsciiStream(long arg0) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public Writer setCharacterStream(long arg0) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public int setString(long arg0, String arg1) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public int setString(long arg0, String arg1, int arg2, int arg3)
- throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public void truncate(long arg0) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/ClobType.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/ClobType.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/ClobType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,227 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.sql.Clob;
-import java.sql.SQLException;
-
-import javax.sql.rowset.serial.SerialClob;
-
-import com.metamatrix.core.MetaMatrixRuntimeException;
-
-/**
- * This is wrapper on top of a "clob" object, which implements the "java.sql.Clob"
- * interface. This class also implements the Streamable interface
- */
-public final class ClobType extends Streamable<Clob> implements Clob, Sequencable {
-
- private static final long serialVersionUID = 2753412502127824104L;
-
- public ClobType() {
- }
-
- public ClobType(Clob clob) {
- super(clob);
- }
-
- /**
- * @see java.sql.Clob#getAsciiStream()
- */
- public InputStream getAsciiStream() throws SQLException {
- return this.reference.getAsciiStream();
- }
-
- /**
- * @see java.sql.Clob#getCharacterStream()
- */
- public Reader getCharacterStream() throws SQLException {
- return this.reference.getCharacterStream();
- }
-
- /**
- * @see java.sql.Clob#getSubString(long, int)
- */
- public String getSubString(long pos, int length) throws SQLException {
- return this.reference.getSubString(pos, length);
- }
-
- /**
- * @see java.sql.Clob#length()
- */
- public long length() throws SQLException {
- if (this.length != -1) {
- return this.length;
- }
-
- this.length = this.reference.length();
- return length;
- }
-
- /**
- * @see java.sql.Clob#position(java.sql.Clob, long)
- */
- public long position(Clob searchstr, long start) throws SQLException {
- return this.reference.position(searchstr, start);
- }
-
- /**
- * @see java.sql.Clob#position(java.lang.String, long)
- */
- public long position(String searchstr, long start) throws SQLException {
- return this.reference.position(searchstr, start);
- }
-
- /**
- * @see java.sql.Clob#setAsciiStream(long)
- */
- public OutputStream setAsciiStream(long pos) throws SQLException {
- return this.reference.setAsciiStream(pos);
- }
-
- /**
- * @see java.sql.Clob#setCharacterStream(long)
- */
- public Writer setCharacterStream(long pos) throws SQLException {
- return this.reference.setCharacterStream(pos);
- }
-
- /**
- * @see java.sql.Clob#setString(long, java.lang.String, int, int)
- */
- public int setString(long pos,
- String str,
- int offset,
- int len) throws SQLException {
- return this.reference.setString(pos, str, offset, len);
- }
-
- /**
- * @see java.sql.Clob#setString(long, java.lang.String)
- */
- public int setString(long pos, String str) throws SQLException {
- return this.reference.setString(pos, str);
- }
-
- /**
- * @see java.sql.Clob#truncate(long)
- */
- public void truncate(long len) throws SQLException {
- this.reference.truncate(len);
- }
-
- /**
- * Utility method to convert to String
- * @param clob
- * @return string form of the clob passed.
- */
- public static String getString(Clob clob) throws SQLException, IOException {
- Reader reader = clob.getCharacterStream();
- StringWriter writer = new StringWriter();
- int c = reader.read();
- while (c != -1) {
- writer.write((char)c);
- c = reader.read();
- }
- reader.close();
- String data = writer.toString();
- writer.close();
- return data;
- }
-
- private final static int CHAR_SEQUENCE_BUFFER_SIZE = 1 << 12;
-
- public CharSequence getCharSequence() {
- return new CharSequence() {
-
- private String buffer;
- private int beginPosition;
-
- public int length() {
- long result;
- try {
- result = ClobType.this.length();
- } catch (SQLException err) {
- throw new MetaMatrixRuntimeException(err);
- }
- if (((int)result) != result) {
- throw new MetaMatrixRuntimeException("Clob value is not representable by CharSequence"); //$NON-NLS-1$
- }
- return (int)result;
- }
-
- public char charAt(int index) {
- try {
- if (buffer == null || index < beginPosition || index >= beginPosition + buffer.length()) {
- buffer = ClobType.this.getSubString(index + 1, CHAR_SEQUENCE_BUFFER_SIZE);
- beginPosition = index;
- }
- return buffer.charAt(index - beginPosition);
- } catch (SQLException err) {
- throw new MetaMatrixRuntimeException(err);
- }
- }
-
- public CharSequence subSequence(int start,
- int end) {
- try {
- return ClobType.this.getSubString(start + 1, end - start);
- } catch (SQLException err) {
- throw new MetaMatrixRuntimeException(err);
- }
- }
-
- };
- }
- //## JDBC4.0-begin ##
- public void free() throws SQLException {
- this.reference.free();
- }
-
- public Reader getCharacterStream(long pos, long length) throws SQLException {
- return this.reference.getCharacterStream(pos, length);
- }
- //## JDBC4.0-end ##
-
- public static SerialClob createClob(char[] chars) {
- try {
- return new SerialClob(chars);
- } catch (SQLException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
-
- private void writeObject(java.io.ObjectOutputStream out) throws IOException {
- try {
- length();
- } catch (SQLException e) {
- }
- out.defaultWriteObject();
- }
-
-}
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,853 +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 com.metamatrix.common.types;
-
-import java.lang.ref.WeakReference;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.SQLXML;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.xml.transform.Source;
-
-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.FixedNumberToBigDecimalTransform;
-import com.metamatrix.common.types.basic.FixedNumberToBigIntegerTransform;
-import com.metamatrix.common.types.basic.FloatingNumberToBigDecimalTransform;
-import com.metamatrix.common.types.basic.FloatingNumberToBigIntegerTransform;
-import com.metamatrix.common.types.basic.NullToAnyTransform;
-import com.metamatrix.common.types.basic.NumberToBooleanTransform;
-import com.metamatrix.common.types.basic.NumberToByteTransform;
-import com.metamatrix.common.types.basic.NumberToDoubleTransform;
-import com.metamatrix.common.types.basic.NumberToFloatTransform;
-import com.metamatrix.common.types.basic.NumberToIntegerTransform;
-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;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.core.util.HashCodeUtil;
-
-/**
- * <p>
- * This class manages data type, conversions between data types, and comparators
- * for data types. In the future other data type information may be managed
- * here.
- * </p>
- *
- * <p>
- * In general, methods are provided to refer to types either by Class, or by
- * Class name. The benefit of the Class name option is that the user does not
- * need to load the Class object, which may not be in the classpath. The
- * advantage of the Class option is speed.
- * </p>
- */
-public class DataTypeManager {
-
- private static final boolean USE_VALUE_CACHE = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.useValueCache", true); //$NON-NLS-1$
-
- private static boolean valueCacheEnabled;
-
- private interface ValueCache<T> {
- T getValue(T value);
- }
-
- private static class HashedValueCache<T> implements ValueCache<T> {
-
- final Object[] cache;
-
- HashedValueCache(int size) {
- cache = new Object[1 << size];
- }
-
- @SuppressWarnings("unchecked")
- public T getValue(T value) {
- int index = hash(primaryHash(value)) & (cache.length - 1);
- Object canonicalValue = get(index);
- if (value.equals(canonicalValue)) {
- return (T)canonicalValue;
- }
- set(index, value);
- return value;
- }
-
- protected Object get(int index) {
- return cache[index];
- }
-
- protected void set(int index, T value) {
- cache[index] = value;
- }
-
- protected int primaryHash(T value) {
- return value.hashCode();
- }
-
- /*
- * The same power of 2 hash bucketing from the Java HashMap
- */
- final static int hash(int h) {
- h ^= (h >>> 20) ^ (h >>> 12);
- return h ^= (h >>> 7) ^ (h >>> 4);
- }
- }
-
- private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
-
- public static final int MAX_STRING_LENGTH = 4000;
-
- public static final class DataTypeAliases {
- public static final String VARCHAR = "varchar"; //$NON-NLS-1$
- public static final String TINYINT = "tinyint"; //$NON-NLS-1$
- public static final String SMALLINT = "smallint"; //$NON-NLS-1$
- public static final String BIGINT = "bigint"; //$NON-NLS-1$
- public static final String REAL = "real"; //$NON-NLS-1$
- public static final String DECIMAL = "decimal"; //$NON-NLS-1$
- }
-
- public static final class DefaultDataTypes {
- public static final String STRING = "string"; //$NON-NLS-1$
- public static final String BOOLEAN = "boolean"; //$NON-NLS-1$
- public static final String BYTE = "byte"; //$NON-NLS-1$
- public static final String SHORT = "short"; //$NON-NLS-1$
- public static final String CHAR = "char"; //$NON-NLS-1$
- public static final String INTEGER = "integer"; //$NON-NLS-1$
- public static final String LONG = "long"; //$NON-NLS-1$
- public static final String BIG_INTEGER = "biginteger"; //$NON-NLS-1$
- public static final String FLOAT = "float"; //$NON-NLS-1$
- public static final String DOUBLE = "double"; //$NON-NLS-1$
- public static final String BIG_DECIMAL = "bigdecimal"; //$NON-NLS-1$
- public static final String DATE = "date"; //$NON-NLS-1$
- public static final String TIME = "time"; //$NON-NLS-1$
- public static final String TIMESTAMP = "timestamp"; //$NON-NLS-1$
- public static final String OBJECT = "object"; //$NON-NLS-1$
- public static final String NULL = "null"; //$NON-NLS-1$
- public static final String BLOB = "blob"; //$NON-NLS-1$
- public static final String CLOB = "clob"; //$NON-NLS-1$
- public static final String XML = "xml"; //$NON-NLS-1$
- }
-
- public static final class DefaultDataClasses {
- public static final Class<String> STRING = String.class;
- public static final Class<Boolean> BOOLEAN = Boolean.class;
- public static final Class<Byte> BYTE = Byte.class;
- public static final Class<Short> SHORT = Short.class;
- public static final Class<Character> CHAR = Character.class;
- public static final Class<Integer> INTEGER = Integer.class;
- public static final Class<Long> LONG = Long.class;
- public static final Class<BigInteger> BIG_INTEGER = BigInteger.class;
- public static final Class<Float> FLOAT = Float.class;
- public static final Class<Double> DOUBLE = Double.class;
- public static final Class<BigDecimal> BIG_DECIMAL = BigDecimal.class;
- public static final Class<java.sql.Date> DATE = java.sql.Date.class;
- public static final Class<Time> TIME = Time.class;
- public static final Class<Timestamp> TIMESTAMP = Timestamp.class;
- public static final Class<Object> OBJECT = Object.class;
- public static final Class<NullType> NULL = NullType.class;
- public static final Class<BlobType> BLOB = BlobType.class;
- public static final Class<ClobType> CLOB = ClobType.class;
- public static final Class<XMLType> XML = XMLType.class;
- }
-
- /**
- * Doubly-nested map of String srcType --> Map of String targetType -->
- * Transform
- */
- private static Map<String, Map<String, Transform>> transforms = new HashMap<String, Map<String, Transform>>(128);
-
- /** Utility to easily get Transform given srcType and targetType */
- private static Transform getTransformFromMaps(String srcType,
- String targetType) {
- Map<String, Transform> innerMap = transforms.get(srcType);
- if (innerMap != null) {
- return innerMap.get(targetType);
- }
- return null;
- }
-
- /** Base data type names and classes, Type name --> Type class */
- private static Map<String, Class> dataTypeNames = new LinkedHashMap<String, Class>(128);
-
- /** Base data type names and classes, Type class --> Type name */
- private static Map<Class, String> dataTypeClasses = new LinkedHashMap<Class, String>(128);
-
- private static Set<String> DATA_TYPE_NAMES;
-
- private static Set<Class> DATA_TYPE_CLASSES = Collections.unmodifiableSet(dataTypeClasses.keySet());
-
- private static Map<Class<?>, SourceTransform> sourceConverters = new HashMap<Class<?>, SourceTransform>();
-
- // Static initializer - loads basic transforms types
- static {
- // Load default data types - not extensible yet
- loadDataTypes();
-
- // Load default transforms
- loadBasicTransforms();
-
- loadSourceConversions();
- }
-
- /**
- * Constructor is private so instance creation is controlled by the class.
- */
- private DataTypeManager() {
- }
-
- /**
- * Add a new data type. For now this consists just of the Class - in the
- * future a data type will be a more complicated entity. This is
- * package-level for now as it is just used to add the default data types.
- *
- * @param dataType
- * New data type defined by Class
- */
- static void addDataType(String typeName, Class dataType) {
- dataTypeNames.put(typeName, dataType);
- dataTypeClasses.put(dataType, typeName);
- }
-
- /**
- * Get a set of all data type names.
- *
- * @return Set of data type names (String)
- */
- public static Set<String> getAllDataTypeNames() {
- return DATA_TYPE_NAMES;
- }
-
- public static Set<Class> getAllDataTypeClasses() {
- return DATA_TYPE_CLASSES;
- }
-
- /**
- * Get data type class.
- *
- * @param name
- * Data type name
- * @return Data type class
- */
- public static Class getDataTypeClass(String name) {
- if (name == null) {
- return DefaultDataClasses.NULL;
- }
-
- // Hope this is the correct case (as it will be if using the constants
- Class dataTypeClass = dataTypeNames.get(name);
-
- // If that fails, do a lower case to make sure we match
- if (dataTypeClass == null) {
- dataTypeClass = dataTypeNames.get(name.toLowerCase());
- }
-
- if (dataTypeClass == null) {
- dataTypeClass = DefaultDataClasses.OBJECT;
- }
- return dataTypeClass;
- }
-
- public static String getDataTypeName(Class typeClass) {
- if (typeClass == null) {
- return DefaultDataTypes.NULL;
- }
-
- String result = dataTypeClasses.get(typeClass);
- if (result == null) {
- result = DefaultDataTypes.OBJECT;
- }
-
- return result;
- }
-
- /**
- * Take an object and determine the MetaMatrix data type. In most cases,
- * this is simply the class of the object. Some special cases are when the
- * value is of type Object or Null.
- */
- public static Class determineDataTypeClass(Object value) {
- // Handle null case
- if (value == null) {
- return DefaultDataClasses.NULL;
- }
-
- return getDataTypeClass(getDataTypeName(convertToRuntimeType(value)
- .getClass()));
- }
-
- /**
- * Get a data value transformation between the sourceType and the
- * targetType.
- *
- * @param sourceType
- * Incoming value type
- * @param targetType
- * Outgoing value type
- * @return A transform if one exists, null otherwise
- */
- public static Transform getTransform(Class sourceType, Class targetType) {
- if (sourceType == null || targetType == null) {
- throw new IllegalArgumentException(CorePlugin.Util.getString(
- ErrorMessageKeys.TYPES_ERR_0002, sourceType, targetType));
- }
- return getTransformFromMaps(
- DataTypeManager.getDataTypeName(sourceType), DataTypeManager
- .getDataTypeName(targetType));
- }
-
- /**
- * Get a data value transformation between the sourceType with given name
- * and the targetType of given name. The Class for source and target type
- * are not needed to do this lookup.
- *
- * @param sourceTypeName
- * Incoming value type name
- * @param targetTypeName
- * Outgoing value type name
- * @return A transform if one exists, null otherwise
- */
- public static Transform getTransform(String sourceTypeName,
- String targetTypeName) {
- if (sourceTypeName == null || targetTypeName == null) {
- throw new IllegalArgumentException(CorePlugin.Util.getString(
- ErrorMessageKeys.TYPES_ERR_0003, sourceTypeName,
- targetTypeName));
- }
- return getTransformFromMaps(sourceTypeName, targetTypeName);
- }
-
- /**
- * Does a transformation exist between the source and target type?
- *
- * @param sourceType
- * Incoming value type
- * @param targetType
- * Outgoing value type
- * @return True if a transform exists
- */
- public static boolean isTransformable(Class sourceType, Class targetType) {
- if (sourceType == null || targetType == null) {
- throw new IllegalArgumentException(CorePlugin.Util.getString(
- ErrorMessageKeys.TYPES_ERR_0002, sourceType, targetType));
- }
- return (getTransformFromMaps(DataTypeManager
- .getDataTypeName(sourceType), DataTypeManager
- .getDataTypeName(targetType)) != null);
- }
-
- /**
- * Does a transformation exist between the source and target type of given
- * names? The Class for source and target type are not needed to do this
- * lookup.
- *
- * @param sourceTypeName
- * Incoming value type name
- * @param targetTypeName
- * Outgoing value type name
- * @return True if a transform exists
- */
- public static boolean isTransformable(String sourceTypeName,
- String targetTypeName) {
- if (sourceTypeName == null || targetTypeName == null) {
- throw new IllegalArgumentException(CorePlugin.Util.getString(
- ErrorMessageKeys.TYPES_ERR_0003, sourceTypeName,
- targetTypeName));
- }
- return (getTransformFromMaps(sourceTypeName, targetTypeName) != null);
- }
-
- /**
- * Add a new transform to the known transform types.
- *
- * @param transform
- * New transform to add
- */
- static void addTransform(Transform transform) {
- ArgCheck.isNotNull(transform);
- String sourceName = transform.getSourceTypeName();
- String targetName = transform.getTargetTypeName();
-
- Map<String, Transform> innerMap = transforms.get(sourceName);
- if (innerMap == null) {
- innerMap = new LinkedHashMap<String, Transform>();
- transforms.put(sourceName, innerMap);
- }
- innerMap.put(targetName, transform);
- }
-
- public static List<String> getImplicitConversions(String type) {
- Map<String, Transform> innerMap = transforms.get(type);
- if (innerMap != null) {
- List<String> result = new ArrayList<String>(innerMap.size());
- for (Map.Entry<String, Transform> entry : innerMap.entrySet()) {
- if (!entry.getValue().isExplicit()) {
- result.add(entry.getKey());
- }
- }
- return result;
- }
- return Collections.emptyList();
- }
-
- public static boolean isImplicitConversion(String srcType, String tgtType) {
- Transform t = getTransform(srcType, tgtType);
- if (t != null) {
- return !t.isExplicit();
- }
- return false;
- }
-
- public static boolean isExplicitConversion(String srcType, String tgtType) {
- Transform t = getTransform(srcType, tgtType);
- if (t != null) {
- return t.isExplicit();
- }
- return false;
- }
-
- /**
- * Is the supplied class type a LOB based data type?
- *
- * @param type
- * @return true if yes; false otherwise
- */
- public static boolean isLOB(Class<?> type) {
- return DataTypeManager.DefaultDataClasses.BLOB.equals(type)
- || DataTypeManager.DefaultDataClasses.CLOB.equals(type)
- || DataTypeManager.DefaultDataClasses.XML.equals(type);
- }
-
- public static boolean isLOB(String type) {
- return DataTypeManager.DefaultDataTypes.BLOB.equals(type)
- || DataTypeManager.DefaultDataTypes.CLOB.equals(type)
- || DataTypeManager.DefaultDataTypes.XML.equals(type);
- }
-
- /**
- * Load default data types.
- */
- static void loadDataTypes() {
- DataTypeManager.addDataType(DefaultDataTypes.BOOLEAN, DefaultDataClasses.BOOLEAN);
- DataTypeManager.addDataType(DefaultDataTypes.BYTE, DefaultDataClasses.BYTE);
- DataTypeManager.addDataType(DefaultDataTypes.SHORT, DefaultDataClasses.SHORT);
- DataTypeManager.addDataType(DefaultDataTypes.CHAR, DefaultDataClasses.CHAR);
- DataTypeManager.addDataType(DefaultDataTypes.INTEGER, DefaultDataClasses.INTEGER);
- DataTypeManager.addDataType(DefaultDataTypes.LONG, DefaultDataClasses.LONG);
- DataTypeManager.addDataType(DefaultDataTypes.BIG_INTEGER, DefaultDataClasses.BIG_INTEGER);
- DataTypeManager.addDataType(DefaultDataTypes.FLOAT, DefaultDataClasses.FLOAT);
- DataTypeManager.addDataType(DefaultDataTypes.DOUBLE, DefaultDataClasses.DOUBLE);
- DataTypeManager.addDataType(DefaultDataTypes.BIG_DECIMAL, DefaultDataClasses.BIG_DECIMAL);
- DataTypeManager.addDataType(DefaultDataTypes.DATE, DefaultDataClasses.DATE);
- DataTypeManager.addDataType(DefaultDataTypes.TIME, DefaultDataClasses.TIME);
- DataTypeManager.addDataType(DefaultDataTypes.TIMESTAMP, DefaultDataClasses.TIMESTAMP);
- DataTypeManager.addDataType(DefaultDataTypes.STRING, DefaultDataClasses.STRING);
- DataTypeManager.addDataType(DefaultDataTypes.CLOB, DefaultDataClasses.CLOB);
- DataTypeManager.addDataType(DefaultDataTypes.XML, DefaultDataClasses.XML);
- DataTypeManager.addDataType(DefaultDataTypes.OBJECT, DefaultDataClasses.OBJECT);
- DataTypeManager.addDataType(DefaultDataTypes.NULL, DefaultDataClasses.NULL);
- DataTypeManager.addDataType(DefaultDataTypes.BLOB, DefaultDataClasses.BLOB);
- DATA_TYPE_NAMES = Collections.unmodifiableSet(new LinkedHashSet<String>(dataTypeNames.keySet()));
- dataTypeNames.put(DataTypeAliases.BIGINT, DefaultDataClasses.LONG);
- dataTypeNames.put(DataTypeAliases.DECIMAL, DefaultDataClasses.BIG_DECIMAL);
- dataTypeNames.put(DataTypeAliases.REAL, DefaultDataClasses.FLOAT);
- dataTypeNames.put(DataTypeAliases.SMALLINT, DefaultDataClasses.SHORT);
- dataTypeNames.put(DataTypeAliases.TINYINT, DefaultDataClasses.BYTE);
- dataTypeNames.put(DataTypeAliases.VARCHAR, DefaultDataClasses.STRING);
-
- if (USE_VALUE_CACHE) {
- valueMaps.put(DefaultDataClasses.BOOLEAN, new ValueCache<Boolean>() {
- @Override
- public Boolean getValue(Boolean value) {
- return Boolean.valueOf(value);
- }
- });
- valueMaps.put(DefaultDataClasses.BYTE, new ValueCache<Byte>() {
- @Override
- public Byte getValue(Byte value) {
- return Byte.valueOf(value);
- }
- });
- valueMaps.put(DefaultDataClasses.SHORT, new HashedValueCache<Short>(13));
- valueMaps.put(DefaultDataClasses.CHAR, new HashedValueCache<Character>(13));
- valueMaps.put(DefaultDataClasses.INTEGER, new HashedValueCache<Integer>(14));
- valueMaps.put(DefaultDataClasses.LONG, new HashedValueCache<Long>(14));
- valueMaps.put(DefaultDataClasses.BIG_INTEGER, new HashedValueCache<BigInteger>(14));
- valueMaps.put(DefaultDataClasses.FLOAT, new HashedValueCache<Float>(14));
- valueMaps.put(DefaultDataClasses.DOUBLE, new HashedValueCache<Double>(14));
- valueMaps.put(DefaultDataClasses.DATE, new HashedValueCache<Date>(14));
- valueMaps.put(DefaultDataClasses.TIME, new HashedValueCache<Time>(14));
- valueMaps.put(DefaultDataClasses.TIMESTAMP, new HashedValueCache<Timestamp>(14));
- valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new HashedValueCache<BigDecimal>(15) {
- @Override
- protected Object get(int index) {
- WeakReference<?> ref = (WeakReference<?>) cache[index];
- if (ref != null) {
- return ref.get();
- }
- return null;
- }
-
- @Override
- protected void set(int index, BigDecimal value) {
- cache[index] = new WeakReference<BigDecimal>(value);
- }
- });
- valueMaps.put(DefaultDataClasses.STRING, new HashedValueCache<String>(15) {
- HashedValueCache<String> smallCache = new HashedValueCache<String>(13);
-
- @Override
- public String getValue(String value) {
- if (value.length() < 14) {
- return smallCache.getValue(value);
- }
- return super.getValue(value);
- }
-
- @Override
- protected Object get(int index) {
- WeakReference<?> ref = (WeakReference<?>) cache[index];
- if (ref != null) {
- return ref.get();
- }
- return null;
- }
-
- @Override
- protected void set(int index, String value) {
- cache[index] = new WeakReference<Object>(value);
- }
-
- @Override
- protected int primaryHash(String value) {
- return HashCodeUtil.expHashCode(value);
- }
- });
- }
- }
-
- /**
- * Load all basic {@link Transform}s into the DataTypeManager. This standard
- * set is always installed but may be overridden.
- */
- static void loadBasicTransforms() {
- 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)));
- DataTypeManager.addTransform(new BooleanToNumberTransform(Long.valueOf(1), Long.valueOf(0)));
- DataTypeManager.addTransform(new BooleanToNumberTransform(BigInteger.valueOf(1), BigInteger.valueOf(0)));
- DataTypeManager.addTransform(new BooleanToNumberTransform(Float.valueOf(1), Float.valueOf(0)));
- DataTypeManager.addTransform(new BooleanToNumberTransform(Double.valueOf(1), Double.valueOf(0)));
- DataTypeManager.addTransform(new BooleanToNumberTransform(BigDecimal.valueOf(1), BigDecimal.valueOf(0)));
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.BOOLEAN));
-
- DataTypeManager.addTransform(new NumberToBooleanTransform(Byte.valueOf((byte)0)));
- DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.BYTE, false));
- DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.BYTE, false));
- DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.BYTE, false, false));
- DataTypeManager.addTransform(new FixedNumberToBigIntegerTransform(DefaultDataClasses.BYTE));
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.BYTE, false, false));
- DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.BYTE, false, false));
- DataTypeManager.addTransform(new FixedNumberToBigDecimalTransform(DefaultDataClasses.BYTE));
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.BYTE));
-
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.CHAR));
-
- 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));
- DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.INTEGER, false, false));
- DataTypeManager.addTransform(new FixedNumberToBigIntegerTransform(DefaultDataClasses.INTEGER));
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.INTEGER, false, true)); //lossy, but not narrowing
- DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.INTEGER, false, false));
- DataTypeManager.addTransform(new FixedNumberToBigDecimalTransform(DefaultDataClasses.INTEGER));
- DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.INTEGER));
-
- DataTypeManager.addTransform(new NumberToBooleanTransform(Long.valueOf(0)));
- DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.LONG));
- DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.LONG, true));
- DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.LONG, true));
- DataTypeManager.addTransform(new FixedNumberToBigIntegerTransform(DefaultDataClasses.LONG));
- DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.LONG, false, true)); //lossy, but not narrowing
- 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(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());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToIntegerTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToLongTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToBigIntegerTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToFloatTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToDoubleTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToBigDecimalTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToTimeTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToDateTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToTimestampTransform());
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.StringToCharacterTransform());
- 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.ClobToStringTransform());
- DataTypeManager.addTransform(new ClobToSQLXMLTransform());
-
- DataTypeManager.addTransform(new com.metamatrix.common.types.basic.SQLXMLToStringTransform());
- DataTypeManager.addTransform(new SQLXMLToClobTransform());
-
- for (Class<?> type : getAllDataTypeClasses()) {
- if (type != DefaultDataClasses.OBJECT) {
- DataTypeManager.addTransform(new AnyToObjectTransform(type));
- DataTypeManager.addTransform(new ObjectToAnyTransform(type));
- }
- if (type != DefaultDataClasses.NULL) {
- DataTypeManager.addTransform(new NullToAnyTransform(type));
- }
- }
-
- }
-
- static void loadSourceConversions() {
- sourceConverters.put(Clob.class, new SourceTransform<Clob, ClobType>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public ClobType transform(Clob value) {
- return new ClobType(value);
- }
- });
- sourceConverters.put(char[].class, new SourceTransform<char[], ClobType>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public ClobType transform(char[] value) {
- return new ClobType(ClobType.createClob(value));
- }
- });
- sourceConverters.put(Blob.class, new SourceTransform<Blob, BlobType>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public BlobType transform(Blob value) {
- return new BlobType(value);
- }
- });
- addSourceTransform(byte[].class, new SourceTransform<byte[], BlobType>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public BlobType transform(byte[] value) {
- return new BlobType(BlobType.createBlob(value));
- }
- });
- addSourceTransform(SQLXML.class, new SourceTransform<SQLXML, XMLType>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public XMLType transform(SQLXML value) {
- return new XMLType(value);
- }
- });
- //Note: the default transform from non-InputStreamFactory source is a fully materialized string
- addSourceTransform(Source.class, new SourceTransform<Source, XMLType>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public XMLType transform(Source value) {
- if (value instanceof InputStreamFactory) {
- return new XMLType(new SQLXMLImpl((InputStreamFactory)value));
- }
- StandardXMLTranslator sxt = new StandardXMLTranslator(value);
- try {
- return new XMLType(new SQLXMLImpl(sxt.getString()));
- } catch (Exception e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
- });
- addSourceTransform(Date.class, new SourceTransform<Date, Timestamp>() {
- //## JDBC4.0-begin ##
- @Override
- //## JDBC4.0-end ##
- public Timestamp transform(Date value) {
- return new Timestamp(value.getTime());
- }
- });
- }
-
- public static Object convertToRuntimeType(Object value) {
- if (value == null) {
- return null;
- }
- Class<?> c = value.getClass();
- if (getAllDataTypeClasses().contains(c)) {
- return value;
- }
- SourceTransform t = sourceConverters.get(c);
- if (t != null) {
- return t.transform(value);
- }
- for (Map.Entry<Class<?>, SourceTransform> entry : sourceConverters.entrySet()) {
- if (entry.getKey().isAssignableFrom(c)) {
- return entry.getValue().transform(value);
- }
- }
- return value; // "object type"
- }
-
- @SuppressWarnings("unchecked")
- public static <T> T transformValue(Object value, Class<T> targetClass)
- throws TransformationException {
- if (value == null) {
- return (T)value;
- }
- return transformValue(value, value.getClass(), targetClass);
- }
-
- @SuppressWarnings("unchecked")
- public static <T> T transformValue(Object value, Class sourceType,
- Class<T> targetClass) throws TransformationException {
- if (value == null || sourceType == targetClass) {
- return (T) value;
- }
- Transform transform = DataTypeManager.getTransform(sourceType,
- targetClass);
- if (transform == null) {
- Object[] params = new Object[] { sourceType, targetClass, value};
- throw new TransformationException(CorePlugin.Util.getString("ObjectToAnyTransform.Invalid_value", params)); //$NON-NLS-1$
- }
- T result = (T) transform.transform(value);
- return getCanonicalValue(result);
- }
-
- public static boolean isNonComparable(String type) {
- return DataTypeManager.DefaultDataTypes.OBJECT.equals(type)
- || DataTypeManager.DefaultDataTypes.BLOB.equals(type)
- || DataTypeManager.DefaultDataTypes.CLOB.equals(type)
- || DataTypeManager.DefaultDataTypes.XML.equals(type);
- }
-
- public static <S> void addSourceTransform(Class<S> sourceClass, SourceTransform<S, ?> transform) {
- sourceConverters.put(sourceClass, transform);
- }
-
- public static void setValueCacheEnabled(boolean enabled) {
- valueCacheEnabled = enabled;
- }
-
- public static boolean isValueCacheEnabled() {
- return valueCacheEnabled;
- }
-
- @SuppressWarnings("unchecked")
- public static <T> T getCanonicalValue(T value) {
- if (USE_VALUE_CACHE && valueCacheEnabled) {
- if (value == null) {
- return null;
- }
- //TODO: this initial lookup is inefficient, since there are likely collisions
- ValueCache valueCache = valueMaps.get(value.getClass());
- if (valueCache != null) {
- value = (T)valueCache.getValue(value);
- }
- }
- return value;
- }
-}
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/InputStreamFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,88 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.Charset;
-
-import javax.xml.transform.Source;
-
-public abstract class InputStreamFactory implements Source {
-
- public interface StreamFactoryReference {
-
- void setStreamFactory(InputStreamFactory inputStreamFactory);
-
- }
-
- private String encoding;
- private String systemId;
- private long length = -1;
-
- public InputStreamFactory() {
- this(Charset.defaultCharset().name());
- }
-
- public InputStreamFactory(String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Get a new InputStream
- * @return
- */
- public abstract InputStream getInputStream() throws IOException;
-
- public String getEncoding() {
- return encoding;
- }
-
- @Override
- public String getSystemId() {
- return this.systemId;
- }
-
- @Override
- public void setSystemId(String systemId) {
- this.systemId = systemId;
- }
-
- public void free() throws IOException {
-
- }
-
- public long getLength() {
- return length;
- }
-
- public void setLength(long length) {
- this.length = length;
- }
-
- public Reader getCharacterStream() throws IOException {
- return new InputStreamReader(this.getInputStream(), this.getEncoding());
- }
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/JDBCSQLTypeInfo.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/JDBCSQLTypeInfo.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/JDBCSQLTypeInfo.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,264 +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 com.metamatrix.common.types;
-
-import java.sql.Blob;
-import java.sql.Clob;
-//## JDBC4.0-begin ##
-import java.sql.SQLXML;
-//## JDBC4.0-end ##
-
-/*## JDBC3.0-JDK1.5-begin ##
-import com.metamatrix.core.jdbc.SQLXML;
-## JDBC3.0-JDK1.5-end ##*/
-import java.sql.Types;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * <p> This is a helper class used to obtain SQL type information for java types.
- * The SQL type information is obtained from java.sql.Types class. The integers and
- * strings returned by methods in this class are based on constants in java.sql.Types.
- */
-
-public final class JDBCSQLTypeInfo {
-
-
- // Prevent instantiation
- private JDBCSQLTypeInfo() {}
-
- // metamatrix types
- public static final String STRING = DataTypeManager.DefaultDataTypes.STRING;
- public static final String BOOLEAN = DataTypeManager.DefaultDataTypes.BOOLEAN;
- public static final String TIME = DataTypeManager.DefaultDataTypes.TIME;
- public static final String DATE = DataTypeManager.DefaultDataTypes.DATE;
- public static final String TIMESTAMP = DataTypeManager.DefaultDataTypes.TIMESTAMP;
- public static final String INTEGER = DataTypeManager.DefaultDataTypes.INTEGER;
- public static final String FLOAT = DataTypeManager.DefaultDataTypes.FLOAT;
- public static final String DOUBLE = DataTypeManager.DefaultDataTypes.DOUBLE;
- public static final String BIGDECIMAL = DataTypeManager.DefaultDataTypes.BIG_DECIMAL;
- public static final String BIGINTEGER = DataTypeManager.DefaultDataTypes.BIG_INTEGER;
- public static final String BYTE = DataTypeManager.DefaultDataTypes.BYTE;
- public static final String SHORT = DataTypeManager.DefaultDataTypes.SHORT;
- public static final String LONG = DataTypeManager.DefaultDataTypes.LONG;
- public static final String CHAR = DataTypeManager.DefaultDataTypes.CHAR;
- public static final String OBJECT = DataTypeManager.DefaultDataTypes.OBJECT;
- public static final String CLOB = DataTypeManager.DefaultDataTypes.CLOB;
- public static final String BLOB = DataTypeManager.DefaultDataTypes.BLOB;
- public static final String XML = DataTypeManager.DefaultDataTypes.XML;
- public static final String NULL = DataTypeManager.DefaultDataTypes.NULL;
-
- //java class names
- public static final String STRING_CLASS = DataTypeManager.DefaultDataClasses.STRING.getName();
- public static final String BOOLEAN_CLASS = DataTypeManager.DefaultDataClasses.BOOLEAN.getName();
- public static final String TIME_CLASS = DataTypeManager.DefaultDataClasses.TIME.getName();
- public static final String DATE_CLASS = DataTypeManager.DefaultDataClasses.DATE.getName();
- public static final String TIMESTAMP_CLASS = DataTypeManager.DefaultDataClasses.TIMESTAMP.getName();
- public static final String INTEGER_CLASS = DataTypeManager.DefaultDataClasses.INTEGER.getName();
- public static final String FLOAT_CLASS = DataTypeManager.DefaultDataClasses.FLOAT.getName();
- public static final String DOUBLE_CLASS = DataTypeManager.DefaultDataClasses.DOUBLE.getName();
- public static final String BIGDECIMAL_CLASS = DataTypeManager.DefaultDataClasses.BIG_DECIMAL.getName();
- public static final String BYTE_CLASS = DataTypeManager.DefaultDataClasses.BYTE.getName();
- public static final String SHORT_CLASS = DataTypeManager.DefaultDataClasses.SHORT.getName();
- public static final String LONG_CLASS = DataTypeManager.DefaultDataClasses.LONG.getName();
- public static final String CHAR_CLASS = DataTypeManager.DefaultDataClasses.CHAR.getName();
- public static final String BIGINTEGER_CLASS = DataTypeManager.DefaultDataClasses.BIG_INTEGER.getName();
- public static final String OBJECT_CLASS = DataTypeManager.DefaultDataClasses.OBJECT.getName();
- public static final String CLOB_CLASS = Clob.class.getName();
- public static final String BLOB_CLASS = Blob.class.getName();
- //## JDBC4.0-begin ##
- public static final String XML_CLASS = SQLXML.class.getName();
- //## JDBC4.0-end ##
- /*## JDBC3.0-JDK1.5-begin ##
- public static final String XML_CLASS = DataTypeManager.DefaultDataClasses.OBJECT.getName();
- ## JDBC3.0-JDK1.5-end ##*/
-
- private static Map<String, Integer> NAME_TO_TYPE_MAP = new HashMap<String, Integer>();
- private static Map<Integer, String> TYPE_TO_NAME_MAP = new HashMap<Integer, String>();
- private static Map<String, String> NAME_TO_CLASSNAME = new HashMap<String, String>();
- private static Map<String, String> CLASSNAME_TO_NAME = new HashMap<String, String>();
-
- static {
- addTypeMapping(STRING, STRING_CLASS, Types.VARCHAR, Types.LONGVARCHAR, Types.CHAR);
- addTypeMapping(CHAR, CHAR_CLASS, Types.CHAR, false);
- addTypeMapping(BOOLEAN, BOOLEAN_CLASS, Types.BIT);
- addTypeMapping(TIME, TIME_CLASS, Types.TIME);
- addTypeMapping(DATE, DATE_CLASS, Types.DATE);
- addTypeMapping(TIMESTAMP, TIMESTAMP_CLASS, Types.TIMESTAMP);
- addTypeMapping(INTEGER, INTEGER_CLASS, Types.INTEGER);
- addTypeMapping(FLOAT, FLOAT_CLASS, Types.REAL);
- addTypeMapping(DOUBLE, DOUBLE_CLASS, Types.DOUBLE, Types.FLOAT);
- addTypeMapping(BIGDECIMAL, BIGDECIMAL_CLASS, Types.NUMERIC, Types.DECIMAL);
- addTypeMapping(BIGINTEGER, BIGINTEGER_CLASS, Types.NUMERIC, false);
- addTypeMapping(BYTE, BYTE_CLASS, Types.TINYINT);
- addTypeMapping(SHORT, SHORT_CLASS, Types.SMALLINT);
- addTypeMapping(LONG, LONG_CLASS, Types.BIGINT);
- addTypeMapping(OBJECT, OBJECT_CLASS, Types.JAVA_OBJECT);
- addTypeMapping(CLOB, CLOB_CLASS, Types.CLOB);
- addTypeMapping(BLOB, BLOB_CLASS, Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY);
-
- addTypeMapping(NULL, null, Types.NULL);
-
- //## JDBC4.0-begin ##
- addTypeMapping(XML, XML_CLASS, Types.SQLXML);
- TYPE_TO_NAME_MAP.put(Types.NVARCHAR, STRING);
- TYPE_TO_NAME_MAP.put(Types.LONGNVARCHAR, STRING);
- TYPE_TO_NAME_MAP.put(Types.NCHAR, CHAR);
- TYPE_TO_NAME_MAP.put(Types.NCLOB, CLOB);
- //## JDBC4.0-end ##
-
- /*## JDBC3.0-JDK1.5-begin ##
- NAME_TO_CLASSNAME.put(XML, OBJECT_CLASS);
- ## JDBC3.0-JDK1.5-end ##*/
- }
-
- private static void addTypeMapping(String typeName, String javaClass, int sqlType, int ... secondaryTypes) {
- addTypeMapping(typeName, javaClass, sqlType, true);
- for (int type : secondaryTypes) {
- TYPE_TO_NAME_MAP.put(type, typeName);
- }
- }
-
- private static void addTypeMapping(String typeName, String javaClass, int sqlType, boolean preferedType) {
- NAME_TO_TYPE_MAP.put(typeName, sqlType);
- if (preferedType) {
- TYPE_TO_NAME_MAP.put(sqlType, typeName);
- }
- if (javaClass != null) {
- NAME_TO_CLASSNAME.put(typeName, javaClass);
- CLASSNAME_TO_NAME.put(javaClass, typeName);
- }
- }
-
- /**
- * This method is used to obtain a short indicating JDBC SQL type for any object.
- * The short values that give the type info are from java.sql.Types.
- * @param Name of the metamatrix type.
- * @return A short value representing SQL Type for the given java type.
- */
- public static final int getSQLType(String typeName) {
-
- if (typeName == null) {
- return Types.NULL;
- }
-
- Integer sqlType = NAME_TO_TYPE_MAP.get(typeName);
-
- if (sqlType == null) {
- return Types.JAVA_OBJECT;
- }
-
- return sqlType.intValue();
- }
-
- /**
- * Get sql Type from java class type name. This should not be called with runtime types
- * as Clob and Blob are represented by ClobType and BlobType respectively.
- * @param typeName
- * @return int
- */
- public static final int getSQLTypeFromClass(String className) {
-
- if (className == null) {
- return Types.NULL;
- }
-
- String name = CLASSNAME_TO_NAME.get(className);
-
- if (name == null) {
- return Types.JAVA_OBJECT;
- }
-
- return getSQLType(name);
- }
-
- /**
- * Get the sql type from the given runtime type
- * @param type
- * @return
- */
- public static final int getSQLTypeFromRuntimeType(Class<?> type) {
- if (type == null) {
- return Types.NULL;
- }
-
- String name = DataTypeManager.getDataTypeName(type);
-
- if (name == null) {
- return Types.JAVA_OBJECT;
- }
-
- return getSQLType(name);
- }
-
- /**
- * This method is used to obtain a the java class name given an int value
- * indicating JDBC SQL type. The int values that give the type info are from
- * java.sql.Types.
- * @param int value giving the SQL type code.
- * @return A String representing the java class name for the given SQL Type.
- */
- public static final String getJavaClassName(int jdbcSQLType) {
- String className = NAME_TO_CLASSNAME.get(getTypeName(jdbcSQLType));
-
- if (className == null) {
- return OBJECT_CLASS;
- }
-
- return className;
- }
-
- public static final String getTypeName(int sqlType) {
- String name = TYPE_TO_NAME_MAP.get(sqlType);
-
- if (name == null) {
- return OBJECT;
- }
-
- return name;
- }
-
- public static String[] getMMTypeNames() {
- return new String[] {
- STRING,
- BOOLEAN,
- TIME,
- DATE,
- TIMESTAMP,
- INTEGER,
- FLOAT,
- DOUBLE,
- BIGDECIMAL,
- BIGINTEGER,
- BYTE,
- SHORT,
- LONG,
- CHAR,
- OBJECT,
- CLOB,
- BLOB,
- XML
- };
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/LobSearchUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/LobSearchUtil.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/LobSearchUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,140 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.SQLException;
-
-import com.metamatrix.core.CorePlugin;
-
-public class LobSearchUtil {
-
- private static final int MOD = 37;
-
- public interface StreamProvider {
-
- InputStream getBinaryStream() throws SQLException;
-
- }
-
- static long position(StreamProvider pattern, long patternLength, StreamProvider target, long targetLength, long start, int bytesPerComparison) throws SQLException {
- if (pattern == null) {
- return -1;
- }
-
- patternLength *= bytesPerComparison;
- targetLength *= bytesPerComparison;
-
- if (start < 1) {
- Object[] params = new Object[] {new Long(start)};
- throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.2", params)); //$NON-NLS-1$
- }
-
- start = (start - 1)*bytesPerComparison;
-
- if (start + patternLength > targetLength) {
- return -1;
- }
- /*
- * Use karp-rabin matching to reduce the cost of back tracing for failed matches
- *
- * TODO: optimize for patterns that are small enough to fit in a reasonable buffer
- */
- try {
- InputStream patternStream = pattern.getBinaryStream();
- InputStream targetStream = target.getBinaryStream();
- InputStream laggingTargetStream = target.getBinaryStream();
- try {
- int patternHash = computeStreamHash(patternStream, patternLength);
- int lastMod = 1;
- for (int i = 0; i < patternLength; i++) {
- lastMod *= MOD;
- }
- targetStream.skip(start);
- laggingTargetStream.skip(start);
-
- long position = start + 1;
-
- int streamHash = computeStreamHash(targetStream, patternLength);
-
- do {
- if ((position -1)%bytesPerComparison == 0 && patternHash == streamHash && validateMatch(pattern, target, position)) {
- return (position - 1)/bytesPerComparison + 1;
- }
-
- streamHash = MOD * streamHash + targetStream.read() - lastMod * laggingTargetStream.read();
- position++;
-
- } while (position + patternLength - 1 <= targetLength);
-
- return -1;
- } finally {
- if (patternStream != null) {
- patternStream.close();
- }
- if (targetStream != null) {
- targetStream.close();
- }
- if (laggingTargetStream != null) {
- laggingTargetStream.close();
- }
- }
- } catch (IOException e) {
- throw new SQLException(e);
- }
- }
-
- /**
- * validate that the pattern matches the given position.
- *
- * TODO: optimize to reuse the same targetstream/buffer for small patterns
- * @throws SQLException
- */
- static private boolean validateMatch(StreamProvider pattern, StreamProvider target, long position) throws IOException, SQLException {
- InputStream targetStream = target.getBinaryStream();
- InputStream patternStream = pattern.getBinaryStream();
- try {
- targetStream.skip(position -1);
- int value = 0;
- while ((value = patternStream.read()) != -1) {
- if (value != targetStream.read()) {
- return false;
- }
- }
- } finally {
- targetStream.close();
- patternStream.close();
- }
- return true;
- }
-
- static private int computeStreamHash(InputStream is, long length) throws IOException {
- int result = 0;
- for (int i = 0; i < length; i++) {
- result = result * MOD + is.read();
- }
- return result;
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/NullType.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/NullType.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/NullType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,29 +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 com.metamatrix.common.types;
-
-public final class NullType {
-
- // can't construct
- NullType() {}
-}
\ No newline at end of file
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,114 +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 com.metamatrix.common.types;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.sql.SQLException;
-import java.sql.SQLXML;
-
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
-import com.metamatrix.common.util.SqlUtil;
-import com.metamatrix.core.util.ObjectConverterUtil;
-
-
-/**
- * Default SQLXML impl
- */
-public class SQLXMLImpl extends BaseLob implements SQLXML {
-
- public SQLXMLImpl() {
-
- }
-
- /**
- * Constructs a SQLXML from bytes that are already encoded in {@link Streamable#ENCODING}
- * @param bytes
- */
- public SQLXMLImpl(final byte[] bytes) {
- super(new InputStreamFactory(Streamable.ENCODING) {
- @Override
- public InputStream getInputStream() throws IOException {
- return new ByteArrayInputStream(bytes);
- }
- });
- }
-
- public SQLXMLImpl(final String str) {
- this(str.getBytes(Charset.forName(Streamable.ENCODING)));
- }
-
- public SQLXMLImpl(InputStreamFactory factory) {
- super(factory);
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException {
- if (sourceClass == null || sourceClass == StreamSource.class) {
- return (T)new StreamSource(getBinaryStream());
- }
- throw new SQLException("Unsupported source type " + sourceClass); //$NON-NLS-1$
- }
-
- public String getString() throws SQLException {
- try {
- return new String(ObjectConverterUtil.convertToByteArray(getBinaryStream()), this.getStreamFactory().getEncoding());
- } catch (IOException e) {
- SQLException ex = new SQLException(e.getMessage());
- ex.initCause(e);
- throw ex;
- }
- }
-
- public OutputStream setBinaryStream() throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public Writer setCharacterStream() throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public void setString(String value) throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-
- public String toString() {
- try {
- return getString();
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- public <T extends Result> T setResult(Class<T> resultClass)
- throws SQLException {
- throw SqlUtil.createFeatureNotSupportedException();
- }
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/Sequencable.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/Sequencable.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/Sequencable.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,31 +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 com.metamatrix.common.types;
-
-import java.sql.SQLException;
-
-public interface Sequencable {
-
- public CharSequence getCharSequence() throws SQLException;
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/SourceTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/SourceTransform.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/SourceTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,37 +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 com.metamatrix.common.types;
-
-public interface SourceTransform<S, T> {
-
- /**
- * 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 T transform(S value);
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/StandardXMLTranslator.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/StandardXMLTranslator.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/StandardXMLTranslator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,48 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-
-public class StandardXMLTranslator extends XMLTranslator {
-
- private Source source;
-
- public StandardXMLTranslator(Source source) {
- this.source = source;
- }
-
- @Override
- public void translate(Writer writer) throws TransformerException, IOException {
- Transformer t = TransformerFactory.newInstance().newTransformer();
- t.transform(source, new StreamResult(writer));
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/Streamable.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/Streamable.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/Streamable.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,102 +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 com.metamatrix.common.types;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-import com.metamatrix.core.CorePlugin;
-
-
-/**
- * A large value object which can be streamable in chunks of data each time
- *
- * <p>A reference stream id is tuple source id for a Streamble object where the
- * object is in buffer manager, but the contents will never be written to disk;
- * this is the ID that client needs to reference to get the chunk of data.
- */
-public abstract class Streamable<T> implements Externalizable {
-
- private static final long serialVersionUID = -8252488562134729374L;
-
- public static final String ENCODING = "UTF-8"; //$NON-NLS-1$
- public static final String FORCE_STREAMING = "FORCE_STREAMING"; //$NON-NLS-1$
- public static final int STREAMING_BATCH_SIZE_IN_BYTES = 102400; // 100K
-
- private String referenceStreamId;
- protected transient T reference;
- protected long length = -1;
-
- public Streamable() {
-
- }
-
- public Streamable(T reference) {
- if (reference == null) {
- throw new IllegalArgumentException(CorePlugin.Util.getString("Streamable.isNUll")); //$NON-NLS-1$
- }
-
- this.reference = reference;
- }
-
- public long getLength() {
- return length;
- }
-
- public T getReference() {
- return reference;
- }
-
- public void setReference(T reference) {
- this.reference = reference;
- }
-
- public String getReferenceStreamId() {
- return this.referenceStreamId;
- }
-
- public void setReferenceStreamId(String id) {
- this.referenceStreamId = id;
- }
-
- @Override
- public String toString() {
- return reference.toString();
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- length = in.readLong();
- referenceStreamId = (String)in.readObject();
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeLong(length);
- out.writeObject(referenceStreamId);
- }
-
-}
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,116 +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 com.metamatrix.common.types;
-
-import com.metamatrix.core.CorePlugin;
-
-/**
- * This interface represents the transformation from one data type to
- * another. For instance, from java.lang.String to java.lang.Integer
- * where java.lang.String is the the source type, "java.lang.String"
- * is the source name, etc.
- */
-public abstract class Transform {
-
- /**
- * 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 transform(Object value) throws TransformationException {
- if (value == null) {
- return null;
- }
- return transformDirect(value);
- }
-
-
- protected abstract Object transformDirect(Object value) throws TransformationException;
-
- /**
- * Type of the incoming value.
- * @return Source type
- */
- public abstract Class<?> getSourceType();
-
- /**
- * Name of the source type.
- * @return Name of source type
- */
- public String getSourceTypeName() {
- return DataTypeManager.getDataTypeName(getSourceType());
- }
-
- /**
- * Type of the outgoing value.
- * @return Target type
- */
- public abstract Class<?> getTargetType();
-
- /**
- * Name of the target type.
- * @return Name of target type
- */
- public String getTargetTypeName() {
- return DataTypeManager.getDataTypeName(getTargetType());
- }
-
- /**
- * Get nice display name for GUIs.
- * @return Display name
- */
- public String getDisplayName() {
- return getSourceTypeName() + " to " + getTargetTypeName(); //$NON-NLS-1$
- }
-
- /**
- * Get description.
- * @return Description of transform
- */
- public String getDescription() {
- return getDisplayName();
- }
-
- public boolean isExplicit() {
- return false;
- }
-
- /**
- * Override Object.toString() to do getDisplayName() version.
- * @return String representation of object
- */
- public String toString() {
- return getDisplayName();
- }
-
- 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) {
- throw new TransformationException(CorePlugin.Util.getString("transform.value_out_of_range", value, getSourceType().getSimpleName(), getTargetType().getSimpleName())); //$NON-NLS-1$
- }
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,80 +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 com.metamatrix.common.types;
-
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-
-/**
- * The exception is thrown when an error occurs during data transformation,
- * typically a formatting error or an invalid input type.
- */
-public class TransformationException extends MetaMatrixProcessingException {
-
- /**
- * No-Arg Constructor
- */
- public TransformationException( ) {
- super( );
- }
- /**
- * Construct an instance with the message specified.
- *
- * @param message A message describing the exception
- */
- public TransformationException( String message ) {
- super( message );
- }
-
- /**
- * Construct an instance with the message and error code specified.
- *
- * @param message A message describing the exception
- * @param code The error code
- */
- public TransformationException( String code, String message ) {
- super( code, message );
- }
-
- /**
- * Construct an instance from a message and an exception to chain to this one.
- *
- * @param code A code denoting the exception
- * @param e An exception to nest within this one
- */
- public TransformationException( Exception e, String message ) {
- super( e, message );
- }
-
- /**
- * Construct an instance from a message and a code and an exception to
- * chain to this one.
- *
- * @param e An exception to nest within this one
- * @param message A message describing the exception
- * @param code A code denoting the exception
- */
- public TransformationException( Exception e, String code, String message ) {
- super( e, code, message );
- }
-}
-
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/types/XMLTranslator.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/XMLTranslator.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/XMLTranslator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,45 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import javax.xml.transform.TransformerException;
-
-/**
- * This an interface defined to convert the various kinds of the XML sources
- * defined into a character stream.
- */
-public abstract class XMLTranslator {
-
- public abstract void translate(Writer writer) throws TransformerException, IOException;
-
- public String getString() throws IOException, TransformerException {
- StringWriter writer = new StringWriter();
- this.translate(writer);
- return writer.toString();
- }
-
-}
Deleted: 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-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,109 +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 com.metamatrix.common.types;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.sql.SQLException;
-//## JDBC4.0-begin ##
-import java.sql.SQLXML;
-//## JDBC4.0-end ##
-
-/*## JDBC3.0-JDK1.5-begin ##
-import com.metamatrix.core.jdbc.SQLXML;
-## JDBC3.0-JDK1.5-end ##*/
-
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-
-/**
- * This class represents the SQLXML object along with the Streamable interface. This is
- * class used everywhere in the MetaMatrix framework, but clients are restricted to use
- * only SQLXML interface on top of this.
- */
-public final class XMLType extends Streamable<SQLXML> implements SQLXML {
-
- public enum Type {
- UNKNOWN, DOCUMENT, FRAGMENT, SIBLINGS, COMMENT, PI, TEXT
- }
-
- private static final long serialVersionUID = -7922647237095135723L;
-
- private transient Type type = Type.UNKNOWN;
-
- public XMLType(){
-
- }
-
- public XMLType(SQLXML xml) {
- super(xml);
- }
-
- public InputStream getBinaryStream() throws SQLException {
- return this.reference.getBinaryStream();
- }
-
- public Reader getCharacterStream() throws SQLException {
- return this.reference.getCharacterStream();
- }
-
- public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException {
- return this.reference.getSource(sourceClass);
- }
-
- public String getString() throws SQLException {
- return this.reference.getString();
- }
-
- public OutputStream setBinaryStream() throws SQLException {
- return this.reference.setBinaryStream();
- }
-
- public Writer setCharacterStream() throws SQLException {
- return this.reference.setCharacterStream();
- }
-
- public void setString(String value) throws SQLException {
- this.reference.setString(value);
- }
-
- public void free() throws SQLException {
- this.reference.free();
- }
-
- public <T extends Result> T setResult(Class<T> resultClass)
- throws SQLException {
- return this.reference.setResult(resultClass);
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/ApplicationInfo.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/ApplicationInfo.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/ApplicationInfo.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,210 +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 com.metamatrix.common.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.net.URL;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.ObjectConverterUtil;
-
-public final class ApplicationInfo implements Serializable {
-
- public static final String APPLICATION_PRODUCT_INFORMATION = "Product Information"; //$NON-NLS-1$
-
- public static final String APPLICATION_BUILD_NUMBER_PROPERTY = "Build"; //$NON-NLS-1$
-
- private static final ApplicationInfo INSTANCE = new ApplicationInfo();
-
- private static final String LINE_SEPARATOR = "\n"; //$NON-NLS-1$
-
- private Properties props = new Properties();
-
- private ApplicationInfo() {
- InputStream is = this.getClass().getResourceAsStream("application.properties"); //$NON-NLS-1$
- try {
- try {
- props.load(is);
- } finally {
- is.close();
- }
- } catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
- }
- }
-
- public String getReleaseNumber() {
- return props.getProperty("build.releaseNumber"); //$NON-NLS-1$
- }
-
- public String getMajorReleaseNumber() {
- return getReleaseNumber().substring(0, getReleaseNumber().lastIndexOf('.'));
- }
-
- public int getMajorReleaseVersion() {
- String version = getReleaseNumber().substring(0, getReleaseNumber().indexOf('.'));
- return Integer.parseInt(version);
- }
-
- public int getMinorReleaseVersion() {
- int majorIndex = getReleaseNumber().indexOf('.');
- String version = getReleaseNumber().substring(majorIndex+1, getReleaseNumber().indexOf('.', majorIndex+1));
- return Integer.parseInt(version);
- }
-
- public String getBuildNumber() {
- return props.getProperty("build.number"); //$NON-NLS-1$
- }
-
- public String getUrl() {
- return props.getProperty("url"); //$NON-NLS-1$
- }
-
- public String getCopyright() {
- return props.getProperty("copyright"); //$NON-NLS-1$
- }
-
- public String getBuildDate() {
- return props.getProperty("build.date"); //$NON-NLS-1$
- }
-
- /**
- * Get the application information instance for this VM.
- * @return the singleton instance for this VM; never null
- */
- public static ApplicationInfo getInstance() {
- return INSTANCE;
- }
-
- private static String getClassPath() {
- return System.getProperty( "java.class.path" ); //$NON-NLS-1$
- }
-
- /**
- * The getClasspathInfo method is used to capture the current classpath
- * information. The initial intent is to write this information
- * to a file at VM startup time for debugging purposes and ensuring
- * patches are applied.
- * @param outputstream
- * @since 4.2
- */
- public String getClasspathInfo() {
- String classPath = getClassPath();
-
- StringBuffer sb = new StringBuffer();
- sb.append("\nDate: " + DateFormat.getDateInstance().format(new Date()));//$NON-NLS-1$
- sb.append( LINE_SEPARATOR );
-
- Map pathResults = new HashMap();
- List reversetList = new ArrayList();
- String separator = System.getProperty( "path.separator" ); //$NON-NLS-1$
-
- StringTokenizer path = new StringTokenizer( classPath, separator );
-
- while(path.hasMoreTokens()){
- String pathElement = path.nextToken();
- File pathFile = new File( pathElement );
- if (pathFile.exists()) {
-// if (resourceExistInClassPath(pathElement)) {
- pathResults.put(pathElement, Boolean.TRUE);
-
- } else {
- pathResults.put(pathElement, Boolean.FALSE);
- }
- reversetList.add(pathElement);
- }
- sb.append("Classpath Information" ); //$NON-NLS-1$
- sb.append( LINE_SEPARATOR );
- sb.append("CLASSPATH: "); //$NON-NLS-1$
- sb.append(classPath);
- sb.append( LINE_SEPARATOR );
- sb.append( LINE_SEPARATOR );
-
- Iterator iter = reversetList.iterator();
- sb.append("---- Classpath Entries ----"); //$NON-NLS-1$
- sb.append( LINE_SEPARATOR );
- while ( iter.hasNext() ) {
- String epath = (String) iter.next();
- Boolean doesExist = (Boolean) pathResults.get(epath);
- sb.append(epath);
- if (!doesExist.booleanValue()) {
- sb.append(" (MISSING)");//$NON-NLS-1$
- }
- sb.append( LINE_SEPARATOR );
-
- }
-
-
- sb.append( LINE_SEPARATOR );
- sb.append("Note the (MISSING) at the end to designate that the classpath entry is missing");//$NON-NLS-1$
-
-
- try {
- // find all the patch readme files and print those out.
- Enumeration readmes = ClassLoader.getSystemResources("patch_readme.txt"); //$NON-NLS-1$
- sb.append( LINE_SEPARATOR );
- sb.append( LINE_SEPARATOR );
-
- sb.append("---- Patch Readme Entries----"); //$NON-NLS-1$
- sb.append( LINE_SEPARATOR );
- int cnt = 0;
- if (readmes != null) {
-
- while(readmes.hasMoreElements()) {
- ++cnt;
- URL url = (URL) readmes.nextElement();
- sb.append("Patch " + url.getFile() + ":"); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append( LINE_SEPARATOR );
- InputStream is = url.openStream();
- byte[] data = ObjectConverterUtil.convertToByteArray(is);
- sb.append(new String(data));
- sb.append("-------------------------------------");//$NON-NLS-1$
- sb.append( LINE_SEPARATOR );
- is.close();
-
- }
- }
- if (cnt == 0) {
- sb.append("no Patch Readme Entries found"); //$NON-NLS-1$
- }
- } catch (IOException ioe) {
-
- }
-
- return sb.toString();
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/PasswordMaskUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/PasswordMaskUtil.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/PasswordMaskUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,122 +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 com.metamatrix.common.util;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * <p>This is a simple utility class to help keep password values from being
- * printed out, primarily from java.util.Properties object, into
- * MetaMatrix log files. This is <i>not</i> a robust security solution
- * for protecting passwords, and is only good insofar as we get all
- * other code to use this when necessary. When passwords are properly
- * encrypted in the database, this class will be no longer necessary.</p>
- *
- * <p>This class can be used in one of two ways. First, a Properties object
- * can be wrapped in an instance of this class - the properties object,
- * wrapped in this instance, can then be safely sent to LogManager to be
- * logged, or can otherwise be printed out. This instance will basically
- * duplicate the toString() method of a normal Properties object, but will
- * obfuscate any property values whose names end in any of the well-known
- * {@link #PASSWORD_PROP_SUFFIXES password property suffixes}.</p>
- *
- * <p>The second way is to just use this class's static
- * {@link #doesNameEndWithPasswordSuffix doesNameEndWithPasswordSuffix}
- * utility method by hand, passing in a String property name to
- * see if it ends with any of the well-known
- * {@link #PASSWORD_PROP_SUFFIXES password property suffixes}.</p>
- */
-public final class PasswordMaskUtil {
-
- /**
- * The known String suffixes that MetaMatrix property names end in.
- * Each of these is checked.
- */
- public static final String[] PASSWORD_PROP_SUFFIXES = new String[]{"password", "Password"}; //$NON-NLS-1$ //$NON-NLS-2$
-
- /**
- * The "mask" String that is printed out of the
- * {@link #toString} method, instead of the actual password value.
- */
- public static final String MASK_STRING = "*****"; //$NON-NLS-1$
-
- private Properties properties;
-
- /**
- * A Properties object can be wrapped by this class before, say,
- * being sent to LogManager. If this {@link #toString} method
- * is called, password properties will be printed out as
- * a {@link #MASK_STRING masked string}.
- * @param propertiesWithPassword Properties object that has
- * password property values inside it
- */
- public PasswordMaskUtil(Properties propertiesWithPassword){
- this.properties = propertiesWithPassword;
- }
-
- /**
- * This toString() method is basically the same as the
- * java.util.Properties class's toString() method, except that
- * if any of the properties in this class end with any of the
- * well-known {@link #PASSWORD_PROP_SUFFIXES password suffixes},
- * then the value will
- * be printed out as {@link #MASK_STRING}
- */
- public String toString(){
- int max = properties.size() - 1;
- StringBuffer buf = new StringBuffer();
- Iterator it = properties.entrySet().iterator();
-
- buf.append("{"); //$NON-NLS-1$
- String key = null;
- for (int i = 0; i <= max; i++) {
- Map.Entry e = (Map.Entry) (it.next());
- key = (String)e.getKey();
- if (doesNameEndWithPasswordSuffix(key)){
- buf.append(key + "=" + MASK_STRING); //$NON-NLS-1$
- } else {
- buf.append(key + "=" + e.getValue()); //$NON-NLS-1$
- }
- if (i < max)
- buf.append(", "); //$NON-NLS-1$
- }
- buf.append("}"); //$NON-NLS-1$
- return buf.toString();
- }
-
- /**
- * Indicates if the String propName ends in any of the well-known
- * {@link #PASSWORD_PROP_SUFFIXES password property suffixes}.</p>
- */
- public static boolean doesNameEndWithPasswordSuffix(String propName){
- for (int i=0; i<PASSWORD_PROP_SUFFIXES.length; i++){
- if (propName.endsWith(PASSWORD_PROP_SUFFIXES[i])){
- return true;
- }
- }
- return false;
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,1018 +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 com.metamatrix.common.util;
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.core.util.StringUtil;
-
-
-/**
- * Static utility methods for common tasks having to do with
- * java.util.Properties.
- */
-public final class PropertiesUtils {
-
- public static class InvalidPropertyException extends MetaMatrixRuntimeException {
-
- public InvalidPropertyException(String propertyName, String value, Class<?> expectedType, Throwable cause) {
- super(cause, CorePlugin.Util.getString("InvalidPropertyException.message", propertyName, value, expectedType.getSimpleName())); //$NON-NLS-1$
- }
-
- }
-
- /**
- * Returns a list of property names matching the given pattern. A '*' may be
- * given to match the pattern exactly up to the '*', then anything after.
- * Note: Should also implement matching with '?' which means match any single
- * char.
- * @param pattern The property name to match which may include a '*'.
- * @param props The properties to search.
- * @return The List of property names matching given pattern - may be empty
- * but never null.
- */
- public static List filter( String pattern, Properties props ) {
- boolean addAll = false;
- String searchStr = null;
- List propNames = new ArrayList();
- int globIndex = pattern.indexOf('*');
- if ( globIndex == -1 ) {
- searchStr = pattern;
- } else if ( globIndex == 0 ) {
- addAll = true;
- } else {
- searchStr = pattern.substring(0, globIndex);
- }
-
- Enumeration propNameEnum = props.propertyNames();
- while ( propNameEnum.hasMoreElements() ) {
- String name = (String) propNameEnum.nextElement();
- if ( name.startsWith(searchStr) || addAll ) {
- propNames.add(name);
- }
- }
-
- return propNames;
- }
-
-
- /**
- * Obtains from this source the list of all properties that match the pattern specified by the filter.
- * <p>
- * The filter is a string that may contain the '*' character as a wildcard one or more times
- * in the string. For example, the following filter:
- * <p>
- * <pre> *metamatrix.*</pre>
- * <p>
- * finds all properties that contain somewhere in the property name the string "metamatrix.".
- * @param filterPattern the string filter pattern that will be used to narrow the set of properties returned.
- * @param props The properties to search.
- * @return the enumeration of all of the property names of the primary source;
- * the enumeration may be empty if there is an error connecting to the property sources.
- */
- public static Properties getProperties(String filterPattern, Properties props) {
- Properties results = new Properties();
-
- boolean addAll = false;
- String searchStr = null;
- int globIndex = filterPattern.indexOf('*');
- if ( globIndex == -1 ) {
- searchStr = filterPattern;
- } else if ( globIndex == 0 ) {
- addAll = true;
- } else {
- searchStr = filterPattern.substring(0, globIndex);
- }
-
- Enumeration propNameEnum = props.propertyNames();
- while ( propNameEnum.hasMoreElements() ) {
- String name = (String) propNameEnum.nextElement();
- if ( name.startsWith(searchStr)) {
- Object value = props.get(name);
- if (value != null) {
- results.put(name.substring(searchStr.length()), value);
- }
- }
- else if (addAll) {
- results.put(name, props.get(name));
- }
- }
-
- return results;
- }
-
-
- /**
- * Performs a correct deep clone of the properties object by capturing
- * all properties in the default(s) and placing them directly into the
- * new Properties object. If the input is an instance of
- * <code>UnmodifiableProperties</code>, this method returns an
- * <code>UnmodifiableProperties</code> instance around a new (flattened)
- * copy of the underlying Properties object.
- */
- public static Properties clone( Properties props ) {
- return clone(props, null, false);
- }
-
- /**
- * Performs a correct deep clone of the properties object by capturing
- * all properties in the default(s) and placing them directly into the
- * new Properties object. If the input is an instance of
- * <code>UnmodifiableProperties</code>, this method returns an
- * <code>UnmodifiableProperties</code> instance around a new (flattened)
- * copy of the underlying Properties object.
- */
- public static Properties clone( Properties props, Properties defaults, boolean deepClone ) {
- Properties result = null;
- if ( defaults != null ) {
- if ( deepClone ) {
- defaults = clone(defaults);
- }
- result = new Properties(defaults);
- } else {
- result = new Properties();
- }
-
- putAll(result, props);
-
- return result;
- }
-
- /**
- * This method implements a 'compareTo' logic for two Properties objects,
- * equivalent to calling <code>p1.compareTo(p2)</code> if the
- * {@link java.util.Properties Properties} class implemented
- * {@link java.lang.Comparable Comparable} (which it does not).
- * @param p1 the first Properties instance to compare; may be null
- * @param p2 the second Properties instance to compare; may be null
- * @return a negative integer, zero, or a positive integer as <code>p1</code>
- * is less than, equal to, or greater than <code>p2</code>, respectively.
- */
- public static int compare( Properties p1, Properties p2 ) {
- if ( p1 != null ) {
- if ( p2 == null ) {
- return 1;
- }
- } else {
- if ( p2 != null ) {
- return -1;
- }
- return 0;
- }
-
-
- // Compare the number of property values ...
- int diff = p1.size() - p2.size();
- if ( diff != 0 ) {
- return diff;
- }
-
- // Iterate through the properties and compare values ...
- Map.Entry entry = null;
- Object p1Value = null;
- Object p2Value = null;
- Iterator iter = p1.entrySet().iterator();
- while ( iter.hasNext() ) {
- entry = (Map.Entry) iter.next();
- p1Value = entry.getValue();
- p2Value = p2.get(entry.getKey());
- if ( p1Value != null ) {
- if ( p2Value == null ) {
- return 1;
- }
- if ( p1Value instanceof Comparable ) {
- diff = ((Comparable)p1Value).compareTo(p2Value);
- } else {
- diff = p1Value.toString().compareTo(p2Value.toString());
- }
- if ( diff != 0 ) {
- return diff;
- }
- } else {
- if ( p2Value != null ) {
- return -1;
- }
- }
- }
- return 0;
- }
-
- /**
- * <p>This method is intended to replace the use of the <code>putAll</code>
- * method of <code>Properties</code> inherited from <code>java.util.Hashtable</code>.
- * The problem with that method is that, since it is inherited from
- * <code>Hashtable</code>, <i>default</i> properties are lost.
- * </p>
- * <p>For example, the following code
- * <pre><code>
- * Properties a;
- * Properties b;
- * //initialize ...
- * a.putAll(b);
- * </code></pre>
- * will fail <i>if</i> <code>b</code> had been constructed with a default
- * <code>Properties</code> object. Those defaults would be lost and
- * not added to <code>a</code>.</p>
- *
- * <p>The above code could be correctly performed with this method,
- * like this:
- * <pre><code>
- * Properties a;
- * Properties b;
- * //initialize ...
- * PropertiesUtils.putAll(a,b);
- * </code></pre>
- * In the above example, <code>a</code> is modified - properties are added to
- * it (note that if <code>a</code> has defaults they will remain unaffected.)
- * The properties from <code>b</code>, <i>including defaults</i>, will be
- * added to <code>a</code> using its <code>setProperty</code> method -
- * these new properties will overwrite any pre-existing ones of the same
- * name.
- * </p>
- *
- * @param addToThis This Properties object is modified; the properties
- * of the other parameter are added to this. The added property values
- * will replace any current property values of the same names.
- * @param withThese The properties (including defaults) of this
- * object are added to the "addToThis" parameter.
- */
- public static void putAll(Properties addToThis,
- Properties withThese) {
- if ( withThese != null && addToThis != null ) {
- Enumeration enumeration = withThese.propertyNames();
- while ( enumeration.hasMoreElements() ) {
- String propName = (String) enumeration.nextElement();
- Object propValue = withThese.get(propName);
- if ( propValue == null ) {
- //defaults can only be retrieved as strings
- propValue = withThese.getProperty(propName);
- }
- if ( propValue != null ) {
- addToThis.put(propName, propValue);
- }
- }
- }
- }
-
- public static void setOverrideProperies(Properties base, Properties override) {
- Enumeration overrideEnum = override.propertyNames();
- while (overrideEnum.hasMoreElements()) {
- String key = (String)overrideEnum.nextElement();
- String value = base.getProperty(key);
- String overRideValue = override.getProperty(key);
- if (value != null && !value.equals(overRideValue)) {
- base.setProperty(key, overRideValue);
- }
- }
- }
-
- public static int getIntProperty(Properties props, String propName, int defaultValue) throws InvalidPropertyException {
- String stringVal = props.getProperty(propName);
- if(stringVal == null) {
- return defaultValue;
- }
- stringVal = stringVal.trim();
- if (stringVal.length() == 0) {
- return defaultValue;
- }
- try {
- return Integer.parseInt(stringVal);
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
- }
- }
-
- public static long getLongProperty(Properties props, String propName, long defaultValue) {
- String stringVal = props.getProperty(propName);
- if(stringVal == null) {
- return defaultValue;
- }
- stringVal = stringVal.trim();
- if (stringVal.length() == 0) {
- return defaultValue;
- }
- try {
- return Long.parseLong(stringVal);
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Long.class, e);
- }
- }
-
- public static float getFloatProperty(Properties props, String propName, float defaultValue) {
- String stringVal = props.getProperty(propName);
- if(stringVal == null) {
- return defaultValue;
- }
- stringVal = stringVal.trim();
- if (stringVal.length() == 0) {
- return defaultValue;
- }
- try {
- return Float.parseFloat(stringVal);
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Float.class, e);
- }
- }
-
- public static double getDoubleProperty(Properties props, String propName, double defaultValue) {
- String stringVal = props.getProperty(propName);
- if(stringVal == null) {
- return defaultValue;
- }
- stringVal = stringVal.trim();
- if (stringVal.length() == 0) {
- return defaultValue;
- }
- try {
- return Double.parseDouble(stringVal);
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Double.class, e);
- }
- }
-
- public static boolean getBooleanProperty(Properties props, String propName, boolean defaultValue) {
- String stringVal = props.getProperty(propName);
- if(stringVal == null) {
- return defaultValue;
- }
- stringVal = stringVal.trim();
- if (stringVal.length() == 0) {
- return defaultValue;
- }
- try {
- return Boolean.valueOf(stringVal);
- } catch(NumberFormatException e) {
- throw new InvalidPropertyException(propName, stringVal, Float.class, e);
- }
- }
-
- /**
- * Read the header part of a properties file into a String.
- * @param fileName
- * @return
- * @throws IOException
- * @since 4.3
- */
- public static String loadHeader(String fileName) throws IOException {
- FileReader fr = null;
- BufferedReader br = null;
- try {
- fr = new FileReader(fileName);
- br = new BufferedReader(fr);
- String header = br.readLine();
- if (header != null && header.indexOf('#') == 0) {
- header = header.substring(1);
- }
- return header;
- } finally {
- if (br != null) {
- br.close();
- }
- if (fr != null) {
- fr.close();
- }
- }
- }
-
- public static Properties load(String fileName) throws IOException {
- InputStream is = null;
- try {
- Properties props = new Properties();
- is = new FileInputStream(fileName);
- props.load(is);
- return props;
- } finally {
- if (is != null) {
- is.close();
- }
- }
- }
-
- public static Properties loadFromURL(URL url) throws MalformedURLException, IOException {
- Properties result = new Properties();
- InputStream is = null;
- try {
- is = url.openStream();
- result.load(is);
- } finally {
- if (is != null) {
- is.close();
- }
- }
- return result;
- }
-
- public static Properties loadAsResource(Class clazz, String resourceName) throws IOException {
- InputStream is = null;
- Properties configProps = new Properties();
- try {
- is = clazz.getResourceAsStream(resourceName);
- ArgCheck.isNotNull(is);
- if (is != null) {
- configProps.load(is);
- }
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (Exception ce) {
-
- }
- }
- }
- return configProps;
- }
-
- public static Properties sort(Properties props) {
-
- List names = new ArrayList();
- Enumeration enumeration = props.propertyNames();
- while ( enumeration.hasMoreElements() ) {
- String name = (String) enumeration.nextElement();
- names.add(name);
- }
- Collections.sort(names);
-
- Properties newProps = new Properties();
- Iterator iter = names.iterator();
- while ( iter.hasNext() ) {
- String name = (String) iter.next();
- String propValue = props.getProperty(name);
- if ( propValue != null ) {
- newProps.setProperty(name, propValue);
- }
- }
- return newProps;
- }
-
-
- /**
- * Write the specified properties to the specified file,
- * with the specified header.
- * Results may not be sorted.
- * @param fileName
- * @param props
- * @param header
- * @throws IOException
- * @since 4.3
- */
- public static void print(String fileName, Properties props, String header) throws IOException {
- FileOutputStream stream = null;
- try {
- stream = new FileOutputStream(fileName);
- props.store(stream, header);
- stream.flush();
- } finally {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (Exception e) {
- }
- }
- }
-
-
-
- /**
- * Write the specified properties to the specified file,
- * with the specified header.
- * Results are sorted by property name.
- */
- public static void print( String fileName, Properties props ) throws IOException {
-
- FileOutputStream stream = null;
- PrintStream writer = null;
-
- try {
-
- stream = new FileOutputStream(fileName);
- writer = new PrintStream(stream);
-
- List names = new ArrayList();
- Enumeration enumeration = props.propertyNames();
- while ( enumeration.hasMoreElements() ) {
- String name = (String) enumeration.nextElement();
- names.add(name);
- }
- Collections.sort(names);
-
- StringBuffer sb;
-
- for (Iterator nIt=names.iterator(); nIt.hasNext(); ) {
- String name = (String) nIt.next();
-
- String value = props.getProperty(name);
-
- sb = new StringBuffer();
-
- sb.append(name);
- sb.append("="); //$NON-NLS-1$
- sb.append(value);
-
- writer.println(sb.toString());
- }
- writer.flush();
- } finally {
- try {
- if (writer != null) {
- writer.close();
- }
- } catch (Exception e){
-
- }
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (Exception e){
-
- }
- }
-
-
- }
-
- public static void print( java.io.PrintStream stream, Properties props ) {
- if (props != null) {
- Collection sorted = sortPropertiesForPrinting(props);
- for (Iterator it=sorted.iterator(); it.hasNext(); ) {
- String value = (String) it.next();
- stream.println(value);
- }
- }
- }
-
- private static final String NEWLINE = "\n"; //$NON-NLS-1$
- public static String prettyPrint( Properties props ) {
- if (props != null) {
- Collection sorted = sortPropertiesForPrinting(props);
-
- StringBuffer outBuf = new StringBuffer();
-
- for (Iterator it=sorted.iterator(); it.hasNext(); ) {
- String value = (String) it.next();
- outBuf.append(value);
- outBuf.append(NEWLINE);
- }
-
- return outBuf.toString();
- }
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Sorts the properties and returns a collection of entries
- * where each entry can be printed. Each entry will print in the
- * format of: Property: <code>name</code> = <code>value</code>
- */
-
- private static final String APREFIX = "Property '"; //$NON-NLS-1$
- private static final String AEQUAL = "'='"; //$NON-NLS-1$
- private static final String ASUFFIX = "'"; //$NON-NLS-1$
- private static final String TAB = "\t"; //$NON-NLS-1$
-
- public static Collection sortPropertiesForPrinting(Properties props) {
-
- Collection sortedProps = new ArrayList(props.size());
-
- List names = new ArrayList();
- Enumeration enumeration = props.propertyNames();
- while ( enumeration.hasMoreElements() ) {
- String name = (String) enumeration.nextElement();
- names.add(name);
- }
- Collections.sort(names);
-
- StringBuffer sb;
-
- for (Iterator nIt=names.iterator(); nIt.hasNext(); ) {
- String name = (String) nIt.next();
-
- String value = null;
- if (PasswordMaskUtil.doesNameEndWithPasswordSuffix(name)){
- value = PasswordMaskUtil.MASK_STRING;
- } else {
- value = props.getProperty(name);
- value= saveConvert(value, false);
- }
-
- name = saveConvert(name, true);
-
- sb = new StringBuffer(APREFIX);
-
- sb.append(name);
- sb.append(TAB);
- sb.append(AEQUAL);
- sb.append(value);
- sb.append(ASUFFIX);
-
-// sortedProps.add(APREFIX + name + TAB + AEQUAL + value + ASUFFIX);
- sortedProps.add(sb.toString());
- }
-
- return sortedProps;
-
- }
-
-// private static final String keyValueSeparators = "=: \t\r\n\f";
-
-// private static final String strictKeyValueSeparators = "=:";
-
- private static final String specialSaveChars = "=: \t\r\n\f#!"; //$NON-NLS-1$
-
-// private static final String whiteSpaceChars = " \t\r\n\f";
-
-
- /*
- * Converts unicodes to encoded \uxxxx
- * and writes out any of the characters in specialSaveChars
- * with a preceding slash
- */
- public static String saveConvert(String theString, boolean escapeSpace) {
- if ( theString == null ) {
- return ""; //$NON-NLS-1$
- }
- int len = theString.length();
- StringBuffer outBuffer = new StringBuffer(len*2);
-
- for(int x=0; x<len; x++) {
- char aChar = theString.charAt(x);
- switch(aChar) {
- case ' ':
- if (x == 0 || escapeSpace)
- outBuffer.append('\\');
-
- outBuffer.append(' ');
- break;
- case '\\':outBuffer.append('\\'); outBuffer.append('\\');
- break;
- case '\t':outBuffer.append('\\'); outBuffer.append('t');
- break;
- case '\n':outBuffer.append('\\'); outBuffer.append('n');
- break;
- case '\r':outBuffer.append('\\'); outBuffer.append('r');
- break;
- case '\f':outBuffer.append('\\'); outBuffer.append('f');
- break;
- default:
- if ((aChar < 0x0020) || (aChar > 0x007e)) {
- outBuffer.append('\\');
- outBuffer.append('u');
- outBuffer.append(toHex((aChar >> 12) & 0xF));
- outBuffer.append(toHex((aChar >> 8) & 0xF));
- outBuffer.append(toHex((aChar >> 4) & 0xF));
- outBuffer.append(toHex( aChar & 0xF));
- } else {
- if (specialSaveChars.indexOf(aChar) != -1)
- outBuffer.append('\\');
- outBuffer.append(aChar);
- }
- }
- }
- return outBuffer.toString();
- }
-
- /**
- * Convert a nibble to a hex character
- * @param nibble the nibble to convert.
- */
- private static char toHex(int nibble) {
- return hexDigit[(nibble & 0xF)];
- }
-
- /** A table of hex digits */
- private static final char[] hexDigit = {
- '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
- };
-
-
- public static final void copyProperty(Properties srcProperties, String srcPropName, Properties tgtProperties, String tgtPropName) {
- if(srcProperties == null || srcPropName == null || tgtProperties == null || tgtPropName == null) {
- return;
- }
-
- String value = srcProperties.getProperty(srcPropName);
- if(value != null) {
- tgtProperties.setProperty(tgtPropName, value);
- }
- }
-
- /**
- * The specialty of nested properties is, in a given property file
- * there can be values with pattern like "${...}"
- * <code>
- * key1=value1
- * key2=${key1}/value2
- * </code>
- * where the value of the <code>key2</code> should resolve to <code>value1/value2</code>
- * also if the property in the pattern <code>${..}</code> is not found in the loaded
- * properties, an exception is thrown. Multiple nesting is OK, however recursive nested is not supported.
- * @param original - Original properties to be resolved
- * @return resolved properties object.
- * @since 4.4
- */
- public static Properties resolveNestedProperties(Properties original) {
-
- for(Enumeration e = original.propertyNames(); e.hasMoreElements();) {
- String key = (String)e.nextElement();
- String value = original.getProperty(key);
-
- // this will take care of the if there are any non-string properties,
- // no nesting allowed on these.
- if (value == null) {
- continue;
- }
-
- boolean matched = true;
- boolean modified = false;
-
- while(matched) {
- // now match the pattern, then extract and find the value
- int start = value.indexOf("${"); //$NON-NLS-1$
- int end = start;
- if (start != -1) {
- end = value.indexOf('}', start);
- }
- matched = ((start != -1) && (end != -1));
- if (matched) {
- String nestedkey = value.substring(start+2, end);
- String nestedvalue = original.getProperty(nestedkey);
-
- // in cases where the key and the nestedkey are the same, this has to be bypassed
- // because it will cause an infinite loop, and because there will be no value
- // for the nestedkey that doesnt contain ${..} in the value
- if (key.equals(nestedkey)) {
- matched = false;
-
- } else {
-
-
- // this will handle case where we did not resolve, mark it blank
- if (nestedvalue == null) {
- throw new MetaMatrixRuntimeException(CorePlugin.Util.getString("PropertiesUtils.failed_to_resolve_property", nestedkey)); //$NON-NLS-1$
- }
- value = value.substring(0,start)+nestedvalue+value.substring(end+1);
- modified = true;
- }
- }
- }
- if(modified) {
- original.setProperty(key, value);
- }
- }
- return original;
- }
-
- // ======================================================
- /**
- * Returns a boolean indicating whether the string matched the given pattern.
- * A '*' may be
- * given to match the pattern exactly up to the '*', then anything after.
- * We will also support a leading star, and match on anything that ends with
- * the string specified after the star.
- * Note: Should also implement matching with '?' which means match any single
- * char.
- * @param pattern The property name to match which may include a '*'.
- * @param props The properties to search.
- * @return The boolean - passed or failed
- * but never null.
- */
- public static boolean filterTest( String pattern, String sCandidate ) {
-
- // Vars for match strategy
- char chStar = '*';
-
- // Match rule booleans. Please note that 'bLeading'
- // and 'bTrailing' refer to the string we are searching for.
- // For example, if the strategy is bLeading, and the Match frag
- // is "wet", and the candidate string is "wetrust", it will pass.
- // Likewise if the strategy is bTrailing and the Match frag is
- // "rust" and the candidate string is "wetrust", it will pass.
- boolean bLeading = false;
- boolean bTrailing = false;
- boolean bFullMatch = false;
- boolean bAnywhere = false;
- boolean bAllMatch = false;
-
- boolean bPass = false;
-
- String sMatchFrag = ""; //$NON-NLS-1$
-// List propNames = new ArrayList();
-
-
- // 1. Analyze pattern to resolve match strategy
-
- // First ensure the pattern is safe to work with.
- // If the pattern is an empty string, set it to '*',
- // which means anything passes.
- pattern = pattern.trim();
- if ( pattern.length() == 0 )
- pattern = "*"; //$NON-NLS-1$
-
- int iFirstStar = pattern.indexOf( chStar );
- int iLastStar = pattern.lastIndexOf( chStar );
-
- // If there are any stars:
- if( (iFirstStar > -1) && ( iLastStar > -1 ) )
- {
- // and their positions are the same (same star, silly)
- if( iFirstStar == iLastStar )
- {
- // and this star is at the front:
- if( iFirstStar == 0 )
- {
- // and the pattern is only one byte long:
- if( pattern.length() == 1 )
- {
- // Then the pattern is a single '*',
- // and all will pass the match:
- bAllMatch = true;
- }
- else
- {
- // Or the pattern is a leading star followed
- // by a string:
- bTrailing = true;
- sMatchFrag = pattern.substring( 1 );
- }
- }
- else
- {
- // OR the star is NOT at the front, so the
- // pattern is a trailing star preceded by a string:
- bLeading = true;
- sMatchFrag = pattern.substring( 0, iLastStar );
-
- }
- }
- else
- {
- // They are not equal
- //sMatchStrategy = ANYWHERE;
- bAnywhere = true;
- sMatchFrag = pattern.substring( iFirstStar + 1, iLastStar );
- }
- }
- else
- {
- // there are no stars at all
- //sMatchStrategy = FULL_MATCH;
- bFullMatch = true;
- sMatchFrag = pattern;
- }
-
- // Now test the string
- String name = sCandidate;
- bPass = false;
-
- // force the match fragment and the test string to UPPER case
- String sMatchFragUpper = sMatchFrag.toUpperCase();
- String sNameUpper = name.toUpperCase();
-
- // Test all of the booleans. Only one should be true.
- if( bAllMatch ) {
- bPass = true;
- }
- else
- if( bAnywhere ) {
- if( sNameUpper.indexOf( sMatchFragUpper ) > -1 )
- bPass = true;
- }
- else
- if( bFullMatch ) {
- if( sNameUpper.equals( sMatchFragUpper ) )
- bPass = true;
- }
- else
- if( bLeading ) {
- if( sNameUpper.startsWith( sMatchFragUpper ) )
- bPass = true;
- }
- else
- if( bTrailing ) {
- if( sNameUpper.endsWith( sMatchFragUpper ) )
- bPass = true;
- }
-
- return bPass;
- }
-
- public static void setBeanProperties(Object bean, Properties props, String prefix) {
- // Move all prop names to lower case so we can use reflection to get
- // method names and look them up in the connection props.
- final Properties connProps = lowerCaseAllPropNames(props);
- final Method[] methods = bean.getClass().getMethods();
- for (int i = 0; i < methods.length; i++) {
- final Method method = methods[i];
- final String methodName = method.getName();
- // If setter ...
- if ( methodName.startsWith("set") && method.getParameterTypes().length == 1 ) { //$NON-NLS-1$
- // Get the property name
- final String propertyName = methodName.substring(3); // remove the "set"
- String shortName = propertyName.toLowerCase();
- String propertyValue = null;
- if (prefix != null) {
- propertyValue = connProps.getProperty(prefix + "." + shortName); //$NON-NLS-1$
- } else {
- propertyValue = connProps.getProperty(shortName);
- }
- if (propertyValue == null) {
- continue;
- }
- final Class<?> argType = method.getParameterTypes()[0];
- try {
- final Object[] params = new Object[] {StringUtil.valueOf(propertyValue, argType)};
- method.invoke(bean, params);
- } catch (Throwable e) {
- throw new InvalidPropertyException(propertyName, propertyValue, argType, e);
- }
- }
- }
- }
-
- public static void setBeanProperty(Object bean, String name, Object value) {
- if (value == null) {
- return;
- }
- name = name.toLowerCase();
- final Method[] methods = bean.getClass().getMethods();
- for (int i = 0; i < methods.length; i++) {
- final Method method = methods[i];
- final String methodName = method.getName();
- // If setter ...
- if ( methodName.startsWith("set") && method.getParameterTypes().length == 1 ) { //$NON-NLS-1$
- // Get the property name
- final String propertyName = methodName.substring(3); // remove the "set"
- String shortName = propertyName.toLowerCase();
- if (!shortName.equals(name)) {
- continue;
- }
- final Class<?> argType = method.getParameterTypes()[0];
- try {
- Object[] params = new Object[] {value};
- if (!argType.isAssignableFrom(value.getClass())) {
- params = new Object[] {StringUtil.valueOf(value.toString(), argType)};
- }
- method.invoke(bean, params);
- } catch (Throwable e) {
- throw new InvalidPropertyException(propertyName, value.toString(), argType, e);
- }
- }
- }
- }
-
- private static Properties lowerCaseAllPropNames(final Properties connectionProps) {
- final Properties lcProps = new Properties();
- final Enumeration<?> itr = connectionProps.propertyNames();
- while ( itr.hasMoreElements() ) {
- final String name = (String) itr.nextElement();
- String propValue = connectionProps.getProperty(name);
- if (propValue != null) {
- lcProps.setProperty(name.toLowerCase(), propValue);
- }
- }
- return lcProps;
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/ReaderInputStream.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/ReaderInputStream.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/ReaderInputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,87 +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 com.metamatrix.common.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-
-import com.metamatrix.common.types.Streamable;
-
-public class ReaderInputStream extends InputStream {
-
- private static final int DEFAULT_BUFFER_SIZE = Streamable.STREAMING_BATCH_SIZE_IN_BYTES;
-
- private final Reader reader;
- private final Charset charSet;
- private char[] charBuffer;
-
- private boolean hasMore = true;
- private ByteBuffer currentBuffer;
- private int prefixBytes;
- private boolean needsPrefix = true;
-
- public ReaderInputStream(Reader reader, Charset charSet) {
- this(reader, charSet, DEFAULT_BUFFER_SIZE);
- }
-
- public ReaderInputStream(Reader reader, Charset charSet, int bufferSize) {
- this.reader = reader;
- this.charSet = charSet;
- this.charBuffer = new char[bufferSize];
- if (charSet.displayName().equalsIgnoreCase("UTF-16")) { //$NON-NLS-1$
- prefixBytes = 2;
- }
- }
-
- @Override
- public int read() throws IOException {
- if (currentBuffer == null || !currentBuffer.hasRemaining()) {
- if (!hasMore) {
- return -1;
- }
- int charsRead = reader.read(charBuffer);
- if (charsRead == -1) {
- hasMore = false;
- return -1;
- }
- currentBuffer = charSet.encode(CharBuffer.wrap(charBuffer, 0, charsRead));
- if (!needsPrefix) {
- currentBuffer.position(prefixBytes);
- }
- needsPrefix = false;
- }
- return currentBuffer.get() & 0xff;
- }
-
- @Override
- public void close() throws IOException {
- this.reader.close();
- }
-}
\ No newline at end of file
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/SqlUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/SqlUtil.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/SqlUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,124 +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 com.metamatrix.common.util;
-
-import java.sql.SQLException;
-
-//## JDBC4.0-begin ##
-import java.sql.SQLFeatureNotSupportedException;
-//## JDBC4.0-end ##
-
-import java.util.regex.Pattern;
-
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.core.util.StringUtil;
-
-/**
- * Utilities for dealing with SQL strings.
- */
-public class SqlUtil {
- public static final char CR_CHAR = StringUtil.Constants.CARRIAGE_RETURN_CHAR;
- public static final char NL_CHAR = StringUtil.Constants.NEW_LINE_CHAR;
- public static final char SPACE_CHAR = StringUtil.Constants.SPACE_CHAR;
- public static final char TAB_CHAR = StringUtil.Constants.TAB_CHAR;
- private static Pattern PATTERN = Pattern.compile("^([\\s]|(/\\*.*\\*/))*(insert|update|delete|create|drop|(select([\\s]|(/\\*.*\\*/))+.*into([\\s]|(/\\*.*\\*/))+)).*", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE); //$NON-NLS-1$
-
- private SqlUtil() {
- super();
- }
-
- /**
- * Determines whether a sql statement is an update (INSERT, UPDATE, or DELETE).
- * Throws exception if SQL statement appears to be invalid (because it's null, has
- * 0 length, etc.
- * @param sql Sql string
- * @return True if INSERT, UPDATE, or DELETE, and false otherwise
- * @throws IllegalArgumentException If sql string is invalid and neither a
- * query or an update
- */
- public static boolean isUpdateSql(String sql) throws IllegalArgumentException {
- ArgCheck.isNotNull(sql);
- return PATTERN.matcher(sql).matches();
- }
-
- /**
- * Simple method which normalizes a SQL string by replacing CR characters, new line characters and Tab characters with spaces,
- * then trimming the string to remove unneeded spaces.
- *
- * @param inputSqlString
- * @return
- * @since 5.0
- */
- public static String normalize(String inputSqlString) {
- String normalizedString = inputSqlString;
- if (inputSqlString != null && inputSqlString.length() > 0) {
- if ( inputSqlString.indexOf(NL_CHAR) > -1 ||
- inputSqlString.indexOf(CR_CHAR) > -1 ||
- inputSqlString.indexOf(TAB_CHAR) > -1 ||
- inputSqlString.indexOf(StringUtil.Constants.DBL_SPACE) > -1) {
- normalizedString = normalizedString.replace(NL_CHAR, SPACE_CHAR);
- normalizedString = normalizedString.replace(CR_CHAR, SPACE_CHAR);
- normalizedString = normalizedString.replace(TAB_CHAR, SPACE_CHAR);
- normalizedString = StringUtil.replaceAll(normalizedString,
- StringUtil.Constants.DBL_SPACE,
- StringUtil.Constants.SPACE);
-
- }
- normalizedString = StringUtil.collapseWhitespace(normalizedString);
- }
- return normalizedString;
- }
-
- /**
- * determine if the supplied sql Strings are different
- * @param newSql the new SQL String
- * @param oldSql the old SQL String
- * @return 'true' if strings differ, 'false' if same
- */
- public static boolean stringsAreDifferent(String newSql, String oldSql) {
- boolean isDifferent = true;
- if(newSql==null) {
- if(oldSql==null) {
- isDifferent = false;
- }
- } else if(oldSql!=null) {
- String normalizedNewSql = normalize(newSql);
- String normalizedOldSql = normalize(oldSql);
- if(normalizedNewSql.equals(normalizedOldSql)) {
- isDifferent=false;
- }
- }
- return isDifferent;
- }
-
- public static SQLException createFeatureNotSupportedException() {
- //## JDBC4.0-begin ##
- return new SQLFeatureNotSupportedException();
- //## JDBC4.0-end ##
-
- /*## JDBC3.0-JDK1.5-begin ##
- return new SQLException("unsupported feature");
- ## JDBC3.0-JDK1.5-end ##*/
-
- }
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/common/util/TimestampWithTimezone.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/TimestampWithTimezone.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/common/util/TimestampWithTimezone.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,203 +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 com.metamatrix.common.util;
-
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.TimeZone;
-
-import com.metamatrix.common.types.DataTypeManager;
-
-/**
- * Utility methods for SQL Timestamps, Time, and Dates with time zones as UTC
- *
- * This is intended to take incoming Strings or Dates that have accurate
- * Calendar fields and give the UTC time by interpretting those fields
- * in the target time zone.
- *
- * Use of the Calendar object passed in will not be thread safe, but
- * it will not alter the contents of the Calendar.
- *
- * Note that normalization occurs only for the transition from one type to another.
- *
- */
-public class TimestampWithTimezone {
-
- private static ThreadLocal<Calendar> CALENDAR = new ThreadLocal<Calendar>() {
- protected Calendar initialValue() {
- return Calendar.getInstance();
- }
- };
-
- public static Calendar getCalendar() {
- return CALENDAR.get();
- }
-
- public static void resetCalendar(TimeZone tz) {
- TimeZone.setDefault(tz);
- CALENDAR.set(Calendar.getInstance());
- }
-
- public static Object create(java.util.Date date, TimeZone initial, Calendar target, Class type) {
- if (type.equals(DataTypeManager.DefaultDataClasses.TIME)) {
- return createTime(date, initial, target);
- }
- if (type.equals(DataTypeManager.DefaultDataClasses.DATE)) {
- return createDate(date, initial, target);
- }
- return createTimestamp(date, initial, target);
- }
-
- public static Timestamp createTimestamp(java.util.Date date, TimeZone initial, Calendar target) {
- if (target == null) {
- target = getCalendar();
- }
-
- long time = target.getTimeInMillis();
-
- adjustCalendar(date, initial, target);
-
- target.set(Calendar.MILLISECOND, 0);
-
- Timestamp tsInTz = new Timestamp(target.getTimeInMillis());
-
- if(date instanceof Timestamp) {
- tsInTz.setNanos(((Timestamp)date).getNanos());
- }
-
- target.setTimeInMillis(time);
- return tsInTz;
- }
-
- public static Time createTime(java.util.Date date, TimeZone initial, Calendar target) {
- if (target == null) {
- target = getCalendar();
- }
-
- long time = target.getTimeInMillis();
-
- adjustCalendar(date, initial, target);
-
- Time result = normalizeTime(date, target);
-
- target.setTimeInMillis(time);
- return result;
- }
-
- public static Date createDate(java.util.Date date, TimeZone initial, Calendar target) {
- if (target == null) {
- target = getCalendar();
- }
-
- long time = target.getTimeInMillis();
-
- adjustCalendar(date, initial, target);
-
- Date result = normalizeDate(date, target);
-
- target.setTimeInMillis(time);
- return result;
- }
-
- /**
- * Creates normalized SQL Time Object
- *
- * @return Time
- * @since 4.3
- */
- public static Time createTime(java.util.Date date) {
- if (date instanceof Time) {
- return (Time)date;
- }
- Calendar cal = getCalendar();
- cal.setTime(date);
- return normalizeTime(date, cal);
- }
-
- /**
- * Creates normalized SQL Date Object
- *
- * @return Date
- * @since 4.3
- */
- public static Date createDate(java.util.Date date) {
- if (date instanceof Date) {
- return (Date)date;
- }
- Calendar cal = getCalendar();
- cal.setTime(date);
- return normalizeDate(date, cal);
- }
-
- public static Timestamp createTimestamp(java.util.Date date) {
- if (date instanceof Timestamp) {
- return (Timestamp)date;
- }
- return new Timestamp(date.getTime());
- }
-
- private static Date normalizeDate(java.util.Date date, Calendar target) {
- if (!(date instanceof Date)) {
- target.set(Calendar.HOUR_OF_DAY, 0);
- target.set(Calendar.MINUTE, 0);
- target.set(Calendar.SECOND, 0);
- target.set(Calendar.MILLISECOND, 0);
- }
- Date result = new Date(target.getTimeInMillis());
- return result;
- }
-
- private static Time normalizeTime(java.util.Date date, Calendar target) {
- if (!(date instanceof Time)) {
- target.set(Calendar.YEAR, 1970);
- target.set(Calendar.MONTH, Calendar.JANUARY);
- target.set(Calendar.DAY_OF_MONTH, 1);
- target.set(Calendar.MILLISECOND, 0);
- }
- Time result = new Time(target.getTimeInMillis());
- return result;
- }
-
- private static void adjustCalendar(java.util.Date date,
- TimeZone initial,
- Calendar target) {
- assert initial != null;
- if (initial.hasSameRules(target.getTimeZone())) {
- target.setTime(date);
- return;
- }
-
- //start with base time
- long time = date.getTime();
-
- Calendar cal = Calendar.getInstance(initial);
- cal.setTimeInMillis(time);
-
- target.clear();
- for (int i = 0; i <= Calendar.MILLISECOND; i++) {
- target.set(i, cal.get(i));
- }
- }
-}
\ No newline at end of file
Deleted: trunk/common-core/src/main/java/com/metamatrix/core/BundleUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/BundleUtil.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/core/BundleUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,223 +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 com.metamatrix.core;
-
-import java.text.MessageFormat;
-import java.util.List;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import com.metamatrix.core.util.ArgCheck;
-import com.metamatrix.core.util.StringUtil;
-
-public class BundleUtil {
- /**
- * The product properties used to override default localized text.
- * @since 5.0.2
- */
- static protected ResourceBundle productProps;
-
- /**
- * The name of the resource bundle.
- */
- private final String bundleName;
-
- /**
- * The {@link ResourceBundle}for localization; initialized in the constructor.
- */
- private final ResourceBundle bundle;
-
- protected final String pluginId;
-
- /**
- * Construct an instance of this class by specifying the plugin ID.
- *
- * @param pluginId
- * the identifier of the plugin for which this utility is being instantiated
- * @param bundleName
- * the name of the resource bundle; used for problem reporting purposes only
- * @param bundle
- * the resource bundle
- */
- public BundleUtil(final String pluginId,
- final String bundleName,
- final ResourceBundle bundle) {
- this.pluginId = pluginId;
- this.bundleName = bundleName;
- this.bundle = bundle;
- }
-
- /**
- * Get the string identified by the given key and localized to the current locale.
- *
- * @param key
- * the key in the resource file
- * @return the localized String, or <code>
- * "Missing message: " + key + " in: " + this.bundleName
- * </code> if the string could
- * not be found in the current locale, or <code>
- * "No message available"
- * </code> if the <code>key</code> is null.
- */
- public String getString(final String key) {
- try {
- // Since this string has no parameters, it will not be run through MessageFormat.
- // MessageFormat eliminates double ticks, so the next two lines replace double ticks
- // with single ticks. This is only needed if the localized string contains double ticks
- // (the policy is that localized strings without parameters should not).
- // COMMENTED OUT BECAUSE OF POLICY
- //char[] messageWithNoDoubleQuotes = CharOperation.replace(text.toCharArray(), DOUBLE_QUOTES, SINGLE_QUOTE);
- //text = new String(messageWithNoDoubleQuotes);
-
- String value = getProductValue(key);
- return ((value == null) ? this.bundle.getString(key) : value);
- } catch (final Exception err) {
- String msg;
-
- if (err instanceof NullPointerException) {
- msg = "<No message available>"; //$NON-NLS-1$
- } else if (err instanceof MissingResourceException) {
- msg = "<Missing message for key \"" + key + "\" in: " + this.bundleName + '>'; //$NON-NLS-1$ //$NON-NLS-2$
- } else {
- msg = err.getLocalizedMessage();
- }
-
- // RMH: See DataAccessPlugin.ResourceLocator.getString(...) method, which tries one bundle before
- // delegating to another. Therefore, this will happen normally in some situations.
- //log(msg);
-
- return msg;
- }
- }
-
- /**
- * Obtains the value that is overriding the default value.
- * @param theKey the key whose product value is being requested
- * @return the value or <code>null</code> if not overridden by the product
- */
- private String getProductValue(String theKey) {
- String result = null;
-
- if ((productProps != null) && !StringUtil.isEmpty(theKey)) {
- String key = this.pluginId + '.' + theKey;
-
- try {
- result = productProps.getString(key);
- } catch (MissingResourceException theException) {
- // not found in product properties
- }
- }
-
- return result;
- }
-
- /**
- * Determines if the given key exists in the resource file.
- *
- * @param key
- * the key in the resource file
- * @return True if the key exists.
- * @since 4.0
- */
- public boolean keyExists(final String key) {
- try {
- return ((getProductValue(key) != null) || (this.bundle.getString(key) != null));
- } catch (final Exception err) {
- return false;
- }
- }
-
- /**
- * Get the string identified by the given key and localized to the current locale, and replace placeholders in the localized
- * string with the string form of the parameters.
- *
- * @param key
- * the key in the resource file
- * @param parameters
- * the list of parameters that should replace placeholders in the localized string (e.g., "{0}", "{1}", etc.)
- * @return the localized String, or <code>
- * "Missing message: " + key + " in: " + this.bundleName
- * </code> if the string could
- * not be found in the current locale, or <code>
- * "No message available"
- * </code> if the <code>key</code> is null.
- */
- public String getString(final String key,
- final List parameters) {
- if (parameters == null) {
- return getString(key);
- }
- return getString(key, parameters.toArray());
- }
-
- /**
- * Get the string identified by the given key and localized to the current locale, and replace placeholders in the localized
- * string with the string form of the parameters.
- *
- * @param key
- * the key in the resource file
- * @param parameters
- * the list of parameters that should replace placeholders in the localized string (e.g., "{0}", "{1}", etc.)
- * @return the localized String, or <code>
- * "Missing message: " + key + " in: " + this.bundleName
- * </code> if the string could
- * not be found in the current locale, or <code>
- * "No message available"
- * </code> if the <code>key</code> is null.
- */
- public String getString(final String key,
- final Object... parameters) {
- String text = getString(key);
-
- // Check the trivial cases ...
- if (text == null) {
- return '<' + key + '>';
- }
- if (parameters == null || parameters.length == 0) {
- return text;
- }
-
- return MessageFormat.format(text, parameters);
- }
-
- /**
- * @see com.metamatrix.core.PluginUtil#getStringOrKey(java.lang.String)
- * @since 4.1
- */
- public String getStringOrKey(final String key) {
- ArgCheck.isNotNull(key);
-
- String value = getProductValue(key);
-
- if (value == null) {
- try {
- return this.bundle.getString(key);
- } catch (final MissingResourceException err) {
- return key;
- }
- }
-
- return value;
- }
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/core/CoreConstants.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/CoreConstants.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/core/CoreConstants.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,112 +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 com.metamatrix.core;
-
-
-/**
- * @since 4.0
- */
-public interface CoreConstants {
- /**<p>
- * Contains ID's for all MetaMatrix plugins.
- * </p>
- * @since 4.0
- */
- interface Plugin {
- String METAMATRIX_PREFIX = "com.metamatrix."; //$NON-NLS-1$
-
- String COMMON = METAMATRIX_PREFIX + "common"; //$NON-NLS-1$
- String COMMON_COMM_PLATFORM = METAMATRIX_PREFIX + "common.comm.platform"; //$NON-NLS-1$
- String CORE_XSLT = METAMATRIX_PREFIX + "core.xslt"; //$NON-NLS-1$
- String MODELER_JDBC = METAMATRIX_PREFIX + "modeler.jdbc"; //$NON-NLS-1$
- String PLATFORM = METAMATRIX_PREFIX + "platform"; //$NON-NLS-1$
- }
-
- interface Debug {
- String PLUGIN_ACTIVATION = "pluginActivation"; //$NON-NLS-1$
- }
-
- interface Trace {
- String PROXIES = "proxies"; //$NON-NLS-1$
- }
-
- public static final String SYSTEM_MODEL = "SYS"; //$NON-NLS-1$
-
- public static final String SYSTEM_VDB = "System.vdb"; //$NON-NLS-1$
-
- public static final String PRODUCT_OWNER_NAME_PROPERTY = "ownerName"; //$NON-NLS-1$
-
- /**
- * Constant that defines the replaceable token in WSDL generated in the VDB which represents
- * the MetaMatrix Server properties for connecting the to VDB.
- */
- public static final String ACTION_PREFIX_FOR_DATA_WEBSERVICE = "http://server.properies.metamatrix.com"; //$NON-NLS-1$
-
- /**
- * Constant that defines the parameter value in WSDL generated of the VDB that will be used to
- * identifiy the fully qualified procedure name when executing the web service.
- */
- public static final String ACTION_PARAMETER_FOR_DATA_WEBSERVICE_PROCEDURE = "procedure="; //$NON-NLS-1$
-
- /**
- * Constant that defines the replaceable token in WSDL generated in the VDB which represents
- * the first part (VDB-independent) of the URL. The general form of the URLs is as follows:
- * <p>
- * <code> [URL ROOT][Path to Resource in VDB][URL Suffix]</code>
- * </p></p>
- * In general, the URL root would be replaced in a particular server with the actual URL to the servlet
- * used to obtain the WSDL and XSD, and the URL suffix replaced with the servlet parameters.
- * </p>
- * @see #URL_SUFFIX_FOR_VDB
- */
- public static final String URL_ROOT_FOR_VDB = "http://vdb.metamatrix.com"; //$NON-NLS-1$
-
- /**
- * Constant that defines the replaceable token in WSDL generated in the VDB which represents
- * the suffix part of the URL. The general form of the URLs is as follows:
- * <p>
- * <code> [URL ROOT][Path to Resource in VDB][URL Suffix]</code>
- * </p></p>
- * In general, the URL root would be replaced in a particular server with the actual URL to the servlet
- * used to obtain the WSDL and XSD, and the URL suffix replaced with the servlet parameters.
- * </p>
- * @see #URL_ROOT_FOR_VDB
- */
- public static final String URL_SUFFIX_FOR_VDB = "?vdbToken=true"; //$NON-NLS-1$
-
-
- /**
- * Constant that defines the replaceable token in WSDL generated in the VDB which represents
- * the URL for the service binding.
- * @see #URL_SUFFIX_FOR_VDB
- * @see #URL_ROOT_FOR_VDB
- */
- public static final String URL_FOR_DATA_WEBSERVICE = "http://vdb.dataservice.metamatrix.com"; //$NON-NLS-1$\
-
- /**
- * Constant for the anonymous Teiid system username
- */
- public static final String DEFAULT_ANON_USERNAME = "teiidanonymous";
-
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/core/CorePlugin.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/CorePlugin.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/core/CorePlugin.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,43 +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 com.metamatrix.core;
-
-import java.util.ResourceBundle;
-
-
-/**
- * CorePlugin
- */
-public class CorePlugin {
- //
- // Class Constants:
- //
- /**
- * The plug-in identifier of this plugin
- * (value <code>"com.metamatrix.core"</code>).
- */
- public static final String PLUGIN_ID = "com.metamatrix.core" ; //$NON-NLS-1$
-
- public static final BundleUtil Util = new BundleUtil(PLUGIN_ID,
- PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/core/ErrorMessageKeys.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/ErrorMessageKeys.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/core/ErrorMessageKeys.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,70 +0,0 @@
-package com.metamatrix.core;
-
-public interface ErrorMessageKeys {
-
- /** types (029) */
- public static final String TYPES_ERR_0001 = "ERR.003.029.0001"; //$NON-NLS-1$
- public static final String TYPES_ERR_0002 = "ERR.003.029.0002"; //$NON-NLS-1$
- public static final String TYPES_ERR_0003 = "ERR.003.029.0003"; //$NON-NLS-1$
- public static final String TYPES_ERR_0004 = "ERR.003.029.0004"; //$NON-NLS-1$
- public static final String TYPES_ERR_0005 = "ERR.003.029.0005"; //$NON-NLS-1$
- public static final String TYPES_ERR_0006 = "ERR.003.029.0006"; //$NON-NLS-1$
- public static final String TYPES_ERR_0007 = "ERR.003.029.0007"; //$NON-NLS-1$
- public static final String TYPES_ERR_0008 = "ERR.003.029.0008"; //$NON-NLS-1$
- public static final String TYPES_ERR_0009 = "ERR.003.029.0009"; //$NON-NLS-1$
- public static final String TYPES_ERR_0010 = "ERR.003.029.0010"; //$NON-NLS-1$
- public static final String TYPES_ERR_0011 = "ERR.003.029.0011"; //$NON-NLS-1$
- public static final String TYPES_ERR_0012 = "ERR.003.029.0012"; //$NON-NLS-1$
- public static final String TYPES_ERR_0013 = "ERR.003.029.0013"; //$NON-NLS-1$
- public static final String TYPES_ERR_0014 = "ERR.003.029.0014"; //$NON-NLS-1$
- public static final String TYPES_ERR_0015 = "ERR.003.029.0015"; //$NON-NLS-1$
- public static final String TYPES_ERR_0016 = "ERR.003.029.0016"; //$NON-NLS-1$
- public static final String TYPES_ERR_0017 = "ERR.003.029.0017"; //$NON-NLS-1$
- public static final String TYPES_ERR_0018 = "ERR.003.029.0018"; //$NON-NLS-1$
- public static final String TYPES_ERR_0019 = "ERR.003.029.0019"; //$NON-NLS-1$
- public static final String TYPES_ERR_0020 = "ERR.003.029.0020"; //$NON-NLS-1$
- public static final String TYPES_ERR_0021 = "ERR.003.029.0021"; //$NON-NLS-1$
- public static final String TYPES_ERR_0022 = "ERR.003.029.0022"; //$NON-NLS-1$
- public static final String TYPES_ERR_0023 = "ERR.003.029.0023"; //$NON-NLS-1$
- public static final String TYPES_ERR_0024 = "ERR.003.029.0024"; //$NON-NLS-1$
- public static final String TYPES_ERR_0025 = "ERR.003.029.0025"; //$NON-NLS-1$
- public static final String TYPES_ERR_0026 = "ERR.003.029.0026"; //$NON-NLS-1$
-
- public static final String CM_UTIL_ERR_0068 = "ERR.003.030.0068"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0062 = "ERR.003.030.0062"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0064 = "ERR.003.030.0064"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0066 = "ERR.003.030.0066"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0067 = "ERR.003.030.0067"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0071 = "ERR.003.030.0071"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0072 = "ERR.003.030.0072"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0073 = "ERR.003.030.0073"; //$NON-NLS-1$
-
- public static final String CM_UTIL_ERR_0074 = "ERR.003.030.0074"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0075 = "ERR.003.030.0075"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0076 = "ERR.003.030.0076"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0077 = "ERR.003.030.0077"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0078 = "ERR.003.030.0078"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0079 = "ERR.003.030.0079"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0081 = "ERR.003.030.0081"; //$NON-NLS-1$
-
-
- public static final String PROPERTIES_ERR_0010 = "ERR.003.021.0010"; //$NON-NLS-1$
- public static final String PROPERTIES_ERR_0011 = "ERR.003.021.0011"; //$NON-NLS-1$
-
- public static final String SEC_MEMBERSHIP_0013 = "ERR.014.407.0013"; //$NON-NLS-1$
- public static final String SEC_MEMBERSHIP_0014 = "ERR.014.407.0014"; //$NON-NLS-1$
- public static final String SEC_MEMBERSHIP_0015 = "ERR.014.407.0015"; //$NON-NLS-1$
- public static final String SEC_MEMBERSHIP_0016 = "ERR.014.407.0016"; //$NON-NLS-1$
- public static final String SEC_MEMBERSHIP_0017 = "ERR.014.407.0017"; //$NON-NLS-1$
- public static final String SEC_MEMBERSHIP_0018 = "ERR.014.407.0018"; //$NON-NLS-1$
- public static final String SEC_MEMBERSHIP_0019 = "ERR.014.407.0019"; //$NON-NLS-1$
-
-
- public static final String CM_UTIL_ERR_0176 = "ERR.003.030.0176"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0177 = "ERR.003.030.0177"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0178 = "ERR.003.030.0178"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0179 = "ERR.003.030.0179"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0180 = "ERR.003.030.0180"; //$NON-NLS-1$
- public static final String CM_UTIL_ERR_0181 = "ERR.003.030.0181"; //$NON-NLS-1$
-
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixCoreException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,98 +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 com.metamatrix.core;
-
-import java.sql.SQLException;
-
-
-
-/**
- * Exception which occurs if an error occurs within the server that is not
- * business-related. For instance, if a service or bean is not available
- * or communication fails.
- */
-public class MetaMatrixCoreException extends Exception {
-
- private static final long serialVersionUID = -3033427629587497938L;
- protected String code;
- private transient String originalType;
-
- public MetaMatrixCoreException() {
- }
-
- public MetaMatrixCoreException(String message) {
- super(message);
- }
-
- public MetaMatrixCoreException(String errorCode, String message) {
- super(message);
- this.code = errorCode;
- }
-
- public MetaMatrixCoreException(Throwable e) {
- this(e, e.getMessage());
- }
-
- public MetaMatrixCoreException(Throwable e, String message) {
- super(message, e);
- setCode(e);
- }
-
- public MetaMatrixCoreException(Throwable e, String errorCode, String message) {
- super(message, e);
- this.code = errorCode;
- }
-
- public String getCode() {
- return this.code;
- }
-
- public void setCode(String code) {
- this.code = code;
- }
-
- public String getOriginalType() {
- return originalType;
- }
-
- public void setOriginalType(String originalType) {
- this.originalType = originalType;
- }
-
- private void setCode(Throwable e) {
- if (e instanceof MetaMatrixCoreException) {
- this.code = (((MetaMatrixCoreException) e).getCode());
- } else if (e instanceof MetaMatrixRuntimeException) {
- this.code = ((MetaMatrixRuntimeException) e).getCode();
- } else if (e instanceof SQLException) {
- this.code = Integer.toString(((SQLException)e).getErrorCode());
- }
- }
-
- public String getMessage() {
- if (code == null || code.length() == 0) {
- return super.getMessage();
- }
- return "Error Code:"+code+" Message:"+super.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$
- }
-}
Deleted: trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,242 +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 com.metamatrix.core;
-
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.sql.SQLException;
-
-import com.metamatrix.api.exception.MetaMatrixException;
-import com.metamatrix.core.util.MetaMatrixExceptionUtil;
-
-/**
- * A generic runtime exception which contains a reference to another exception
- * and which represents a condition that should never occur during runtime. This
- * class can be used to maintain a linked list of exceptions. <p>
- *
- * Subclasses of this exception typically only need to implement whatever
- * constructors they need. <p>
- */
-public class MetaMatrixRuntimeException extends RuntimeException {
- public static final long serialVersionUID = -4035276728007979320L;
-
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- public static final String CAUSED_BY_STRING = CorePlugin.Util.getString("MetaMatrixRuntimeException.Caused_by"); //$NON-NLS-1$
-
- //############################################################################################################################
- //# Static Methods #
- //############################################################################################################################
-
- /**
- * Utility method to get the name of a class, without package information.
- *
- * @param cls The class to get the name of
- * @return The name of the class, without package info
- */
- public static String getClassShortName( Class cls ) {
- if ( cls == null ) return EMPTY_STRING;
- String className = cls.getName();
- return className.substring( className.lastIndexOf('.')+1 );
- }
-
- //############################################################################################################################
- //# Variables #
- //############################################################################################################################
-
- /** An error code. */
- private String code;
-
- //############################################################################################################################
- //# Constructors #
- //############################################################################################################################
-
- /**
- * Construct a default instance of this class.
- */
- public MetaMatrixRuntimeException() {
- }
-
- /**
- * Construct an instance with the specified error message. If the message is actually a key, the actual message will be
- * retrieved from a resource bundle using the key, the specified parameters will be substituted for placeholders within the
- * message, and the code will be set to the key.
- * @param message The error message or a resource bundle key
- */
- public MetaMatrixRuntimeException(final String message) {
- super(message);
- }
-
- /**
- * Construct an instance with the specified error code and message. If the message is actually a key, the actual message will
- * be retrieved from a resource bundle using the key, and the specified parameters will be substituted for placeholders within
- * the message.
- * @param code The error code
- * @param message The error message or a resource bundle key
- */
- public MetaMatrixRuntimeException(final int code, final String message) {
- super(message);
- // The following setCode call should be executed after setting the message
- setCode(code);
- }
-
- public MetaMatrixRuntimeException(final String code, final String message) {
- super(message);
- // The following setCode call should be executed after setting the message
- setCode(code);
- }
-
- /**
- * Construct an instance with a linked exception specified. If the exception is a {@link MetaMatrixCoreException} or a
- * MetaMatrixRuntimeException, then the code will be set to the exception's code.
- * @param e An exception to chain to this exception
- */
- public MetaMatrixRuntimeException(final Throwable e) {
- this(e, ( e instanceof java.lang.reflect.InvocationTargetException )
- ? ((java.lang.reflect.InvocationTargetException)e).getTargetException().getMessage()
- : (e == null ? null : e.getMessage()));
- }
-
- /**
- * Construct an instance with the linked exception and error message specified. If the message is actually a key, the error
- * message will be retrieved from a resource bundle the key, and code will be set to that key. Otherwise, if the specified
- * exception is a {@link MetaMatrixCoreException} or a MetaMatrixRuntimeException, the code will be set to the exception's code.
- * @param e The exception to chain to this exception
- * @param message The error message or a resource bundle key
- */
- public MetaMatrixRuntimeException(final Throwable e, final String message) {
- super(message, e);
- setCode(e);
- }
-
- /**
- * Construct an instance with the linked exception, error code, and error message specified. If the message is actually a
- * key, the error message will be retrieved from a resource bundle using the key.
- * @param e The exception to chain to this exception
- * @param code The error code
- * @param message The error message or a resource bundle key
- */
- public MetaMatrixRuntimeException(final Throwable e, final int code, final String message) {
- super(message, e);
- // The following setCode call should be executed after setting the message
- setCode(code);
- }
-
- /**
- * Construct an instance with the linked exception, error code, and error message specified. If the specified
- * exception is a {@link MetaMatrixException} or a MetaMatrixRuntimeException, the code will
- * be set to the exception's code.
- * @param e The exception to chain to this exception
- * @param code The error code
- * @param message The error message
- */
- public MetaMatrixRuntimeException(final Throwable e, final String code, final String message) {
- super(message, e);
- // Overwrite code set in other ctor from exception.
- setCode(code);
- }
-
-
- //############################################################################################################################
- //# Methods #
- //############################################################################################################################
-
- /**
- * Get the exception which is linked to this exception.
- *
- * @return The linked exception
- */
- public Throwable getChild() {
- return this.getCause();
- }
-
- /**
- * Get the error code.
- *
- * @return The error code
- */
- public String getCode() {
- if (code == null) {
- return "0"; //$NON-NLS-1$
- }
- return this.code;
- }
-
- public int getIntCode() {
- if (code == null) {
- return 0;
- }
- try {
- return Integer.parseInt(code);
- } catch (NumberFormatException e) {
-
- }
- return 0;
- }
-
- /**
- * Set the error code.
- *
- * @param code The error code
- */
- private void setCode( int code ) {
- this.code = Integer.toString(code);
- }
-
- private void setCode( String code ) {
- this.code = code;
- }
-
- private void setCode(Throwable e) {
- if (e instanceof MetaMatrixCoreException) {
- this.code = (((MetaMatrixCoreException) e).getCode());
- } else if (e instanceof MetaMatrixRuntimeException) {
- this.code = ((MetaMatrixRuntimeException) e).getCode();
- } else if (e instanceof SQLException) {
- this.code = Integer.toString(((SQLException)e).getErrorCode());
- }
- }
-
- /**
- * Returns a string representation of this class.
- *
- * @return String representation of instance
- */
- public String toString() {
- return MetaMatrixExceptionUtil.getLinkedMessages(this);
- }
-
- /*
- * @see com.metamatrix.core.util.MetaMatrixNestedException#superPrintStackTrace(java.io.PrintStream)
- */
- public void superPrintStackTrace(PrintStream output) {
- super.printStackTrace(output);
- }
-
- /*
- * @see com.metamatrix.core.util.MetaMatrixNestedException#superPrintStackTrace(java.io.PrintWriter)
- */
- public void superPrintStackTrace(PrintWriter output) {
- super.printStackTrace(output);
- }
-
-}
Copied: trunk/common-core/src/main/java/org/teiid/core/BundleUtil.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/BundleUtil.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/BundleUtil.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/BundleUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,224 @@
+/*
+ * 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.core;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.teiid.core.util.ArgCheck;
+import org.teiid.core.util.StringUtil;
+
+
+public class BundleUtil {
+ /**
+ * The product properties used to override default localized text.
+ * @since 5.0.2
+ */
+ static protected ResourceBundle productProps;
+
+ /**
+ * The name of the resource bundle.
+ */
+ private final String bundleName;
+
+ /**
+ * The {@link ResourceBundle}for localization; initialized in the constructor.
+ */
+ private final ResourceBundle bundle;
+
+ protected final String pluginId;
+
+ /**
+ * Construct an instance of this class by specifying the plugin ID.
+ *
+ * @param pluginId
+ * the identifier of the plugin for which this utility is being instantiated
+ * @param bundleName
+ * the name of the resource bundle; used for problem reporting purposes only
+ * @param bundle
+ * the resource bundle
+ */
+ public BundleUtil(final String pluginId,
+ final String bundleName,
+ final ResourceBundle bundle) {
+ this.pluginId = pluginId;
+ this.bundleName = bundleName;
+ this.bundle = bundle;
+ }
+
+ /**
+ * Get the string identified by the given key and localized to the current locale.
+ *
+ * @param key
+ * the key in the resource file
+ * @return the localized String, or <code>
+ * "Missing message: " + key + " in: " + this.bundleName
+ * </code> if the string could
+ * not be found in the current locale, or <code>
+ * "No message available"
+ * </code> if the <code>key</code> is null.
+ */
+ public String getString(final String key) {
+ try {
+ // Since this string has no parameters, it will not be run through MessageFormat.
+ // MessageFormat eliminates double ticks, so the next two lines replace double ticks
+ // with single ticks. This is only needed if the localized string contains double ticks
+ // (the policy is that localized strings without parameters should not).
+ // COMMENTED OUT BECAUSE OF POLICY
+ //char[] messageWithNoDoubleQuotes = CharOperation.replace(text.toCharArray(), DOUBLE_QUOTES, SINGLE_QUOTE);
+ //text = new String(messageWithNoDoubleQuotes);
+
+ String value = getProductValue(key);
+ return ((value == null) ? this.bundle.getString(key) : value);
+ } catch (final Exception err) {
+ String msg;
+
+ if (err instanceof NullPointerException) {
+ msg = "<No message available>"; //$NON-NLS-1$
+ } else if (err instanceof MissingResourceException) {
+ msg = "<Missing message for key \"" + key + "\" in: " + this.bundleName + '>'; //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ msg = err.getLocalizedMessage();
+ }
+
+ // RMH: See DataAccessPlugin.ResourceLocator.getString(...) method, which tries one bundle before
+ // delegating to another. Therefore, this will happen normally in some situations.
+ //log(msg);
+
+ return msg;
+ }
+ }
+
+ /**
+ * Obtains the value that is overriding the default value.
+ * @param theKey the key whose product value is being requested
+ * @return the value or <code>null</code> if not overridden by the product
+ */
+ private String getProductValue(String theKey) {
+ String result = null;
+
+ if ((productProps != null) && !StringUtil.isEmpty(theKey)) {
+ String key = this.pluginId + '.' + theKey;
+
+ try {
+ result = productProps.getString(key);
+ } catch (MissingResourceException theException) {
+ // not found in product properties
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Determines if the given key exists in the resource file.
+ *
+ * @param key
+ * the key in the resource file
+ * @return True if the key exists.
+ * @since 4.0
+ */
+ public boolean keyExists(final String key) {
+ try {
+ return ((getProductValue(key) != null) || (this.bundle.getString(key) != null));
+ } catch (final Exception err) {
+ return false;
+ }
+ }
+
+ /**
+ * Get the string identified by the given key and localized to the current locale, and replace placeholders in the localized
+ * string with the string form of the parameters.
+ *
+ * @param key
+ * the key in the resource file
+ * @param parameters
+ * the list of parameters that should replace placeholders in the localized string (e.g., "{0}", "{1}", etc.)
+ * @return the localized String, or <code>
+ * "Missing message: " + key + " in: " + this.bundleName
+ * </code> if the string could
+ * not be found in the current locale, or <code>
+ * "No message available"
+ * </code> if the <code>key</code> is null.
+ */
+ public String getString(final String key,
+ final List parameters) {
+ if (parameters == null) {
+ return getString(key);
+ }
+ return getString(key, parameters.toArray());
+ }
+
+ /**
+ * Get the string identified by the given key and localized to the current locale, and replace placeholders in the localized
+ * string with the string form of the parameters.
+ *
+ * @param key
+ * the key in the resource file
+ * @param parameters
+ * the list of parameters that should replace placeholders in the localized string (e.g., "{0}", "{1}", etc.)
+ * @return the localized String, or <code>
+ * "Missing message: " + key + " in: " + this.bundleName
+ * </code> if the string could
+ * not be found in the current locale, or <code>
+ * "No message available"
+ * </code> if the <code>key</code> is null.
+ */
+ public String getString(final String key,
+ final Object... parameters) {
+ String text = getString(key);
+
+ // Check the trivial cases ...
+ if (text == null) {
+ return '<' + key + '>';
+ }
+ if (parameters == null || parameters.length == 0) {
+ return text;
+ }
+
+ return MessageFormat.format(text, parameters);
+ }
+
+ /**
+ * @see com.metamatrix.core.PluginUtil#getStringOrKey(java.lang.String)
+ * @since 4.1
+ */
+ public String getStringOrKey(final String key) {
+ ArgCheck.isNotNull(key);
+
+ String value = getProductValue(key);
+
+ if (value == null) {
+ try {
+ return this.bundle.getString(key);
+ } catch (final MissingResourceException err) {
+ return key;
+ }
+ }
+
+ return value;
+ }
+
+}
Added: trunk/common-core/src/main/java/org/teiid/core/ComponentNotFoundException.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/ComponentNotFoundException.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/ComponentNotFoundException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,81 @@
+/*
+ * 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.core;
+
+/**
+ * Exception which occurs if a system component could not be found by another
+ * component.
+ */
+public class ComponentNotFoundException extends TeiidComponentException {
+
+ private static final long serialVersionUID = 8484545412724259223L;
+
+ /**
+ * No-Arg Constructor
+ */
+ public ComponentNotFoundException( ) {
+ super( );
+ }
+ /**
+ * Construct an instance with the message specified.
+ *
+ * @param message A message describing the exception
+ */
+ public ComponentNotFoundException( String message ) {
+ super( message );
+ }
+
+ /**
+ * Construct an instance with the message and error code specified.
+ *
+ * @param message A message describing the exception
+ * @param code The error code
+ */
+ public ComponentNotFoundException( String code, String message ) {
+ super( code, message );
+ }
+
+ /**
+ * Construct an instance from a message and an exception to chain to this one.
+ *
+ * @param e An exception to nest within this one
+ * @param message A message describing the exception
+ */
+ public ComponentNotFoundException( Throwable e, String message ) {
+ super( e, message );
+ }
+
+ /**
+ * Construct an instance from a message and a code and an exception to
+ * chain to this one.
+ *
+ * @param e An exception to nest within this one
+ * @param message A message describing the exception
+ * @param code A code denoting the exception
+ */
+ public ComponentNotFoundException( Throwable e, String code, String message ) {
+ super( e, code, message );
+ }
+
+} // END CLASS
+
Copied: trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/CoreConstants.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,112 @@
+/*
+ * 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.core;
+
+
+/**
+ * @since 4.0
+ */
+public interface CoreConstants {
+ /**<p>
+ * Contains ID's for all MetaMatrix plugins.
+ * </p>
+ * @since 4.0
+ */
+ interface Plugin {
+ String METAMATRIX_PREFIX = "com.metamatrix."; //$NON-NLS-1$
+
+ String COMMON = METAMATRIX_PREFIX + "common"; //$NON-NLS-1$
+ String COMMON_COMM_PLATFORM = METAMATRIX_PREFIX + "common.comm.platform"; //$NON-NLS-1$
+ String CORE_XSLT = METAMATRIX_PREFIX + "core.xslt"; //$NON-NLS-1$
+ String MODELER_JDBC = METAMATRIX_PREFIX + "modeler.jdbc"; //$NON-NLS-1$
+ String PLATFORM = METAMATRIX_PREFIX + "platform"; //$NON-NLS-1$
+ }
+
+ interface Debug {
+ String PLUGIN_ACTIVATION = "pluginActivation"; //$NON-NLS-1$
+ }
+
+ interface Trace {
+ String PROXIES = "proxies"; //$NON-NLS-1$
+ }
+
+ public static final String SYSTEM_MODEL = "SYS"; //$NON-NLS-1$
+
+ public static final String SYSTEM_VDB = "System.vdb"; //$NON-NLS-1$
+
+ public static final String PRODUCT_OWNER_NAME_PROPERTY = "ownerName"; //$NON-NLS-1$
+
+ /**
+ * Constant that defines the replaceable token in WSDL generated in the VDB which represents
+ * the MetaMatrix Server properties for connecting the to VDB.
+ */
+ public static final String ACTION_PREFIX_FOR_DATA_WEBSERVICE = "http://server.properies.metamatrix.com"; //$NON-NLS-1$
+
+ /**
+ * Constant that defines the parameter value in WSDL generated of the VDB that will be used to
+ * identifiy the fully qualified procedure name when executing the web service.
+ */
+ public static final String ACTION_PARAMETER_FOR_DATA_WEBSERVICE_PROCEDURE = "procedure="; //$NON-NLS-1$
+
+ /**
+ * Constant that defines the replaceable token in WSDL generated in the VDB which represents
+ * the first part (VDB-independent) of the URL. The general form of the URLs is as follows:
+ * <p>
+ * <code> [URL ROOT][Path to Resource in VDB][URL Suffix]</code>
+ * </p></p>
+ * In general, the URL root would be replaced in a particular server with the actual URL to the servlet
+ * used to obtain the WSDL and XSD, and the URL suffix replaced with the servlet parameters.
+ * </p>
+ * @see #URL_SUFFIX_FOR_VDB
+ */
+ public static final String URL_ROOT_FOR_VDB = "http://vdb.metamatrix.com"; //$NON-NLS-1$
+
+ /**
+ * Constant that defines the replaceable token in WSDL generated in the VDB which represents
+ * the suffix part of the URL. The general form of the URLs is as follows:
+ * <p>
+ * <code> [URL ROOT][Path to Resource in VDB][URL Suffix]</code>
+ * </p></p>
+ * In general, the URL root would be replaced in a particular server with the actual URL to the servlet
+ * used to obtain the WSDL and XSD, and the URL suffix replaced with the servlet parameters.
+ * </p>
+ * @see #URL_ROOT_FOR_VDB
+ */
+ public static final String URL_SUFFIX_FOR_VDB = "?vdbToken=true"; //$NON-NLS-1$
+
+
+ /**
+ * Constant that defines the replaceable token in WSDL generated in the VDB which represents
+ * the URL for the service binding.
+ * @see #URL_SUFFIX_FOR_VDB
+ * @see #URL_ROOT_FOR_VDB
+ */
+ public static final String URL_FOR_DATA_WEBSERVICE = "http://vdb.dataservice.metamatrix.com"; //$NON-NLS-1$\
+
+ /**
+ * Constant for the anonymous Teiid system username
+ */
+ public static final String DEFAULT_ANON_USERNAME = "teiidanonymous";
+
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/CorePlugin.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/CorePlugin.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/CorePlugin.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/CorePlugin.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,43 @@
+/*
+ * 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.core;
+
+import java.util.ResourceBundle;
+
+
+/**
+ * CorePlugin
+ */
+public class CorePlugin {
+ //
+ // Class Constants:
+ //
+ /**
+ * The plug-in identifier of this plugin
+ * (value <code>"com.metamatrix.core"</code>).
+ */
+ public static final String PLUGIN_ID = CorePlugin.class.getPackage().getName();
+
+ public static final BundleUtil Util = new BundleUtil(PLUGIN_ID,
+ PLUGIN_ID + ".i18n", ResourceBundle.getBundle(PLUGIN_ID + ".i18n")); //$NON-NLS-1$ //$NON-NLS-2$
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/ErrorMessageKeys.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/ErrorMessageKeys.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/ErrorMessageKeys.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/ErrorMessageKeys.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,70 @@
+package org.teiid.core;
+
+public interface ErrorMessageKeys {
+
+ /** types (029) */
+ public static final String TYPES_ERR_0001 = "ERR.003.029.0001"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0002 = "ERR.003.029.0002"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0003 = "ERR.003.029.0003"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0004 = "ERR.003.029.0004"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0005 = "ERR.003.029.0005"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0006 = "ERR.003.029.0006"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0007 = "ERR.003.029.0007"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0008 = "ERR.003.029.0008"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0009 = "ERR.003.029.0009"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0010 = "ERR.003.029.0010"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0011 = "ERR.003.029.0011"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0012 = "ERR.003.029.0012"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0013 = "ERR.003.029.0013"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0014 = "ERR.003.029.0014"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0015 = "ERR.003.029.0015"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0016 = "ERR.003.029.0016"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0017 = "ERR.003.029.0017"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0018 = "ERR.003.029.0018"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0019 = "ERR.003.029.0019"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0020 = "ERR.003.029.0020"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0021 = "ERR.003.029.0021"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0022 = "ERR.003.029.0022"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0023 = "ERR.003.029.0023"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0024 = "ERR.003.029.0024"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0025 = "ERR.003.029.0025"; //$NON-NLS-1$
+ public static final String TYPES_ERR_0026 = "ERR.003.029.0026"; //$NON-NLS-1$
+
+ public static final String CM_UTIL_ERR_0068 = "ERR.003.030.0068"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0062 = "ERR.003.030.0062"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0064 = "ERR.003.030.0064"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0066 = "ERR.003.030.0066"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0067 = "ERR.003.030.0067"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0071 = "ERR.003.030.0071"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0072 = "ERR.003.030.0072"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0073 = "ERR.003.030.0073"; //$NON-NLS-1$
+
+ public static final String CM_UTIL_ERR_0074 = "ERR.003.030.0074"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0075 = "ERR.003.030.0075"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0076 = "ERR.003.030.0076"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0077 = "ERR.003.030.0077"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0078 = "ERR.003.030.0078"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0079 = "ERR.003.030.0079"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0081 = "ERR.003.030.0081"; //$NON-NLS-1$
+
+
+ public static final String PROPERTIES_ERR_0010 = "ERR.003.021.0010"; //$NON-NLS-1$
+ public static final String PROPERTIES_ERR_0011 = "ERR.003.021.0011"; //$NON-NLS-1$
+
+ public static final String SEC_MEMBERSHIP_0013 = "ERR.014.407.0013"; //$NON-NLS-1$
+ public static final String SEC_MEMBERSHIP_0014 = "ERR.014.407.0014"; //$NON-NLS-1$
+ public static final String SEC_MEMBERSHIP_0015 = "ERR.014.407.0015"; //$NON-NLS-1$
+ public static final String SEC_MEMBERSHIP_0016 = "ERR.014.407.0016"; //$NON-NLS-1$
+ public static final String SEC_MEMBERSHIP_0017 = "ERR.014.407.0017"; //$NON-NLS-1$
+ public static final String SEC_MEMBERSHIP_0018 = "ERR.014.407.0018"; //$NON-NLS-1$
+ public static final String SEC_MEMBERSHIP_0019 = "ERR.014.407.0019"; //$NON-NLS-1$
+
+
+ public static final String CM_UTIL_ERR_0176 = "ERR.003.030.0176"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0177 = "ERR.003.030.0177"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0178 = "ERR.003.030.0178"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0179 = "ERR.003.030.0179"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0180 = "ERR.003.030.0180"; //$NON-NLS-1$
+ public static final String CM_UTIL_ERR_0181 = "ERR.003.030.0181"; //$NON-NLS-1$
+
+}
Property changes on: trunk/common-core/src/main/java/org/teiid/core/ErrorMessageKeys.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/common-core/src/main/java/org/teiid/core/TeiidComponentException.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/TeiidComponentException.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/TeiidComponentException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,92 @@
+/*
+ * 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.core;
+
+
+/**
+ * Exception which occurs if an error occurs within the server that is not
+ * business-related. For instance, if a service or bean is not available
+ * or communication fails.
+ */
+public class TeiidComponentException extends TeiidException {
+
+ private static final long serialVersionUID = 5853804556425201591L;
+
+ /**
+ * No-arg CTOR
+ */
+ public TeiidComponentException( ) {
+ super( );
+ }
+ /**
+ * Construct an instance with the message specified.
+ *
+ * @param message A message describing the exception
+ */
+ public TeiidComponentException( String message ) {
+ super( message );
+ }
+
+ /**
+ * Construct an instance with a linked exception specified.
+ *
+ * @param e An exception to chain to this exception
+ */
+ public TeiidComponentException( Throwable e ) {
+ super( e );
+ }
+
+ /**
+ * Construct an instance with the message and error code specified.
+ *
+ * @param message A message describing the exception
+ * @param code The error code
+ */
+ public TeiidComponentException( String code, String message ) {
+ super( code, message );
+ }
+
+ /**
+ * Construct an instance from a message and an exception to chain to this one.
+ *
+ * @param e An exception to nest within this one
+ * @param message A message describing the exception
+ */
+ public TeiidComponentException( Throwable e, String message ) {
+ super( e, message );
+ }
+
+ /**
+ * Construct an instance from a message and a code and an exception to
+ * chain to this one.
+ *
+ * @param e An exception to nest within this one
+ * @param message A message describing the exception
+ * @param code A code denoting the exception
+ */
+ public TeiidComponentException( Throwable e, String code, String message ) {
+ super( e, code, message );
+ }
+
+} // END CLASS
+
Added: trunk/common-core/src/main/java/org/teiid/core/TeiidException.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/TeiidException.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/TeiidException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,171 @@
+/*
+ * 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.core;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+import org.teiid.core.util.ExceptionUtil;
+
+
+
+/**
+ * Exception which occurs if an error occurs within the server that is not
+ * business-related. For instance, if a service or bean is not available
+ * or communication fails.
+ */
+public class TeiidException extends Exception {
+
+ private static final long serialVersionUID = -3033427629587497938L;
+ protected String code;
+ private transient String originalType;
+
+ public TeiidException() {
+ }
+
+ public TeiidException(String message) {
+ super(message);
+ }
+
+ public TeiidException(String errorCode, String message) {
+ super(message);
+ this.code = errorCode;
+ }
+
+ public TeiidException(Throwable e) {
+ this(e, e != null? e.getMessage() : null);
+ }
+
+ public TeiidException(Throwable e, String message) {
+ super(message, e);
+ setCode(e);
+ }
+
+ public TeiidException(Throwable e, String errorCode, String message) {
+ super(message, e);
+ this.code = errorCode;
+ }
+
+ public String getCode() {
+ return this.code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getOriginalType() {
+ return originalType;
+ }
+
+ public void setOriginalType(String originalType) {
+ this.originalType = originalType;
+ }
+
+ private void setCode(Throwable e) {
+ if (e instanceof TeiidException) {
+ this.code = (((TeiidException) e).getCode());
+ } else if (e instanceof TeiidRuntimeException) {
+ this.code = ((TeiidRuntimeException) e).getCode();
+ } else if (e instanceof SQLException) {
+ this.code = Integer.toString(((SQLException)e).getErrorCode());
+ }
+ }
+
+ public String getMessage() {
+ if (code == null || code.length() == 0) {
+ return super.getMessage();
+ }
+ return "Error Code:"+code+" Message:"+super.getMessage(); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Returns the error message, formatted for output. <P>
+ *
+ * The default formatting provided by this method is to prepend the
+ * error message with the level and the name of the class, and to
+ * append the error code on the end if a non-zero code is defined. <P>
+ *
+ * This method provides a hook for subclasses to override the default
+ * formatting of any one exception.
+ *
+ * @param throwable The exception to print
+ * @param level The depth of the exception in the chain of exceptions
+ * @return A formatted string for the exception
+ */
+ static String getFormattedMessage(final Throwable throwable, final int level) {
+ String code;
+ if (throwable instanceof TeiidException) {
+ code = ((TeiidException) throwable).getCode();
+ } else if (throwable instanceof TeiidRuntimeException) {
+ code = ((TeiidRuntimeException) throwable).getCode();
+ } else {
+ code = null;
+ }
+ return ((level != 0) ? ("\n" + level + " ") : "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + "[" + throwable.getClass().getSimpleName() + "]" //$NON-NLS-1$ //$NON-NLS-2$
+ + ((code != null) ? (' ' + code + ": ") : "") //$NON-NLS-1$ //$NON-NLS-2$
+ + (throwable.getMessage() == null ? "" : throwable.getMessage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Get the full error message, including any message(s) from child
+ * exceptions. Messages of any exceptions chained to this exception are
+ * prepended with their "level" in the chain.
+ *
+ * @return The full error message
+ *
+ * @see #getFormattedMessage
+ */
+ public String getFullMessage() {
+ int level = 0;
+ StringBuffer buf = new StringBuffer();
+ buf.append(getFormattedMessage(this,level));
+ Iterator children = ExceptionUtil.getChildrenIterator(this);
+ while ( children.hasNext() ){
+ level++;
+ Throwable exception = (Throwable)children.next();
+ buf.append(getFormattedMessage(exception,level));
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Get the exception which is linked to this exception.
+ *
+ * @return The linked exception
+ * @deprecated - {@see #getCause()}
+ */
+ public Throwable getChild() {
+ return super.getCause();
+ }
+
+ /**
+ * Returns a string representation of this class.
+ *
+ * @return String representation of instance
+ */
+ public String toString() {
+ return getFullMessage();
+ }
+}
Added: trunk/common-core/src/main/java/org/teiid/core/TeiidProcessingException.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/TeiidProcessingException.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/TeiidProcessingException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,93 @@
+/*
+ * 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.core;
+
+
+/**
+ * This exception is a superclass for exceptions that are thrown during
+ * processing as a result of user input. This exception is the result
+ * of handling a user request, not the result of an internal error.
+ */
+public class TeiidProcessingException extends TeiidException {
+
+ private static final long serialVersionUID = -4013536109023540872L;
+
+ /**
+ * No-arg Constructor
+ */
+ public TeiidProcessingException() {
+ super();
+ }
+
+ /**
+ * Construct an instance with the message specified.
+ *
+ * @param message A message describing the exception
+ */
+ public TeiidProcessingException( String message ) {
+ super( message );
+ }
+
+ /**
+ * Construct an instance with a linked exception specified.
+ *
+ * @param e An exception to chain to this exception
+ */
+ public TeiidProcessingException( Throwable e ) {
+ super( e );
+ }
+
+ /**
+ * Construct an instance with the message and error code specified.
+ *
+ * @param message A message describing the exception
+ * @param code The error code
+ */
+ public TeiidProcessingException( String code, String message ) {
+ super( code, message );
+ }
+
+ /**
+ * Construct an instance from a message and an exception to chain to this one.
+ *
+ * @param message A message describing the exception
+ * @param e An exception to nest within this one
+ */
+ public TeiidProcessingException( Throwable e, String message ) {
+ super( e, message );
+ }
+
+ /**
+ * Construct an instance from a message and a code and an exception to
+ * chain to this one.
+ *
+ * @param e An exception to nest within this one
+ * @param message A message describing the exception
+ * @param code A code denoting the exception
+ */
+ public TeiidProcessingException( Throwable e, String code, String message ) {
+ super( e, code, message );
+ }
+
+} // END CLASS
+
Copied: trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/MetaMatrixRuntimeException.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/TeiidRuntimeException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,242 @@
+/*
+ * 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.core;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.sql.SQLException;
+
+import org.teiid.core.util.ExceptionUtil;
+
+
+/**
+ * A generic runtime exception which contains a reference to another exception
+ * and which represents a condition that should never occur during runtime. This
+ * class can be used to maintain a linked list of exceptions. <p>
+ *
+ * Subclasses of this exception typically only need to implement whatever
+ * constructors they need. <p>
+ */
+public class TeiidRuntimeException extends RuntimeException {
+ public static final long serialVersionUID = -4035276728007979320L;
+
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ public static final String CAUSED_BY_STRING = CorePlugin.Util.getString("MetaMatrixRuntimeException.Caused_by"); //$NON-NLS-1$
+
+ //############################################################################################################################
+ //# Static Methods #
+ //############################################################################################################################
+
+ /**
+ * Utility method to get the name of a class, without package information.
+ *
+ * @param cls The class to get the name of
+ * @return The name of the class, without package info
+ */
+ public static String getClassShortName( Class cls ) {
+ if ( cls == null ) return EMPTY_STRING;
+ String className = cls.getName();
+ return className.substring( className.lastIndexOf('.')+1 );
+ }
+
+ //############################################################################################################################
+ //# Variables #
+ //############################################################################################################################
+
+ /** An error code. */
+ private String code;
+
+ //############################################################################################################################
+ //# Constructors #
+ //############################################################################################################################
+
+ /**
+ * Construct a default instance of this class.
+ */
+ public TeiidRuntimeException() {
+ }
+
+ /**
+ * Construct an instance with the specified error message. If the message is actually a key, the actual message will be
+ * retrieved from a resource bundle using the key, the specified parameters will be substituted for placeholders within the
+ * message, and the code will be set to the key.
+ * @param message The error message or a resource bundle key
+ */
+ public TeiidRuntimeException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Construct an instance with the specified error code and message. If the message is actually a key, the actual message will
+ * be retrieved from a resource bundle using the key, and the specified parameters will be substituted for placeholders within
+ * the message.
+ * @param code The error code
+ * @param message The error message or a resource bundle key
+ */
+ public TeiidRuntimeException(final int code, final String message) {
+ super(message);
+ // The following setCode call should be executed after setting the message
+ setCode(code);
+ }
+
+ public TeiidRuntimeException(final String code, final String message) {
+ super(message);
+ // The following setCode call should be executed after setting the message
+ setCode(code);
+ }
+
+ /**
+ * Construct an instance with a linked exception specified. If the exception is a {@link TeiidException} or a
+ * MetaMatrixRuntimeException, then the code will be set to the exception's code.
+ * @param e An exception to chain to this exception
+ */
+ public TeiidRuntimeException(final Throwable e) {
+ this(e, ( e instanceof java.lang.reflect.InvocationTargetException )
+ ? ((java.lang.reflect.InvocationTargetException)e).getTargetException().getMessage()
+ : (e == null ? null : e.getMessage()));
+ }
+
+ /**
+ * Construct an instance with the linked exception and error message specified. If the message is actually a key, the error
+ * message will be retrieved from a resource bundle the key, and code will be set to that key. Otherwise, if the specified
+ * exception is a {@link TeiidException} or a MetaMatrixRuntimeException, the code will be set to the exception's code.
+ * @param e The exception to chain to this exception
+ * @param message The error message or a resource bundle key
+ */
+ public TeiidRuntimeException(final Throwable e, final String message) {
+ super(message, e);
+ setCode(e);
+ }
+
+ /**
+ * Construct an instance with the linked exception, error code, and error message specified. If the message is actually a
+ * key, the error message will be retrieved from a resource bundle using the key.
+ * @param e The exception to chain to this exception
+ * @param code The error code
+ * @param message The error message or a resource bundle key
+ */
+ public TeiidRuntimeException(final Throwable e, final int code, final String message) {
+ super(message, e);
+ // The following setCode call should be executed after setting the message
+ setCode(code);
+ }
+
+ /**
+ * Construct an instance with the linked exception, error code, and error message specified. If the specified
+ * exception is a {@link TeiidException} or a MetaMatrixRuntimeException, the code will
+ * be set to the exception's code.
+ * @param e The exception to chain to this exception
+ * @param code The error code
+ * @param message The error message
+ */
+ public TeiidRuntimeException(final Throwable e, final String code, final String message) {
+ super(message, e);
+ // Overwrite code set in other ctor from exception.
+ setCode(code);
+ }
+
+
+ //############################################################################################################################
+ //# Methods #
+ //############################################################################################################################
+
+ /**
+ * Get the exception which is linked to this exception.
+ *
+ * @return The linked exception
+ */
+ public Throwable getChild() {
+ return this.getCause();
+ }
+
+ /**
+ * Get the error code.
+ *
+ * @return The error code
+ */
+ public String getCode() {
+ if (code == null) {
+ return "0"; //$NON-NLS-1$
+ }
+ return this.code;
+ }
+
+ public int getIntCode() {
+ if (code == null) {
+ return 0;
+ }
+ try {
+ return Integer.parseInt(code);
+ } catch (NumberFormatException e) {
+
+ }
+ return 0;
+ }
+
+ /**
+ * Set the error code.
+ *
+ * @param code The error code
+ */
+ private void setCode( int code ) {
+ this.code = Integer.toString(code);
+ }
+
+ private void setCode( String code ) {
+ this.code = code;
+ }
+
+ private void setCode(Throwable e) {
+ if (e instanceof TeiidException) {
+ this.code = (((TeiidException) e).getCode());
+ } else if (e instanceof TeiidRuntimeException) {
+ this.code = ((TeiidRuntimeException) e).getCode();
+ } else if (e instanceof SQLException) {
+ this.code = Integer.toString(((SQLException)e).getErrorCode());
+ }
+ }
+
+ /**
+ * Returns a string representation of this class.
+ *
+ * @return String representation of instance
+ */
+ public String toString() {
+ return ExceptionUtil.getLinkedMessages(this);
+ }
+
+ /*
+ * @see com.metamatrix.core.util.MetaMatrixNestedException#superPrintStackTrace(java.io.PrintStream)
+ */
+ public void superPrintStackTrace(PrintStream output) {
+ super.printStackTrace(output);
+ }
+
+ /*
+ * @see com.metamatrix.core.util.MetaMatrixNestedException#superPrintStackTrace(java.io.PrintWriter)
+ */
+ public void superPrintStackTrace(PrintWriter output) {
+ super.printStackTrace(output);
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/crypto (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/crypto)
Modified: trunk/common-core/src/main/java/org/teiid/core/crypto/BasicCryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/BasicCryptor.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/crypto/BasicCryptor.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
import java.io.Serializable;
import java.security.InvalidKeyException;
@@ -31,10 +31,11 @@
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SealedObject;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
-import com.metamatrix.core.util.Base64;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.util.Base64;
+
/**
* <p>Public methods in this class throw only <code>CryptoException</code>s. </p>
*/
Modified: trunk/common-core/src/main/java/org/teiid/core/crypto/CryptoException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/CryptoException.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/crypto/CryptoException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
-import com.metamatrix.api.exception.MetaMatrixException;
+import org.teiid.core.TeiidException;
/**
* A catch-all exception for any exceptions related to encryption and decryption
* operations.
*/
-public class CryptoException extends MetaMatrixException {
+public class CryptoException extends TeiidException {
/**
* No-Arg Constructor
Modified: trunk/common-core/src/main/java/org/teiid/core/crypto/Cryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/Cryptor.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/crypto/Cryptor.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/crypto/DhKeyGenerator.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/DhKeyGenerator.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/crypto/DhKeyGenerator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
import java.io.IOException;
import java.io.InputStream;
@@ -43,8 +43,9 @@
import javax.crypto.KeyAgreement;
import javax.crypto.spec.DHParameterSpec;
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import org.teiid.core.TeiidRuntimeException;
+
/**
* Helper class that supports anonymous ephemeral Diffie-Hellman
*
@@ -63,7 +64,7 @@
is = DhKeyGenerator.class.getResourceAsStream("dh.properties"); //$NON-NLS-1$
props.load(is);
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
} finally {
try {
if (is != null) {
Modified: trunk/common-core/src/main/java/org/teiid/core/crypto/NullCryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/NullCryptor.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/crypto/NullCryptor.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
public class NullCryptor implements Cryptor {
Modified: trunk/common-core/src/main/java/org/teiid/core/crypto/SymmetricCryptor.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/util/crypto/SymmetricCryptor.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/crypto/SymmetricCryptor.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -34,8 +34,9 @@
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
-import com.metamatrix.core.util.ArgCheck;
+import org.teiid.core.util.ArgCheck;
+
/**
* Provides a symmetric cryptor using AES
*/
Copied: trunk/common-core/src/main/java/org/teiid/core/id (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/id)
Modified: trunk/common-core/src/main/java/org/teiid/core/id/IDGenerator.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/IDGenerator.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/IDGenerator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.util.Collection;
import java.util.HashMap;
@@ -28,8 +28,9 @@
import java.util.Map;
import java.util.Set;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+
/**
* IDGenerator
*/
Modified: trunk/common-core/src/main/java/org/teiid/core/id/IntegerID.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/IntegerID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/IntegerID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.Serializable;
-import com.metamatrix.core.util.Assertion;
+import org.teiid.core.util.Assertion;
+
public class IntegerID implements ObjectID, Serializable {
public static final String PROTOCOL = "mmint"; //$NON-NLS-1$
@@ -103,7 +104,7 @@
return PROTOCOL + ObjectID.DELIMITER + this.id;
}
/**
- * @see com.metamatrix.core.id.ObjectID#toString(char)
+ * @see org.teiid.core.id.ObjectID#toString(char)
*/
public String toString(char delim) {
return PROTOCOL + delim + this.id;
Modified: trunk/common-core/src/main/java/org/teiid/core/id/IntegerIDFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/IntegerIDFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/IntegerIDFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.Serializable;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+
public class IntegerIDFactory implements ObjectIDFactory, Serializable {
private int lastID = 0;
public IntegerIDFactory() {
Modified: trunk/common-core/src/main/java/org/teiid/core/id/InvalidIDException.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/InvalidIDException.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/InvalidIDException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,17 +20,17 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.MetaMatrixCoreException;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.TeiidException;
/**
* Exception which occurs if an error occurs within the server that is not
* business-related. For instance, if a service or bean is not available
* or communication fails.
*/
-public class InvalidIDException extends MetaMatrixCoreException {
+public class InvalidIDException extends TeiidException {
private static final String INVALID_ID_MESSAGE = CorePlugin.Util.getString("InvalidIDException.Invalid_ID_1"); //$NON-NLS-1$
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/id/LongID.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/LongID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/LongID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.Serializable;
-import com.metamatrix.core.util.Assertion;
+import org.teiid.core.util.Assertion;
+
public class LongID implements ObjectID, Serializable {
public static final String PROTOCOL = "mmlong"; //$NON-NLS-1$
@@ -104,7 +105,7 @@
}
/**
- * @see com.metamatrix.core.id.ObjectID#toString(char)
+ * @see org.teiid.core.id.ObjectID#toString(char)
*/
public String toString(char delim) {
return PROTOCOL + delim + this.id;
Modified: trunk/common-core/src/main/java/org/teiid/core/id/LongIDFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/LongIDFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/LongIDFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.Serializable;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+
public class LongIDFactory implements ObjectIDFactory, Serializable {
private long lastID = 0;
public LongIDFactory() {
Modified: trunk/common-core/src/main/java/org/teiid/core/id/ObjectID.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/ObjectID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/ObjectID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
Modified: trunk/common-core/src/main/java/org/teiid/core/id/ObjectIDFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/ObjectIDFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/ObjectIDFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/id/ParsedObjectID.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/ParsedObjectID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/ParsedObjectID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.util.Iterator;
import java.util.Set;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+
/**
* ParsedObjectID
*/
Modified: trunk/common-core/src/main/java/org/teiid/core/id/StringID.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/StringID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/StringID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.Serializable;
-import com.metamatrix.core.util.Assertion;
+import org.teiid.core.util.Assertion;
+
public class StringID implements ObjectID, Serializable {
public static final String PROTOCOL = "strid"; //$NON-NLS-1$
@@ -98,7 +99,7 @@
return PROTOCOL + ObjectID.DELIMITER + this.id;
}
/**
- * @see com.metamatrix.core.id.ObjectID#toString(char)
+ * @see org.teiid.core.id.ObjectID#toString(char)
*/
public String toString(char delim) {
return PROTOCOL + delim + this.id;
Modified: trunk/common-core/src/main/java/org/teiid/core/id/StringIDFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/StringIDFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/StringIDFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,9 +20,9 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
Modified: trunk/common-core/src/main/java/org/teiid/core/id/UUID.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/UUID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/UUID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.Serializable;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.util.Assertion;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.util.Assertion;
+
/**
* <p>This class represents a universally unique identifier, consisting of
* two long integral values. </p>
@@ -182,7 +183,7 @@
}
/**
- * @see com.metamatrix.core.id.ObjectID#toString(char)
+ * @see org.teiid.core.id.ObjectID#toString(char)
*/
public String toString(char delim) {
return new StringBuffer(43).append(PROTOCOL).append(delim).append(this.exportableForm()).toString();
Modified: trunk/common-core/src/main/java/org/teiid/core/id/UUIDFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/id/UUIDFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/id/UUIDFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,9 +20,9 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
/**
* <p>This class is a factory for generating universally unique identifiers
Copied: trunk/common-core/src/main/java/org/teiid/core/types/BaseLob.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/BaseLob.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/BaseLob.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/BaseLob.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,82 @@
+package org.teiid.core.types;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Reader;
+import java.sql.SQLException;
+
+import org.teiid.core.types.InputStreamFactory.StreamFactoryReference;
+
+
+public class BaseLob implements Externalizable, StreamFactoryReference {
+
+ private static final long serialVersionUID = -1586959324208959519L;
+ private InputStreamFactory streamFactory;
+
+ public BaseLob() {
+
+ }
+
+ protected BaseLob(InputStreamFactory streamFactory) {
+ this.streamFactory = streamFactory;
+ }
+
+ public void setStreamFactory(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 this.getStreamFactory().getCharacterStream();
+ } 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;
+ }
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ streamFactory = (InputStreamFactory)in.readObject();
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(streamFactory);
+ }
+
+}
Property changes on: trunk/common-core/src/main/java/org/teiid/core/types/BaseLob.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/BlobImpl.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/BlobImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,211 @@
+/*
+ * 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.core.types;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Blob;
+import java.sql.SQLException;
+
+import javax.sql.rowset.serial.SerialBlob;
+
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.LobSearchUtil.StreamProvider;
+import org.teiid.core.util.SqlUtil;
+
+
+/**
+ * This object holds a chunk of binary data and implements the JDBC Blob interface.
+ * It presents a streaming interface and provides a way to access partial
+ * of the blob data. Connectors can use this object when dealing with large
+ * objects.
+ */
+public class BlobImpl extends BaseLob implements Blob, StreamProvider {
+
+ public BlobImpl() {
+
+ }
+
+ /**
+ * Creates a MMBlob object with the <code>valueID</code>.
+ * @param valueID reference to value chunk in data source.
+ */
+ public BlobImpl(InputStreamFactory streamFactory) {
+ super(streamFactory);
+ }
+
+ /**
+ * 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
+ * starting at position <code>pos</code>.
+ * @param pos the ordinal position of the first byte in the
+ * <code>BLOB</code> value to be extracted; the first byte is at
+ * position 1
+ * @param length the number of consecutive bytes to be copied
+ * @return a byte array containing up to <code>length</code>
+ * consecutive bytes from the <code>BLOB</code> value designated
+ * by this <code>Blob</code> object, starting with the
+ * byte at position <code>pos</code>
+ * @exception SQLException if there is an error accessing the
+ * <code>BLOB</code>
+ */
+ public byte[] getBytes(long pos, int length) throws SQLException {
+ if (pos < 1) {
+ Object[] params = new Object[] {new Long(pos)};
+ throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.0", params)); //$NON-NLS-1$
+ }
+ else if (pos > length()) {
+ return null;
+ }
+ pos = pos - 1;
+
+ if (length < 0) {
+ Object[] params = new Object[] {new Integer( length)};
+ throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.3", params)); //$NON-NLS-1$
+ }
+ else if (pos + length > length()) {
+ length = (int)(length() - pos);
+ }
+ byte[] dataCopy = new byte[length];
+ InputStream in = getBinaryStream();
+ try {
+ try {
+ in.skip(pos);
+ in.read(dataCopy);
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ throw new SQLException(e);
+ }
+ return dataCopy;
+ }
+
+ /**
+ * Returns the number of bytes in the <code>BLOB</code> value
+ * designated by this <code>Blob</code> object.
+ * @return length of the <code>BLOB</code> in bytes
+ */
+ public long length() throws SQLException{
+ if (getStreamFactory().getLength() == -1) {
+ InputStream is = new BufferedInputStream(getBinaryStream());
+ try {
+ long length = 0;
+ while (is.read() != -1) {
+ length++;
+ }
+ getStreamFactory().setLength(length);
+ } catch (IOException e) {
+ throw new SQLException(e);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ return getStreamFactory().getLength();
+ }
+
+ /**
+ * Determines the byte position in the <code>BLOB</code> value
+ * designated by this <code>Blob</code> object at which
+ * <code>pattern</code> begins. The search begins at position
+ * <code>start</code>.
+ * @param pattern the <code>Blob</code> object designating
+ * the <code>BLOB</code> value for which to search
+ * @param start the position in the <code>BLOB</code> value
+ * at which to begin searching; the first position is 1
+ * @return the position at which the pattern begins, else -1
+ * @exception SQLException if there is an error accessing the
+ * <code>BLOB</code>
+ */
+ public long position(final Blob pattern, long start) throws SQLException {
+ if (pattern == null) {
+ return -1;
+ }
+
+ return LobSearchUtil.position(new LobSearchUtil.StreamProvider() {
+ public InputStream getBinaryStream() throws SQLException {
+ return pattern.getBinaryStream();
+ }
+ }, pattern.length(), this, this.length(), start, 1);
+ }
+
+ /**
+ * Determines the byte position at which the specified byte
+ * <code>pattern</code> begins within the <code>BLOB</code>
+ * value that this <code>Blob</code> object represents. The
+ * search for <code>pattern</code> begins at position
+ * <code>start</code>.
+ * @param pattern the byte array for which to search
+ * @param start the position at which to begin searching; the
+ * first position is 1
+ * @return the position at which the pattern appears, else -1
+ * @exception SQLException if there is an error accessing the
+ * <code>BLOB</code>
+ */
+ public long position(byte[] pattern, long start) throws SQLException {
+ if (pattern == null) {
+ return -1;
+ }
+ return position(new SerialBlob(pattern), start);
+ }
+
+ public InputStream getBinaryStream(long arg0, long arg1)
+ throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+
+ /**
+ * @see java.sql.Blob#setBytes(long, byte[])
+ */
+ public int setBytes(long pos, byte[] bytes) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ /**
+ * @see java.sql.Blob#setBytes(long, byte[], int, int)
+ */
+ public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ /**
+ * @see java.sql.Blob#setBinaryStream(long)
+ */
+ public OutputStream setBinaryStream(long pos) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ /**
+ * @see java.sql.Blob#truncate(long)
+ */
+ public void truncate(long len) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/BlobType.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/BlobType.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/BlobType.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/BlobType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,153 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Blob;
+import java.sql.SQLException;
+
+import javax.sql.rowset.serial.SerialBlob;
+
+import org.teiid.core.TeiidRuntimeException;
+
+
+/**
+ * Represent a value of type "blob", which can be streamable from client
+ */
+public final class BlobType extends Streamable<Blob> implements Blob {
+
+ private static final long serialVersionUID = 1294191629070433450L;
+
+ public BlobType() {
+ }
+
+ public BlobType(Blob blob) {
+ super(blob);
+ }
+
+ /**
+ * @see java.sql.Blob#getBinaryStream()
+ */
+ public InputStream getBinaryStream() throws SQLException {
+ return this.reference.getBinaryStream();
+ }
+
+ /**
+ * @see java.sql.Blob#getBytes(long, int)
+ */
+ public byte[] getBytes(long pos, int length) throws SQLException {
+ return this.reference.getBytes(pos, length);
+ }
+
+ /**
+ * @see java.sql.Blob#length()
+ */
+ public long length() throws SQLException {
+ //caching the length
+ if (this.length != -1) {
+ return this.length;
+ }
+ // if did not find before then do it again.
+ this.length = this.reference.length();
+ return length;
+ }
+
+ /**
+ * @see java.sql.Blob#position(java.sql.Blob, long)
+ */
+ public long position(Blob pattern, long start) throws SQLException {
+ return this.reference.position(pattern, start);
+ }
+
+ /**
+ * @see java.sql.Blob#position(byte[], long)
+ */
+ public long position(byte[] pattern, long start) throws SQLException {
+ return this.reference.position(pattern, start);
+ }
+
+ /**
+ * @see java.sql.Blob#setBinaryStream(long)
+ */
+ public OutputStream setBinaryStream(long pos) throws SQLException {
+ return this.reference.setBinaryStream(pos);
+ }
+
+ /**
+ * @see java.sql.Blob#setBytes(long, byte[], int, int)
+ * @since 4.3
+ */
+ public int setBytes(long pos,
+ byte[] bytes,
+ int offset,
+ int len) throws SQLException {
+ return this.reference.setBytes(pos, bytes, offset, len);
+ }
+
+ /**
+ * @see java.sql.Blob#setBytes(long, byte[])
+ */
+ public int setBytes(long pos, byte[] bytes) throws SQLException {
+ return this.reference.setBytes(pos, bytes);
+ }
+
+ /**
+ * @see java.sql.Blob#truncate(long)
+ */
+ public void truncate(long len) throws SQLException {
+ this.reference.truncate(len);
+ }
+
+ //## JDBC4.0-begin ##
+ public void free() throws SQLException {
+ this.reference.free();
+ }
+
+ public InputStream getBinaryStream(long pos, long length)
+ throws SQLException {
+ return this.reference.getBinaryStream(pos, length);
+ }
+ //## JDBC4.0-end ##
+
+ public static SerialBlob createBlob(byte[] bytes) {
+ if (bytes == null) {
+ return null;
+ }
+ try {
+ return new SerialBlob(bytes);
+ } catch (SQLException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+ try {
+ length();
+ } catch (SQLException e) {
+ }
+ out.defaultWriteObject();
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/ClobImpl.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/ClobImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,230 @@
+/*
+ * 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.core.types;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+import javax.sql.rowset.serial.SerialClob;
+
+import org.teiid.core.CorePlugin;
+import org.teiid.core.util.ReaderInputStream;
+import org.teiid.core.util.SqlUtil;
+
+
+/**
+ * This object holds a chunk of char data and implements the JDBC Clob interface.
+ * This object presents a streaming interface and provides a way to access partial
+ * of the Clob data. Connectors can use this object when dealing with large
+ * objects.
+ */
+public class ClobImpl extends BaseLob implements Clob {
+
+ private final static class ClobStreamProvider implements
+ LobSearchUtil.StreamProvider {
+ private final Clob searchstr;
+
+ private ClobStreamProvider(Clob searchstr) {
+ this.searchstr = searchstr;
+ }
+
+ public InputStream getBinaryStream() throws SQLException {
+ ReaderInputStream ris = new ReaderInputStream(searchstr.getCharacterStream(), Charset.forName("UTF-16")); //$NON-NLS-1$
+ try {
+ ris.skip(2);
+ return ris;
+ } catch (IOException e) {
+ throw new SQLException(e);
+ }
+ }
+ }
+
+ private long len = -1;
+
+ public ClobImpl() {
+
+ }
+
+ /**
+ * Creates a new ClobImpl. Note that the length is not taken from the {@link InputStreamFactory} since
+ * it refers to bytes and not chars.
+ * @param streamFactory
+ * @param length
+ */
+ public ClobImpl(InputStreamFactory streamFactory, long length) {
+ super(streamFactory);
+ this.len = length;
+ }
+
+ /**
+ * Gets the <code>CLOB</code> value designated by this <code>Clob</code>
+ * object as a stream of Ascii bytes.
+ * @return an ascii stream containing the <code>CLOB</code> data
+ * @exception SQLException if there is an error accessing the
+ * <code>CLOB</code> value
+ */
+ public InputStream getAsciiStream() throws SQLException {
+ return new ReaderInputStream(getCharacterStream(), Charset.forName("US-ASCII")); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns a copy of the specified substring
+ * in the <code>CLOB</code> value
+ * designated by this <code>Clob</code> object.
+ * The substring begins at position
+ * <code>pos</code> and has up to <code>length</code> consecutive
+ * characters.
+ * @param pos the first character of the substring to be extracted.
+ * The first character is at position 1.
+ * @param length the number of consecutive characters to be copied
+ * @return a <code>String</code> that is the specified substring in
+ * the <code>CLOB</code> value designated by this <code>Clob</code> object
+ * @exception SQLException if there is an error accessing the <code>CLOB</code>
+ */
+ public String getSubString(long pos, int length) throws SQLException {
+ if (pos < 1) {
+ Object[] params = new Object[] {new Long(pos)};
+ throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.0", params)); //$NON-NLS-1$
+ } else if (pos > length()) {
+ return null;
+ }
+ pos = pos - 1;
+ if (length < 0) {
+ Object[] params = new Object[] {new Integer( length)};
+ throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.1", params)); //$NON-NLS-1$
+ } else if ((pos+length) > length()) {
+ length = (int)(length()-pos);
+ }
+ char[] dataCopy = new char[length];
+ Reader in = getCharacterStream();
+ try {
+ try {
+ in.skip(pos);
+ in.read(dataCopy);
+ } finally {
+ in.close();
+ }
+ } catch (IOException e) {
+ throw new SQLException(e);
+ }
+ return new String(dataCopy);
+ }
+
+ /**
+ * Returns the number of characters in the <code>CLOB</code> value
+ * designated by this <code>Clob</code> object.
+ * @return length of the <code>CLOB</code> in characters
+ */
+ public long length() throws SQLException {
+ if (len == -1) {
+ long length = 0;
+ Reader r = new BufferedReader(getCharacterStream());
+ try {
+ while (r.read() != -1) {
+ length++;
+ }
+ } catch (IOException e) {
+ throw new SQLException(e);
+ } finally {
+ try {
+ r.close();
+ } catch (IOException e) {
+ }
+ }
+ this.len = length;
+ }
+ return len;
+ }
+
+ /**
+ * Determines the character position at which the specified
+ * <code>Clob</code> object <code>searchstr</code> appears in this
+ * <code>Clob</code> object. The search begins at position
+ * <code>start</code>.
+ * @param searchstr the <code>Clob</code> object for which to search
+ * @param start the position at which to begin searching; the first
+ * position is 1
+ * @return the position at which the <code>Clob</code> object appears,
+ * else -1; the first position is 1
+ */
+ public long position(final Clob searchstr, long start) throws SQLException {
+ if (searchstr == null) {
+ return -1;
+ }
+
+ return LobSearchUtil.position(new ClobStreamProvider(searchstr), searchstr.length(), new ClobStreamProvider(this), this.length(), start, 2);
+ }
+
+ /**
+ * Determines the character position at which the specified substring
+ * <code>searchstr</code> appears in the SQL <code>CLOB</code> value
+ * represented by this <code>Clob</code> object. The search
+ * begins at position <code>start</code>.
+ * @param searchstr the substring for which to search
+ * @param start the position at which to begin searching; the first position
+ * is 1
+ * @return the position at which the substring appears, else -1; the first
+ * position is 1
+ * @exception SQLException if there is an error accessing the
+ * <code>CLOB</code> value
+ */
+ public long position(String searchstr, long start) throws SQLException {
+ if (searchstr == null) {
+ return -1;
+ }
+ return position(new SerialClob(searchstr.toCharArray()), start);
+ }
+
+ public Reader getCharacterStream(long arg0, long arg1) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public OutputStream setAsciiStream(long arg0) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public Writer setCharacterStream(long arg0) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public int setString(long arg0, String arg1) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public int setString(long arg0, String arg1, int arg2, int arg3)
+ throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public void truncate(long arg0) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/ClobType.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/ClobType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,228 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+import javax.sql.rowset.serial.SerialClob;
+
+import org.teiid.core.TeiidRuntimeException;
+
+
+/**
+ * This is wrapper on top of a "clob" object, which implements the "java.sql.Clob"
+ * interface. This class also implements the Streamable interface
+ */
+public final class ClobType extends Streamable<Clob> implements Clob, Sequencable {
+
+ private static final long serialVersionUID = 2753412502127824104L;
+
+ public ClobType() {
+ }
+
+ public ClobType(Clob clob) {
+ super(clob);
+ }
+
+ /**
+ * @see java.sql.Clob#getAsciiStream()
+ */
+ public InputStream getAsciiStream() throws SQLException {
+ return this.reference.getAsciiStream();
+ }
+
+ /**
+ * @see java.sql.Clob#getCharacterStream()
+ */
+ public Reader getCharacterStream() throws SQLException {
+ return this.reference.getCharacterStream();
+ }
+
+ /**
+ * @see java.sql.Clob#getSubString(long, int)
+ */
+ public String getSubString(long pos, int length) throws SQLException {
+ return this.reference.getSubString(pos, length);
+ }
+
+ /**
+ * @see java.sql.Clob#length()
+ */
+ public long length() throws SQLException {
+ if (this.length != -1) {
+ return this.length;
+ }
+
+ this.length = this.reference.length();
+ return length;
+ }
+
+ /**
+ * @see java.sql.Clob#position(java.sql.Clob, long)
+ */
+ public long position(Clob searchstr, long start) throws SQLException {
+ return this.reference.position(searchstr, start);
+ }
+
+ /**
+ * @see java.sql.Clob#position(java.lang.String, long)
+ */
+ public long position(String searchstr, long start) throws SQLException {
+ return this.reference.position(searchstr, start);
+ }
+
+ /**
+ * @see java.sql.Clob#setAsciiStream(long)
+ */
+ public OutputStream setAsciiStream(long pos) throws SQLException {
+ return this.reference.setAsciiStream(pos);
+ }
+
+ /**
+ * @see java.sql.Clob#setCharacterStream(long)
+ */
+ public Writer setCharacterStream(long pos) throws SQLException {
+ return this.reference.setCharacterStream(pos);
+ }
+
+ /**
+ * @see java.sql.Clob#setString(long, java.lang.String, int, int)
+ */
+ public int setString(long pos,
+ String str,
+ int offset,
+ int len) throws SQLException {
+ return this.reference.setString(pos, str, offset, len);
+ }
+
+ /**
+ * @see java.sql.Clob#setString(long, java.lang.String)
+ */
+ public int setString(long pos, String str) throws SQLException {
+ return this.reference.setString(pos, str);
+ }
+
+ /**
+ * @see java.sql.Clob#truncate(long)
+ */
+ public void truncate(long len) throws SQLException {
+ this.reference.truncate(len);
+ }
+
+ /**
+ * Utility method to convert to String
+ * @param clob
+ * @return string form of the clob passed.
+ */
+ public static String getString(Clob clob) throws SQLException, IOException {
+ Reader reader = clob.getCharacterStream();
+ StringWriter writer = new StringWriter();
+ int c = reader.read();
+ while (c != -1) {
+ writer.write((char)c);
+ c = reader.read();
+ }
+ reader.close();
+ String data = writer.toString();
+ writer.close();
+ return data;
+ }
+
+ private final static int CHAR_SEQUENCE_BUFFER_SIZE = 1 << 12;
+
+ public CharSequence getCharSequence() {
+ return new CharSequence() {
+
+ private String buffer;
+ private int beginPosition;
+
+ public int length() {
+ long result;
+ try {
+ result = ClobType.this.length();
+ } catch (SQLException err) {
+ throw new TeiidRuntimeException(err);
+ }
+ if (((int)result) != result) {
+ throw new TeiidRuntimeException("Clob value is not representable by CharSequence"); //$NON-NLS-1$
+ }
+ return (int)result;
+ }
+
+ public char charAt(int index) {
+ try {
+ if (buffer == null || index < beginPosition || index >= beginPosition + buffer.length()) {
+ buffer = ClobType.this.getSubString(index + 1, CHAR_SEQUENCE_BUFFER_SIZE);
+ beginPosition = index;
+ }
+ return buffer.charAt(index - beginPosition);
+ } catch (SQLException err) {
+ throw new TeiidRuntimeException(err);
+ }
+ }
+
+ public CharSequence subSequence(int start,
+ int end) {
+ try {
+ return ClobType.this.getSubString(start + 1, end - start);
+ } catch (SQLException err) {
+ throw new TeiidRuntimeException(err);
+ }
+ }
+
+ };
+ }
+ //## JDBC4.0-begin ##
+ public void free() throws SQLException {
+ this.reference.free();
+ }
+
+ public Reader getCharacterStream(long pos, long length) throws SQLException {
+ return this.reference.getCharacterStream(pos, length);
+ }
+ //## JDBC4.0-end ##
+
+ public static SerialClob createClob(char[] chars) {
+ try {
+ return new SerialClob(chars);
+ } catch (SQLException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+ try {
+ length();
+ } catch (SQLException e) {
+ }
+ out.defaultWriteObject();
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/DataTypeManager.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,854 @@
+/*
+ * 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.core.types;
+
+import java.lang.ref.WeakReference;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.transform.Source;
+
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.basic.AnyToObjectTransform;
+import org.teiid.core.types.basic.AnyToStringTransform;
+import org.teiid.core.types.basic.BooleanToNumberTransform;
+import org.teiid.core.types.basic.ClobToSQLXMLTransform;
+import org.teiid.core.types.basic.FixedNumberToBigDecimalTransform;
+import org.teiid.core.types.basic.FixedNumberToBigIntegerTransform;
+import org.teiid.core.types.basic.FloatingNumberToBigDecimalTransform;
+import org.teiid.core.types.basic.FloatingNumberToBigIntegerTransform;
+import org.teiid.core.types.basic.NullToAnyTransform;
+import org.teiid.core.types.basic.NumberToBooleanTransform;
+import org.teiid.core.types.basic.NumberToByteTransform;
+import org.teiid.core.types.basic.NumberToDoubleTransform;
+import org.teiid.core.types.basic.NumberToFloatTransform;
+import org.teiid.core.types.basic.NumberToIntegerTransform;
+import org.teiid.core.types.basic.NumberToLongTransform;
+import org.teiid.core.types.basic.NumberToShortTransform;
+import org.teiid.core.types.basic.ObjectToAnyTransform;
+import org.teiid.core.types.basic.SQLXMLToClobTransform;
+import org.teiid.core.util.ArgCheck;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.core.util.PropertiesUtils;
+
+
+/**
+ * <p>
+ * This class manages data type, conversions between data types, and comparators
+ * for data types. In the future other data type information may be managed
+ * here.
+ * </p>
+ *
+ * <p>
+ * In general, methods are provided to refer to types either by Class, or by
+ * Class name. The benefit of the Class name option is that the user does not
+ * need to load the Class object, which may not be in the classpath. The
+ * advantage of the Class option is speed.
+ * </p>
+ */
+public class DataTypeManager {
+
+ private static final boolean USE_VALUE_CACHE = PropertiesUtils.getBooleanProperty(System.getProperties(), "org.teiid.useValueCache", true); //$NON-NLS-1$
+
+ private static boolean valueCacheEnabled;
+
+ private interface ValueCache<T> {
+ T getValue(T value);
+ }
+
+ private static class HashedValueCache<T> implements ValueCache<T> {
+
+ final Object[] cache;
+
+ HashedValueCache(int size) {
+ cache = new Object[1 << size];
+ }
+
+ @SuppressWarnings("unchecked")
+ public T getValue(T value) {
+ int index = hash(primaryHash(value)) & (cache.length - 1);
+ Object canonicalValue = get(index);
+ if (value.equals(canonicalValue)) {
+ return (T)canonicalValue;
+ }
+ set(index, value);
+ return value;
+ }
+
+ protected Object get(int index) {
+ return cache[index];
+ }
+
+ protected void set(int index, T value) {
+ cache[index] = value;
+ }
+
+ protected int primaryHash(T value) {
+ return value.hashCode();
+ }
+
+ /*
+ * The same power of 2 hash bucketing from the Java HashMap
+ */
+ final static int hash(int h) {
+ h ^= (h >>> 20) ^ (h >>> 12);
+ return h ^= (h >>> 7) ^ (h >>> 4);
+ }
+ }
+
+ private static Map<Class<?>, ValueCache<?>> valueMaps = new HashMap<Class<?>, ValueCache<?>>(128);
+
+ public static final int MAX_STRING_LENGTH = 4000;
+
+ public static final class DataTypeAliases {
+ public static final String VARCHAR = "varchar"; //$NON-NLS-1$
+ public static final String TINYINT = "tinyint"; //$NON-NLS-1$
+ public static final String SMALLINT = "smallint"; //$NON-NLS-1$
+ public static final String BIGINT = "bigint"; //$NON-NLS-1$
+ public static final String REAL = "real"; //$NON-NLS-1$
+ public static final String DECIMAL = "decimal"; //$NON-NLS-1$
+ }
+
+ public static final class DefaultDataTypes {
+ public static final String STRING = "string"; //$NON-NLS-1$
+ public static final String BOOLEAN = "boolean"; //$NON-NLS-1$
+ public static final String BYTE = "byte"; //$NON-NLS-1$
+ public static final String SHORT = "short"; //$NON-NLS-1$
+ public static final String CHAR = "char"; //$NON-NLS-1$
+ public static final String INTEGER = "integer"; //$NON-NLS-1$
+ public static final String LONG = "long"; //$NON-NLS-1$
+ public static final String BIG_INTEGER = "biginteger"; //$NON-NLS-1$
+ public static final String FLOAT = "float"; //$NON-NLS-1$
+ public static final String DOUBLE = "double"; //$NON-NLS-1$
+ public static final String BIG_DECIMAL = "bigdecimal"; //$NON-NLS-1$
+ public static final String DATE = "date"; //$NON-NLS-1$
+ public static final String TIME = "time"; //$NON-NLS-1$
+ public static final String TIMESTAMP = "timestamp"; //$NON-NLS-1$
+ public static final String OBJECT = "object"; //$NON-NLS-1$
+ public static final String NULL = "null"; //$NON-NLS-1$
+ public static final String BLOB = "blob"; //$NON-NLS-1$
+ public static final String CLOB = "clob"; //$NON-NLS-1$
+ public static final String XML = "xml"; //$NON-NLS-1$
+ }
+
+ public static final class DefaultDataClasses {
+ public static final Class<String> STRING = String.class;
+ public static final Class<Boolean> BOOLEAN = Boolean.class;
+ public static final Class<Byte> BYTE = Byte.class;
+ public static final Class<Short> SHORT = Short.class;
+ public static final Class<Character> CHAR = Character.class;
+ public static final Class<Integer> INTEGER = Integer.class;
+ public static final Class<Long> LONG = Long.class;
+ public static final Class<BigInteger> BIG_INTEGER = BigInteger.class;
+ public static final Class<Float> FLOAT = Float.class;
+ public static final Class<Double> DOUBLE = Double.class;
+ public static final Class<BigDecimal> BIG_DECIMAL = BigDecimal.class;
+ public static final Class<java.sql.Date> DATE = java.sql.Date.class;
+ public static final Class<Time> TIME = Time.class;
+ public static final Class<Timestamp> TIMESTAMP = Timestamp.class;
+ public static final Class<Object> OBJECT = Object.class;
+ public static final Class<NullType> NULL = NullType.class;
+ public static final Class<BlobType> BLOB = BlobType.class;
+ public static final Class<ClobType> CLOB = ClobType.class;
+ public static final Class<XMLType> XML = XMLType.class;
+ }
+
+ /**
+ * Doubly-nested map of String srcType --> Map of String targetType -->
+ * Transform
+ */
+ private static Map<String, Map<String, Transform>> transforms = new HashMap<String, Map<String, Transform>>(128);
+
+ /** Utility to easily get Transform given srcType and targetType */
+ private static Transform getTransformFromMaps(String srcType,
+ String targetType) {
+ Map<String, Transform> innerMap = transforms.get(srcType);
+ if (innerMap != null) {
+ return innerMap.get(targetType);
+ }
+ return null;
+ }
+
+ /** Base data type names and classes, Type name --> Type class */
+ private static Map<String, Class> dataTypeNames = new LinkedHashMap<String, Class>(128);
+
+ /** Base data type names and classes, Type class --> Type name */
+ private static Map<Class, String> dataTypeClasses = new LinkedHashMap<Class, String>(128);
+
+ private static Set<String> DATA_TYPE_NAMES;
+
+ private static Set<Class> DATA_TYPE_CLASSES = Collections.unmodifiableSet(dataTypeClasses.keySet());
+
+ private static Map<Class<?>, SourceTransform> sourceConverters = new HashMap<Class<?>, SourceTransform>();
+
+ // Static initializer - loads basic transforms types
+ static {
+ // Load default data types - not extensible yet
+ loadDataTypes();
+
+ // Load default transforms
+ loadBasicTransforms();
+
+ loadSourceConversions();
+ }
+
+ /**
+ * Constructor is private so instance creation is controlled by the class.
+ */
+ private DataTypeManager() {
+ }
+
+ /**
+ * Add a new data type. For now this consists just of the Class - in the
+ * future a data type will be a more complicated entity. This is
+ * package-level for now as it is just used to add the default data types.
+ *
+ * @param dataType
+ * New data type defined by Class
+ */
+ static void addDataType(String typeName, Class dataType) {
+ dataTypeNames.put(typeName, dataType);
+ dataTypeClasses.put(dataType, typeName);
+ }
+
+ /**
+ * Get a set of all data type names.
+ *
+ * @return Set of data type names (String)
+ */
+ public static Set<String> getAllDataTypeNames() {
+ return DATA_TYPE_NAMES;
+ }
+
+ public static Set<Class> getAllDataTypeClasses() {
+ return DATA_TYPE_CLASSES;
+ }
+
+ /**
+ * Get data type class.
+ *
+ * @param name
+ * Data type name
+ * @return Data type class
+ */
+ public static Class getDataTypeClass(String name) {
+ if (name == null) {
+ return DefaultDataClasses.NULL;
+ }
+
+ // Hope this is the correct case (as it will be if using the constants
+ Class dataTypeClass = dataTypeNames.get(name);
+
+ // If that fails, do a lower case to make sure we match
+ if (dataTypeClass == null) {
+ dataTypeClass = dataTypeNames.get(name.toLowerCase());
+ }
+
+ if (dataTypeClass == null) {
+ dataTypeClass = DefaultDataClasses.OBJECT;
+ }
+ return dataTypeClass;
+ }
+
+ public static String getDataTypeName(Class typeClass) {
+ if (typeClass == null) {
+ return DefaultDataTypes.NULL;
+ }
+
+ String result = dataTypeClasses.get(typeClass);
+ if (result == null) {
+ result = DefaultDataTypes.OBJECT;
+ }
+
+ return result;
+ }
+
+ /**
+ * Take an object and determine the MetaMatrix data type. In most cases,
+ * this is simply the class of the object. Some special cases are when the
+ * value is of type Object or Null.
+ */
+ public static Class determineDataTypeClass(Object value) {
+ // Handle null case
+ if (value == null) {
+ return DefaultDataClasses.NULL;
+ }
+
+ return getDataTypeClass(getDataTypeName(convertToRuntimeType(value)
+ .getClass()));
+ }
+
+ /**
+ * Get a data value transformation between the sourceType and the
+ * targetType.
+ *
+ * @param sourceType
+ * Incoming value type
+ * @param targetType
+ * Outgoing value type
+ * @return A transform if one exists, null otherwise
+ */
+ public static Transform getTransform(Class sourceType, Class targetType) {
+ if (sourceType == null || targetType == null) {
+ throw new IllegalArgumentException(CorePlugin.Util.getString(
+ ErrorMessageKeys.TYPES_ERR_0002, sourceType, targetType));
+ }
+ return getTransformFromMaps(
+ DataTypeManager.getDataTypeName(sourceType), DataTypeManager
+ .getDataTypeName(targetType));
+ }
+
+ /**
+ * Get a data value transformation between the sourceType with given name
+ * and the targetType of given name. The Class for source and target type
+ * are not needed to do this lookup.
+ *
+ * @param sourceTypeName
+ * Incoming value type name
+ * @param targetTypeName
+ * Outgoing value type name
+ * @return A transform if one exists, null otherwise
+ */
+ public static Transform getTransform(String sourceTypeName,
+ String targetTypeName) {
+ if (sourceTypeName == null || targetTypeName == null) {
+ throw new IllegalArgumentException(CorePlugin.Util.getString(
+ ErrorMessageKeys.TYPES_ERR_0003, sourceTypeName,
+ targetTypeName));
+ }
+ return getTransformFromMaps(sourceTypeName, targetTypeName);
+ }
+
+ /**
+ * Does a transformation exist between the source and target type?
+ *
+ * @param sourceType
+ * Incoming value type
+ * @param targetType
+ * Outgoing value type
+ * @return True if a transform exists
+ */
+ public static boolean isTransformable(Class sourceType, Class targetType) {
+ if (sourceType == null || targetType == null) {
+ throw new IllegalArgumentException(CorePlugin.Util.getString(
+ ErrorMessageKeys.TYPES_ERR_0002, sourceType, targetType));
+ }
+ return (getTransformFromMaps(DataTypeManager
+ .getDataTypeName(sourceType), DataTypeManager
+ .getDataTypeName(targetType)) != null);
+ }
+
+ /**
+ * Does a transformation exist between the source and target type of given
+ * names? The Class for source and target type are not needed to do this
+ * lookup.
+ *
+ * @param sourceTypeName
+ * Incoming value type name
+ * @param targetTypeName
+ * Outgoing value type name
+ * @return True if a transform exists
+ */
+ public static boolean isTransformable(String sourceTypeName,
+ String targetTypeName) {
+ if (sourceTypeName == null || targetTypeName == null) {
+ throw new IllegalArgumentException(CorePlugin.Util.getString(
+ ErrorMessageKeys.TYPES_ERR_0003, sourceTypeName,
+ targetTypeName));
+ }
+ return (getTransformFromMaps(sourceTypeName, targetTypeName) != null);
+ }
+
+ /**
+ * Add a new transform to the known transform types.
+ *
+ * @param transform
+ * New transform to add
+ */
+ static void addTransform(Transform transform) {
+ ArgCheck.isNotNull(transform);
+ String sourceName = transform.getSourceTypeName();
+ String targetName = transform.getTargetTypeName();
+
+ Map<String, Transform> innerMap = transforms.get(sourceName);
+ if (innerMap == null) {
+ innerMap = new LinkedHashMap<String, Transform>();
+ transforms.put(sourceName, innerMap);
+ }
+ innerMap.put(targetName, transform);
+ }
+
+ public static List<String> getImplicitConversions(String type) {
+ Map<String, Transform> innerMap = transforms.get(type);
+ if (innerMap != null) {
+ List<String> result = new ArrayList<String>(innerMap.size());
+ for (Map.Entry<String, Transform> entry : innerMap.entrySet()) {
+ if (!entry.getValue().isExplicit()) {
+ result.add(entry.getKey());
+ }
+ }
+ return result;
+ }
+ return Collections.emptyList();
+ }
+
+ public static boolean isImplicitConversion(String srcType, String tgtType) {
+ Transform t = getTransform(srcType, tgtType);
+ if (t != null) {
+ return !t.isExplicit();
+ }
+ return false;
+ }
+
+ public static boolean isExplicitConversion(String srcType, String tgtType) {
+ Transform t = getTransform(srcType, tgtType);
+ if (t != null) {
+ return t.isExplicit();
+ }
+ return false;
+ }
+
+ /**
+ * Is the supplied class type a LOB based data type?
+ *
+ * @param type
+ * @return true if yes; false otherwise
+ */
+ public static boolean isLOB(Class<?> type) {
+ return DataTypeManager.DefaultDataClasses.BLOB.equals(type)
+ || DataTypeManager.DefaultDataClasses.CLOB.equals(type)
+ || DataTypeManager.DefaultDataClasses.XML.equals(type);
+ }
+
+ public static boolean isLOB(String type) {
+ return DataTypeManager.DefaultDataTypes.BLOB.equals(type)
+ || DataTypeManager.DefaultDataTypes.CLOB.equals(type)
+ || DataTypeManager.DefaultDataTypes.XML.equals(type);
+ }
+
+ /**
+ * Load default data types.
+ */
+ static void loadDataTypes() {
+ DataTypeManager.addDataType(DefaultDataTypes.BOOLEAN, DefaultDataClasses.BOOLEAN);
+ DataTypeManager.addDataType(DefaultDataTypes.BYTE, DefaultDataClasses.BYTE);
+ DataTypeManager.addDataType(DefaultDataTypes.SHORT, DefaultDataClasses.SHORT);
+ DataTypeManager.addDataType(DefaultDataTypes.CHAR, DefaultDataClasses.CHAR);
+ DataTypeManager.addDataType(DefaultDataTypes.INTEGER, DefaultDataClasses.INTEGER);
+ DataTypeManager.addDataType(DefaultDataTypes.LONG, DefaultDataClasses.LONG);
+ DataTypeManager.addDataType(DefaultDataTypes.BIG_INTEGER, DefaultDataClasses.BIG_INTEGER);
+ DataTypeManager.addDataType(DefaultDataTypes.FLOAT, DefaultDataClasses.FLOAT);
+ DataTypeManager.addDataType(DefaultDataTypes.DOUBLE, DefaultDataClasses.DOUBLE);
+ DataTypeManager.addDataType(DefaultDataTypes.BIG_DECIMAL, DefaultDataClasses.BIG_DECIMAL);
+ DataTypeManager.addDataType(DefaultDataTypes.DATE, DefaultDataClasses.DATE);
+ DataTypeManager.addDataType(DefaultDataTypes.TIME, DefaultDataClasses.TIME);
+ DataTypeManager.addDataType(DefaultDataTypes.TIMESTAMP, DefaultDataClasses.TIMESTAMP);
+ DataTypeManager.addDataType(DefaultDataTypes.STRING, DefaultDataClasses.STRING);
+ DataTypeManager.addDataType(DefaultDataTypes.CLOB, DefaultDataClasses.CLOB);
+ DataTypeManager.addDataType(DefaultDataTypes.XML, DefaultDataClasses.XML);
+ DataTypeManager.addDataType(DefaultDataTypes.OBJECT, DefaultDataClasses.OBJECT);
+ DataTypeManager.addDataType(DefaultDataTypes.NULL, DefaultDataClasses.NULL);
+ DataTypeManager.addDataType(DefaultDataTypes.BLOB, DefaultDataClasses.BLOB);
+ DATA_TYPE_NAMES = Collections.unmodifiableSet(new LinkedHashSet<String>(dataTypeNames.keySet()));
+ dataTypeNames.put(DataTypeAliases.BIGINT, DefaultDataClasses.LONG);
+ dataTypeNames.put(DataTypeAliases.DECIMAL, DefaultDataClasses.BIG_DECIMAL);
+ dataTypeNames.put(DataTypeAliases.REAL, DefaultDataClasses.FLOAT);
+ dataTypeNames.put(DataTypeAliases.SMALLINT, DefaultDataClasses.SHORT);
+ dataTypeNames.put(DataTypeAliases.TINYINT, DefaultDataClasses.BYTE);
+ dataTypeNames.put(DataTypeAliases.VARCHAR, DefaultDataClasses.STRING);
+
+ if (USE_VALUE_CACHE) {
+ valueMaps.put(DefaultDataClasses.BOOLEAN, new ValueCache<Boolean>() {
+ @Override
+ public Boolean getValue(Boolean value) {
+ return Boolean.valueOf(value);
+ }
+ });
+ valueMaps.put(DefaultDataClasses.BYTE, new ValueCache<Byte>() {
+ @Override
+ public Byte getValue(Byte value) {
+ return Byte.valueOf(value);
+ }
+ });
+ valueMaps.put(DefaultDataClasses.SHORT, new HashedValueCache<Short>(13));
+ valueMaps.put(DefaultDataClasses.CHAR, new HashedValueCache<Character>(13));
+ valueMaps.put(DefaultDataClasses.INTEGER, new HashedValueCache<Integer>(14));
+ valueMaps.put(DefaultDataClasses.LONG, new HashedValueCache<Long>(14));
+ valueMaps.put(DefaultDataClasses.BIG_INTEGER, new HashedValueCache<BigInteger>(14));
+ valueMaps.put(DefaultDataClasses.FLOAT, new HashedValueCache<Float>(14));
+ valueMaps.put(DefaultDataClasses.DOUBLE, new HashedValueCache<Double>(14));
+ valueMaps.put(DefaultDataClasses.DATE, new HashedValueCache<Date>(14));
+ valueMaps.put(DefaultDataClasses.TIME, new HashedValueCache<Time>(14));
+ valueMaps.put(DefaultDataClasses.TIMESTAMP, new HashedValueCache<Timestamp>(14));
+ valueMaps.put(DefaultDataClasses.BIG_DECIMAL, new HashedValueCache<BigDecimal>(15) {
+ @Override
+ protected Object get(int index) {
+ WeakReference<?> ref = (WeakReference<?>) cache[index];
+ if (ref != null) {
+ return ref.get();
+ }
+ return null;
+ }
+
+ @Override
+ protected void set(int index, BigDecimal value) {
+ cache[index] = new WeakReference<BigDecimal>(value);
+ }
+ });
+ valueMaps.put(DefaultDataClasses.STRING, new HashedValueCache<String>(15) {
+ HashedValueCache<String> smallCache = new HashedValueCache<String>(13);
+
+ @Override
+ public String getValue(String value) {
+ if (value.length() < 14) {
+ return smallCache.getValue(value);
+ }
+ return super.getValue(value);
+ }
+
+ @Override
+ protected Object get(int index) {
+ WeakReference<?> ref = (WeakReference<?>) cache[index];
+ if (ref != null) {
+ return ref.get();
+ }
+ return null;
+ }
+
+ @Override
+ protected void set(int index, String value) {
+ cache[index] = new WeakReference<Object>(value);
+ }
+
+ @Override
+ protected int primaryHash(String value) {
+ return HashCodeUtil.expHashCode(value);
+ }
+ });
+ }
+ }
+
+ /**
+ * Load all basic {@link Transform}s into the DataTypeManager. This standard
+ * set is always installed but may be overridden.
+ */
+ static void loadBasicTransforms() {
+ 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)));
+ DataTypeManager.addTransform(new BooleanToNumberTransform(Long.valueOf(1), Long.valueOf(0)));
+ DataTypeManager.addTransform(new BooleanToNumberTransform(BigInteger.valueOf(1), BigInteger.valueOf(0)));
+ DataTypeManager.addTransform(new BooleanToNumberTransform(Float.valueOf(1), Float.valueOf(0)));
+ DataTypeManager.addTransform(new BooleanToNumberTransform(Double.valueOf(1), Double.valueOf(0)));
+ DataTypeManager.addTransform(new BooleanToNumberTransform(BigDecimal.valueOf(1), BigDecimal.valueOf(0)));
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.BOOLEAN));
+
+ DataTypeManager.addTransform(new NumberToBooleanTransform(Byte.valueOf((byte)0)));
+ DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.BYTE, false));
+ DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.BYTE, false));
+ DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.BYTE, false, false));
+ DataTypeManager.addTransform(new FixedNumberToBigIntegerTransform(DefaultDataClasses.BYTE));
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.BYTE, false, false));
+ DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.BYTE, false, false));
+ DataTypeManager.addTransform(new FixedNumberToBigDecimalTransform(DefaultDataClasses.BYTE));
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.BYTE));
+
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.CHAR));
+
+ 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));
+ DataTypeManager.addTransform(new NumberToLongTransform(DefaultDataClasses.INTEGER, false, false));
+ DataTypeManager.addTransform(new FixedNumberToBigIntegerTransform(DefaultDataClasses.INTEGER));
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.INTEGER, false, true)); //lossy, but not narrowing
+ DataTypeManager.addTransform(new NumberToDoubleTransform(DefaultDataClasses.INTEGER, false, false));
+ DataTypeManager.addTransform(new FixedNumberToBigDecimalTransform(DefaultDataClasses.INTEGER));
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.INTEGER));
+
+ DataTypeManager.addTransform(new NumberToBooleanTransform(Long.valueOf(0)));
+ DataTypeManager.addTransform(new NumberToByteTransform(DefaultDataClasses.LONG));
+ DataTypeManager.addTransform(new NumberToShortTransform(DefaultDataClasses.LONG, true));
+ DataTypeManager.addTransform(new NumberToIntegerTransform(DefaultDataClasses.LONG, true));
+ DataTypeManager.addTransform(new FixedNumberToBigIntegerTransform(DefaultDataClasses.LONG));
+ DataTypeManager.addTransform(new NumberToFloatTransform(DefaultDataClasses.LONG, false, true)); //lossy, but not narrowing
+ 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(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 org.teiid.core.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 org.teiid.core.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 org.teiid.core.types.basic.DateToTimestampTransform());
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.DATE));
+
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.TimeToTimestampTransform());
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.TIME));
+
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.TimestampToTimeTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.TimestampToDateTransform());
+ DataTypeManager.addTransform(new AnyToStringTransform(DefaultDataClasses.TIMESTAMP));
+
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToBooleanTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToByteTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToShortTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToIntegerTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToLongTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToBigIntegerTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToFloatTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToDoubleTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToBigDecimalTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToTimeTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToDateTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToTimestampTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToCharacterTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToClobTransform());
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.StringToSQLXMLTransform());
+
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.ClobToStringTransform());
+ DataTypeManager.addTransform(new ClobToSQLXMLTransform());
+
+ DataTypeManager.addTransform(new org.teiid.core.types.basic.SQLXMLToStringTransform());
+ DataTypeManager.addTransform(new SQLXMLToClobTransform());
+
+ for (Class<?> type : getAllDataTypeClasses()) {
+ if (type != DefaultDataClasses.OBJECT) {
+ DataTypeManager.addTransform(new AnyToObjectTransform(type));
+ DataTypeManager.addTransform(new ObjectToAnyTransform(type));
+ }
+ if (type != DefaultDataClasses.NULL) {
+ DataTypeManager.addTransform(new NullToAnyTransform(type));
+ }
+ }
+
+ }
+
+ static void loadSourceConversions() {
+ sourceConverters.put(Clob.class, new SourceTransform<Clob, ClobType>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public ClobType transform(Clob value) {
+ return new ClobType(value);
+ }
+ });
+ sourceConverters.put(char[].class, new SourceTransform<char[], ClobType>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public ClobType transform(char[] value) {
+ return new ClobType(ClobType.createClob(value));
+ }
+ });
+ sourceConverters.put(Blob.class, new SourceTransform<Blob, BlobType>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public BlobType transform(Blob value) {
+ return new BlobType(value);
+ }
+ });
+ addSourceTransform(byte[].class, new SourceTransform<byte[], BlobType>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public BlobType transform(byte[] value) {
+ return new BlobType(BlobType.createBlob(value));
+ }
+ });
+ addSourceTransform(SQLXML.class, new SourceTransform<SQLXML, XMLType>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public XMLType transform(SQLXML value) {
+ return new XMLType(value);
+ }
+ });
+ //Note: the default transform from non-InputStreamFactory source is a fully materialized string
+ addSourceTransform(Source.class, new SourceTransform<Source, XMLType>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public XMLType transform(Source value) {
+ if (value instanceof InputStreamFactory) {
+ return new XMLType(new SQLXMLImpl((InputStreamFactory)value));
+ }
+ StandardXMLTranslator sxt = new StandardXMLTranslator(value);
+ try {
+ return new XMLType(new SQLXMLImpl(sxt.getString()));
+ } catch (Exception e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+ });
+ addSourceTransform(Date.class, new SourceTransform<Date, Timestamp>() {
+ //## JDBC4.0-begin ##
+ @Override
+ //## JDBC4.0-end ##
+ public Timestamp transform(Date value) {
+ return new Timestamp(value.getTime());
+ }
+ });
+ }
+
+ public static Object convertToRuntimeType(Object value) {
+ if (value == null) {
+ return null;
+ }
+ Class<?> c = value.getClass();
+ if (getAllDataTypeClasses().contains(c)) {
+ return value;
+ }
+ SourceTransform t = sourceConverters.get(c);
+ if (t != null) {
+ return t.transform(value);
+ }
+ for (Map.Entry<Class<?>, SourceTransform> entry : sourceConverters.entrySet()) {
+ if (entry.getKey().isAssignableFrom(c)) {
+ return entry.getValue().transform(value);
+ }
+ }
+ return value; // "object type"
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T transformValue(Object value, Class<T> targetClass)
+ throws TransformationException {
+ if (value == null) {
+ return (T)value;
+ }
+ return transformValue(value, value.getClass(), targetClass);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T transformValue(Object value, Class sourceType,
+ Class<T> targetClass) throws TransformationException {
+ if (value == null || sourceType == targetClass) {
+ return (T) value;
+ }
+ Transform transform = DataTypeManager.getTransform(sourceType,
+ targetClass);
+ if (transform == null) {
+ Object[] params = new Object[] { sourceType, targetClass, value};
+ throw new TransformationException(CorePlugin.Util.getString("ObjectToAnyTransform.Invalid_value", params)); //$NON-NLS-1$
+ }
+ T result = (T) transform.transform(value);
+ return getCanonicalValue(result);
+ }
+
+ public static boolean isNonComparable(String type) {
+ return DataTypeManager.DefaultDataTypes.OBJECT.equals(type)
+ || DataTypeManager.DefaultDataTypes.BLOB.equals(type)
+ || DataTypeManager.DefaultDataTypes.CLOB.equals(type)
+ || DataTypeManager.DefaultDataTypes.XML.equals(type);
+ }
+
+ public static <S> void addSourceTransform(Class<S> sourceClass, SourceTransform<S, ?> transform) {
+ sourceConverters.put(sourceClass, transform);
+ }
+
+ public static void setValueCacheEnabled(boolean enabled) {
+ valueCacheEnabled = enabled;
+ }
+
+ public static boolean isValueCacheEnabled() {
+ return valueCacheEnabled;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> T getCanonicalValue(T value) {
+ if (USE_VALUE_CACHE && valueCacheEnabled) {
+ if (value == null) {
+ return null;
+ }
+ //TODO: this initial lookup is inefficient, since there are likely collisions
+ ValueCache valueCache = valueMaps.get(value.getClass());
+ if (valueCache != null) {
+ value = (T)valueCache.getValue(value);
+ }
+ }
+ return value;
+ }
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/InputStreamFactory.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,88 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+
+import javax.xml.transform.Source;
+
+public abstract class InputStreamFactory implements Source {
+
+ public interface StreamFactoryReference {
+
+ void setStreamFactory(InputStreamFactory inputStreamFactory);
+
+ }
+
+ private String encoding;
+ private String systemId;
+ private long length = -1;
+
+ public InputStreamFactory() {
+ this(Charset.defaultCharset().name());
+ }
+
+ public InputStreamFactory(String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
+ * Get a new InputStream
+ * @return
+ */
+ public abstract InputStream getInputStream() throws IOException;
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ @Override
+ public String getSystemId() {
+ return this.systemId;
+ }
+
+ @Override
+ public void setSystemId(String systemId) {
+ this.systemId = systemId;
+ }
+
+ public void free() throws IOException {
+
+ }
+
+ public long getLength() {
+ return length;
+ }
+
+ public void setLength(long length) {
+ this.length = length;
+ }
+
+ public Reader getCharacterStream() throws IOException {
+ return new InputStreamReader(this.getInputStream(), this.getEncoding());
+ }
+}
Property changes on: trunk/common-core/src/main/java/org/teiid/core/types/InputStreamFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/JDBCSQLTypeInfo.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/JDBCSQLTypeInfo.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,264 @@
+/*
+ * 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.core.types;
+
+import java.sql.Blob;
+import java.sql.Clob;
+//## JDBC4.0-begin ##
+import java.sql.SQLXML;
+//## JDBC4.0-end ##
+
+/*## JDBC3.0-JDK1.5-begin ##
+import com.metamatrix.core.jdbc.SQLXML;
+## JDBC3.0-JDK1.5-end ##*/
+import java.sql.Types;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p> This is a helper class used to obtain SQL type information for java types.
+ * The SQL type information is obtained from java.sql.Types class. The integers and
+ * strings returned by methods in this class are based on constants in java.sql.Types.
+ */
+
+public final class JDBCSQLTypeInfo {
+
+
+ // Prevent instantiation
+ private JDBCSQLTypeInfo() {}
+
+ // metamatrix types
+ public static final String STRING = DataTypeManager.DefaultDataTypes.STRING;
+ public static final String BOOLEAN = DataTypeManager.DefaultDataTypes.BOOLEAN;
+ public static final String TIME = DataTypeManager.DefaultDataTypes.TIME;
+ public static final String DATE = DataTypeManager.DefaultDataTypes.DATE;
+ public static final String TIMESTAMP = DataTypeManager.DefaultDataTypes.TIMESTAMP;
+ public static final String INTEGER = DataTypeManager.DefaultDataTypes.INTEGER;
+ public static final String FLOAT = DataTypeManager.DefaultDataTypes.FLOAT;
+ public static final String DOUBLE = DataTypeManager.DefaultDataTypes.DOUBLE;
+ public static final String BIGDECIMAL = DataTypeManager.DefaultDataTypes.BIG_DECIMAL;
+ public static final String BIGINTEGER = DataTypeManager.DefaultDataTypes.BIG_INTEGER;
+ public static final String BYTE = DataTypeManager.DefaultDataTypes.BYTE;
+ public static final String SHORT = DataTypeManager.DefaultDataTypes.SHORT;
+ public static final String LONG = DataTypeManager.DefaultDataTypes.LONG;
+ public static final String CHAR = DataTypeManager.DefaultDataTypes.CHAR;
+ public static final String OBJECT = DataTypeManager.DefaultDataTypes.OBJECT;
+ public static final String CLOB = DataTypeManager.DefaultDataTypes.CLOB;
+ public static final String BLOB = DataTypeManager.DefaultDataTypes.BLOB;
+ public static final String XML = DataTypeManager.DefaultDataTypes.XML;
+ public static final String NULL = DataTypeManager.DefaultDataTypes.NULL;
+
+ //java class names
+ public static final String STRING_CLASS = DataTypeManager.DefaultDataClasses.STRING.getName();
+ public static final String BOOLEAN_CLASS = DataTypeManager.DefaultDataClasses.BOOLEAN.getName();
+ public static final String TIME_CLASS = DataTypeManager.DefaultDataClasses.TIME.getName();
+ public static final String DATE_CLASS = DataTypeManager.DefaultDataClasses.DATE.getName();
+ public static final String TIMESTAMP_CLASS = DataTypeManager.DefaultDataClasses.TIMESTAMP.getName();
+ public static final String INTEGER_CLASS = DataTypeManager.DefaultDataClasses.INTEGER.getName();
+ public static final String FLOAT_CLASS = DataTypeManager.DefaultDataClasses.FLOAT.getName();
+ public static final String DOUBLE_CLASS = DataTypeManager.DefaultDataClasses.DOUBLE.getName();
+ public static final String BIGDECIMAL_CLASS = DataTypeManager.DefaultDataClasses.BIG_DECIMAL.getName();
+ public static final String BYTE_CLASS = DataTypeManager.DefaultDataClasses.BYTE.getName();
+ public static final String SHORT_CLASS = DataTypeManager.DefaultDataClasses.SHORT.getName();
+ public static final String LONG_CLASS = DataTypeManager.DefaultDataClasses.LONG.getName();
+ public static final String CHAR_CLASS = DataTypeManager.DefaultDataClasses.CHAR.getName();
+ public static final String BIGINTEGER_CLASS = DataTypeManager.DefaultDataClasses.BIG_INTEGER.getName();
+ public static final String OBJECT_CLASS = DataTypeManager.DefaultDataClasses.OBJECT.getName();
+ public static final String CLOB_CLASS = Clob.class.getName();
+ public static final String BLOB_CLASS = Blob.class.getName();
+ //## JDBC4.0-begin ##
+ public static final String XML_CLASS = SQLXML.class.getName();
+ //## JDBC4.0-end ##
+ /*## JDBC3.0-JDK1.5-begin ##
+ public static final String XML_CLASS = DataTypeManager.DefaultDataClasses.OBJECT.getName();
+ ## JDBC3.0-JDK1.5-end ##*/
+
+ private static Map<String, Integer> NAME_TO_TYPE_MAP = new HashMap<String, Integer>();
+ private static Map<Integer, String> TYPE_TO_NAME_MAP = new HashMap<Integer, String>();
+ private static Map<String, String> NAME_TO_CLASSNAME = new HashMap<String, String>();
+ private static Map<String, String> CLASSNAME_TO_NAME = new HashMap<String, String>();
+
+ static {
+ addTypeMapping(STRING, STRING_CLASS, Types.VARCHAR, Types.LONGVARCHAR, Types.CHAR);
+ addTypeMapping(CHAR, CHAR_CLASS, Types.CHAR, false);
+ addTypeMapping(BOOLEAN, BOOLEAN_CLASS, Types.BIT);
+ addTypeMapping(TIME, TIME_CLASS, Types.TIME);
+ addTypeMapping(DATE, DATE_CLASS, Types.DATE);
+ addTypeMapping(TIMESTAMP, TIMESTAMP_CLASS, Types.TIMESTAMP);
+ addTypeMapping(INTEGER, INTEGER_CLASS, Types.INTEGER);
+ addTypeMapping(FLOAT, FLOAT_CLASS, Types.REAL);
+ addTypeMapping(DOUBLE, DOUBLE_CLASS, Types.DOUBLE, Types.FLOAT);
+ addTypeMapping(BIGDECIMAL, BIGDECIMAL_CLASS, Types.NUMERIC, Types.DECIMAL);
+ addTypeMapping(BIGINTEGER, BIGINTEGER_CLASS, Types.NUMERIC, false);
+ addTypeMapping(BYTE, BYTE_CLASS, Types.TINYINT);
+ addTypeMapping(SHORT, SHORT_CLASS, Types.SMALLINT);
+ addTypeMapping(LONG, LONG_CLASS, Types.BIGINT);
+ addTypeMapping(OBJECT, OBJECT_CLASS, Types.JAVA_OBJECT);
+ addTypeMapping(CLOB, CLOB_CLASS, Types.CLOB);
+ addTypeMapping(BLOB, BLOB_CLASS, Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY);
+
+ addTypeMapping(NULL, null, Types.NULL);
+
+ //## JDBC4.0-begin ##
+ addTypeMapping(XML, XML_CLASS, Types.SQLXML);
+ TYPE_TO_NAME_MAP.put(Types.NVARCHAR, STRING);
+ TYPE_TO_NAME_MAP.put(Types.LONGNVARCHAR, STRING);
+ TYPE_TO_NAME_MAP.put(Types.NCHAR, CHAR);
+ TYPE_TO_NAME_MAP.put(Types.NCLOB, CLOB);
+ //## JDBC4.0-end ##
+
+ /*## JDBC3.0-JDK1.5-begin ##
+ NAME_TO_CLASSNAME.put(XML, OBJECT_CLASS);
+ ## JDBC3.0-JDK1.5-end ##*/
+ }
+
+ private static void addTypeMapping(String typeName, String javaClass, int sqlType, int ... secondaryTypes) {
+ addTypeMapping(typeName, javaClass, sqlType, true);
+ for (int type : secondaryTypes) {
+ TYPE_TO_NAME_MAP.put(type, typeName);
+ }
+ }
+
+ private static void addTypeMapping(String typeName, String javaClass, int sqlType, boolean preferedType) {
+ NAME_TO_TYPE_MAP.put(typeName, sqlType);
+ if (preferedType) {
+ TYPE_TO_NAME_MAP.put(sqlType, typeName);
+ }
+ if (javaClass != null) {
+ NAME_TO_CLASSNAME.put(typeName, javaClass);
+ CLASSNAME_TO_NAME.put(javaClass, typeName);
+ }
+ }
+
+ /**
+ * This method is used to obtain a short indicating JDBC SQL type for any object.
+ * The short values that give the type info are from java.sql.Types.
+ * @param Name of the metamatrix type.
+ * @return A short value representing SQL Type for the given java type.
+ */
+ public static final int getSQLType(String typeName) {
+
+ if (typeName == null) {
+ return Types.NULL;
+ }
+
+ Integer sqlType = NAME_TO_TYPE_MAP.get(typeName);
+
+ if (sqlType == null) {
+ return Types.JAVA_OBJECT;
+ }
+
+ return sqlType.intValue();
+ }
+
+ /**
+ * Get sql Type from java class type name. This should not be called with runtime types
+ * as Clob and Blob are represented by ClobType and BlobType respectively.
+ * @param typeName
+ * @return int
+ */
+ public static final int getSQLTypeFromClass(String className) {
+
+ if (className == null) {
+ return Types.NULL;
+ }
+
+ String name = CLASSNAME_TO_NAME.get(className);
+
+ if (name == null) {
+ return Types.JAVA_OBJECT;
+ }
+
+ return getSQLType(name);
+ }
+
+ /**
+ * Get the sql type from the given runtime type
+ * @param type
+ * @return
+ */
+ public static final int getSQLTypeFromRuntimeType(Class<?> type) {
+ if (type == null) {
+ return Types.NULL;
+ }
+
+ String name = DataTypeManager.getDataTypeName(type);
+
+ if (name == null) {
+ return Types.JAVA_OBJECT;
+ }
+
+ return getSQLType(name);
+ }
+
+ /**
+ * This method is used to obtain a the java class name given an int value
+ * indicating JDBC SQL type. The int values that give the type info are from
+ * java.sql.Types.
+ * @param int value giving the SQL type code.
+ * @return A String representing the java class name for the given SQL Type.
+ */
+ public static final String getJavaClassName(int jdbcSQLType) {
+ String className = NAME_TO_CLASSNAME.get(getTypeName(jdbcSQLType));
+
+ if (className == null) {
+ return OBJECT_CLASS;
+ }
+
+ return className;
+ }
+
+ public static final String getTypeName(int sqlType) {
+ String name = TYPE_TO_NAME_MAP.get(sqlType);
+
+ if (name == null) {
+ return OBJECT;
+ }
+
+ return name;
+ }
+
+ public static String[] getMMTypeNames() {
+ return new String[] {
+ STRING,
+ BOOLEAN,
+ TIME,
+ DATE,
+ TIMESTAMP,
+ INTEGER,
+ FLOAT,
+ DOUBLE,
+ BIGDECIMAL,
+ BIGINTEGER,
+ BYTE,
+ SHORT,
+ LONG,
+ CHAR,
+ OBJECT,
+ CLOB,
+ BLOB,
+ XML
+ };
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/LobSearchUtil.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/LobSearchUtil.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/LobSearchUtil.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/LobSearchUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,141 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.SQLException;
+
+import org.teiid.core.CorePlugin;
+
+
+public class LobSearchUtil {
+
+ private static final int MOD = 37;
+
+ public interface StreamProvider {
+
+ InputStream getBinaryStream() throws SQLException;
+
+ }
+
+ static long position(StreamProvider pattern, long patternLength, StreamProvider target, long targetLength, long start, int bytesPerComparison) throws SQLException {
+ if (pattern == null) {
+ return -1;
+ }
+
+ patternLength *= bytesPerComparison;
+ targetLength *= bytesPerComparison;
+
+ if (start < 1) {
+ Object[] params = new Object[] {new Long(start)};
+ throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.2", params)); //$NON-NLS-1$
+ }
+
+ start = (start - 1)*bytesPerComparison;
+
+ if (start + patternLength > targetLength) {
+ return -1;
+ }
+ /*
+ * Use karp-rabin matching to reduce the cost of back tracing for failed matches
+ *
+ * TODO: optimize for patterns that are small enough to fit in a reasonable buffer
+ */
+ try {
+ InputStream patternStream = pattern.getBinaryStream();
+ InputStream targetStream = target.getBinaryStream();
+ InputStream laggingTargetStream = target.getBinaryStream();
+ try {
+ int patternHash = computeStreamHash(patternStream, patternLength);
+ int lastMod = 1;
+ for (int i = 0; i < patternLength; i++) {
+ lastMod *= MOD;
+ }
+ targetStream.skip(start);
+ laggingTargetStream.skip(start);
+
+ long position = start + 1;
+
+ int streamHash = computeStreamHash(targetStream, patternLength);
+
+ do {
+ if ((position -1)%bytesPerComparison == 0 && patternHash == streamHash && validateMatch(pattern, target, position)) {
+ return (position - 1)/bytesPerComparison + 1;
+ }
+
+ streamHash = MOD * streamHash + targetStream.read() - lastMod * laggingTargetStream.read();
+ position++;
+
+ } while (position + patternLength - 1 <= targetLength);
+
+ return -1;
+ } finally {
+ if (patternStream != null) {
+ patternStream.close();
+ }
+ if (targetStream != null) {
+ targetStream.close();
+ }
+ if (laggingTargetStream != null) {
+ laggingTargetStream.close();
+ }
+ }
+ } catch (IOException e) {
+ throw new SQLException(e);
+ }
+ }
+
+ /**
+ * validate that the pattern matches the given position.
+ *
+ * TODO: optimize to reuse the same targetstream/buffer for small patterns
+ * @throws SQLException
+ */
+ static private boolean validateMatch(StreamProvider pattern, StreamProvider target, long position) throws IOException, SQLException {
+ InputStream targetStream = target.getBinaryStream();
+ InputStream patternStream = pattern.getBinaryStream();
+ try {
+ targetStream.skip(position -1);
+ int value = 0;
+ while ((value = patternStream.read()) != -1) {
+ if (value != targetStream.read()) {
+ return false;
+ }
+ }
+ } finally {
+ targetStream.close();
+ patternStream.close();
+ }
+ return true;
+ }
+
+ static private int computeStreamHash(InputStream is, long length) throws IOException {
+ int result = 0;
+ for (int i = 0; i < length; i++) {
+ result = result * MOD + is.read();
+ }
+ return result;
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/NullType.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/NullType.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/NullType.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/NullType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,29 @@
+/*
+ * 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.core.types;
+
+public final class NullType {
+
+ // can't construct
+ NullType() {}
+}
\ No newline at end of file
Copied: trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/SQLXMLImpl.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,115 @@
+/*
+ * 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.core.types;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.sql.SQLException;
+import java.sql.SQLXML;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.teiid.core.util.ObjectConverterUtil;
+import org.teiid.core.util.SqlUtil;
+
+
+
+/**
+ * Default SQLXML impl
+ */
+public class SQLXMLImpl extends BaseLob implements SQLXML {
+
+ public SQLXMLImpl() {
+
+ }
+
+ /**
+ * Constructs a SQLXML from bytes that are already encoded in {@link Streamable#ENCODING}
+ * @param bytes
+ */
+ public SQLXMLImpl(final byte[] bytes) {
+ super(new InputStreamFactory(Streamable.ENCODING) {
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return new ByteArrayInputStream(bytes);
+ }
+ });
+ }
+
+ public SQLXMLImpl(final String str) {
+ this(str.getBytes(Charset.forName(Streamable.ENCODING)));
+ }
+
+ public SQLXMLImpl(InputStreamFactory factory) {
+ super(factory);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException {
+ if (sourceClass == null || sourceClass == StreamSource.class) {
+ return (T)new StreamSource(getBinaryStream());
+ }
+ throw new SQLException("Unsupported source type " + sourceClass); //$NON-NLS-1$
+ }
+
+ public String getString() throws SQLException {
+ try {
+ return new String(ObjectConverterUtil.convertToByteArray(getBinaryStream()), this.getStreamFactory().getEncoding());
+ } catch (IOException e) {
+ SQLException ex = new SQLException(e.getMessage());
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+
+ public OutputStream setBinaryStream() throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public Writer setCharacterStream() throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public void setString(String value) throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+
+ public String toString() {
+ try {
+ return getString();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public <T extends Result> T setResult(Class<T> resultClass)
+ throws SQLException {
+ throw SqlUtil.createFeatureNotSupportedException();
+ }
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/Sequencable.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/Sequencable.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/Sequencable.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/Sequencable.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,31 @@
+/*
+ * 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.core.types;
+
+import java.sql.SQLException;
+
+public interface Sequencable {
+
+ public CharSequence getCharSequence() throws SQLException;
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/SourceTransform.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/SourceTransform.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/SourceTransform.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/SourceTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,37 @@
+/*
+ * 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.core.types;
+
+public interface SourceTransform<S, T> {
+
+ /**
+ * 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 T transform(S value);
+
+}
Property changes on: trunk/common-core/src/main/java/org/teiid/core/types/SourceTransform.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/common-core/src/main/java/org/teiid/core/types/StandardXMLTranslator.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/StandardXMLTranslator.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/StandardXMLTranslator.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/StandardXMLTranslator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,48 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+
+public class StandardXMLTranslator extends XMLTranslator {
+
+ private Source source;
+
+ public StandardXMLTranslator(Source source) {
+ this.source = source;
+ }
+
+ @Override
+ public void translate(Writer writer) throws TransformerException, IOException {
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ t.transform(source, new StreamResult(writer));
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/Streamable.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,103 @@
+/*
+ * 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.core.types;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.teiid.core.CorePlugin;
+
+
+
+/**
+ * A large value object which can be streamable in chunks of data each time
+ *
+ * <p>A reference stream id is tuple source id for a Streamble object where the
+ * object is in buffer manager, but the contents will never be written to disk;
+ * this is the ID that client needs to reference to get the chunk of data.
+ */
+public abstract class Streamable<T> implements Externalizable {
+
+ private static final long serialVersionUID = -8252488562134729374L;
+
+ public static final String ENCODING = "UTF-8"; //$NON-NLS-1$
+ public static final String FORCE_STREAMING = "FORCE_STREAMING"; //$NON-NLS-1$
+ public static final int STREAMING_BATCH_SIZE_IN_BYTES = 102400; // 100K
+
+ private String referenceStreamId;
+ protected transient T reference;
+ protected long length = -1;
+
+ public Streamable() {
+
+ }
+
+ public Streamable(T reference) {
+ if (reference == null) {
+ throw new IllegalArgumentException(CorePlugin.Util.getString("Streamable.isNUll")); //$NON-NLS-1$
+ }
+
+ this.reference = reference;
+ }
+
+ public long getLength() {
+ return length;
+ }
+
+ public T getReference() {
+ return reference;
+ }
+
+ public void setReference(T reference) {
+ this.reference = reference;
+ }
+
+ public String getReferenceStreamId() {
+ return this.referenceStreamId;
+ }
+
+ public void setReferenceStreamId(String id) {
+ this.referenceStreamId = id;
+ }
+
+ @Override
+ public String toString() {
+ return reference.toString();
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ length = in.readLong();
+ referenceStreamId = (String)in.readObject();
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeLong(length);
+ out.writeObject(referenceStreamId);
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/Transform.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/Transform.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/Transform.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/Transform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,116 @@
+/*
+ * 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.core.types;
+
+import org.teiid.core.CorePlugin;
+
+/**
+ * This interface represents the transformation from one data type to
+ * another. For instance, from java.lang.String to java.lang.Integer
+ * where java.lang.String is the the source type, "java.lang.String"
+ * is the source name, etc.
+ */
+public abstract class Transform {
+
+ /**
+ * 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 transform(Object value) throws TransformationException {
+ if (value == null) {
+ return null;
+ }
+ return transformDirect(value);
+ }
+
+
+ protected abstract Object transformDirect(Object value) throws TransformationException;
+
+ /**
+ * Type of the incoming value.
+ * @return Source type
+ */
+ public abstract Class<?> getSourceType();
+
+ /**
+ * Name of the source type.
+ * @return Name of source type
+ */
+ public String getSourceTypeName() {
+ return DataTypeManager.getDataTypeName(getSourceType());
+ }
+
+ /**
+ * Type of the outgoing value.
+ * @return Target type
+ */
+ public abstract Class<?> getTargetType();
+
+ /**
+ * Name of the target type.
+ * @return Name of target type
+ */
+ public String getTargetTypeName() {
+ return DataTypeManager.getDataTypeName(getTargetType());
+ }
+
+ /**
+ * Get nice display name for GUIs.
+ * @return Display name
+ */
+ public String getDisplayName() {
+ return getSourceTypeName() + " to " + getTargetTypeName(); //$NON-NLS-1$
+ }
+
+ /**
+ * Get description.
+ * @return Description of transform
+ */
+ public String getDescription() {
+ return getDisplayName();
+ }
+
+ public boolean isExplicit() {
+ return false;
+ }
+
+ /**
+ * Override Object.toString() to do getDisplayName() version.
+ * @return String representation of object
+ */
+ public String toString() {
+ return getDisplayName();
+ }
+
+ 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) {
+ throw new TransformationException(CorePlugin.Util.getString("transform.value_out_of_range", value, getSourceType().getSimpleName(), getTargetType().getSimpleName())); //$NON-NLS-1$
+ }
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/TransformationException.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/TransformationException.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/TransformationException.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/TransformationException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,80 @@
+/*
+ * 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.core.types;
+
+import org.teiid.core.TeiidProcessingException;
+
+/**
+ * The exception is thrown when an error occurs during data transformation,
+ * typically a formatting error or an invalid input type.
+ */
+public class TransformationException extends TeiidProcessingException {
+
+ /**
+ * No-Arg Constructor
+ */
+ public TransformationException( ) {
+ super( );
+ }
+ /**
+ * Construct an instance with the message specified.
+ *
+ * @param message A message describing the exception
+ */
+ public TransformationException( String message ) {
+ super( message );
+ }
+
+ /**
+ * Construct an instance with the message and error code specified.
+ *
+ * @param message A message describing the exception
+ * @param code The error code
+ */
+ public TransformationException( String code, String message ) {
+ super( code, message );
+ }
+
+ /**
+ * Construct an instance from a message and an exception to chain to this one.
+ *
+ * @param code A code denoting the exception
+ * @param e An exception to nest within this one
+ */
+ public TransformationException( Exception e, String message ) {
+ super( e, message );
+ }
+
+ /**
+ * Construct an instance from a message and a code and an exception to
+ * chain to this one.
+ *
+ * @param e An exception to nest within this one
+ * @param message A message describing the exception
+ * @param code A code denoting the exception
+ */
+ public TransformationException( Exception e, String code, String message ) {
+ super( e, code, message );
+ }
+}
+
Copied: trunk/common-core/src/main/java/org/teiid/core/types/XMLTranslator.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/XMLTranslator.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/XMLTranslator.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/XMLTranslator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,45 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.xml.transform.TransformerException;
+
+/**
+ * This an interface defined to convert the various kinds of the XML sources
+ * defined into a character stream.
+ */
+public abstract class XMLTranslator {
+
+ public abstract void translate(Writer writer) throws TransformerException, IOException;
+
+ public String getString() throws IOException, TransformerException {
+ StringWriter writer = new StringWriter();
+ this.translate(writer);
+ return writer.toString();
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/XMLType.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,109 @@
+/*
+ * 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.core.types;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.sql.SQLException;
+//## JDBC4.0-begin ##
+import java.sql.SQLXML;
+//## JDBC4.0-end ##
+
+/*## JDBC3.0-JDK1.5-begin ##
+import com.metamatrix.core.jdbc.SQLXML;
+## JDBC3.0-JDK1.5-end ##*/
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+
+/**
+ * This class represents the SQLXML object along with the Streamable interface. This is
+ * class used everywhere in the MetaMatrix framework, but clients are restricted to use
+ * only SQLXML interface on top of this.
+ */
+public final class XMLType extends Streamable<SQLXML> implements SQLXML {
+
+ public enum Type {
+ UNKNOWN, DOCUMENT, FRAGMENT, SIBLINGS, COMMENT, PI, TEXT
+ }
+
+ private static final long serialVersionUID = -7922647237095135723L;
+
+ private transient Type type = Type.UNKNOWN;
+
+ public XMLType(){
+
+ }
+
+ public XMLType(SQLXML xml) {
+ super(xml);
+ }
+
+ public InputStream getBinaryStream() throws SQLException {
+ return this.reference.getBinaryStream();
+ }
+
+ public Reader getCharacterStream() throws SQLException {
+ return this.reference.getCharacterStream();
+ }
+
+ public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException {
+ return this.reference.getSource(sourceClass);
+ }
+
+ public String getString() throws SQLException {
+ return this.reference.getString();
+ }
+
+ public OutputStream setBinaryStream() throws SQLException {
+ return this.reference.setBinaryStream();
+ }
+
+ public Writer setCharacterStream() throws SQLException {
+ return this.reference.setCharacterStream();
+ }
+
+ public void setString(String value) throws SQLException {
+ this.reference.setString(value);
+ }
+
+ public void free() throws SQLException {
+ this.reference.free();
+ }
+
+ public <T extends Result> T setResult(Class<T> resultClass)
+ throws SQLException {
+ return this.reference.setResult(resultClass);
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/types/basic (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/types/basic)
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/AnyToObjectTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToObjectTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class AnyToObjectTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToStringTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/AnyToStringTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/AnyToStringTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
/**
* This class can be subclassed to do a simple anything-->String by
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/BigDecimalToBigIntegerTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/BigDecimalToBigIntegerTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/BigDecimalToBigIntegerTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigDecimal;
import java.math.BigInteger;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class BigDecimalToBigIntegerTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/BigIntegerToBigDecimalTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/BigIntegerToBigDecimalTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/BigIntegerToBigDecimalTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigDecimal;
import java.math.BigInteger;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class BigIntegerToBigDecimalTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/BooleanToNumberTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/BooleanToNumberTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/BooleanToNumberTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class BooleanToNumberTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/ClobToSQLXMLTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToSQLXMLTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/ClobToSQLXMLTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.io.IOException;
import java.io.InputStream;
@@ -28,19 +28,20 @@
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.types.XMLType.Type;
-import com.metamatrix.common.util.ReaderInputStream;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.ClobImpl;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.InputStreamFactory;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.Streamable;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.types.XMLType.Type;
+import org.teiid.core.util.ReaderInputStream;
+
public class ClobToSQLXMLTransform extends Transform {
@Override
@@ -99,7 +100,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/ClobToStringTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ClobToStringTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/ClobToStringTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,18 +20,19 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.io.BufferedReader;
import java.io.IOException;
import java.sql.SQLException;
-import com.metamatrix.common.types.ClobType;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
+
public class ClobToStringTransform extends AnyToStringTransform {
public ClobToStringTransform() {
@@ -69,7 +70,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/DateToTimestampTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/DateToTimestampTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/DateToTimestampTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Timestamp;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class DateToTimestampTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/FixedNumberToBigDecimalTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/FixedNumberToBigDecimalTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/FixedNumberToBigDecimalTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigDecimal;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class FixedNumberToBigDecimalTransform extends Transform {
private Class<?> sourceType;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/FixedNumberToBigIntegerTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/FixedNumberToBigIntegerTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/FixedNumberToBigIntegerTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigInteger;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class FixedNumberToBigIntegerTransform extends Transform {
private Class<?> sourceType;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/FloatingNumberToBigDecimalTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/FloatingNumberToBigDecimalTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/FloatingNumberToBigDecimalTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigDecimal;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class FloatingNumberToBigDecimalTransform extends Transform {
private Class<?> sourceType;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/FloatingNumberToBigIntegerTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/FloatingNumberToBigIntegerTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/FloatingNumberToBigIntegerTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigDecimal;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class FloatingNumberToBigIntegerTransform extends Transform {
private Class<?> sourceType;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NullToAnyTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NullToAnyTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NullToAnyTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.NullType;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.util.Assertion;
+import org.teiid.core.types.NullType;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.util.Assertion;
/**
* This class can do a simple null-->anything.
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToBooleanTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToBooleanTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToBooleanTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToBooleanTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToByteTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToByteTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToByteTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToByteTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToDoubleTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToDoubleTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToDoubleTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToDoubleTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToFloatTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToFloatTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToFloatTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToFloatTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToIntegerTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToIntegerTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToIntegerTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToIntegerTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToLongTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToLongTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToLongTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToLongTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToShortTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/NumberToShortTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/NumberToShortTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class NumberToShortTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/ObjectToAnyTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/ObjectToAnyTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/ObjectToAnyTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class ObjectToAnyTransform extends Transform {
@@ -68,7 +68,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/SQLXMLToClobTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToClobTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/SQLXMLToClobTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,25 +20,26 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.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;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.ClobImpl;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.InputStreamFactory;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.Streamable;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.util.ReaderInputStream;
+
public class SQLXMLToClobTransform extends Transform {
@Override
@@ -83,7 +84,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/SQLXMLToStringTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/SQLXMLToStringTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/SQLXMLToStringTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,18 +20,19 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
+
public class SQLXMLToStringTransform extends AnyToStringTransform {
public SQLXMLToStringTransform() {
@@ -69,7 +70,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBigDecimalTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToBigDecimalTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBigDecimalTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,16 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigDecimal;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class StringToBigDecimalTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBigIntegerTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToBigIntegerTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBigIntegerTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,16 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.math.BigInteger;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class StringToBigIntegerTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBooleanTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToBooleanTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToBooleanTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,16 +20,17 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
+
public class StringToBooleanTransform extends Transform {
private static final Set<String> FALSE = new HashSet<String>(Arrays.asList("0", "false")); //$NON-NLS-1$ //$NON-NLS-2$
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToByteTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToByteTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToByteTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToByteTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToCharacterTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToCharacterTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToCharacterTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,10 +20,10 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToCharacterTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToClobTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToClobTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToClobTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.ClobType;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToClobTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToDateTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToDateTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToDateTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,16 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Date;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class StringToDateTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToDoubleTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToDoubleTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToDoubleTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToDoubleTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToFloatTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToFloatTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToFloatTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToFloatTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToIntegerTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToIntegerTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToIntegerTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToIntegerTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToLongTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToLongTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToLongTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToLongTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToSQLXMLTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.io.IOException;
import java.io.Reader;
@@ -30,14 +30,15 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.XMLEvent;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.SQLXMLImpl;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.common.types.XMLType.Type;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.types.XMLType.Type;
+
public class StringToSQLXMLTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToShortTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToShortTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToShortTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
public class StringToShortTransform extends Transform {
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToTimeTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToTimeTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToTimeTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,16 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Time;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class StringToTimeTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToTimestampTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/StringToTimestampTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToTimestampTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,16 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Timestamp;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.ErrorMessageKeys;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.ErrorMessageKeys;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class StringToTimestampTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/TimeToTimestampTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/TimeToTimestampTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/TimeToTimestampTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Timestamp;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
public class TimeToTimestampTransform extends Transform {
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/TimestampToDateTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/TimestampToDateTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/TimestampToDateTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,16 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Timestamp;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.util.TimestampWithTimezone;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.util.TimestampWithTimezone;
+
public class TimestampToDateTransform extends Transform {
/**
@@ -60,7 +61,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/TimestampToTimeTransform.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/basic/TimestampToTimeTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/TimestampToTimeTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,14 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import java.sql.Timestamp;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.util.TimestampWithTimezone;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.util.TimestampWithTimezone;
+
public class TimestampToTimeTransform extends Transform {
/**
@@ -59,7 +60,7 @@
}
/**
- * @see com.metamatrix.common.types.Transform#isExplicit()
+ * @see org.teiid.core.types.Transform#isExplicit()
*/
public boolean isExplicit() {
return true;
Copied: trunk/common-core/src/main/java/org/teiid/core/util (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/core/util)
Modified: trunk/common-core/src/main/java/org/teiid/core/util/AccessibleByteArrayOutputStream.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/AccessibleByteArrayOutputStream.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/AccessibleByteArrayOutputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.ByteArrayOutputStream;
Copied: trunk/common-core/src/main/java/org/teiid/core/util/ApplicationInfo.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/ApplicationInfo.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/ApplicationInfo.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ApplicationInfo.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,210 @@
+/*
+ * 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.core.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URL;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.teiid.core.TeiidRuntimeException;
+
+
+public final class ApplicationInfo implements Serializable {
+
+ public static final String APPLICATION_PRODUCT_INFORMATION = "Product Information"; //$NON-NLS-1$
+
+ public static final String APPLICATION_BUILD_NUMBER_PROPERTY = "Build"; //$NON-NLS-1$
+
+ private static final ApplicationInfo INSTANCE = new ApplicationInfo();
+
+ private static final String LINE_SEPARATOR = "\n"; //$NON-NLS-1$
+
+ private Properties props = new Properties();
+
+ private ApplicationInfo() {
+ InputStream is = this.getClass().getResourceAsStream("application.properties"); //$NON-NLS-1$
+ try {
+ try {
+ props.load(is);
+ } finally {
+ is.close();
+ }
+ } catch (IOException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ public String getReleaseNumber() {
+ return props.getProperty("build.releaseNumber"); //$NON-NLS-1$
+ }
+
+ public String getMajorReleaseNumber() {
+ return getReleaseNumber().substring(0, getReleaseNumber().lastIndexOf('.'));
+ }
+
+ public int getMajorReleaseVersion() {
+ String version = getReleaseNumber().substring(0, getReleaseNumber().indexOf('.'));
+ return Integer.parseInt(version);
+ }
+
+ public int getMinorReleaseVersion() {
+ int majorIndex = getReleaseNumber().indexOf('.');
+ String version = getReleaseNumber().substring(majorIndex+1, getReleaseNumber().indexOf('.', majorIndex+1));
+ return Integer.parseInt(version);
+ }
+
+ public String getBuildNumber() {
+ return props.getProperty("build.number"); //$NON-NLS-1$
+ }
+
+ public String getUrl() {
+ return props.getProperty("url"); //$NON-NLS-1$
+ }
+
+ public String getCopyright() {
+ return props.getProperty("copyright"); //$NON-NLS-1$
+ }
+
+ public String getBuildDate() {
+ return props.getProperty("build.date"); //$NON-NLS-1$
+ }
+
+ /**
+ * Get the application information instance for this VM.
+ * @return the singleton instance for this VM; never null
+ */
+ public static ApplicationInfo getInstance() {
+ return INSTANCE;
+ }
+
+ private static String getClassPath() {
+ return System.getProperty( "java.class.path" ); //$NON-NLS-1$
+ }
+
+ /**
+ * The getClasspathInfo method is used to capture the current classpath
+ * information. The initial intent is to write this information
+ * to a file at VM startup time for debugging purposes and ensuring
+ * patches are applied.
+ * @param outputstream
+ * @since 4.2
+ */
+ public String getClasspathInfo() {
+ String classPath = getClassPath();
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("\nDate: " + DateFormat.getDateInstance().format(new Date()));//$NON-NLS-1$
+ sb.append( LINE_SEPARATOR );
+
+ Map pathResults = new HashMap();
+ List reversetList = new ArrayList();
+ String separator = System.getProperty( "path.separator" ); //$NON-NLS-1$
+
+ StringTokenizer path = new StringTokenizer( classPath, separator );
+
+ while(path.hasMoreTokens()){
+ String pathElement = path.nextToken();
+ File pathFile = new File( pathElement );
+ if (pathFile.exists()) {
+// if (resourceExistInClassPath(pathElement)) {
+ pathResults.put(pathElement, Boolean.TRUE);
+
+ } else {
+ pathResults.put(pathElement, Boolean.FALSE);
+ }
+ reversetList.add(pathElement);
+ }
+ sb.append("Classpath Information" ); //$NON-NLS-1$
+ sb.append( LINE_SEPARATOR );
+ sb.append("CLASSPATH: "); //$NON-NLS-1$
+ sb.append(classPath);
+ sb.append( LINE_SEPARATOR );
+ sb.append( LINE_SEPARATOR );
+
+ Iterator iter = reversetList.iterator();
+ sb.append("---- Classpath Entries ----"); //$NON-NLS-1$
+ sb.append( LINE_SEPARATOR );
+ while ( iter.hasNext() ) {
+ String epath = (String) iter.next();
+ Boolean doesExist = (Boolean) pathResults.get(epath);
+ sb.append(epath);
+ if (!doesExist.booleanValue()) {
+ sb.append(" (MISSING)");//$NON-NLS-1$
+ }
+ sb.append( LINE_SEPARATOR );
+
+ }
+
+
+ sb.append( LINE_SEPARATOR );
+ sb.append("Note the (MISSING) at the end to designate that the classpath entry is missing");//$NON-NLS-1$
+
+
+ try {
+ // find all the patch readme files and print those out.
+ Enumeration readmes = ClassLoader.getSystemResources("patch_readme.txt"); //$NON-NLS-1$
+ sb.append( LINE_SEPARATOR );
+ sb.append( LINE_SEPARATOR );
+
+ sb.append("---- Patch Readme Entries----"); //$NON-NLS-1$
+ sb.append( LINE_SEPARATOR );
+ int cnt = 0;
+ if (readmes != null) {
+
+ while(readmes.hasMoreElements()) {
+ ++cnt;
+ URL url = (URL) readmes.nextElement();
+ sb.append("Patch " + url.getFile() + ":"); //$NON-NLS-1$ //$NON-NLS-2$
+ sb.append( LINE_SEPARATOR );
+ InputStream is = url.openStream();
+ byte[] data = ObjectConverterUtil.convertToByteArray(is);
+ sb.append(new String(data));
+ sb.append("-------------------------------------");//$NON-NLS-1$
+ sb.append( LINE_SEPARATOR );
+ is.close();
+
+ }
+ }
+ if (cnt == 0) {
+ sb.append("no Patch Readme Entries found"); //$NON-NLS-1$
+ }
+ } catch (IOException ioe) {
+
+ }
+
+ return sb.toString();
+ }
+
+}
Property changes on: trunk/common-core/src/main/java/org/teiid/core/util/ApplicationInfo.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/common-core/src/main/java/org/teiid/core/util/ArgCheck.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ArgCheck.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ArgCheck.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.Collection;
import java.util.Map;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+
/**
* This class contains a set of static utility methods for checking method arguments.
* It contains many of the common checks that are done, such as checking that an
Modified: trunk/common-core/src/main/java/org/teiid/core/util/Assertion.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/Assertion.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/Assertion.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.Collection;
import java.util.Map;
-import com.metamatrix.core.CorePlugin;
+import org.teiid.core.CorePlugin;
+
/**
* <p>
* This class contains a set of static utility methods for assertion checking.
Modified: trunk/common-core/src/main/java/org/teiid/core/util/Base64.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/Base64.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/Base64.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
/**
* <p>Encodes and decodes to and from Base64 notation.</p>
Modified: trunk/common-core/src/main/java/org/teiid/core/util/EquivalenceUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/EquivalenceUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/EquivalenceUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.Arrays;
Added: trunk/common-core/src/main/java/org/teiid/core/util/ExceptionUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/ExceptionUtil.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ExceptionUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,245 @@
+/*
+ * 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.core.util;
+
+import java.io.PrintStream;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.naming.ConfigurationException;
+
+import org.teiid.core.TeiidRuntimeException;
+
+
+/**
+ * Utility class that provides some useful things for users of the
+ * com.metamatrix.api.exception package. Also provides package-level
+ * functionality that is shared among classes in this package.
+ */
+public class ExceptionUtil {
+
+ /**
+ * Prevent instantiation
+ */
+ private ExceptionUtil() {
+ super();
+ }
+
+ /**
+ * Convenience method that takes any Throwable and returns an appropriate
+ * Iterator over any nested exceptions in that Throwable. Currently,
+ * only instances of MetaMatrixException and MetaMatrixRuntimeException
+ * are capable of nesting Throwables - calling this method in that case
+ * is equivalent to calling
+ * {@link TeiidException#getChildren MetaMatrixException.getChildren()}
+ * or
+ * {@link TeiidRuntimeException#getChildren MetaMatrixRuntimeException.getChildren()}.
+ * Otherwise, a non-null "empty" Iterator is returned, one that simply has
+ * no Objects in it.
+ * @param e any Throwable
+ * @return an appropriate Iterator over any nested children Throwables;
+ */
+ public static Iterator getChildrenIterator(Throwable e){
+ return new NestedExceptionIterator(e);
+ }
+
+ public static void printNestedStackTrace(Throwable exception, PrintStream output) {
+ if (exception != null){
+ exception.printStackTrace(output);
+
+ Iterator children = getChildrenIterator(exception);
+ while ( children.hasNext() ){
+ exception = (Throwable)children.next();
+ output.print(TeiidRuntimeException.CAUSED_BY_STRING);
+ exception.printStackTrace(output);
+ }
+ }
+ }
+
+ public static String getLinkedMessagesVerbose(Throwable exception) {
+ return getLinkedMessagesVerbose(exception, 0);
+ }
+
+ public static String getLinkedMessagesVerbose( Throwable exception, int level ) {
+ if (exception != null){
+ StringBuffer buf = new StringBuffer();
+ String lastMessage = appendMessage("", buf, null, exception); //$NON-NLS-1$
+ Iterator children = getChildrenIterator(exception);
+ while ( children.hasNext() ){
+ level++;
+ exception = (Throwable)children.next();
+ lastMessage = appendMessage("->", buf, lastMessage, exception); //$NON-NLS-1$
+ }
+ return buf.toString();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public static String getLinkedMessages(Throwable exception) {
+ return getLinkedMessages(exception, 0);
+ }
+
+ /**
+ * Get the chain of messages, starting with the specified exception. The
+ * level number in the chain is prepended. <P>
+ *
+ * This method calls the <CODE>getMessage</CODE> method for the exception
+ * passed in, and appends on the result returned from a recursive call to
+ * this method for the child of the passed in exception. The passed in
+ * exception is updated on each recursive call to be the child of the
+ * original exception, and the level is incremented on each call.
+ *
+ * @param exception The exception to print the chained message list of
+ * @param level (zero-based) The depth of the exception parameter in
+ * the chain of exceptions.
+ * @param messageFormatter the formatter of the message; may not be null
+ * @return A string of chained messages, each prepended by its level
+ * in the chain, and each followed by a newline (blank string if
+ * the exception passed in is null)
+ *
+ * @see Throwable#getMessage()
+ */
+ public static String getLinkedMessages( Throwable exception, int level ) {
+ if (exception != null){
+ StringBuffer buf = new StringBuffer();
+ buf.append(exception.getMessage());
+ Iterator children = getChildrenIterator(exception);
+ while ( children.hasNext() ){
+ level++;
+ exception = (Throwable)children.next();
+ buf.append(exception.getMessage());
+ }
+ return buf.toString();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private static final String appendMessage(String prefix, StringBuffer buffer, String lastMessage, Throwable exception) {
+ String message = exception.getMessage();
+ buffer.append(prefix);
+ buffer.append(getClassName(exception));
+ if (message != null && !message.equals(lastMessage)) {
+ buffer.append('-');
+ buffer.append(message);
+ }
+ return message;
+ }
+
+ private static final String getClassName(Throwable exception) {
+ String className = exception.getClass().getName();
+ int index = className.lastIndexOf('.');
+ if (index >= 0 && index < className.length()-1) {
+ return className.substring(index+1);
+ }
+ return className;
+ }
+
+ /**
+ * <p>An Iterator over any nested children <code>Throwable</code>s
+ * of either a MetaMatrixException or a MetaMatrixRuntimeException.
+ * The first Object returned (if any) by <code>next()</code> will be the same
+ * <code>Throwable</code> as returned by the {@link #getChild} method of
+ * the root</p>
+ *
+ * <p>In general, each Object A returned by the <code>next()</code>
+ * method is guaranteed to be an instance of
+ * <code>Throwable</code>; the <i>previous</i> Object B will have been a
+ * <code>MetaMatrixException</code> or <code>MetaMatrixRuntimeException</code>
+ * whose {@link #getChild} method will return the same Object A.</p>
+ */
+ public static class NestedExceptionIterator implements Iterator{
+
+ Throwable exception;
+ Throwable child;
+
+ public NestedExceptionIterator(Throwable e){
+ exception = e;
+ }
+
+ /**
+ * Returns <tt>true</tt> if the iteration has more elements. (In other
+ * words, returns <tt>true</tt> if <tt>next</tt> would return an element
+ * rather than throwing an exception.)
+ *
+ * @return <tt>true</tt> if the iterator has more elements.
+ */
+ public boolean hasNext(){
+ check();
+ return (child != null);
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ *
+ * @return the next element in the iteration.
+ * @exception NoSuchElementException iteration has no more elements.
+ */
+ public Object next(){
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ exception = child;
+ child = null;
+ return exception;
+ }
+
+ private void check(){
+ if (child == null){
+ if (exception instanceof ConfigurationException) {
+ ConfigurationException e = (ConfigurationException) exception;
+ child = e.getRootCause();
+ } else if (exception instanceof SQLException) {
+ SQLException e = (SQLException) exception;
+ child = e.getNextException();
+ }
+ if (child == null) {
+ child = exception.getCause();
+ }
+ if (child == exception) {
+ child = null;
+ }
+ }
+ }
+
+ /**
+ *
+ * Removes from the underlying collection the last element returned by the
+ * iterator (optional operation). This method can be called only once per
+ * call to <tt>next</tt>. The behavior of an iterator is unspecified if
+ * the underlying collection is modified while the iteration is in
+ * progress in any way other than by calling this method.
+ *
+ * @exception UnsupportedOperationException if the <tt>remove</tt>
+ * operation is not supported by this Iterator.
+
+ * @exception IllegalStateException if the <tt>next</tt> method has not
+ * yet been called, or the <tt>remove</tt> method has already
+ * been called after the last call to the <tt>next</tt>
+ * method.
+ */
+ public void remove(){
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ExternalizeUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ExternalizeUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.IOException;
import java.io.ObjectInput;
Modified: trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/FileUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/FileUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -34,8 +34,9 @@
import java.io.Reader;
import java.io.StringWriter;
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import org.teiid.core.TeiidRuntimeException;
+
/**
* Utility class for dealing with files. Hides exception handling and file resource management.
*/
@@ -54,7 +55,7 @@
try {
return new FileWriter(this.file, append);
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
}
}
@@ -70,7 +71,7 @@
}
}
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
}
}
@@ -97,9 +98,9 @@
}
}
} catch (FileNotFoundException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
}
}
@@ -107,7 +108,7 @@
try {
return readSafe();
} catch (FileNotFoundException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
}
}
@@ -140,7 +141,7 @@
writer.write(StringUtil.LINE_SEPARATOR);
}
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
} finally {
if (bufferedReader != null) {
try {
@@ -156,9 +157,9 @@
try {
return readBytesSafe();
} catch (FileNotFoundException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
}
}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/FileUtils.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -36,11 +36,12 @@
import java.util.ArrayList;
import java.util.List;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+
public final class FileUtils {
public interface Constants {
@@ -169,7 +170,7 @@
* @param fromFileName
* @param toFileName
* @param overwrite whether to overwrite the destination file if it exists.
- * @throws MetaMatrixCoreException
+ * @throws TeiidException
* @since 4.3
*/
public static void copy(String fromFileName, String toFileName, boolean overwrite) throws IOException {
@@ -669,7 +670,7 @@
os.write(contents);
return temp;
} catch (Exception e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
} finally {
if (os != null) {
try {
@@ -752,10 +753,10 @@
/**
* Test whether it's possible to read and write files in the specified directory.
* @param dirPath Name of the directory to test
- * @throws MetaMatrixException
+ * @throws TeiidException
* @since 4.3
*/
- public static void testDirectoryPermissions(String dirPath) throws MetaMatrixCoreException {
+ public static void testDirectoryPermissions(String dirPath) throws TeiidException {
//try to create a file
File tmpFile = new File(dirPath + File.separatorChar + TEMP_FILE);
@@ -766,20 +767,20 @@
}
if (!success) {
final String msg = CorePlugin.Util.getString("FileUtils.Unable_to_create_file_in", dirPath); //$NON-NLS-1$
- throw new MetaMatrixCoreException(msg);
+ throw new TeiidException(msg);
}
//test if file can be written to
if (!tmpFile.canWrite()) {
final String msg = CorePlugin.Util.getString("FileUtils.Unable_to_write_file_in", dirPath); //$NON-NLS-1$
- throw new MetaMatrixCoreException(msg);
+ throw new TeiidException(msg);
}
//test if file can be read
if (!tmpFile.canRead()) {
final String msg = CorePlugin.Util.getString("FileUtils.Unable_to_read_file_in", dirPath); //$NON-NLS-1$
- throw new MetaMatrixCoreException(msg);
+ throw new TeiidException(msg);
}
//test if file can be renamed
@@ -791,7 +792,7 @@
}
if (!success) {
final String msg = CorePlugin.Util.getString("FileUtils.Unable_to_rename_file_in", dirPath); //$NON-NLS-1$
- throw new MetaMatrixCoreException(msg);
+ throw new TeiidException(msg);
}
//test if file can be deleted
@@ -802,7 +803,7 @@
}
if (!success) {
final String msg = CorePlugin.Util.getString("FileUtils.Unable_to_delete_file_in", dirPath); //$NON-NLS-1$
- throw new MetaMatrixCoreException(msg);
+ throw new TeiidException(msg);
}
}
@@ -811,7 +812,7 @@
* @param oldFilePath
* @param newFilePath
* @param overwrite If true, overwrite the old file if it exists. If false, throw an exception if the old file exists.
- * @throws MetaMatrixCoreException
+ * @throws TeiidException
* @since 4.3
*/
public static void rename(String oldFilePath, String newFilePath, boolean overwrite) throws IOException {
Modified: trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/HashCodeUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/HashCodeUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.Iterator;
import java.util.List;
Modified: trunk/common-core/src/main/java/org/teiid/core/util/LRUCache.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/LRUCache.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/LRUCache.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
Deleted: trunk/common-core/src/main/java/org/teiid/core/util/MetaMatrixExceptionUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/MetaMatrixExceptionUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/MetaMatrixExceptionUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,244 +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 com.metamatrix.core.util;
-
-import java.io.PrintStream;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import javax.naming.ConfigurationException;
-
-import com.metamatrix.core.MetaMatrixRuntimeException;
-
-/**
- * Utility class that provides some useful things for users of the
- * com.metamatrix.api.exception package. Also provides package-level
- * functionality that is shared among classes in this package.
- */
-public class MetaMatrixExceptionUtil {
-
- /**
- * Prevent instantiation
- */
- private MetaMatrixExceptionUtil() {
- super();
- }
-
- /**
- * Convenience method that takes any Throwable and returns an appropriate
- * Iterator over any nested exceptions in that Throwable. Currently,
- * only instances of MetaMatrixException and MetaMatrixRuntimeException
- * are capable of nesting Throwables - calling this method in that case
- * is equivalent to calling
- * {@link MetaMatrixException#getChildren MetaMatrixException.getChildren()}
- * or
- * {@link MetaMatrixRuntimeException#getChildren MetaMatrixRuntimeException.getChildren()}.
- * Otherwise, a non-null "empty" Iterator is returned, one that simply has
- * no Objects in it.
- * @param e any Throwable
- * @return an appropriate Iterator over any nested children Throwables;
- */
- public static Iterator getChildrenIterator(Throwable e){
- return new NestedExceptionIterator(e);
- }
-
- public static void printNestedStackTrace(Throwable exception, PrintStream output) {
- if (exception != null){
- exception.printStackTrace(output);
-
- Iterator children = getChildrenIterator(exception);
- while ( children.hasNext() ){
- exception = (Throwable)children.next();
- output.print(MetaMatrixRuntimeException.CAUSED_BY_STRING);
- exception.printStackTrace(output);
- }
- }
- }
-
- public static String getLinkedMessagesVerbose(Throwable exception) {
- return getLinkedMessagesVerbose(exception, 0);
- }
-
- public static String getLinkedMessagesVerbose( Throwable exception, int level ) {
- if (exception != null){
- StringBuffer buf = new StringBuffer();
- String lastMessage = appendMessage("", buf, null, exception); //$NON-NLS-1$
- Iterator children = getChildrenIterator(exception);
- while ( children.hasNext() ){
- level++;
- exception = (Throwable)children.next();
- lastMessage = appendMessage("->", buf, lastMessage, exception); //$NON-NLS-1$
- }
- return buf.toString();
- }
- return ""; //$NON-NLS-1$
- }
-
- public static String getLinkedMessages(Throwable exception) {
- return getLinkedMessages(exception, 0);
- }
-
- /**
- * Get the chain of messages, starting with the specified exception. The
- * level number in the chain is prepended. <P>
- *
- * This method calls the <CODE>getMessage</CODE> method for the exception
- * passed in, and appends on the result returned from a recursive call to
- * this method for the child of the passed in exception. The passed in
- * exception is updated on each recursive call to be the child of the
- * original exception, and the level is incremented on each call.
- *
- * @param exception The exception to print the chained message list of
- * @param level (zero-based) The depth of the exception parameter in
- * the chain of exceptions.
- * @param messageFormatter the formatter of the message; may not be null
- * @return A string of chained messages, each prepended by its level
- * in the chain, and each followed by a newline (blank string if
- * the exception passed in is null)
- *
- * @see Throwable#getMessage()
- */
- public static String getLinkedMessages( Throwable exception, int level ) {
- if (exception != null){
- StringBuffer buf = new StringBuffer();
- buf.append(exception.getMessage());
- Iterator children = getChildrenIterator(exception);
- while ( children.hasNext() ){
- level++;
- exception = (Throwable)children.next();
- buf.append(exception.getMessage());
- }
- return buf.toString();
- }
- return ""; //$NON-NLS-1$
- }
-
- private static final String appendMessage(String prefix, StringBuffer buffer, String lastMessage, Throwable exception) {
- String message = exception.getMessage();
- buffer.append(prefix);
- buffer.append(getClassName(exception));
- if (message != null && !message.equals(lastMessage)) {
- buffer.append('-');
- buffer.append(message);
- }
- return message;
- }
-
- private static final String getClassName(Throwable exception) {
- String className = exception.getClass().getName();
- int index = className.lastIndexOf('.');
- if (index >= 0 && index < className.length()-1) {
- return className.substring(index+1);
- }
- return className;
- }
-
- /**
- * <p>An Iterator over any nested children <code>Throwable</code>s
- * of either a MetaMatrixException or a MetaMatrixRuntimeException.
- * The first Object returned (if any) by <code>next()</code> will be the same
- * <code>Throwable</code> as returned by the {@link #getChild} method of
- * the root</p>
- *
- * <p>In general, each Object A returned by the <code>next()</code>
- * method is guaranteed to be an instance of
- * <code>Throwable</code>; the <i>previous</i> Object B will have been a
- * <code>MetaMatrixException</code> or <code>MetaMatrixRuntimeException</code>
- * whose {@link #getChild} method will return the same Object A.</p>
- */
- public static class NestedExceptionIterator implements Iterator{
-
- Throwable exception;
- Throwable child;
-
- public NestedExceptionIterator(Throwable e){
- exception = e;
- }
-
- /**
- * Returns <tt>true</tt> if the iteration has more elements. (In other
- * words, returns <tt>true</tt> if <tt>next</tt> would return an element
- * rather than throwing an exception.)
- *
- * @return <tt>true</tt> if the iterator has more elements.
- */
- public boolean hasNext(){
- check();
- return (child != null);
- }
-
- /**
- * Returns the next element in the iteration.
- *
- * @return the next element in the iteration.
- * @exception NoSuchElementException iteration has no more elements.
- */
- public Object next(){
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
- exception = child;
- child = null;
- return exception;
- }
-
- private void check(){
- if (child == null){
- if (exception instanceof ConfigurationException) {
- ConfigurationException e = (ConfigurationException) exception;
- child = e.getRootCause();
- } else if (exception instanceof SQLException) {
- SQLException e = (SQLException) exception;
- child = e.getNextException();
- }
- if (child == null) {
- child = exception.getCause();
- }
- if (child == exception) {
- child = null;
- }
- }
- }
-
- /**
- *
- * Removes from the underlying collection the last element returned by the
- * iterator (optional operation). This method can be called only once per
- * call to <tt>next</tt>. The behavior of an iterator is unspecified if
- * the underlying collection is modified while the iteration is in
- * progress in any way other than by calling this method.
- *
- * @exception UnsupportedOperationException if the <tt>remove</tt>
- * operation is not supported by this Iterator.
-
- * @exception IllegalStateException if the <tt>next</tt> method has not
- * yet been called, or the <tt>remove</tt> method has already
- * been called after the last call to the <tt>next</tt>
- * method.
- */
- public void remove(){
- throw new UnsupportedOperationException();
- }
- }
-}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/MixinProxy.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/MixinProxy.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/MixinProxy.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
Modified: trunk/common-core/src/main/java/org/teiid/core/util/NamedThreadFactory.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/NamedThreadFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/NamedThreadFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
Modified: trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectConverterUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -38,14 +38,15 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.MetaMatrixCoreException;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.TeiidException;
+
public class ObjectConverterUtil {
private static final int DEFAULT_READING_SIZE = 8192;
- protected static byte[] convertBlobToByteArray(final java.sql.Blob data) throws MetaMatrixCoreException {
+ protected static byte[] convertBlobToByteArray(final java.sql.Blob data) throws TeiidException {
try {
// Open a stream to read the BLOB data
InputStream l_blobStream = data.getBinaryStream();
@@ -69,14 +70,14 @@
} catch (IOException ioe) {
final Object[] params = new Object[]{data.getClass().getName()};
- throw new MetaMatrixCoreException(ioe,CorePlugin.Util.getString("ObjectConverterUtil.Error_translating_results_from_data_type_to_a_byte[]._1",params)); //$NON-NLS-1$
+ throw new TeiidException(ioe,CorePlugin.Util.getString("ObjectConverterUtil.Error_translating_results_from_data_type_to_a_byte[]._1",params)); //$NON-NLS-1$
} catch (SQLException sqe) {
final Object[] params = new Object[]{data.getClass().getName()};
- throw new MetaMatrixCoreException(sqe,CorePlugin.Util.getString("ObjectConverterUtil.Error_translating_results_from_data_type_to_a_byte[]._2",params)); //$NON-NLS-1$
+ throw new TeiidException(sqe,CorePlugin.Util.getString("ObjectConverterUtil.Error_translating_results_from_data_type_to_a_byte[]._2",params)); //$NON-NLS-1$
}
}
- public static byte[] convertToByteArray(final Object data) throws MetaMatrixCoreException, IOException {
+ public static byte[] convertToByteArray(final Object data) throws TeiidException, IOException {
if (data instanceof InputStream) {
return convertToByteArray((InputStream) data);
} else if (data instanceof byte[]) {
@@ -87,7 +88,7 @@
return convertFileToByteArray((File)data);
}
final Object[] params = new Object[]{data.getClass().getName()};
- throw new MetaMatrixCoreException(CorePlugin.Util.getString("ObjectConverterUtil.Object_type_not_supported_for_object_conversion._3",params)); //$NON-NLS-1$
+ throw new TeiidException(CorePlugin.Util.getString("ObjectConverterUtil.Object_type_not_supported_for_object_conversion._3",params)); //$NON-NLS-1$
}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/ObjectInputStreamWithClassloader.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ObjectInputStreamWithClassloader.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ObjectInputStreamWithClassloader.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.IOException;
import java.io.InputStream;
Copied: trunk/common-core/src/main/java/org/teiid/core/util/PasswordMaskUtil.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/PasswordMaskUtil.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/PasswordMaskUtil.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/PasswordMaskUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,122 @@
+/*
+ * 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.core.util;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * <p>This is a simple utility class to help keep password values from being
+ * printed out, primarily from java.util.Properties object, into
+ * MetaMatrix log files. This is <i>not</i> a robust security solution
+ * for protecting passwords, and is only good insofar as we get all
+ * other code to use this when necessary. When passwords are properly
+ * encrypted in the database, this class will be no longer necessary.</p>
+ *
+ * <p>This class can be used in one of two ways. First, a Properties object
+ * can be wrapped in an instance of this class - the properties object,
+ * wrapped in this instance, can then be safely sent to LogManager to be
+ * logged, or can otherwise be printed out. This instance will basically
+ * duplicate the toString() method of a normal Properties object, but will
+ * obfuscate any property values whose names end in any of the well-known
+ * {@link #PASSWORD_PROP_SUFFIXES password property suffixes}.</p>
+ *
+ * <p>The second way is to just use this class's static
+ * {@link #doesNameEndWithPasswordSuffix doesNameEndWithPasswordSuffix}
+ * utility method by hand, passing in a String property name to
+ * see if it ends with any of the well-known
+ * {@link #PASSWORD_PROP_SUFFIXES password property suffixes}.</p>
+ */
+public final class PasswordMaskUtil {
+
+ /**
+ * The known String suffixes that MetaMatrix property names end in.
+ * Each of these is checked.
+ */
+ public static final String[] PASSWORD_PROP_SUFFIXES = new String[]{"password", "Password"}; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * The "mask" String that is printed out of the
+ * {@link #toString} method, instead of the actual password value.
+ */
+ public static final String MASK_STRING = "*****"; //$NON-NLS-1$
+
+ private Properties properties;
+
+ /**
+ * A Properties object can be wrapped by this class before, say,
+ * being sent to LogManager. If this {@link #toString} method
+ * is called, password properties will be printed out as
+ * a {@link #MASK_STRING masked string}.
+ * @param propertiesWithPassword Properties object that has
+ * password property values inside it
+ */
+ public PasswordMaskUtil(Properties propertiesWithPassword){
+ this.properties = propertiesWithPassword;
+ }
+
+ /**
+ * This toString() method is basically the same as the
+ * java.util.Properties class's toString() method, except that
+ * if any of the properties in this class end with any of the
+ * well-known {@link #PASSWORD_PROP_SUFFIXES password suffixes},
+ * then the value will
+ * be printed out as {@link #MASK_STRING}
+ */
+ public String toString(){
+ int max = properties.size() - 1;
+ StringBuffer buf = new StringBuffer();
+ Iterator it = properties.entrySet().iterator();
+
+ buf.append("{"); //$NON-NLS-1$
+ String key = null;
+ for (int i = 0; i <= max; i++) {
+ Map.Entry e = (Map.Entry) (it.next());
+ key = (String)e.getKey();
+ if (doesNameEndWithPasswordSuffix(key)){
+ buf.append(key + "=" + MASK_STRING); //$NON-NLS-1$
+ } else {
+ buf.append(key + "=" + e.getValue()); //$NON-NLS-1$
+ }
+ if (i < max)
+ buf.append(", "); //$NON-NLS-1$
+ }
+ buf.append("}"); //$NON-NLS-1$
+ return buf.toString();
+ }
+
+ /**
+ * Indicates if the String propName ends in any of the well-known
+ * {@link #PASSWORD_PROP_SUFFIXES password property suffixes}.</p>
+ */
+ public static boolean doesNameEndWithPasswordSuffix(String propName){
+ for (int i=0; i<PASSWORD_PROP_SUFFIXES.length; i++){
+ if (propName.endsWith(PASSWORD_PROP_SUFFIXES[i])){
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/PropertiesUtils.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,1017 @@
+/*
+ * 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.core.util;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.core.CorePlugin;
+import org.teiid.core.TeiidRuntimeException;
+
+
+
+/**
+ * Static utility methods for common tasks having to do with
+ * java.util.Properties.
+ */
+public final class PropertiesUtils {
+
+ public static class InvalidPropertyException extends TeiidRuntimeException {
+
+ public InvalidPropertyException(String propertyName, String value, Class<?> expectedType, Throwable cause) {
+ super(cause, CorePlugin.Util.getString("InvalidPropertyException.message", propertyName, value, expectedType.getSimpleName())); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
+ * Returns a list of property names matching the given pattern. A '*' may be
+ * given to match the pattern exactly up to the '*', then anything after.
+ * Note: Should also implement matching with '?' which means match any single
+ * char.
+ * @param pattern The property name to match which may include a '*'.
+ * @param props The properties to search.
+ * @return The List of property names matching given pattern - may be empty
+ * but never null.
+ */
+ public static List filter( String pattern, Properties props ) {
+ boolean addAll = false;
+ String searchStr = null;
+ List propNames = new ArrayList();
+ int globIndex = pattern.indexOf('*');
+ if ( globIndex == -1 ) {
+ searchStr = pattern;
+ } else if ( globIndex == 0 ) {
+ addAll = true;
+ } else {
+ searchStr = pattern.substring(0, globIndex);
+ }
+
+ Enumeration propNameEnum = props.propertyNames();
+ while ( propNameEnum.hasMoreElements() ) {
+ String name = (String) propNameEnum.nextElement();
+ if ( name.startsWith(searchStr) || addAll ) {
+ propNames.add(name);
+ }
+ }
+
+ return propNames;
+ }
+
+
+ /**
+ * Obtains from this source the list of all properties that match the pattern specified by the filter.
+ * <p>
+ * The filter is a string that may contain the '*' character as a wildcard one or more times
+ * in the string. For example, the following filter:
+ * <p>
+ * <pre> *metamatrix.*</pre>
+ * <p>
+ * finds all properties that contain somewhere in the property name the string "metamatrix.".
+ * @param filterPattern the string filter pattern that will be used to narrow the set of properties returned.
+ * @param props The properties to search.
+ * @return the enumeration of all of the property names of the primary source;
+ * the enumeration may be empty if there is an error connecting to the property sources.
+ */
+ public static Properties getProperties(String filterPattern, Properties props) {
+ Properties results = new Properties();
+
+ boolean addAll = false;
+ String searchStr = null;
+ int globIndex = filterPattern.indexOf('*');
+ if ( globIndex == -1 ) {
+ searchStr = filterPattern;
+ } else if ( globIndex == 0 ) {
+ addAll = true;
+ } else {
+ searchStr = filterPattern.substring(0, globIndex);
+ }
+
+ Enumeration propNameEnum = props.propertyNames();
+ while ( propNameEnum.hasMoreElements() ) {
+ String name = (String) propNameEnum.nextElement();
+ if ( name.startsWith(searchStr)) {
+ Object value = props.get(name);
+ if (value != null) {
+ results.put(name.substring(searchStr.length()), value);
+ }
+ }
+ else if (addAll) {
+ results.put(name, props.get(name));
+ }
+ }
+
+ return results;
+ }
+
+
+ /**
+ * Performs a correct deep clone of the properties object by capturing
+ * all properties in the default(s) and placing them directly into the
+ * new Properties object. If the input is an instance of
+ * <code>UnmodifiableProperties</code>, this method returns an
+ * <code>UnmodifiableProperties</code> instance around a new (flattened)
+ * copy of the underlying Properties object.
+ */
+ public static Properties clone( Properties props ) {
+ return clone(props, null, false);
+ }
+
+ /**
+ * Performs a correct deep clone of the properties object by capturing
+ * all properties in the default(s) and placing them directly into the
+ * new Properties object. If the input is an instance of
+ * <code>UnmodifiableProperties</code>, this method returns an
+ * <code>UnmodifiableProperties</code> instance around a new (flattened)
+ * copy of the underlying Properties object.
+ */
+ public static Properties clone( Properties props, Properties defaults, boolean deepClone ) {
+ Properties result = null;
+ if ( defaults != null ) {
+ if ( deepClone ) {
+ defaults = clone(defaults);
+ }
+ result = new Properties(defaults);
+ } else {
+ result = new Properties();
+ }
+
+ putAll(result, props);
+
+ return result;
+ }
+
+ /**
+ * This method implements a 'compareTo' logic for two Properties objects,
+ * equivalent to calling <code>p1.compareTo(p2)</code> if the
+ * {@link java.util.Properties Properties} class implemented
+ * {@link java.lang.Comparable Comparable} (which it does not).
+ * @param p1 the first Properties instance to compare; may be null
+ * @param p2 the second Properties instance to compare; may be null
+ * @return a negative integer, zero, or a positive integer as <code>p1</code>
+ * is less than, equal to, or greater than <code>p2</code>, respectively.
+ */
+ public static int compare( Properties p1, Properties p2 ) {
+ if ( p1 != null ) {
+ if ( p2 == null ) {
+ return 1;
+ }
+ } else {
+ if ( p2 != null ) {
+ return -1;
+ }
+ return 0;
+ }
+
+
+ // Compare the number of property values ...
+ int diff = p1.size() - p2.size();
+ if ( diff != 0 ) {
+ return diff;
+ }
+
+ // Iterate through the properties and compare values ...
+ Map.Entry entry = null;
+ Object p1Value = null;
+ Object p2Value = null;
+ Iterator iter = p1.entrySet().iterator();
+ while ( iter.hasNext() ) {
+ entry = (Map.Entry) iter.next();
+ p1Value = entry.getValue();
+ p2Value = p2.get(entry.getKey());
+ if ( p1Value != null ) {
+ if ( p2Value == null ) {
+ return 1;
+ }
+ if ( p1Value instanceof Comparable ) {
+ diff = ((Comparable)p1Value).compareTo(p2Value);
+ } else {
+ diff = p1Value.toString().compareTo(p2Value.toString());
+ }
+ if ( diff != 0 ) {
+ return diff;
+ }
+ } else {
+ if ( p2Value != null ) {
+ return -1;
+ }
+ }
+ }
+ return 0;
+ }
+
+ /**
+ * <p>This method is intended to replace the use of the <code>putAll</code>
+ * method of <code>Properties</code> inherited from <code>java.util.Hashtable</code>.
+ * The problem with that method is that, since it is inherited from
+ * <code>Hashtable</code>, <i>default</i> properties are lost.
+ * </p>
+ * <p>For example, the following code
+ * <pre><code>
+ * Properties a;
+ * Properties b;
+ * //initialize ...
+ * a.putAll(b);
+ * </code></pre>
+ * will fail <i>if</i> <code>b</code> had been constructed with a default
+ * <code>Properties</code> object. Those defaults would be lost and
+ * not added to <code>a</code>.</p>
+ *
+ * <p>The above code could be correctly performed with this method,
+ * like this:
+ * <pre><code>
+ * Properties a;
+ * Properties b;
+ * //initialize ...
+ * PropertiesUtils.putAll(a,b);
+ * </code></pre>
+ * In the above example, <code>a</code> is modified - properties are added to
+ * it (note that if <code>a</code> has defaults they will remain unaffected.)
+ * The properties from <code>b</code>, <i>including defaults</i>, will be
+ * added to <code>a</code> using its <code>setProperty</code> method -
+ * these new properties will overwrite any pre-existing ones of the same
+ * name.
+ * </p>
+ *
+ * @param addToThis This Properties object is modified; the properties
+ * of the other parameter are added to this. The added property values
+ * will replace any current property values of the same names.
+ * @param withThese The properties (including defaults) of this
+ * object are added to the "addToThis" parameter.
+ */
+ public static void putAll(Properties addToThis,
+ Properties withThese) {
+ if ( withThese != null && addToThis != null ) {
+ Enumeration enumeration = withThese.propertyNames();
+ while ( enumeration.hasMoreElements() ) {
+ String propName = (String) enumeration.nextElement();
+ Object propValue = withThese.get(propName);
+ if ( propValue == null ) {
+ //defaults can only be retrieved as strings
+ propValue = withThese.getProperty(propName);
+ }
+ if ( propValue != null ) {
+ addToThis.put(propName, propValue);
+ }
+ }
+ }
+ }
+
+ public static void setOverrideProperies(Properties base, Properties override) {
+ Enumeration overrideEnum = override.propertyNames();
+ while (overrideEnum.hasMoreElements()) {
+ String key = (String)overrideEnum.nextElement();
+ String value = base.getProperty(key);
+ String overRideValue = override.getProperty(key);
+ if (value != null && !value.equals(overRideValue)) {
+ base.setProperty(key, overRideValue);
+ }
+ }
+ }
+
+ public static int getIntProperty(Properties props, String propName, int defaultValue) throws InvalidPropertyException {
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
+ }
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Integer.parseInt(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Integer.class, e);
+ }
+ }
+
+ public static long getLongProperty(Properties props, String propName, long defaultValue) {
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
+ }
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Long.parseLong(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Long.class, e);
+ }
+ }
+
+ public static float getFloatProperty(Properties props, String propName, float defaultValue) {
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
+ }
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Float.parseFloat(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Float.class, e);
+ }
+ }
+
+ public static double getDoubleProperty(Properties props, String propName, double defaultValue) {
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
+ }
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Double.parseDouble(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Double.class, e);
+ }
+ }
+
+ public static boolean getBooleanProperty(Properties props, String propName, boolean defaultValue) {
+ String stringVal = props.getProperty(propName);
+ if(stringVal == null) {
+ return defaultValue;
+ }
+ stringVal = stringVal.trim();
+ if (stringVal.length() == 0) {
+ return defaultValue;
+ }
+ try {
+ return Boolean.valueOf(stringVal);
+ } catch(NumberFormatException e) {
+ throw new InvalidPropertyException(propName, stringVal, Float.class, e);
+ }
+ }
+
+ /**
+ * Read the header part of a properties file into a String.
+ * @param fileName
+ * @return
+ * @throws IOException
+ * @since 4.3
+ */
+ public static String loadHeader(String fileName) throws IOException {
+ FileReader fr = null;
+ BufferedReader br = null;
+ try {
+ fr = new FileReader(fileName);
+ br = new BufferedReader(fr);
+ String header = br.readLine();
+ if (header != null && header.indexOf('#') == 0) {
+ header = header.substring(1);
+ }
+ return header;
+ } finally {
+ if (br != null) {
+ br.close();
+ }
+ if (fr != null) {
+ fr.close();
+ }
+ }
+ }
+
+ public static Properties load(String fileName) throws IOException {
+ InputStream is = null;
+ try {
+ Properties props = new Properties();
+ is = new FileInputStream(fileName);
+ props.load(is);
+ return props;
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+
+ public static Properties loadFromURL(URL url) throws MalformedURLException, IOException {
+ Properties result = new Properties();
+ InputStream is = null;
+ try {
+ is = url.openStream();
+ result.load(is);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ return result;
+ }
+
+ public static Properties loadAsResource(Class clazz, String resourceName) throws IOException {
+ InputStream is = null;
+ Properties configProps = new Properties();
+ try {
+ is = clazz.getResourceAsStream(resourceName);
+ ArgCheck.isNotNull(is);
+ if (is != null) {
+ configProps.load(is);
+ }
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (Exception ce) {
+
+ }
+ }
+ }
+ return configProps;
+ }
+
+ public static Properties sort(Properties props) {
+
+ List names = new ArrayList();
+ Enumeration enumeration = props.propertyNames();
+ while ( enumeration.hasMoreElements() ) {
+ String name = (String) enumeration.nextElement();
+ names.add(name);
+ }
+ Collections.sort(names);
+
+ Properties newProps = new Properties();
+ Iterator iter = names.iterator();
+ while ( iter.hasNext() ) {
+ String name = (String) iter.next();
+ String propValue = props.getProperty(name);
+ if ( propValue != null ) {
+ newProps.setProperty(name, propValue);
+ }
+ }
+ return newProps;
+ }
+
+
+ /**
+ * Write the specified properties to the specified file,
+ * with the specified header.
+ * Results may not be sorted.
+ * @param fileName
+ * @param props
+ * @param header
+ * @throws IOException
+ * @since 4.3
+ */
+ public static void print(String fileName, Properties props, String header) throws IOException {
+ FileOutputStream stream = null;
+ try {
+ stream = new FileOutputStream(fileName);
+ props.store(stream, header);
+ stream.flush();
+ } finally {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+
+
+
+ /**
+ * Write the specified properties to the specified file,
+ * with the specified header.
+ * Results are sorted by property name.
+ */
+ public static void print( String fileName, Properties props ) throws IOException {
+
+ FileOutputStream stream = null;
+ PrintStream writer = null;
+
+ try {
+
+ stream = new FileOutputStream(fileName);
+ writer = new PrintStream(stream);
+
+ List names = new ArrayList();
+ Enumeration enumeration = props.propertyNames();
+ while ( enumeration.hasMoreElements() ) {
+ String name = (String) enumeration.nextElement();
+ names.add(name);
+ }
+ Collections.sort(names);
+
+ StringBuffer sb;
+
+ for (Iterator nIt=names.iterator(); nIt.hasNext(); ) {
+ String name = (String) nIt.next();
+
+ String value = props.getProperty(name);
+
+ sb = new StringBuffer();
+
+ sb.append(name);
+ sb.append("="); //$NON-NLS-1$
+ sb.append(value);
+
+ writer.println(sb.toString());
+ }
+ writer.flush();
+ } finally {
+ try {
+ if (writer != null) {
+ writer.close();
+ }
+ } catch (Exception e){
+
+ }
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (Exception e){
+
+ }
+ }
+
+
+ }
+
+ public static void print( java.io.PrintStream stream, Properties props ) {
+ if (props != null) {
+ Collection sorted = sortPropertiesForPrinting(props);
+ for (Iterator it=sorted.iterator(); it.hasNext(); ) {
+ String value = (String) it.next();
+ stream.println(value);
+ }
+ }
+ }
+
+ private static final String NEWLINE = "\n"; //$NON-NLS-1$
+ public static String prettyPrint( Properties props ) {
+ if (props != null) {
+ Collection sorted = sortPropertiesForPrinting(props);
+
+ StringBuffer outBuf = new StringBuffer();
+
+ for (Iterator it=sorted.iterator(); it.hasNext(); ) {
+ String value = (String) it.next();
+ outBuf.append(value);
+ outBuf.append(NEWLINE);
+ }
+
+ return outBuf.toString();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Sorts the properties and returns a collection of entries
+ * where each entry can be printed. Each entry will print in the
+ * format of: Property: <code>name</code> = <code>value</code>
+ */
+
+ private static final String APREFIX = "Property '"; //$NON-NLS-1$
+ private static final String AEQUAL = "'='"; //$NON-NLS-1$
+ private static final String ASUFFIX = "'"; //$NON-NLS-1$
+ private static final String TAB = "\t"; //$NON-NLS-1$
+
+ public static Collection sortPropertiesForPrinting(Properties props) {
+
+ Collection sortedProps = new ArrayList(props.size());
+
+ List names = new ArrayList();
+ Enumeration enumeration = props.propertyNames();
+ while ( enumeration.hasMoreElements() ) {
+ String name = (String) enumeration.nextElement();
+ names.add(name);
+ }
+ Collections.sort(names);
+
+ StringBuffer sb;
+
+ for (Iterator nIt=names.iterator(); nIt.hasNext(); ) {
+ String name = (String) nIt.next();
+
+ String value = null;
+ if (PasswordMaskUtil.doesNameEndWithPasswordSuffix(name)){
+ value = PasswordMaskUtil.MASK_STRING;
+ } else {
+ value = props.getProperty(name);
+ value= saveConvert(value, false);
+ }
+
+ name = saveConvert(name, true);
+
+ sb = new StringBuffer(APREFIX);
+
+ sb.append(name);
+ sb.append(TAB);
+ sb.append(AEQUAL);
+ sb.append(value);
+ sb.append(ASUFFIX);
+
+// sortedProps.add(APREFIX + name + TAB + AEQUAL + value + ASUFFIX);
+ sortedProps.add(sb.toString());
+ }
+
+ return sortedProps;
+
+ }
+
+// private static final String keyValueSeparators = "=: \t\r\n\f";
+
+// private static final String strictKeyValueSeparators = "=:";
+
+ private static final String specialSaveChars = "=: \t\r\n\f#!"; //$NON-NLS-1$
+
+// private static final String whiteSpaceChars = " \t\r\n\f";
+
+
+ /*
+ * Converts unicodes to encoded \uxxxx
+ * and writes out any of the characters in specialSaveChars
+ * with a preceding slash
+ */
+ public static String saveConvert(String theString, boolean escapeSpace) {
+ if ( theString == null ) {
+ return ""; //$NON-NLS-1$
+ }
+ int len = theString.length();
+ StringBuffer outBuffer = new StringBuffer(len*2);
+
+ for(int x=0; x<len; x++) {
+ char aChar = theString.charAt(x);
+ switch(aChar) {
+ case ' ':
+ if (x == 0 || escapeSpace)
+ outBuffer.append('\\');
+
+ outBuffer.append(' ');
+ break;
+ case '\\':outBuffer.append('\\'); outBuffer.append('\\');
+ break;
+ case '\t':outBuffer.append('\\'); outBuffer.append('t');
+ break;
+ case '\n':outBuffer.append('\\'); outBuffer.append('n');
+ break;
+ case '\r':outBuffer.append('\\'); outBuffer.append('r');
+ break;
+ case '\f':outBuffer.append('\\'); outBuffer.append('f');
+ break;
+ default:
+ if ((aChar < 0x0020) || (aChar > 0x007e)) {
+ outBuffer.append('\\');
+ outBuffer.append('u');
+ outBuffer.append(toHex((aChar >> 12) & 0xF));
+ outBuffer.append(toHex((aChar >> 8) & 0xF));
+ outBuffer.append(toHex((aChar >> 4) & 0xF));
+ outBuffer.append(toHex( aChar & 0xF));
+ } else {
+ if (specialSaveChars.indexOf(aChar) != -1)
+ outBuffer.append('\\');
+ outBuffer.append(aChar);
+ }
+ }
+ }
+ return outBuffer.toString();
+ }
+
+ /**
+ * Convert a nibble to a hex character
+ * @param nibble the nibble to convert.
+ */
+ private static char toHex(int nibble) {
+ return hexDigit[(nibble & 0xF)];
+ }
+
+ /** A table of hex digits */
+ private static final char[] hexDigit = {
+ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
+ };
+
+
+ public static final void copyProperty(Properties srcProperties, String srcPropName, Properties tgtProperties, String tgtPropName) {
+ if(srcProperties == null || srcPropName == null || tgtProperties == null || tgtPropName == null) {
+ return;
+ }
+
+ String value = srcProperties.getProperty(srcPropName);
+ if(value != null) {
+ tgtProperties.setProperty(tgtPropName, value);
+ }
+ }
+
+ /**
+ * The specialty of nested properties is, in a given property file
+ * there can be values with pattern like "${...}"
+ * <code>
+ * key1=value1
+ * key2=${key1}/value2
+ * </code>
+ * where the value of the <code>key2</code> should resolve to <code>value1/value2</code>
+ * also if the property in the pattern <code>${..}</code> is not found in the loaded
+ * properties, an exception is thrown. Multiple nesting is OK, however recursive nested is not supported.
+ * @param original - Original properties to be resolved
+ * @return resolved properties object.
+ * @since 4.4
+ */
+ public static Properties resolveNestedProperties(Properties original) {
+
+ for(Enumeration e = original.propertyNames(); e.hasMoreElements();) {
+ String key = (String)e.nextElement();
+ String value = original.getProperty(key);
+
+ // this will take care of the if there are any non-string properties,
+ // no nesting allowed on these.
+ if (value == null) {
+ continue;
+ }
+
+ boolean matched = true;
+ boolean modified = false;
+
+ while(matched) {
+ // now match the pattern, then extract and find the value
+ int start = value.indexOf("${"); //$NON-NLS-1$
+ int end = start;
+ if (start != -1) {
+ end = value.indexOf('}', start);
+ }
+ matched = ((start != -1) && (end != -1));
+ if (matched) {
+ String nestedkey = value.substring(start+2, end);
+ String nestedvalue = original.getProperty(nestedkey);
+
+ // in cases where the key and the nestedkey are the same, this has to be bypassed
+ // because it will cause an infinite loop, and because there will be no value
+ // for the nestedkey that doesnt contain ${..} in the value
+ if (key.equals(nestedkey)) {
+ matched = false;
+
+ } else {
+
+
+ // this will handle case where we did not resolve, mark it blank
+ if (nestedvalue == null) {
+ throw new TeiidRuntimeException(CorePlugin.Util.getString("PropertiesUtils.failed_to_resolve_property", nestedkey)); //$NON-NLS-1$
+ }
+ value = value.substring(0,start)+nestedvalue+value.substring(end+1);
+ modified = true;
+ }
+ }
+ }
+ if(modified) {
+ original.setProperty(key, value);
+ }
+ }
+ return original;
+ }
+
+ // ======================================================
+ /**
+ * Returns a boolean indicating whether the string matched the given pattern.
+ * A '*' may be
+ * given to match the pattern exactly up to the '*', then anything after.
+ * We will also support a leading star, and match on anything that ends with
+ * the string specified after the star.
+ * Note: Should also implement matching with '?' which means match any single
+ * char.
+ * @param pattern The property name to match which may include a '*'.
+ * @param props The properties to search.
+ * @return The boolean - passed or failed
+ * but never null.
+ */
+ public static boolean filterTest( String pattern, String sCandidate ) {
+
+ // Vars for match strategy
+ char chStar = '*';
+
+ // Match rule booleans. Please note that 'bLeading'
+ // and 'bTrailing' refer to the string we are searching for.
+ // For example, if the strategy is bLeading, and the Match frag
+ // is "wet", and the candidate string is "wetrust", it will pass.
+ // Likewise if the strategy is bTrailing and the Match frag is
+ // "rust" and the candidate string is "wetrust", it will pass.
+ boolean bLeading = false;
+ boolean bTrailing = false;
+ boolean bFullMatch = false;
+ boolean bAnywhere = false;
+ boolean bAllMatch = false;
+
+ boolean bPass = false;
+
+ String sMatchFrag = ""; //$NON-NLS-1$
+// List propNames = new ArrayList();
+
+
+ // 1. Analyze pattern to resolve match strategy
+
+ // First ensure the pattern is safe to work with.
+ // If the pattern is an empty string, set it to '*',
+ // which means anything passes.
+ pattern = pattern.trim();
+ if ( pattern.length() == 0 )
+ pattern = "*"; //$NON-NLS-1$
+
+ int iFirstStar = pattern.indexOf( chStar );
+ int iLastStar = pattern.lastIndexOf( chStar );
+
+ // If there are any stars:
+ if( (iFirstStar > -1) && ( iLastStar > -1 ) )
+ {
+ // and their positions are the same (same star, silly)
+ if( iFirstStar == iLastStar )
+ {
+ // and this star is at the front:
+ if( iFirstStar == 0 )
+ {
+ // and the pattern is only one byte long:
+ if( pattern.length() == 1 )
+ {
+ // Then the pattern is a single '*',
+ // and all will pass the match:
+ bAllMatch = true;
+ }
+ else
+ {
+ // Or the pattern is a leading star followed
+ // by a string:
+ bTrailing = true;
+ sMatchFrag = pattern.substring( 1 );
+ }
+ }
+ else
+ {
+ // OR the star is NOT at the front, so the
+ // pattern is a trailing star preceded by a string:
+ bLeading = true;
+ sMatchFrag = pattern.substring( 0, iLastStar );
+
+ }
+ }
+ else
+ {
+ // They are not equal
+ //sMatchStrategy = ANYWHERE;
+ bAnywhere = true;
+ sMatchFrag = pattern.substring( iFirstStar + 1, iLastStar );
+ }
+ }
+ else
+ {
+ // there are no stars at all
+ //sMatchStrategy = FULL_MATCH;
+ bFullMatch = true;
+ sMatchFrag = pattern;
+ }
+
+ // Now test the string
+ String name = sCandidate;
+ bPass = false;
+
+ // force the match fragment and the test string to UPPER case
+ String sMatchFragUpper = sMatchFrag.toUpperCase();
+ String sNameUpper = name.toUpperCase();
+
+ // Test all of the booleans. Only one should be true.
+ if( bAllMatch ) {
+ bPass = true;
+ }
+ else
+ if( bAnywhere ) {
+ if( sNameUpper.indexOf( sMatchFragUpper ) > -1 )
+ bPass = true;
+ }
+ else
+ if( bFullMatch ) {
+ if( sNameUpper.equals( sMatchFragUpper ) )
+ bPass = true;
+ }
+ else
+ if( bLeading ) {
+ if( sNameUpper.startsWith( sMatchFragUpper ) )
+ bPass = true;
+ }
+ else
+ if( bTrailing ) {
+ if( sNameUpper.endsWith( sMatchFragUpper ) )
+ bPass = true;
+ }
+
+ return bPass;
+ }
+
+ public static void setBeanProperties(Object bean, Properties props, String prefix) {
+ // Move all prop names to lower case so we can use reflection to get
+ // method names and look them up in the connection props.
+ final Properties connProps = lowerCaseAllPropNames(props);
+ final Method[] methods = bean.getClass().getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ final Method method = methods[i];
+ final String methodName = method.getName();
+ // If setter ...
+ if ( methodName.startsWith("set") && method.getParameterTypes().length == 1 ) { //$NON-NLS-1$
+ // Get the property name
+ final String propertyName = methodName.substring(3); // remove the "set"
+ String shortName = propertyName.toLowerCase();
+ String propertyValue = null;
+ if (prefix != null) {
+ propertyValue = connProps.getProperty(prefix + "." + shortName); //$NON-NLS-1$
+ } else {
+ propertyValue = connProps.getProperty(shortName);
+ }
+ if (propertyValue == null) {
+ continue;
+ }
+ final Class<?> argType = method.getParameterTypes()[0];
+ try {
+ final Object[] params = new Object[] {StringUtil.valueOf(propertyValue, argType)};
+ method.invoke(bean, params);
+ } catch (Throwable e) {
+ throw new InvalidPropertyException(propertyName, propertyValue, argType, e);
+ }
+ }
+ }
+ }
+
+ public static void setBeanProperty(Object bean, String name, Object value) {
+ if (value == null) {
+ return;
+ }
+ name = name.toLowerCase();
+ final Method[] methods = bean.getClass().getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ final Method method = methods[i];
+ final String methodName = method.getName();
+ // If setter ...
+ if ( methodName.startsWith("set") && method.getParameterTypes().length == 1 ) { //$NON-NLS-1$
+ // Get the property name
+ final String propertyName = methodName.substring(3); // remove the "set"
+ String shortName = propertyName.toLowerCase();
+ if (!shortName.equals(name)) {
+ continue;
+ }
+ final Class<?> argType = method.getParameterTypes()[0];
+ try {
+ Object[] params = new Object[] {value};
+ if (!argType.isAssignableFrom(value.getClass())) {
+ params = new Object[] {StringUtil.valueOf(value.toString(), argType)};
+ }
+ method.invoke(bean, params);
+ } catch (Throwable e) {
+ throw new InvalidPropertyException(propertyName, value.toString(), argType, e);
+ }
+ }
+ }
+ }
+
+ private static Properties lowerCaseAllPropNames(final Properties connectionProps) {
+ final Properties lcProps = new Properties();
+ final Enumeration<?> itr = connectionProps.propertyNames();
+ while ( itr.hasMoreElements() ) {
+ final String name = (String) itr.nextElement();
+ String propValue = connectionProps.getProperty(name);
+ if (propValue != null) {
+ lcProps.setProperty(name.toLowerCase(), propValue);
+ }
+ }
+ return lcProps;
+ }
+
+}
Copied: trunk/common-core/src/main/java/org/teiid/core/util/ReaderInputStream.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/ReaderInputStream.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/ReaderInputStream.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ReaderInputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,88 @@
+/*
+ * 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.core.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+
+import org.teiid.core.types.Streamable;
+
+
+public class ReaderInputStream extends InputStream {
+
+ private static final int DEFAULT_BUFFER_SIZE = Streamable.STREAMING_BATCH_SIZE_IN_BYTES;
+
+ private final Reader reader;
+ private final Charset charSet;
+ private char[] charBuffer;
+
+ private boolean hasMore = true;
+ private ByteBuffer currentBuffer;
+ private int prefixBytes;
+ private boolean needsPrefix = true;
+
+ public ReaderInputStream(Reader reader, Charset charSet) {
+ this(reader, charSet, DEFAULT_BUFFER_SIZE);
+ }
+
+ public ReaderInputStream(Reader reader, Charset charSet, int bufferSize) {
+ this.reader = reader;
+ this.charSet = charSet;
+ this.charBuffer = new char[bufferSize];
+ if (charSet.displayName().equalsIgnoreCase("UTF-16")) { //$NON-NLS-1$
+ prefixBytes = 2;
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (currentBuffer == null || !currentBuffer.hasRemaining()) {
+ if (!hasMore) {
+ return -1;
+ }
+ int charsRead = reader.read(charBuffer);
+ if (charsRead == -1) {
+ hasMore = false;
+ return -1;
+ }
+ currentBuffer = charSet.encode(CharBuffer.wrap(charBuffer, 0, charsRead));
+ if (!needsPrefix) {
+ currentBuffer.position(prefixBytes);
+ }
+ needsPrefix = false;
+ }
+ return currentBuffer.get() & 0xff;
+ }
+
+ @Override
+ public void close() throws IOException {
+ this.reader.close();
+ }
+}
\ No newline at end of file
Modified: trunk/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/ReflectionHelper.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/ReflectionHelper.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
@@ -34,9 +34,10 @@
import java.util.List;
import java.util.Map;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.MetaMatrixCoreException;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.TeiidException;
+
public class ReflectionHelper {
private Class targetClass;
@@ -261,11 +262,11 @@
* @param classLoader the class loader to use; may be null if the current
* class loader is to be used
* @return Object is the instance of the class
- * @throws MetaMatrixCoreException if an error occurrs instantiating the class
+ * @throws TeiidException if an error occurrs instantiating the class
*/
public static final Object create(String className, Collection ctorObjs,
- final ClassLoader classLoader) throws MetaMatrixCoreException {
+ final ClassLoader classLoader) throws TeiidException {
try {
int size = (ctorObjs == null ? 0 : ctorObjs.size());
Class[] names = new Class[size];
@@ -282,12 +283,12 @@
}
return create(className, objArray, names, classLoader);
} catch (Exception e) {
- throw new MetaMatrixCoreException(e);
+ throw new TeiidException(e);
}
}
public static final Object create(String className, Object[] ctorObjs, Class<?>[] argTypes,
- final ClassLoader classLoader) throws MetaMatrixCoreException {
+ final ClassLoader classLoader) throws TeiidException {
try {
final Class cls = loadClass(className,classLoader);
@@ -296,7 +297,7 @@
return ctor.newInstance(ctorObjs);
} catch(Exception e) {
- throw new MetaMatrixCoreException(e);
+ throw new TeiidException(e);
}
}
Copied: trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/SqlUtil.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/SqlUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,123 @@
+/*
+ * 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.core.util;
+
+import java.sql.SQLException;
+
+//## JDBC4.0-begin ##
+import java.sql.SQLFeatureNotSupportedException;
+//## JDBC4.0-end ##
+
+import java.util.regex.Pattern;
+
+
+
+/**
+ * Utilities for dealing with SQL strings.
+ */
+public class SqlUtil {
+ public static final char CR_CHAR = StringUtil.Constants.CARRIAGE_RETURN_CHAR;
+ public static final char NL_CHAR = StringUtil.Constants.NEW_LINE_CHAR;
+ public static final char SPACE_CHAR = StringUtil.Constants.SPACE_CHAR;
+ public static final char TAB_CHAR = StringUtil.Constants.TAB_CHAR;
+ private static Pattern PATTERN = Pattern.compile("^([\\s]|(/\\*.*\\*/))*(insert|update|delete|create|drop|(select([\\s]|(/\\*.*\\*/))+.*into([\\s]|(/\\*.*\\*/))+)).*", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE); //$NON-NLS-1$
+
+ private SqlUtil() {
+ super();
+ }
+
+ /**
+ * Determines whether a sql statement is an update (INSERT, UPDATE, or DELETE).
+ * Throws exception if SQL statement appears to be invalid (because it's null, has
+ * 0 length, etc.
+ * @param sql Sql string
+ * @return True if INSERT, UPDATE, or DELETE, and false otherwise
+ * @throws IllegalArgumentException If sql string is invalid and neither a
+ * query or an update
+ */
+ public static boolean isUpdateSql(String sql) throws IllegalArgumentException {
+ ArgCheck.isNotNull(sql);
+ return PATTERN.matcher(sql).matches();
+ }
+
+ /**
+ * Simple method which normalizes a SQL string by replacing CR characters, new line characters and Tab characters with spaces,
+ * then trimming the string to remove unneeded spaces.
+ *
+ * @param inputSqlString
+ * @return
+ * @since 5.0
+ */
+ public static String normalize(String inputSqlString) {
+ String normalizedString = inputSqlString;
+ if (inputSqlString != null && inputSqlString.length() > 0) {
+ if ( inputSqlString.indexOf(NL_CHAR) > -1 ||
+ inputSqlString.indexOf(CR_CHAR) > -1 ||
+ inputSqlString.indexOf(TAB_CHAR) > -1 ||
+ inputSqlString.indexOf(StringUtil.Constants.DBL_SPACE) > -1) {
+ normalizedString = normalizedString.replace(NL_CHAR, SPACE_CHAR);
+ normalizedString = normalizedString.replace(CR_CHAR, SPACE_CHAR);
+ normalizedString = normalizedString.replace(TAB_CHAR, SPACE_CHAR);
+ normalizedString = StringUtil.replaceAll(normalizedString,
+ StringUtil.Constants.DBL_SPACE,
+ StringUtil.Constants.SPACE);
+
+ }
+ normalizedString = StringUtil.collapseWhitespace(normalizedString);
+ }
+ return normalizedString;
+ }
+
+ /**
+ * determine if the supplied sql Strings are different
+ * @param newSql the new SQL String
+ * @param oldSql the old SQL String
+ * @return 'true' if strings differ, 'false' if same
+ */
+ public static boolean stringsAreDifferent(String newSql, String oldSql) {
+ boolean isDifferent = true;
+ if(newSql==null) {
+ if(oldSql==null) {
+ isDifferent = false;
+ }
+ } else if(oldSql!=null) {
+ String normalizedNewSql = normalize(newSql);
+ String normalizedOldSql = normalize(oldSql);
+ if(normalizedNewSql.equals(normalizedOldSql)) {
+ isDifferent=false;
+ }
+ }
+ return isDifferent;
+ }
+
+ public static SQLException createFeatureNotSupportedException() {
+ //## JDBC4.0-begin ##
+ return new SQLFeatureNotSupportedException();
+ //## JDBC4.0-end ##
+
+ /*## JDBC3.0-JDK1.5-begin ##
+ return new SQLException("unsupported feature");
+ ## JDBC3.0-JDK1.5-end ##*/
+
+ }
+}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/core/util/StringUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -10,7 +10,7 @@
* License, version 1.0.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -28,9 +28,10 @@
import java.util.StringTokenizer;
import java.util.regex.Pattern;
-import com.metamatrix.core.CorePlugin;
-import com.metamatrix.core.MetaMatrixRuntimeException;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.TeiidRuntimeException;
+
/**
* This is a common place to put String utility methods.
*/
@@ -1059,7 +1060,7 @@
line = reader.readLine();
}
} catch (IOException e) {
- throw new MetaMatrixRuntimeException(e);
+ throw new TeiidRuntimeException(e);
}
return (String[]) result.toArray(new String[result.size()]);
}
Copied: trunk/common-core/src/main/java/org/teiid/core/util/TimestampWithTimezone.java (from rev 2112, trunk/common-core/src/main/java/com/metamatrix/common/util/TimestampWithTimezone.java)
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/TimestampWithTimezone.java (rev 0)
+++ trunk/common-core/src/main/java/org/teiid/core/util/TimestampWithTimezone.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,204 @@
+/*
+ * 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.core.util;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.teiid.core.types.DataTypeManager;
+
+
+/**
+ * Utility methods for SQL Timestamps, Time, and Dates with time zones as UTC
+ *
+ * This is intended to take incoming Strings or Dates that have accurate
+ * Calendar fields and give the UTC time by interpretting those fields
+ * in the target time zone.
+ *
+ * Use of the Calendar object passed in will not be thread safe, but
+ * it will not alter the contents of the Calendar.
+ *
+ * Note that normalization occurs only for the transition from one type to another.
+ *
+ */
+public class TimestampWithTimezone {
+
+ private static ThreadLocal<Calendar> CALENDAR = new ThreadLocal<Calendar>() {
+ protected Calendar initialValue() {
+ return Calendar.getInstance();
+ }
+ };
+
+ public static Calendar getCalendar() {
+ return CALENDAR.get();
+ }
+
+ public static void resetCalendar(TimeZone tz) {
+ TimeZone.setDefault(tz);
+ CALENDAR.set(Calendar.getInstance());
+ }
+
+ public static Object create(java.util.Date date, TimeZone initial, Calendar target, Class<?> type) {
+ if (type.equals(DataTypeManager.DefaultDataClasses.TIME)) {
+ return type.cast(createTime(date, initial, target));
+ }
+ if (type.equals(DataTypeManager.DefaultDataClasses.DATE)) {
+ return type.cast(createDate(date, initial, target));
+ }
+ return type.cast(createTimestamp(date, initial, target));
+ }
+
+ public static Timestamp createTimestamp(java.util.Date date, TimeZone initial, Calendar target) {
+ if (target == null) {
+ target = getCalendar();
+ }
+
+ long time = target.getTimeInMillis();
+
+ adjustCalendar(date, initial, target);
+
+ target.set(Calendar.MILLISECOND, 0);
+
+ Timestamp tsInTz = new Timestamp(target.getTimeInMillis());
+
+ if(date instanceof Timestamp) {
+ tsInTz.setNanos(((Timestamp)date).getNanos());
+ }
+
+ target.setTimeInMillis(time);
+ return tsInTz;
+ }
+
+ public static Time createTime(java.util.Date date, TimeZone initial, Calendar target) {
+ if (target == null) {
+ target = getCalendar();
+ }
+
+ long time = target.getTimeInMillis();
+
+ adjustCalendar(date, initial, target);
+
+ Time result = normalizeTime(date, target);
+
+ target.setTimeInMillis(time);
+ return result;
+ }
+
+ public static Date createDate(java.util.Date date, TimeZone initial, Calendar target) {
+ if (target == null) {
+ target = getCalendar();
+ }
+
+ long time = target.getTimeInMillis();
+
+ adjustCalendar(date, initial, target);
+
+ Date result = normalizeDate(date, target);
+
+ target.setTimeInMillis(time);
+ return result;
+ }
+
+ /**
+ * Creates normalized SQL Time Object
+ *
+ * @return Time
+ * @since 4.3
+ */
+ public static Time createTime(java.util.Date date) {
+ if (date instanceof Time) {
+ return (Time)date;
+ }
+ Calendar cal = getCalendar();
+ cal.setTime(date);
+ return normalizeTime(date, cal);
+ }
+
+ /**
+ * Creates normalized SQL Date Object
+ *
+ * @return Date
+ * @since 4.3
+ */
+ public static Date createDate(java.util.Date date) {
+ if (date instanceof Date) {
+ return (Date)date;
+ }
+ Calendar cal = getCalendar();
+ cal.setTime(date);
+ return normalizeDate(date, cal);
+ }
+
+ public static Timestamp createTimestamp(java.util.Date date) {
+ if (date instanceof Timestamp) {
+ return (Timestamp)date;
+ }
+ return new Timestamp(date.getTime());
+ }
+
+ private static Date normalizeDate(java.util.Date date, Calendar target) {
+ if (!(date instanceof Date)) {
+ target.set(Calendar.HOUR_OF_DAY, 0);
+ target.set(Calendar.MINUTE, 0);
+ target.set(Calendar.SECOND, 0);
+ target.set(Calendar.MILLISECOND, 0);
+ }
+ Date result = new Date(target.getTimeInMillis());
+ return result;
+ }
+
+ private static Time normalizeTime(java.util.Date date, Calendar target) {
+ if (!(date instanceof Time)) {
+ target.set(Calendar.YEAR, 1970);
+ target.set(Calendar.MONTH, Calendar.JANUARY);
+ target.set(Calendar.DAY_OF_MONTH, 1);
+ target.set(Calendar.MILLISECOND, 0);
+ }
+ Time result = new Time(target.getTimeInMillis());
+ return result;
+ }
+
+ private static void adjustCalendar(java.util.Date date,
+ TimeZone initial,
+ Calendar target) {
+ assert initial != null;
+ if (initial.hasSameRules(target.getTimeZone())) {
+ target.setTime(date);
+ return;
+ }
+
+ //start with base time
+ long time = date.getTime();
+
+ Calendar cal = Calendar.getInstance(initial);
+ cal.setTimeInMillis(time);
+
+ target.clear();
+ for (int i = 0; i <= Calendar.MILLISECOND; i++) {
+ target.set(i, cal.get(i));
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/common-core/src/main/resources/org (from rev 2112, trunk/common-core/src/main/resources/com)
Copied: trunk/common-core/src/main/resources/org/teiid (from rev 2112, trunk/common-core/src/main/resources/com/metamatrix)
Added: trunk/common-core/src/main/resources/org/teiid/core/crypto/dh.properties
===================================================================
--- trunk/common-core/src/main/resources/org/teiid/core/crypto/dh.properties (rev 0)
+++ trunk/common-core/src/main/resources/org/teiid/core/crypto/dh.properties 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+l=1023
+g=65476153261383108624840021863998246093709586224962907052686140953941599438816169930153889694632983438469862599756901552486265440405017552695104068576059353038515915292702390210034620287621061715213680152081614271756448482999508620289874066938958639538265504107725684460411433731570820253815359301833789900369
+p=91486708821195143519350593856640210508460388919268552559270683605679843924064493007548185819322195422458326889166652085263292015070318371861045236990557879217929613856964138062966850688610964882043602934380737432020282965006721409374518731633783361548347472294564234747097310682444725035696923352543622936769
\ No newline at end of file
Added: trunk/common-core/src/main/resources/org/teiid/core/util/application.properties
===================================================================
--- trunk/common-core/src/main/resources/org/teiid/core/util/application.properties (rev 0)
+++ trunk/common-core/src/main/resources/org/teiid/core/util/application.properties 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,5 @@
+build.releaseNumber=${pom.version}
+build.number=${pom.version}
+build.date=@build-date@
+copyright=Copyright (C) 2008-2009 Red Hat, Inc
+url=${site.url}
\ No newline at end of file
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/types/TestBlobValue.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/TestBlobValue.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/TestBlobValue.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,76 +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 com.metamatrix.common.types;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import javax.sql.rowset.serial.SerialBlob;
-
-import com.metamatrix.core.util.UnitTestUtil;
-
-import junit.framework.TestCase;
-
-
-public class TestBlobValue extends TestCase {
-
- public void testBlobValue() throws Exception {
- String testString = "this is test blob"; //$NON-NLS-1$
- SerialBlob blob = new SerialBlob(testString.getBytes());
-
- BlobType bv = new BlobType(blob);
- assertEquals(testString, new String(bv.getBytes(1L, (int)bv.length())));
- }
-
-
- public void testBlobValuePersistence() throws Exception {
- String testString = "this is test clob"; //$NON-NLS-1$
- SerialBlob blob = new SerialBlob(testString.getBytes());
-
- String key = "keytodata"; //$NON-NLS-1$
- BlobType bv = new BlobType(blob);
- bv.setReferenceStreamId(key);
-
- // now force to serialize
- File saved = new File(UnitTestUtil.getTestScratchPath()+"/blobassaved.bin"); //$NON-NLS-1$
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
- out.writeObject(bv);
- out.close();
-
- // now read back the object from serilized state
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
- BlobType read = (BlobType)in.readObject();
-
- // make sure we have kept the reference stream id
- assertEquals(key, read.getReferenceStreamId());
-
- // and lost the original object
- assertNull(read.getReference());
-
- saved.delete();
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/types/TestClobValue.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/TestClobValue.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/TestClobValue.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,76 +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 com.metamatrix.common.types;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import javax.sql.rowset.serial.SerialClob;
-
-import com.metamatrix.core.util.UnitTestUtil;
-
-import junit.framework.TestCase;
-
-
-public class TestClobValue extends TestCase {
-
- public void testClobValue() throws Exception {
- String testString = "this is test clob"; //$NON-NLS-1$
- SerialClob clob = new SerialClob(testString.toCharArray());
-
- ClobType cv = new ClobType(clob);
- assertEquals(testString, cv.getSubString(1L, (int)cv.length()));
- }
-
-
- public void testClobValuePersistence() throws Exception {
- String testString = "this is test clob"; //$NON-NLS-1$
- SerialClob clob = new SerialClob(testString.toCharArray());
-
- String key = "keytodata"; //$NON-NLS-1$
- ClobType cv = new ClobType(clob);
- cv.setReferenceStreamId(key);
-
- // now force to serialize
- File saved = new File(UnitTestUtil.getTestScratchPath()+"/clobassaved.bin"); //$NON-NLS-1$
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
- out.writeObject(cv);
- out.close();
-
- // now read back the object from serilized state
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
- ClobType read = (ClobType)in.readObject();
-
- // make sure we have kept the reference stream id
- assertEquals(key, read.getReferenceStreamId());
-
- // and lost the original object
- assertNull(read.getReference());
-
- saved.delete();
- }
-
-}
Deleted: 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-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,225 +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 com.metamatrix.common.types;
-
-import static org.junit.Assert.*;
-
-import java.sql.Types;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.sql.rowset.serial.SerialBlob;
-
-import org.junit.Test;
-
-public class TestDataTypeManager {
-
- private void helpDetermineDataType(Object value, Class expectedClass) {
- Class actualClass = DataTypeManager.determineDataTypeClass(value);
- assertNotNull("Should never receive null when determining data type of object: " + value); //$NON-NLS-1$
- assertEquals("Mismatch in expected and actual MetaMatrix type class for [" + value + "]: ", expectedClass, actualClass); //$NON-NLS-1$ //$NON-NLS-2$
- }
- public static String[] dataTypes = {"string","char","boolean","byte","short","integer","long","biginteger", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
- "float","double","bigdecimal","date","time","timestamp","object","blob","clob", DataTypeManager.DefaultDataTypes.XML}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
-
- /**
- * I - Implicitly Converted
- * C - Explicitly Converted
- * N - Cannot be converted
- * o - No conversion needed
- */
- public static char conversions [][] =
- {
- /* Big */
- /* i d */
- /* s n b d e Time o */
- /* t s t i f o c s b */
- /* r c b b h e L g l u i d t t j b c */
- /* i h o y o g o i o b m a i a e l l x */
- /* n a o t r e n n a l a t m m c o o m */
- /* g r l e t r g t t e l e e p t b b l */
- /* -------------------------------------------------------------------------*/
- /*String*/ { 'O','C','C','C','C','C','C','C','C','C','C','C','C','C','I','N','I','C' },
- /*char*/ { 'I','O','N','N','N','N','N','N','N','N','N','N','N','N','I','N','N','N' },
- /*bool*/ { 'I','N','O','I','I','I','I','I','I','I','I','N','N','N','I','N','N','N' },
- /*byte*/ { 'I','N','C','O','I','I','I','I','I','I','I','N','N','N','I','N','N','N' },
- /*short*/ { 'I','N','C','C','O','I','I','I','I','I','I','N','N','N','I','N','N','N' },
- /*int*/ { 'I','N','C','C','C','O','I','I','C','I','I','N','N','N','I','N','N','N' },
- /*long*/ { 'I','N','C','C','C','C','O','I','C','C','I','N','N','N','I','N','N','N' },
- /*bigint*/ { 'I','N','C','C','C','C','C','O','C','C','I','N','N','N','I','N','N','N' },
- /*float*/ { 'I','N','C','C','C','C','C','C','O','I','I','N','N','N','I','N','N','N' },
- /*double*/ { 'I','N','C','C','C','C','C','C','C','O','I','N','N','N','I','N','N','N' },
- /*bigdecimal*/ { 'I','N','C','C','C','C','C','C','C','C','O','N','N','N','I','N','N','N' },
- /*date*/ { 'I','N','N','N','N','N','N','N','N','N','N','O','N','I','I','N','N','N' },
- /*time*/ { 'I','N','N','N','N','N','N','N','N','N','N','N','O','I','I','N','N','N' },
- /*timestamp*/ { 'I','N','N','N','N','N','N','N','N','N','N','C','C','O','I','N','N','N' },
- /*object*/ { 'C','C','C','C','C','C','C','C','C','C','C','C','C','C','O','C','C','C' },
- /*blob*/ { 'N','N','N','N','N','N','N','N','N','N','N','N','N','N','I','O','N','N' },
- /*clob*/ { 'C','N','N','N','N','N','N','N','N','N','N','N','N','N','I','N','O','C' },
- /*xml*/ { 'C','N','N','N','N','N','N','N','N','N','N','N','N','N','I','N','C','O' }
- };
-
-
- // ################################## ACTUAL TESTS ################################
-
- @Test public void testTypeMappings() {
- Set dataTypeNames = DataTypeManager.getAllDataTypeNames();
- Iterator iter = dataTypeNames.iterator();
- while(iter.hasNext()) {
- String dataTypeName = (String) iter.next();
- Class dataTypeClass = DataTypeManager.getDataTypeClass(dataTypeName);
- assertNotNull("Data type class was null for type " + dataTypeName, dataTypeClass); //$NON-NLS-1$
- String dataTypeName2 = DataTypeManager.getDataTypeName(dataTypeClass);
- assertEquals("Name to class to name not equals: ", dataTypeName, dataTypeName2); //$NON-NLS-1$
- }
- }
-
- @Test public void testCheckConversions() {
- for (int src = 0; src < dataTypes.length; src++) {
- for (int tgt =0; tgt < dataTypes.length; tgt++) {
- char c = conversions[src][tgt];
-
- if (c == 'I') {
- assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should be Implicit", DataTypeManager.isImplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should be not be Explicit", DataTypeManager.isExplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" transform should be avaialble", DataTypeManager.isTransformable(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- else if (c == 'C') {
- assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should not be Implicit", DataTypeManager.isImplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should be Explicit", DataTypeManager.isExplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" transform should be avaialble", DataTypeManager.isTransformable(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- else if ( c == 'O' || c == 'N') {
- assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should not be Implicit", DataTypeManager.isImplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should not be Explicit", DataTypeManager.isExplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" No transform should be avaialble", DataTypeManager.isTransformable(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
- }
- }
-
- /** Test determine data type for a STRING object. */
- @Test public void testDetermineDataType1() {
- helpDetermineDataType("abc", DataTypeManager.DefaultDataClasses.STRING); //$NON-NLS-1$
- }
-
- /** Test determine data type for a NULL object. */
- @Test public void testDetermineDataType2() {
- helpDetermineDataType(null, DataTypeManager.DefaultDataClasses.NULL);
- }
-
- /** Test determine data type for an unknown object type - should be typed as an OBJECT. */
- @Test public void testDetermineDataType3() throws Exception {
- java.net.URL url = new java.net.URL("http://fake"); //$NON-NLS-1$
- helpDetermineDataType(url, DataTypeManager.DefaultDataClasses.OBJECT);
- }
-
- @Test public void testCheckAllConversions() {
- Set allTypes = DataTypeManager.getAllDataTypeNames();
- Iterator srcIter = allTypes.iterator();
- while(srcIter.hasNext()) {
- String src = (String) srcIter.next();
-
- Iterator tgtIter = allTypes.iterator();
- while(tgtIter.hasNext()) {
- String tgt = (String) tgtIter.next();
-
- boolean isImplicit = DataTypeManager.isImplicitConversion(src, tgt);
- boolean isExplicit = DataTypeManager.isExplicitConversion(src, tgt);
-
- if(isImplicit && isExplicit) {
- fail("Can't be both implicit and explicit for " + src + " to " + tgt); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
- }
-
- @Test public void testTimeConversions() {
- Transform t = DataTypeManager.getTransform(DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.DATE);
-
- assertEquals(DataTypeManager.DefaultDataClasses.DATE, t.getTargetType());
-
- t = DataTypeManager.getTransform(DataTypeManager.DefaultDataTypes.TIME, DataTypeManager.DefaultDataTypes.TIMESTAMP);
-
- assertEquals(DataTypeManager.DefaultDataClasses.TIMESTAMP, t.getTargetType());
- }
-
- @Test public void testJDBCSQLTypeInfo() {
-
- String[] types = JDBCSQLTypeInfo.getMMTypeNames();
-
- for (int i = 0; i < types.length; i++) {
- String type = types[i];
-
- assertEquals("Didn't get match for "+ type, JDBCSQLTypeInfo.getSQLType(type), JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.getDataTypeClass(type))); //$NON-NLS-1$
-
- //the classnames will not match the runtime types for xml, clob, blob
- if (!type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.XML) && !type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.CLOB) && !type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.BLOB)) {
- assertEquals("Didn't get match for "+ type, JDBCSQLTypeInfo.getSQLType(type), JDBCSQLTypeInfo.getSQLTypeFromClass(DataTypeManager.getDataTypeClass(type).getName())); //$NON-NLS-1$
- }
- }
-
- assertEquals(Types.TIMESTAMP, JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.TIMESTAMP));
- //## JDBC4.0-begin ##
- assertEquals(Types.SQLXML, JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.XML));
- //## JDBC4.0-end ##
- assertEquals(DataTypeManager.DefaultDataTypes.STRING, JDBCSQLTypeInfo.getTypeName(Types.CHAR));
- assertEquals(Types.CHAR, JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.CHAR));
- }
-
- @Test public void testRuntimeTypeConversion() throws Exception {
- assertNull(DataTypeManager.convertToRuntimeType(null));
-
- assertTrue(DataTypeManager.convertToRuntimeType(new SerialBlob(new byte[0])) instanceof BlobType);
-
- //unknown type should return as same
- Object foo = new Object();
- assertEquals(foo, DataTypeManager.convertToRuntimeType(foo));
-
- //known type should return as same
- Integer bar = new Integer(1);
- assertEquals(bar, DataTypeManager.convertToRuntimeType(bar));
- }
-
- @Test public void testObjectType() {
- assertEquals(DataTypeManager.DefaultDataClasses.OBJECT, DataTypeManager.getDataTypeClass("foo")); //$NON-NLS-1$
-
- assertEquals(DataTypeManager.DefaultDataTypes.OBJECT, DataTypeManager.getDataTypeName(TestDataTypeManager.class));
- }
-
- @Test public void testImplicitConversions() {
- assertEquals(Arrays.asList(DataTypeManager.DefaultDataTypes.LONG,
- DataTypeManager.DefaultDataTypes.BIG_INTEGER,
- DataTypeManager.DefaultDataTypes.DOUBLE,
- DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
- 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$
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/types/TestSQLXMLImpl.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/TestSQLXMLImpl.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/TestSQLXMLImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,106 +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 com.metamatrix.common.types;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.sql.SQLException;
-
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.core.util.ObjectConverterUtil;
-
-/**
- * Basically we want to make sure that nobody has changed the fundamental contract
- * of translator
- */
-public class TestSQLXMLImpl extends TestCase {
-
- String testStr = "<foo>test</foo>"; //$NON-NLS-1$
-
- //## JDBC4.0-begin ##
- public void testGetSource() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- assertTrue(xml.getSource(null) instanceof StreamSource);
-
- StreamSource ss = (StreamSource)xml.getSource(null);
- assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(ss.getInputStream()), Streamable.ENCODING));
- }
- //## JDBC4.0-end ##
-
- public void testGetCharacterStream() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- assertEquals(testStr, getContents(xml.getCharacterStream()));
- }
-
- public void testGetBinaryStream() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(xml.getBinaryStream()), Streamable.ENCODING));
- }
-
- public void testGetString() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- assertEquals(testStr, xml.getString());
- }
-
- public void testSetBinaryStream() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- try {
- xml.setBinaryStream();
- fail("we do not support this yet.."); //$NON-NLS-1$
- } catch (SQLException e) {
- }
- }
-
- public void testSetCharacterStream() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- try {
- xml.setCharacterStream();
- fail("we do not support this yet.."); //$NON-NLS-1$
- } catch (SQLException e) {
- }
- }
-
- public void testSetString() throws Exception {
- SQLXMLImpl xml = new SQLXMLImpl(testStr);
- try {
- xml.setString(testStr);
- fail("we do not support this yet.."); //$NON-NLS-1$
- } catch (SQLException e) {
- }
- }
-
- private String getContents(Reader reader) throws IOException {
- StringBuffer sb = new StringBuffer();
- int chr = reader.read();
- while(chr != -1) {
- sb.append((char)chr);
- chr = reader.read();
- }
- reader.close();
- return sb.toString();
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLStreamSourceTranslator.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLStreamSourceTranslator.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLStreamSourceTranslator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,99 +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 com.metamatrix.common.types;
-
-import java.io.StringReader;
-import java.util.StringTokenizer;
-
-import javax.xml.transform.stream.StreamSource;
-
-import junit.framework.TestCase;
-
-
-/**
- * XML StreamSource Translator.
- */
-public class TestXMLStreamSourceTranslator extends TestCase {
-
- private static final String sourceXML =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
- "<Books:bookCollection xmlns:Books=\"http://www.metamatrix.com/XMLSchema/DataSets/Books\">\r\n" + //$NON-NLS-1$
- " <book isbn=\"0-7356-0877-6\">\r\n" + //$NON-NLS-1$
- " <title>After the Gold Rush</title>\r\n" + //$NON-NLS-1$
- " <subtitle>Creating a True Profession of Software Engineering</subtitle>\r\n" + //$NON-NLS-1$
- " <edition>1</edition>\r\n" + //$NON-NLS-1$
- " <authors>\r\n" + //$NON-NLS-1$
- " <author>McConnell</author>\r\n" + //$NON-NLS-1$
- " </authors>\r\n" + //$NON-NLS-1$
- " <publishingInformation>\r\n" + //$NON-NLS-1$
- " <publisher>Microsoft Press</publisher>\r\n" + //$NON-NLS-1$
- " <publishDate>1999</publishDate>\r\n" + //$NON-NLS-1$
- " </publishingInformation>\r\n" + //$NON-NLS-1$
- " </book>\r\n" + //$NON-NLS-1$
- " <book isbn=\"1-55615-484-4\">\r\n" + //$NON-NLS-1$
- " <title>Code Complete</title>\r\n" + //$NON-NLS-1$
- " <subtitle>A Practical Handbook of Software Construction</subtitle>\r\n" + //$NON-NLS-1$
- " <edition>1</edition>\r\n" + //$NON-NLS-1$
- " <authors>\r\n" + //$NON-NLS-1$
- " <author>McConnell</author>\r\n" + //$NON-NLS-1$
- " </authors>\r\n" + //$NON-NLS-1$
- " <publishingInformation>\r\n" + //$NON-NLS-1$
- " <publisher>Microsoft Press</publisher>\r\n" + //$NON-NLS-1$
- " <publishDate>1993</publishDate>\r\n" + //$NON-NLS-1$
- " </publishingInformation>\r\n" + //$NON-NLS-1$
- " </book>\r\n" + //$NON-NLS-1$
- " <book isbn=\"1-556-15900-5\">\r\n" + //$NON-NLS-1$
- " <title>Rapid Development</title>\r\n" + //$NON-NLS-1$
- " <subtitle>Taming Wild Software Schedules</subtitle>\r\n" + //$NON-NLS-1$
- " <edition>1</edition>\r\n" + //$NON-NLS-1$
- " <authors>\r\n" + //$NON-NLS-1$
- " <author>McConnell</author>\r\n" + //$NON-NLS-1$
- " </authors>\r\n" + //$NON-NLS-1$
- " <publishingInformation>\r\n" + //$NON-NLS-1$
- " <publisher>Microsoft Press</publisher>\r\n" + //$NON-NLS-1$
- " <publishDate>1996</publishDate>\r\n" + //$NON-NLS-1$
- " </publishingInformation>\r\n" + //$NON-NLS-1$
- " </book>\r\n" + //$NON-NLS-1$
- "</Books:bookCollection>"; //$NON-NLS-1$
-
- public void testStreamSourceWithStream() throws Exception {
- StandardXMLTranslator translator = new StandardXMLTranslator(new StreamSource(new StringReader(sourceXML)));
- compareDocuments(sourceXML, translator.getString());
- }
-
- private void compareDocuments(String expectedDoc, String actualDoc) {
- StringTokenizer tokens1 = new StringTokenizer(expectedDoc, "\r\n"); //$NON-NLS-1$
- StringTokenizer tokens2 = new StringTokenizer(actualDoc, "\n");//$NON-NLS-1$
- while(tokens1.hasMoreTokens()){
- String token1 = tokens1.nextToken().trim();
- if(!tokens2.hasMoreTokens()){
- fail("XML doc mismatch: expected=" + token1 + "\nactual=none");//$NON-NLS-1$ //$NON-NLS-2$
- }
- String token2 = tokens2.nextToken().trim();
- assertEquals("XML doc mismatch: ", token1, token2); //$NON-NLS-1$
- }
- if(tokens2.hasMoreTokens()){
- fail("XML doc mismatch: expected=none\nactual=" + tokens2.nextToken().trim());//$NON-NLS-1$
- }
- }
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLValue.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLValue.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLValue.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,75 +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 com.metamatrix.common.types;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import com.metamatrix.core.util.UnitTestUtil;
-
-import junit.framework.TestCase;
-
-
-public class TestXMLValue extends TestCase {
-
- public void testXMLValue() throws Exception {
- String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
- SQLXMLImpl xml = new SQLXMLImpl(testString);
-
- XMLType xv = new XMLType(xml);
- assertEquals(testString, xv.getString());
- }
-
-
- public void testXMLValuePersistence() throws Exception {
- String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
- SQLXMLImpl xml = new SQLXMLImpl(testString);
-
- String key = "keytodata"; //$NON-NLS-1$
- String pkey = "peresistkeytodata"; //$NON-NLS-1$
- XMLType xv = new XMLType(xml);
- xv.setReferenceStreamId(key);
-
- // now force to serialize
- File saved = new File(UnitTestUtil.getTestScratchPath()+"/xmlsaved.bin"); //$NON-NLS-1$
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
- out.writeObject(xv);
- out.close();
-
- // now read back the object from serilized state
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
- XMLType read = (XMLType)in.readObject();
-
- // make sure we have kept the reference stream id
- assertEquals(key, read.getReferenceStreamId());
-
- // and lost the original object
- assertNull(read.getReference());
-
- saved.delete();
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/FakeInputStream.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/FakeInputStream.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/FakeInputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,68 +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 com.metamatrix.common.util;
-
-import java.io.ByteArrayInputStream;
-
-/**
- * This test input stream overrides the <code>available</code>
- * to return "1" until <i>after</i> the {@link #read} method returns
- * "-1" to indicate EOF, which is how java.util.zip.ZipInputStream
- * works, which is what is used by ExtensionSourceManager to retrieve
- * Class files from JAR files. The <code>available</code> method
- * therefore can't be relied on by ByteArrayHelper to either
- * indicate how many bytes can be read, or if more are
- * available or not. In the latter case, ByteArrayHelper
- * relies on the <code>read</code> method returning "-1".
- */
-public class FakeInputStream extends ByteArrayInputStream {
-
- private int available = 1;
-
- public FakeInputStream(byte[] buf) {
- super(buf);
- }
-
- /**
- * Overriden to return "1" <i>until</i> the <code>read</code> method
- * has returned "-1" to indicate EOF.
- */
- public int available(){
- super.available();
- return available;
- }
-
- /**
- * Overriden - basically calls to super method, but checks returned
- * number of bytes read; if "-1", then the next call to
- * {@link #available} will return "0".
- */
- public int read(byte b[], int off, int len) {
- int result = super.read(b, off, len);
- if (result<0){
- available = 0;
- }
- return result;
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,566 +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 com.metamatrix.common.util;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.common.util.PropertiesUtils.InvalidPropertyException;
-import com.metamatrix.core.util.UnitTestUtil;
-
-/**
- * Tests primarily the various cloning scenarios available with PropertiesUtils
- */
-public class TestPropertiesUtils extends TestCase {
-
- private final static String TEMP_FILE = UnitTestUtil.getTestScratchPath() + "/temp.properties"; //$NON-NLS-1$
-
-
-
- // ################################## FRAMEWORK ################################
-
- public TestPropertiesUtils(String name) {
- super(name);
- }
-
- public void tearDown() throws Exception{
- try {
- File temp = new File(TEMP_FILE);
- temp.delete();
- } catch (Exception e) {
- //ignore
- }
- }
-
-
- //===================================================================
- //ACTUAL TESTS
- //===================================================================
-
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#print(String, Properties, String header)}
- * and {@link com.metamatrix.common.utils.PropertiesUtils#load(String)}
- * and {@link com.metamatrix.common.utils.PropertiesUtils#loadHeader(String)}
- */
- public void testPrintLoadWithHeader() throws Exception {
- Properties props1 = make(MAP_C, null, !UNMODIFIABLE);
-
- //print to file
- PropertiesUtils.print(TEMP_FILE, props1, "header"); //$NON-NLS-1$
-
- //load from file
- Properties props2 = PropertiesUtils.load(TEMP_FILE);
- assertEquals("Expected props1 to be equal to props2", 0, PropertiesUtils.compare(props1, props2)); //$NON-NLS-1$
-
- String header = PropertiesUtils.loadHeader(TEMP_FILE);
- assertEquals("header", header); //$NON-NLS-1$
- }
-
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#print(String, Properties)}
- * and {@link com.metamatrix.common.utils.PropertiesUtils#load(String)}
- * and {@link com.metamatrix.common.utils.PropertiesUtils#loadHeader(String)}
- */
- public void testPrintLoadWithoutHeader() throws Exception {
- Properties props1 = make(MAP_C, null, !UNMODIFIABLE);
-
- //print to file
- PropertiesUtils.print(TEMP_FILE, props1);
-
- //load from file
- Properties props2 = PropertiesUtils.load(TEMP_FILE);
- assertEquals("Expected props1 to be equal to props2", 0, PropertiesUtils.compare(props1, props2)); //$NON-NLS-1$
- }
-
-
-
-
- // ################ putAll(Properties, Properties) ###########################
-
- public void testPutAllWithDefaults(){
- Properties c = make(MAP_C, null, !UNMODIFIABLE);
- Properties ab = make(MAP_A, make(MAP_B, null, UNMODIFIABLE), UNMODIFIABLE);
- PropertiesUtils.putAll(c, ab);
- assertTrue(verifyProps(c, LIST_ABC));
- }
-
- // ##################### clone(Properties) ###################################
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties)}
- */
- public void testSimpleModifiableClone(){
- Properties a = make(MAP_A, null, !UNMODIFIABLE);
- a = PropertiesUtils.clone(a);
- assertTrue(verifyProps(a, LIST_A));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties)}
- */
- public void testSimpleModifiableCloneWithUnmodifiableDefaults(){
- Properties ab = make(MAP_A, make(MAP_B, null, UNMODIFIABLE), !UNMODIFIABLE);
- ab = PropertiesUtils.clone(ab);
- assertTrue(verifyProps(ab, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties)}
- */
- public void testSimpleModifiableCloneWithModifiableDefaults(){
- Properties ab = make(MAP_A, make(MAP_B, null, !UNMODIFIABLE), !UNMODIFIABLE);
- ab = PropertiesUtils.clone(ab);
- assertTrue(verifyProps(ab, LIST_AB));
- }
-
- // ##################### clone(Properties, boolean) ##########################
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, boolean)}
- */
- public void testCloneModifiableAsModifiable(){
- Properties a = make(MAP_A, null, !UNMODIFIABLE);
- a = PropertiesUtils.clone(a);
- assertTrue(verifyProps(a, LIST_A));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, boolean)}
- */
- public void testCloneUnmodifiableAsModifiable(){
- Properties a = make(MAP_A, null, UNMODIFIABLE);
- a = PropertiesUtils.clone(a);
- assertTrue(verifyProps(a, LIST_A));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, boolean)}
- */
- public void testCloneModifiableWithModifiableAsModifiable(){
- Properties ab = make(MAP_A, make(MAP_B, null, !UNMODIFIABLE), !UNMODIFIABLE);
- ab = PropertiesUtils.clone(ab);
- assertTrue(verifyProps(ab, LIST_AB));
- }
-
- // ######## clone(Properties, Properties, boolean, boolean) ##################
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testCloneModAndModAsMod(){
- Properties a = make(MAP_A, null, !UNMODIFIABLE);
- Properties b = make(MAP_B, null, !UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testDeepcloneModAndModAsMod(){
- Properties a = make(MAP_A, null, !UNMODIFIABLE);
- Properties b = make(MAP_B, null, !UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testCloneModAndUnmodAsMod(){
- Properties a = make(MAP_A, null, !UNMODIFIABLE);
- Properties b = make(MAP_B, null, UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testDeepcloneModAndUnmodAsMod(){
- Properties a = make(MAP_A, null, !UNMODIFIABLE);
- Properties b = make(MAP_B, null, UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testCloneUnmodAndModAsMod(){
- Properties a = make(MAP_A, null, UNMODIFIABLE);
- Properties b = make(MAP_B, null, !UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testDeepcloneUnmodAndModAsMod(){
- Properties a = make(MAP_A, null, UNMODIFIABLE);
- Properties b = make(MAP_B, null, !UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testCloneUnmodAndUnmodAsMod(){
- Properties a = make(MAP_A, null, UNMODIFIABLE);
- Properties b = make(MAP_B, null, UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- /**
- * Tests {@link com.metamatrix.common.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
- */
- public void testDeepcloneUnmodAndUnmodAsMod(){
- Properties a = make(MAP_A, null, UNMODIFIABLE);
- Properties b = make(MAP_B, null, UNMODIFIABLE);
- a = PropertiesUtils.clone(a, b, DEEP_CLONE);
- assertTrue(verifyProps(a, LIST_AB));
- }
-
- // ########################## ADVANCED #######################################
-
- //===================================================================
- //TESTS HELPERS
- //===================================================================
-
- /**
- * Checks the Properties against the static test data defined in this Class.
- * @param props Properties to check
- * @param chainOfMappings a List of Map objects in order of defaults. That is,
- * the first Map should represent the properties itself, the second Map the internal
- * defaults of the properties, the third Map the defaults of the second Map, and so on...
- * @return true or false for pass or fail
- */
- private static final boolean verifyProps(Properties props, List chainOfMappings){
- boolean result = verifyAllPropsPresent(props, chainOfMappings);
- if (result){
- result = verifyCorrectMappings(props, chainOfMappings);
- }
- return result;
- }
-
- /**
- * Check that the Set of all keys in the List<Map> chainOfMappings is present in props.
- * @param props Properties to check
- * @param chainOfMappings a List of Map objects in order of defaults. That is,
- * the first Map should represent the properties itself, the second Map the internal
- * defaults of the properties, the third Map the defaults of the second Map, and so on...
- * @return true all keys are present, false otherwise
- */
- private static final boolean verifyAllPropsPresent(Properties props, List chainOfMappings){
- Enumeration e = props.propertyNames();
- HashSet propNames = new HashSet();
- while (e.hasMoreElements()) {
- propNames.add( e.nextElement());
- }
-
- HashSet testNames = new HashSet();
- Iterator i = chainOfMappings.iterator();
- while (i.hasNext()) {
- Map aMapping = (Map) i.next();
- testNames.addAll(aMapping.keySet());
- }
- return propNames.containsAll(testNames);
- }
-
- /**
- * Verify that the Properties props correctly reflects the chain of mappings (which
- * simulate an arbitrary chain of Properties and default Properties). For each
- * property name, look in order through each Map in the List chainOfMappings to
- * see if (a) that property name is there, and (b) that it is mapped to the same
- * property. There are two conditions that will cause this method to returns
- * false: (1) if a property name maps to an incorrect, non-null value the first
- * time a mapping for that property name is found; (2) if no mapping is found at
- * for a property name.
- * @param props Properties to check
- * @param chainOfMappings a List of Map objects in order of defaults. That is,
- * the first Map should represent the properties itself, the second Map the internal
- * defaults of the properties, the third Map the defaults of the second Map, and so on...
- * @return true if props correctly reflects the chainOfMappings, false otherwise
- */
- private static final boolean verifyCorrectMappings(Properties props, List chainOfMappings){
- Enumeration e = props.propertyNames();
- boolean allGood = true;
- while (e.hasMoreElements() && allGood) {
- boolean foundKey = false;
- String propName = (String) e.nextElement();
- String propValue = props.getProperty(propName);
- Iterator i = chainOfMappings.iterator();
- while (i.hasNext() && !foundKey) {
- Map aMapping = (Map) i.next();
- Object value = aMapping.get(propName);
- if (value != null){
- foundKey = true;
- allGood = propValue.equals(value);
- }
- }
- }
- return allGood;
- }
-
- /**
- * Constructs a Properties object from the supplied Map of properties,
- * the supplied defaults, and optionally wraps the returned Properties
- * in an UnmodifiableProperties instance
- * @param mappings Map of String propName to String propValue
- * @param defaults optional default Properties; may be null
- * @param makeUnmodifiable If true, the returned Properties object will be
- * an instance of UnmodifiableProperties wrapping a Properties object
- */
- private static final Properties make(Map mappings, Properties defaults, boolean makeUnmodifiable){
- Properties props = null;
- if (defaults != null){
- props = new Properties(defaults);
- } else {
- props = new Properties();
- }
- Iterator i = mappings.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry anEntry = (Map.Entry) i.next();
- props.setProperty((String)anEntry.getKey(),(String)anEntry.getValue());
- }
- return props;
- }
-
- private static final boolean UNMODIFIABLE = true;
- private static final boolean DEEP_CLONE = true;
-
- private static final String PROP_NAME_1 = "prop1"; //$NON-NLS-1$
- private static final String PROP_NAME_2 = "prop2"; //$NON-NLS-1$
- private static final String PROP_NAME_3 = "prop3"; //$NON-NLS-1$
- private static final String PROP_NAME_4 = "prop4"; //$NON-NLS-1$
- private static final String PROP_NAME_5 = "prop5"; //$NON-NLS-1$
- private static final String PROP_NAME_6 = "prop6"; //$NON-NLS-1$
-
- //"a", "b", or "c" designates which of the test Properties
- //the values will go in
- private static final String PROP_VALUE_1A = "value1a"; //$NON-NLS-1$
- private static final String PROP_VALUE_1B = "value1b"; //$NON-NLS-1$
- private static final String PROP_VALUE_2A = "value2a"; //$NON-NLS-1$
- private static final String PROP_VALUE_2C = "value2c"; //$NON-NLS-1$
- private static final String PROP_VALUE_3A = "value3a"; //$NON-NLS-1$
- private static final String PROP_VALUE_4B = "value4b"; //$NON-NLS-1$
- private static final String PROP_VALUE_4C = "value4c"; //$NON-NLS-1$
- private static final String PROP_VALUE_5B = "value5b"; //$NON-NLS-1$
- private static final String PROP_VALUE_6C = "value6c"; //$NON-NLS-1$
-
- private static final Map MAP_A;
- private static final Map MAP_B;
- private static final Map MAP_C;
- private static final List LIST_A;
-// private static final List LIST_B;
- private static final List LIST_AB;
- private static final List LIST_ABC;
- static{
- //A
- Map temp = new HashMap();
- temp.put(PROP_NAME_1, PROP_VALUE_1A);
- temp.put(PROP_NAME_2, PROP_VALUE_2A);
- temp.put(PROP_NAME_3, PROP_VALUE_3A);
- MAP_A = Collections.unmodifiableMap(temp);
- //B
- temp = new HashMap();
- temp.put(PROP_NAME_1, PROP_VALUE_1B);
- temp.put(PROP_NAME_4, PROP_VALUE_4B);
- temp.put(PROP_NAME_5, PROP_VALUE_5B);
- MAP_B = Collections.unmodifiableMap(temp);
- //C
- temp = new HashMap();
- temp.put(PROP_NAME_2, PROP_VALUE_2C);
- temp.put(PROP_NAME_4, PROP_VALUE_4C);
- temp.put(PROP_NAME_6, PROP_VALUE_6C);
- MAP_C = Collections.unmodifiableMap(temp);
- //LISTS OF BINDINGS
- List tempList = new ArrayList(1);
- tempList.add(MAP_A);
- LIST_A = Collections.unmodifiableList(tempList);
- tempList = new ArrayList(1);
- tempList.add(MAP_B);
-// LIST_B = Collections.unmodifiableList(tempList);
- tempList = new ArrayList(2);
- tempList.add(MAP_A);
- tempList.add(MAP_B);
- LIST_AB = Collections.unmodifiableList(tempList);
- tempList = new ArrayList(3);
- tempList.add(MAP_A);
- tempList.add(MAP_B);
- tempList.add(MAP_C);
- LIST_ABC = Collections.unmodifiableList(tempList);
- }
-
- public void testNestedProperties() throws Exception {
- System.setProperty("testdirectory", "c:/metamatrix/testdirectory"); //$NON-NLS-1$ //$NON-NLS-2$
-
- Properties p = new Properties(System.getProperties());
- p.setProperty("key1", "value1"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("key2", "${key1}/value2"); //$NON-NLS-1$ //$NON-NLS-2$
- p.put("key3", new Integer(-234)); //$NON-NLS-1$
- p.setProperty("key4", "${key2}/value4"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("key5", "${testdirectory}/testdata"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("key7", "anotherdir/${testdirectory}/${key1}"); //$NON-NLS-1$ //$NON-NLS-2$
- int currentSize = p.size();
-
- Properties m = PropertiesUtils.resolveNestedProperties(p);
- assertEquals("value1/value2", m.getProperty("key2")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(new Integer(-234), m.get("key3")); //$NON-NLS-1$
- assertEquals("value1/value2/value4", m.getProperty("key4")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("c:/metamatrix/testdirectory/testdata", m.getProperty("key5")); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals("anotherdir/c:/metamatrix/testdirectory/value1", m.getProperty("key7")); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue(p == m); // no cloning.
- assertTrue(currentSize == m.size());
-
- p.setProperty("key6", "${foo}"); //$NON-NLS-1$ //$NON-NLS-2$
-
- try {
- m = PropertiesUtils.resolveNestedProperties(p);
- fail("must have failed to resovle as {foo} does not exist"); //$NON-NLS-1$
- } catch(RuntimeException e) {
- // pass
- }
-
-
- // JIRA: TEIID-909 - The resolveNestedProperties logic goes in a loop when the key is also in the value as ${key}.
- Properties dups = new Properties();
- dups.setProperty("usethis", "${usethis}");
-
- dups = PropertiesUtils.resolveNestedProperties(dups);
-
-
-
- }
-
- public void testOverrideProperties() {
- Properties p = new Properties();
-
- p.setProperty("foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("foo1", "bar1"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("foo2", "bar2"); //$NON-NLS-1$ //$NON-NLS-2$
-
- Properties p1 = new Properties(p);
-
- p1.setProperty("foo", "x"); //$NON-NLS-1$ //$NON-NLS-2$
-
- PropertiesUtils.setOverrideProperies(p1, p);
-
- assertEquals("bar", p1.getProperty("foo")); //$NON-NLS-1$ //$NON-NLS-2$
-
- assertEquals(1, p1.size());
- }
-
- public void testGetInvalidInt() {
- Properties p = new Properties();
- p.setProperty("x", "y"); //$NON-NLS-1$ //$NON-NLS-2$
- try {
- PropertiesUtils.getIntProperty(p, "x", 1); //$NON-NLS-1$
- fail("expected exception"); //$NON-NLS-1$
- } catch (InvalidPropertyException e) {
- assertEquals("Property 'x' with value 'y' is not a valid Integer.", e.getMessage()); //$NON-NLS-1$
- }
- }
-
- static class Bean {
- private int prop;
- private String prop1;
- private double prop2;
- private List<String> prop3;
-
- public int getProp() {
- return prop;
- }
- public void setProp(int prop) {
- this.prop = prop;
- }
- public String getProp1() {
- return prop1;
- }
- public void setProp1(String prop1) {
- this.prop1 = prop1;
- }
- public double getProp2() {
- return prop2;
- }
- public void setProp2(double prop2) {
- this.prop2 = prop2;
- }
- public List<String> getProp3() {
- return prop3;
- }
- public void setProp3(List<String> prop3) {
- this.prop3 = prop3;
- }
- }
-
- public void testSetBeanProperties() {
- Bean bean = new Bean();
- Properties p = new Properties();
- p.setProperty("prop", "0"); //$NON-NLS-1$//$NON-NLS-2$
- p.setProperty("prop1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("prop2", "2"); //$NON-NLS-1$ //$NON-NLS-2$
- p.setProperty("prop3", "3"); //$NON-NLS-1$ //$NON-NLS-2$
-
- p = new Properties(p);
- p.put("object", new Object()); //$NON-NLS-1$
-
- PropertiesUtils.setBeanProperties(bean, p, null);
-
- assertEquals(0, bean.getProp());
- assertEquals("1", bean.getProp1()); //$NON-NLS-1$
- assertEquals(2d, bean.getProp2());
- assertEquals(Arrays.asList("3"), bean.getProp3()); //$NON-NLS-1$
-
- p.setProperty("prop", "?"); //$NON-NLS-1$ //$NON-NLS-2$
-
- try {
- PropertiesUtils.setBeanProperties(bean, p, null);
- fail("expected exception"); //$NON-NLS-1$
- } catch (InvalidPropertyException e) {
-
- }
- }
-
- public void testGetInt() {
- Properties p = new Properties();
- p.setProperty("prop", "0 "); //$NON-NLS-1$ //$NON-NLS-2$
- assertEquals(PropertiesUtils.getIntProperty(p, "prop", -1), 0); //$NON-NLS-1$
- }
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/TestReaderInputStream.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestReaderInputStream.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestReaderInputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,70 +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 com.metamatrix.common.util;
-
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.StringReader;
-import java.nio.charset.Charset;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.common.util.ReaderInputStream;
-import com.metamatrix.core.util.UnitTestUtil;
-
-public class TestReaderInputStream extends TestCase {
-
- public void testUTF8() throws Exception {
- FileInputStream fis = new FileInputStream(UnitTestUtil.getTestDataFile("legal_notice.xml")); //$NON-NLS-1$
- ReaderInputStream ris = new ReaderInputStream(new FileReader(UnitTestUtil.getTestDataFile("legal_notice.xml")), Charset.forName("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
-
- int value;
- while (true) {
- value = fis.read();
- assertEquals(value, ris.read());
- if (value == -1) {
- break;
- }
- }
- }
-
- //the encoding strategy is roughly equivalent to utf-16
- public void testUTF16() throws Exception {
- String actual = "!?abc"; //$NON-NLS-1$
- ReaderInputStream ris = new ReaderInputStream(new StringReader(actual), Charset.forName("UTF-16"), 1); //$NON-NLS-1$
- byte[] result = new byte[(actual.length()) * 2 + 2];
- ris.read(result);
- String resultString = new String(result, "UTF-16"); //$NON-NLS-1$
- assertEquals(resultString, actual);
- }
-
- public void testASCII() throws Exception {
- String actual = "!?abc"; //$NON-NLS-1$
- ReaderInputStream ris = new ReaderInputStream(new StringReader(actual), Charset.forName("US-ASCII"), 1); //$NON-NLS-1$
- byte[] result = new byte[actual.length()];
- ris.read(result);
- String resultString = new String(result, "US-ASCII"); //$NON-NLS-1$
- assertEquals(resultString, actual);
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/TestSqlUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestSqlUtil.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestSqlUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,92 +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 com.metamatrix.common.util;
-
-import junit.framework.TestCase;
-
-/**
- */
-public class TestSqlUtil extends TestCase {
-
- public TestSqlUtil(String name) {
- super(name);
- }
-
- public void helpTest(String sql, boolean isUpdate) {
- boolean actual = SqlUtil.isUpdateSql(sql);
- assertEquals(isUpdate, actual);
- }
-
- public void testSelect() {
- helpTest("SELECT x FROM y", false); //$NON-NLS-1$
- }
-
- public void testInsert() {
- helpTest("Insert INTO g (a) VALUES (1)", true); //$NON-NLS-1$
- }
-
- public void testUpdate() {
- helpTest("upDate x set a=5", true); //$NON-NLS-1$
- }
-
- public void testDelete() {
- helpTest("delete FROM x", true); //$NON-NLS-1$
- }
-
- public void testInsertWithWhitespace() {
- helpTest("\nINSERT INTO g (a) VALUES (1)", true); //$NON-NLS-1$
- }
-
- public void testExec() {
- helpTest("exec sq1()", false); //$NON-NLS-1$
- }
-
- public void testXquery() {
- helpTest("<i/>", false); //$NON-NLS-1$
- }
-
- public void testSelectInto1() {
- helpTest("SELECT x INTO z FROM y", true); //$NON-NLS-1$
- }
-
- public void testSelectInto2() {
- helpTest("SELECT x, INTOz FROM y", false); //$NON-NLS-1$
- }
-
- public void testSelectInto3() {
- helpTest("SELECT x into z FROM y", true); //$NON-NLS-1$
- }
-
- public void testSelectInto4() {
- helpTest("SELECT x into z", true); //$NON-NLS-1$
- }
-
- public void testCreate() {
- helpTest(" create table x", true); //$NON-NLS-1$
- }
-
- public void testDrop() {
- helpTest("/* */ drop table x", true); //$NON-NLS-1$
- }
-
-}
Deleted: trunk/common-core/src/test/java/com/metamatrix/common/util/TestTimestampWithTimezone.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/TestTimestampWithTimezone.java 2010-05-11 21:30:12 UTC (rev 2114)
+++ trunk/common-core/src/test/java/com/metamatrix/common/util/TestTimestampWithTimezone.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,217 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.common.util;
-
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
-
-public class TestTimestampWithTimezone extends TestCase {
-
- /**
- * Constructor for TestTimestampWithTimezone.
- *
- * @param name
- */
- public TestTimestampWithTimezone(String name) {
- super(name);
- }
-
- public void setUp() {
- TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("America/Chicago")); //$NON-NLS-1$
- }
-
- public void tearDown() {
- TimestampWithTimezone.resetCalendar(null);
- }
-
- /**
- * Ensures that the same calendar fields in different timezones (initially different UTC) can be converted to the same UTC in
- * the local time zone
- *
- * @param startts
- * @param startnanos
- * @param starttz
- * @param endtz
- * @since 4.3
- */
- public void helpTestSame(String startts,
- int startnanos,
- String starttz,
- String endtz) {
- try {
- Timestamp start = getTimestamp(startts, startnanos, starttz);
- Timestamp end = getTimestamp(startts, startnanos, endtz);
-
- assertFalse("Initial timestamps should be different UTC times", start.getTime() == end.getTime()); //$NON-NLS-1$
-
- assertEquals(TimestampWithTimezone.createTimestamp(start, TimeZone.getTimeZone(starttz), Calendar.getInstance())
- .getTime(), TimestampWithTimezone.createTimestamp(end,
- TimeZone.getTimeZone(endtz),
- Calendar.getInstance()).getTime());
- } catch (ParseException e) {
- fail(e.toString());
- }
- }
-
- /**
- * Assuming local time zone of -06:00, change ts to endtz and compare to expected
- *
- * @param ts
- * @param endtz
- * @since 4.3
- */
- public void helpTestChange(String ts,
- String endtz,
- String expected) {
- Timestamp start = Timestamp.valueOf(ts);
- Calendar target = Calendar.getInstance(TimeZone.getTimeZone(endtz));
- assertEquals(expected,
- TimestampWithTimezone.createTimestamp(start, TimeZone.getTimeZone("America/Chicago"), target).toString()); //$NON-NLS-1$
- }
-
- /**
- * @param startts
- * @param startnanos
- * @param starttz
- * @throws ParseException
- * @since 4.3
- */
- private Timestamp getTimestamp(String startts,
- int startnanos,
- String starttz) throws ParseException {
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //$NON-NLS-1$
- df.setTimeZone(TimeZone.getTimeZone(starttz));
-
- Timestamp ts = new Timestamp(df.parse(startts).getTime());
- ts.setNanos(startnanos);
- return ts;
- }
-
- public void testDST() {
- helpTestSame("2005-10-30 02:39:10", 1, "America/Chicago", //$NON-NLS-1$ //$NON-NLS-2$
- "GMT-05:00"); //$NON-NLS-1$
-
- // ambiguous times are defaulted to standard time equivalent
- helpTestSame("2005-10-30 01:39:10", 1, "America/Chicago", //$NON-NLS-1$ //$NON-NLS-2$
- "GMT"); //$NON-NLS-1$
-
- // test to ensure a time not representable in DST is converted correctly
- helpTestSame("2005-04-03 02:39:10", 1, "GMT", //$NON-NLS-1$ //$NON-NLS-2$
- "America/Chicago"); //$NON-NLS-1$
-
- //expected is in DST
- helpTestChange("2005-10-30 02:39:10.1", "GMT", "2005-10-29 21:39:10.1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- //expected is in standard time
- helpTestChange("2005-10-30 10:39:10.1", "GMT", "2005-10-30 04:39:10.1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- }
-
- public void testTimezone() {
- helpTestSame("2004-06-29 15:39:10", 1, "GMT-06:00", //$NON-NLS-1$ //$NON-NLS-2$
- "GMT-05:00"); //$NON-NLS-1$
- }
-
- public void testTimezone2() {
- helpTestSame("2004-06-29 15:39:10", 1, "GMT-08:00", //$NON-NLS-1$ //$NON-NLS-2$
- "GMT-06:00"); //$NON-NLS-1$
- }
-
- public void testTimezone3() {
- helpTestSame("2004-08-31 18:25:54", 1, "Europe/London", //$NON-NLS-1$ //$NON-NLS-2$
- "GMT"); //$NON-NLS-1$
- }
-
- public void testTimezoneOverMidnight() {
- helpTestSame("2004-06-30 23:39:10", 1, "America/Los_Angeles", //$NON-NLS-1$ //$NON-NLS-2$
- "America/Chicago"); //$NON-NLS-1$
- }
-
- public void testCase2852() {
- helpTestSame("2005-05-17 22:35:33", 508659, "GMT", //$NON-NLS-1$ //$NON-NLS-2$
- "America/New_York"); //$NON-NLS-1$
- }
-
- public void testCreateDate() {
- Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201"); //$NON-NLS-1$
- Date date = TimestampWithTimezone.createDate(t);
-
- Calendar cal = Calendar.getInstance();
-
- cal.setTimeInMillis(date.getTime());
-
- assertEquals(cal.get(Calendar.HOUR_OF_DAY), 0);
- assertEquals(cal.get(Calendar.MINUTE), 0);
- assertEquals(cal.get(Calendar.SECOND), 0);
- assertEquals(cal.get(Calendar.MILLISECOND), 0);
- assertEquals(cal.get(Calendar.YEAR), 2004);
- assertEquals(cal.get(Calendar.MONTH), Calendar.JUNE);
- assertEquals(cal.get(Calendar.DATE), 30);
- }
-
- public void testCreateTime() {
- Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201"); //$NON-NLS-1$
- Time date = TimestampWithTimezone.createTime(t);
-
- Calendar cal = Calendar.getInstance();
-
- cal.setTimeInMillis(date.getTime());
-
- assertEquals(cal.get(Calendar.HOUR_OF_DAY), 23);
- assertEquals(cal.get(Calendar.MINUTE), 39);
- assertEquals(cal.get(Calendar.SECOND), 10);
- assertEquals(cal.get(Calendar.MILLISECOND), 0);
- assertEquals(cal.get(Calendar.YEAR), 1970);
- assertEquals(cal.get(Calendar.MONTH), Calendar.JANUARY);
- assertEquals(cal.get(Calendar.DATE), 1);
- }
-
- /**
- * Even though the id of the timezones are different, this should not change the result
- */
- public void testDateToDateConversion() {
- Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
- Date converted = TimestampWithTimezone.createDate(t, TimeZone.getTimeZone("America/Chicago"), Calendar.getInstance(TimeZone.getTimeZone("US/Central"))); //$NON-NLS-1$ //$NON-NLS-2$
-
- assertEquals(t.getTime(), converted.getTime());
- }
-
- public void testDateToDateConversion1() {
- Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
- Date converted = TimestampWithTimezone.createDate(t, TimeZone.getTimeZone("America/Chicago"), Calendar.getInstance(TimeZone.getTimeZone("GMT"))); //$NON-NLS-1$ //$NON-NLS-2$
-
- Calendar cal = Calendar.getInstance();
- cal.setTime(converted);
-
- assertEquals(0, cal.get(Calendar.MILLISECOND));
- }
-
-}
\ No newline at end of file
Copied: trunk/common-core/src/test/java/org/teiid/api/exception (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/api/exception)
Deleted: trunk/common-core/src/test/java/org/teiid/api/exception/TestExceptionHolder.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/api/exception/TestExceptionHolder.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/api/exception/TestExceptionHolder.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,104 +0,0 @@
-package com.metamatrix.api.exception;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.SQLException;
-import java.util.ArrayList;
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-
-import com.metamatrix.core.MetaMatrixRuntimeException;
-import com.metamatrix.core.util.ReflectionHelper;
-import com.metamatrix.core.util.UnitTestUtil;
-
-public class TestExceptionHolder extends TestCase {
-
- //## JDBC4.0-begin ##
- @SuppressWarnings("all")
- public static class BadException extends MetaMatrixProcessingException {
- private Object obj;
- public BadException(String msg) {super(msg);}
- public BadException(Object obj) {
- this.obj = obj;
- }
- }
-
- @Test public void testDeserializationUnknownException() throws Exception {
- ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
- Object obj = ReflectionHelper.create("test.Test", null, cl); //$NON-NLS-1$
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new ExceptionHolder(new BadException(obj)));
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
- ExceptionHolder holder = (ExceptionHolder)ois.readObject();
- assertTrue(holder.getException() instanceof BadException);
- assertEquals("Remote exception: null ... Original type hierarchy [com.metamatrix.api.exception.TestExceptionHolder$BadException, com.metamatrix.api.exception.MetaMatrixProcessingException, com.metamatrix.api.exception.MetaMatrixException, com.metamatrix.core.MetaMatrixCoreException].", holder.getException().getMessage()); //$NON-NLS-1$
- }
-
-
- @SuppressWarnings("all")
- public static class BadException2 extends MetaMatrixProcessingException {
- public BadException2(String msg) {
- super(msg);
- }
- public BadException2(Throwable e, String msg) {
- super(e, msg);
- }
- }
-
- @Test public void testDeserializationUnknownChildException() throws Exception {
- ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
- Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); //$NON-NLS-1$
- obj.initCause(new SQLException("something bad happended")); //$NON-NLS-1$
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new ExceptionHolder(new BadException2(obj, "I have foreign exception embedded in me"))); //$NON-NLS-1$
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
- ExceptionHolder holder = (ExceptionHolder)ois.readObject();
- Throwable e = holder.getException();
- assertTrue(e instanceof BadException2);
- assertEquals("Remote exception: I have foreign exception embedded in me ... Original type hierarchy [com.metamatrix.api.exception.TestExceptionHolder$BadException2, com.metamatrix.api.exception.MetaMatrixProcessingException, com.metamatrix.api.exception.MetaMatrixException, com.metamatrix.core.MetaMatrixCoreException].", e.getMessage()); //$NON-NLS-1$
-
- // now unknown exception is not found, so promote known SQL exception up
- e = e.getCause();
- assertTrue(e instanceof SQLException);
- assertEquals("Remote exception: something bad happended ... Original type hierarchy [java.sql.SQLException].", e.getMessage()); //$NON-NLS-1$
- }
-
- @Test public void testDeserializationUnknownChildException2() throws Exception {
- ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); //$NON-NLS-1$
- ArrayList<String> args = new ArrayList<String>();
- args.add("Unknown Exception"); //$NON-NLS-1$
- Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", args, cl); //$NON-NLS-1$
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new ExceptionHolder(obj));
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
- ExceptionHolder holder = (ExceptionHolder)ois.readObject();
- Throwable e = holder.getException();
- assertTrue(e instanceof MetaMatrixRuntimeException);
- assertEquals("Unknown Exception", e.getMessage()); //$NON-NLS-1$
- }
- //## JDBC4.0-end ##
-
- /*## JDBC3.0-JDK1.5-begin ##
- public void testPass(){
- // since the jar files required are built with 1.6, it will always fail, so just comment the test for 1.5
- }
- ## JDBC3.0-JDK1.5-end ##*/
-}
Deleted: trunk/common-core/src/test/java/org/teiid/api/exception/TestMetaMatrixException.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/api/exception/TestMetaMatrixException.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/api/exception/TestMetaMatrixException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,98 +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 com.metamatrix.api.exception;
-
-import junit.framework.TestCase;
-
-/**
- * Tests the children Iterator of the MetaMatrixException. Primarily it does
- * this by comparing two Lists for equality: one List is created by Iterating
- * using the
- * {@link com.metamatrix.api.exception.MetaMatrixException#getChildren Iterator},
- * the other List is created by manually using the
- * {@link com.metamatrix.api.exception.MetaMatrixException#getChild getChild}
- * method recursively.
- */
-public class TestMetaMatrixException extends TestCase {
-
- // ################################## FRAMEWORK ################################
-
- public TestMetaMatrixException(String name) {
- super(name);
- }
-
- // ################################## ACTUAL TESTS ################################
-
- public void testFailMetaMatrixExceptionWithNullMessage() {
- Throwable e = null;
- try {
- new MetaMatrixException((String)null); // should throw NPE
- fail("Should not get here"); //$NON-NLS-1$
- } catch ( Throwable ex ) {
- e = ex;
- }
- assertNotNull(e);
- }
-
- public void testMetaMatrixExceptionWithNullThrowable() {
- final MetaMatrixException err = new MetaMatrixException((Throwable)null);
- assertNull(err.getChild());
- assertNull(err.getCode());
- assertNull(err.getMessage());
-
- }
-
- public void testMetaMatrixExceptionWithMessage() {
- final MetaMatrixException err = new MetaMatrixException("Test"); //$NON-NLS-1$
- assertNull(err.getChild());
- assertNull(err.getCode());
- assertEquals("Test", err.getMessage()); //$NON-NLS-1$
-
- }
-
- public void testMetaMatrixExceptionWithCodeAndMessage() {
- final MetaMatrixException err = new MetaMatrixException("Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
- assertNull(err.getChild());
- assertEquals("Code", err.getCode()); //$NON-NLS-1$
- assertEquals("Error Code:Code Message:Test", err.getMessage()); //$NON-NLS-1$
-
- }
-
- public void testMetaMatrixExceptionWithExceptionAndMessage() {
- final MetaMatrixException child = new MetaMatrixException("propertyValuePhrase", "Child"); //$NON-NLS-1$ //$NON-NLS-2$
- final MetaMatrixException err = new MetaMatrixException(child, "Test"); //$NON-NLS-1$
- assertSame(child, err.getChild());
- assertEquals("propertyValuePhrase", err.getCode()); //$NON-NLS-1$
- assertEquals("Error Code:propertyValuePhrase Message:Test", err.getMessage()); //$NON-NLS-1$
-
- }
-
- public void testMetaMatrixExceptionWithExceptionAndCodeAndMessage() {
- final MetaMatrixException child = new MetaMatrixException("propertyValuePhrase", "Child"); //$NON-NLS-1$ //$NON-NLS-2$
- final MetaMatrixException err = new MetaMatrixException(child, "Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
- assertSame(child, err.getChild());
- assertEquals("Code", err.getCode()); //$NON-NLS-1$
- assertEquals("Error Code:Code Message:Test", err.getMessage()); //$NON-NLS-1$
-
- }
-}
Deleted: trunk/common-core/src/test/java/org/teiid/api/exception/TestMetaMatrixRuntimeException.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/api/exception/TestMetaMatrixRuntimeException.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/api/exception/TestMetaMatrixRuntimeException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -1,107 +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.
- */
-
-/*
- * Date: Sep 25, 2003
- * Time: 1:18:10 PM
- */
-package com.metamatrix.api.exception;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.core.MetaMatrixRuntimeException;
-
-/**
- * JUnit test for MetaMatrixRuntimeException
- */
-public final class TestMetaMatrixRuntimeException extends TestCase {
- // =========================================================================
- // F R A M E W O R K
- // =========================================================================
- /**
- * Constructor for TestMetaMatrixRuntimeException.
- * @param name
- */
- public TestMetaMatrixRuntimeException(final String name) {
- super(name);
- }
-
- // =========================================================================
- // T E S T C A S E S
- // =========================================================================
-
- public void testFailMetaMatrixRuntimeExceptionWithNullMessage() {
- Throwable e = null;
- try {
- new MetaMatrixRuntimeException((String)null); // should throw NPE
- fail("Should not get here"); //$NON-NLS-1$
- } catch ( Throwable ex ) {
- e = ex;
- }
- assertNotNull(e);
- }
-
- public void testMetaMatrixRuntimeExceptionWithNullThrowable() {
- final MetaMatrixRuntimeException err = new MetaMatrixRuntimeException((Throwable)null);
- assertNull(err.getChild());
- assertEquals("0", err.getCode()); //$NON-NLS-1$
- assertNull(err.getMessage());
-
- }
-
- public void testMetaMatrixRuntimeExceptionWithMessage() {
- final MetaMatrixRuntimeException err = new MetaMatrixRuntimeException("Test"); //$NON-NLS-1$
- assertNull(err.getChild());
- assertEquals("0", err.getCode()); //$NON-NLS-1$
- assertEquals("Test", err.getMessage()); //$NON-NLS-1$
-
- }
-
- public void testMetaMatrixRuntimeExceptionWithCodeAndMessage() {
- final String code = "1234"; //$NON-NLS-1$
- final MetaMatrixRuntimeException err = new MetaMatrixRuntimeException(code, "Test"); //$NON-NLS-1$
- assertNull(err.getChild());
- assertEquals(code, err.getCode());
- assertEquals("Test", err.getMessage()); //$NON-NLS-1$
-
- }
-
- public void testMetaMatrixRuntimeExceptionWithExceptionAndMessage() {
- final String code = "1234"; //$NON-NLS-1$
- final MetaMatrixRuntimeException child = new MetaMatrixRuntimeException(code, "Child"); //$NON-NLS-1$
- final MetaMatrixRuntimeException err = new MetaMatrixRuntimeException(child, "Test"); //$NON-NLS-1$
- assertSame(child, err.getChild());
- assertEquals(code, err.getCode());
- assertEquals("Test", err.getMessage()); //$NON-NLS-1$
-
- }
-
- public void testMetaMatrixRuntimeExceptionWithExceptionAndCodeAndMessage() {
- final String code = "1234"; //$NON-NLS-1$
- final MetaMatrixRuntimeException child = new MetaMatrixRuntimeException(code, "Child"); //$NON-NLS-1$
- final MetaMatrixRuntimeException err = new MetaMatrixRuntimeException(child, "Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
- assertSame(child, err.getChild());
- assertEquals("Code", err.getCode()); //$NON-NLS-1$
- assertEquals("Test", err.getMessage()); //$NON-NLS-1$
-
- }
-}
\ No newline at end of file
Added: trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixException.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixException.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,100 @@
+/*
+ * 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.core;
+
+import org.teiid.core.TeiidException;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the children Iterator of the MetaMatrixException. Primarily it does
+ * this by comparing two Lists for equality: one List is created by Iterating
+ * using the
+ * {@link org.teiid.core.TeiidException#getChildren Iterator},
+ * the other List is created by manually using the
+ * {@link org.teiid.core.TeiidException#getChild getChild}
+ * method recursively.
+ */
+public class TestMetaMatrixException extends TestCase {
+
+ // ################################## FRAMEWORK ################################
+
+ public TestMetaMatrixException(String name) {
+ super(name);
+ }
+
+ // ################################## ACTUAL TESTS ################################
+
+ public void testFailMetaMatrixExceptionWithNullMessage() {
+ Throwable e = null;
+ try {
+ new TeiidException((String)null); // should throw NPE
+ fail("Should not get here"); //$NON-NLS-1$
+ } catch ( Throwable ex ) {
+ e = ex;
+ }
+ assertNotNull(e);
+ }
+
+ public void testMetaMatrixExceptionWithNullThrowable() {
+ final TeiidException err = new TeiidException((Throwable)null);
+ assertNull(err.getChild());
+ assertNull(err.getCode());
+ assertNull(err.getMessage());
+
+ }
+
+ public void testMetaMatrixExceptionWithMessage() {
+ final TeiidException err = new TeiidException("Test"); //$NON-NLS-1$
+ assertNull(err.getChild());
+ assertNull(err.getCode());
+ assertEquals("Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+
+ public void testMetaMatrixExceptionWithCodeAndMessage() {
+ final TeiidException err = new TeiidException("Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertNull(err.getChild());
+ assertEquals("Code", err.getCode()); //$NON-NLS-1$
+ assertEquals("Error Code:Code Message:Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+
+ public void testMetaMatrixExceptionWithExceptionAndMessage() {
+ final TeiidException child = new TeiidException("propertyValuePhrase", "Child"); //$NON-NLS-1$ //$NON-NLS-2$
+ final TeiidException err = new TeiidException(child, "Test"); //$NON-NLS-1$
+ assertSame(child, err.getChild());
+ assertEquals("propertyValuePhrase", err.getCode()); //$NON-NLS-1$
+ assertEquals("Error Code:propertyValuePhrase Message:Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+
+ public void testMetaMatrixExceptionWithExceptionAndCodeAndMessage() {
+ final TeiidException child = new TeiidException("propertyValuePhrase", "Child"); //$NON-NLS-1$ //$NON-NLS-2$
+ final TeiidException err = new TeiidException(child, "Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertSame(child, err.getChild());
+ assertEquals("Code", err.getCode()); //$NON-NLS-1$
+ assertEquals("Error Code:Code Message:Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+}
Added: trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/TestMetaMatrixRuntimeException.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,108 @@
+/*
+ * 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.
+ */
+
+/*
+ * Date: Sep 25, 2003
+ * Time: 1:18:10 PM
+ */
+package org.teiid.core;
+
+import org.teiid.core.TeiidRuntimeException;
+
+import junit.framework.TestCase;
+
+
+/**
+ * JUnit test for MetaMatrixRuntimeException
+ */
+public final class TestMetaMatrixRuntimeException extends TestCase {
+ // =========================================================================
+ // F R A M E W O R K
+ // =========================================================================
+ /**
+ * Constructor for TestMetaMatrixRuntimeException.
+ * @param name
+ */
+ public TestMetaMatrixRuntimeException(final String name) {
+ super(name);
+ }
+
+ // =========================================================================
+ // T E S T C A S E S
+ // =========================================================================
+
+ public void testFailMetaMatrixRuntimeExceptionWithNullMessage() {
+ Throwable e = null;
+ try {
+ new TeiidRuntimeException((String)null); // should throw NPE
+ fail("Should not get here"); //$NON-NLS-1$
+ } catch ( Throwable ex ) {
+ e = ex;
+ }
+ assertNotNull(e);
+ }
+
+ public void testMetaMatrixRuntimeExceptionWithNullThrowable() {
+ final TeiidRuntimeException err = new TeiidRuntimeException((Throwable)null);
+ assertNull(err.getChild());
+ assertEquals("0", err.getCode()); //$NON-NLS-1$
+ assertNull(err.getMessage());
+
+ }
+
+ public void testMetaMatrixRuntimeExceptionWithMessage() {
+ final TeiidRuntimeException err = new TeiidRuntimeException("Test"); //$NON-NLS-1$
+ assertNull(err.getChild());
+ assertEquals("0", err.getCode()); //$NON-NLS-1$
+ assertEquals("Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+
+ public void testMetaMatrixRuntimeExceptionWithCodeAndMessage() {
+ final String code = "1234"; //$NON-NLS-1$
+ final TeiidRuntimeException err = new TeiidRuntimeException(code, "Test"); //$NON-NLS-1$
+ assertNull(err.getChild());
+ assertEquals(code, err.getCode());
+ assertEquals("Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+
+ public void testMetaMatrixRuntimeExceptionWithExceptionAndMessage() {
+ final String code = "1234"; //$NON-NLS-1$
+ final TeiidRuntimeException child = new TeiidRuntimeException(code, "Child"); //$NON-NLS-1$
+ final TeiidRuntimeException err = new TeiidRuntimeException(child, "Test"); //$NON-NLS-1$
+ assertSame(child, err.getChild());
+ assertEquals(code, err.getCode());
+ assertEquals("Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+
+ public void testMetaMatrixRuntimeExceptionWithExceptionAndCodeAndMessage() {
+ final String code = "1234"; //$NON-NLS-1$
+ final TeiidRuntimeException child = new TeiidRuntimeException(code, "Child"); //$NON-NLS-1$
+ final TeiidRuntimeException err = new TeiidRuntimeException(child, "Code", "Test"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertSame(child, err.getChild());
+ assertEquals("Code", err.getCode()); //$NON-NLS-1$
+ assertEquals("Test", err.getMessage()); //$NON-NLS-1$
+
+ }
+}
\ No newline at end of file
Copied: trunk/common-core/src/test/java/org/teiid/core/crypto (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/util/crypto)
Modified: trunk/common-core/src/test/java/org/teiid/core/crypto/TestDhKeyGenerator.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/TestDhKeyGenerator.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/crypto/TestDhKeyGenerator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,8 +20,12 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
+import org.teiid.core.crypto.CryptoException;
+import org.teiid.core.crypto.DhKeyGenerator;
+import org.teiid.core.crypto.SymmetricCryptor;
+
import junit.framework.TestCase;
Modified: trunk/common-core/src/test/java/org/teiid/core/crypto/TestEncryptDecrypt.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/util/crypto/TestEncryptDecrypt.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/crypto/TestEncryptDecrypt.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.util.crypto;
+package org.teiid.core.crypto;
import static org.junit.Assert.*;
@@ -34,6 +34,10 @@
import org.junit.BeforeClass;
import org.junit.Test;
+import org.teiid.core.crypto.BasicCryptor;
+import org.teiid.core.crypto.CryptoException;
+import org.teiid.core.crypto.Cryptor;
+import org.teiid.core.crypto.SymmetricCryptor;
/**
Copied: trunk/common-core/src/test/java/org/teiid/core/id (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/core/id)
Modified: trunk/common-core/src/test/java/org/teiid/core/id/TestIDGenerator.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/id/TestIDGenerator.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/id/TestIDGenerator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,21 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.util.Collection;
import java.util.Iterator;
+import org.teiid.core.id.IDGenerator;
+import org.teiid.core.id.IntegerID;
+import org.teiid.core.id.IntegerIDFactory;
+import org.teiid.core.id.InvalidIDException;
+import org.teiid.core.id.LongID;
+import org.teiid.core.id.ObjectID;
+import org.teiid.core.id.ObjectIDFactory;
+import org.teiid.core.id.StringID;
+import org.teiid.core.id.UUID;
+
import junit.framework.TestCase;
/**
Modified: trunk/common-core/src/test/java/org/teiid/core/id/TestParsedObjectID.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/id/TestParsedObjectID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/id/TestParsedObjectID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,8 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
+import org.teiid.core.id.InvalidIDException;
+import org.teiid.core.id.ParsedObjectID;
+
import junit.framework.TestCase;
/**
Modified: trunk/common-core/src/test/java/org/teiid/core/id/TestParsingObjectIDs.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/id/TestParsingObjectIDs.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/id/TestParsingObjectIDs.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.io.BufferedReader;
import java.io.FileInputStream;
@@ -35,8 +35,9 @@
import junit.framework.TestCase;
-import com.metamatrix.core.util.UnitTestUtil;
+import org.teiid.core.util.UnitTestUtil;
+
/**
* TestParsingObjectIDs
*/
Modified: trunk/common-core/src/test/java/org/teiid/core/id/TestUUID.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/id/TestUUID.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/id/TestUUID.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.util.HashSet;
import java.util.Set;
+import org.teiid.core.id.InvalidIDException;
+import org.teiid.core.id.UUID;
+
import junit.framework.TestCase;
/**
Modified: trunk/common-core/src/test/java/org/teiid/core/id/TestUUIDFactory.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/id/TestUUIDFactory.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/id/TestUUIDFactory.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
import java.util.Collection;
import java.util.HashSet;
Modified: trunk/common-core/src/test/java/org/teiid/core/id/TestUUIDFactoryWithoutCreation.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/id/TestUUIDFactoryWithoutCreation.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/id/TestUUIDFactoryWithoutCreation.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,8 +20,11 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.id;
+package org.teiid.core.id;
+import org.teiid.core.id.InvalidIDException;
+import org.teiid.core.id.UUIDFactory;
+
import junit.framework.TestCase;
/**
Copied: trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/TestBlobValue.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestBlobValue.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,78 @@
+/*
+ * 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.core.types;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.sql.rowset.serial.SerialBlob;
+
+import org.teiid.core.types.BlobType;
+import org.teiid.core.util.UnitTestUtil;
+
+
+import junit.framework.TestCase;
+
+
+public class TestBlobValue extends TestCase {
+
+ public void testBlobValue() throws Exception {
+ String testString = "this is test blob"; //$NON-NLS-1$
+ SerialBlob blob = new SerialBlob(testString.getBytes());
+
+ BlobType bv = new BlobType(blob);
+ assertEquals(testString, new String(bv.getBytes(1L, (int)bv.length())));
+ }
+
+
+ public void testBlobValuePersistence() throws Exception {
+ String testString = "this is test clob"; //$NON-NLS-1$
+ SerialBlob blob = new SerialBlob(testString.getBytes());
+
+ String key = "keytodata"; //$NON-NLS-1$
+ BlobType bv = new BlobType(blob);
+ bv.setReferenceStreamId(key);
+
+ // now force to serialize
+ File saved = new File(UnitTestUtil.getTestScratchPath()+"/blobassaved.bin"); //$NON-NLS-1$
+ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
+ out.writeObject(bv);
+ out.close();
+
+ // now read back the object from serilized state
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
+ BlobType read = (BlobType)in.readObject();
+
+ // make sure we have kept the reference stream id
+ assertEquals(key, read.getReferenceStreamId());
+
+ // and lost the original object
+ assertNull(read.getReference());
+
+ saved.delete();
+ }
+
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/TestClobValue.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestClobValue.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,78 @@
+/*
+ * 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.core.types;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.sql.rowset.serial.SerialClob;
+
+import org.teiid.core.types.ClobType;
+import org.teiid.core.util.UnitTestUtil;
+
+
+import junit.framework.TestCase;
+
+
+public class TestClobValue extends TestCase {
+
+ public void testClobValue() throws Exception {
+ String testString = "this is test clob"; //$NON-NLS-1$
+ SerialClob clob = new SerialClob(testString.toCharArray());
+
+ ClobType cv = new ClobType(clob);
+ assertEquals(testString, cv.getSubString(1L, (int)cv.length()));
+ }
+
+
+ public void testClobValuePersistence() throws Exception {
+ String testString = "this is test clob"; //$NON-NLS-1$
+ SerialClob clob = new SerialClob(testString.toCharArray());
+
+ String key = "keytodata"; //$NON-NLS-1$
+ ClobType cv = new ClobType(clob);
+ cv.setReferenceStreamId(key);
+
+ // now force to serialize
+ File saved = new File(UnitTestUtil.getTestScratchPath()+"/clobassaved.bin"); //$NON-NLS-1$
+ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
+ out.writeObject(cv);
+ out.close();
+
+ // now read back the object from serilized state
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
+ ClobType read = (ClobType)in.readObject();
+
+ // make sure we have kept the reference stream id
+ assertEquals(key, read.getReferenceStreamId());
+
+ // and lost the original object
+ assertNull(read.getReference());
+
+ saved.delete();
+ }
+
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/TestDataTypeManager.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestDataTypeManager.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,230 @@
+/*
+ * 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.core.types;
+
+import static org.junit.Assert.*;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.sql.rowset.serial.SerialBlob;
+
+import org.junit.Test;
+import org.teiid.core.types.BlobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.JDBCSQLTypeInfo;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+
+public class TestDataTypeManager {
+
+ private void helpDetermineDataType(Object value, Class expectedClass) {
+ Class actualClass = DataTypeManager.determineDataTypeClass(value);
+ assertNotNull("Should never receive null when determining data type of object: " + value); //$NON-NLS-1$
+ assertEquals("Mismatch in expected and actual MetaMatrix type class for [" + value + "]: ", expectedClass, actualClass); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ public static String[] dataTypes = {"string","char","boolean","byte","short","integer","long","biginteger", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
+ "float","double","bigdecimal","date","time","timestamp","object","blob","clob", DataTypeManager.DefaultDataTypes.XML}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
+
+ /**
+ * I - Implicitly Converted
+ * C - Explicitly Converted
+ * N - Cannot be converted
+ * o - No conversion needed
+ */
+ public static char conversions [][] =
+ {
+ /* Big */
+ /* i d */
+ /* s n b d e Time o */
+ /* t s t i f o c s b */
+ /* r c b b h e L g l u i d t t j b c */
+ /* i h o y o g o i o b m a i a e l l x */
+ /* n a o t r e n n a l a t m m c o o m */
+ /* g r l e t r g t t e l e e p t b b l */
+ /* -------------------------------------------------------------------------*/
+ /*String*/ { 'O','C','C','C','C','C','C','C','C','C','C','C','C','C','I','N','I','C' },
+ /*char*/ { 'I','O','N','N','N','N','N','N','N','N','N','N','N','N','I','N','N','N' },
+ /*bool*/ { 'I','N','O','I','I','I','I','I','I','I','I','N','N','N','I','N','N','N' },
+ /*byte*/ { 'I','N','C','O','I','I','I','I','I','I','I','N','N','N','I','N','N','N' },
+ /*short*/ { 'I','N','C','C','O','I','I','I','I','I','I','N','N','N','I','N','N','N' },
+ /*int*/ { 'I','N','C','C','C','O','I','I','C','I','I','N','N','N','I','N','N','N' },
+ /*long*/ { 'I','N','C','C','C','C','O','I','C','C','I','N','N','N','I','N','N','N' },
+ /*bigint*/ { 'I','N','C','C','C','C','C','O','C','C','I','N','N','N','I','N','N','N' },
+ /*float*/ { 'I','N','C','C','C','C','C','C','O','I','I','N','N','N','I','N','N','N' },
+ /*double*/ { 'I','N','C','C','C','C','C','C','C','O','I','N','N','N','I','N','N','N' },
+ /*bigdecimal*/ { 'I','N','C','C','C','C','C','C','C','C','O','N','N','N','I','N','N','N' },
+ /*date*/ { 'I','N','N','N','N','N','N','N','N','N','N','O','N','I','I','N','N','N' },
+ /*time*/ { 'I','N','N','N','N','N','N','N','N','N','N','N','O','I','I','N','N','N' },
+ /*timestamp*/ { 'I','N','N','N','N','N','N','N','N','N','N','C','C','O','I','N','N','N' },
+ /*object*/ { 'C','C','C','C','C','C','C','C','C','C','C','C','C','C','O','C','C','C' },
+ /*blob*/ { 'N','N','N','N','N','N','N','N','N','N','N','N','N','N','I','O','N','N' },
+ /*clob*/ { 'C','N','N','N','N','N','N','N','N','N','N','N','N','N','I','N','O','C' },
+ /*xml*/ { 'C','N','N','N','N','N','N','N','N','N','N','N','N','N','I','N','C','O' }
+ };
+
+
+ // ################################## ACTUAL TESTS ################################
+
+ @Test public void testTypeMappings() {
+ Set dataTypeNames = DataTypeManager.getAllDataTypeNames();
+ Iterator iter = dataTypeNames.iterator();
+ while(iter.hasNext()) {
+ String dataTypeName = (String) iter.next();
+ Class dataTypeClass = DataTypeManager.getDataTypeClass(dataTypeName);
+ assertNotNull("Data type class was null for type " + dataTypeName, dataTypeClass); //$NON-NLS-1$
+ String dataTypeName2 = DataTypeManager.getDataTypeName(dataTypeClass);
+ assertEquals("Name to class to name not equals: ", dataTypeName, dataTypeName2); //$NON-NLS-1$
+ }
+ }
+
+ @Test public void testCheckConversions() {
+ for (int src = 0; src < dataTypes.length; src++) {
+ for (int tgt =0; tgt < dataTypes.length; tgt++) {
+ char c = conversions[src][tgt];
+
+ if (c == 'I') {
+ assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should be Implicit", DataTypeManager.isImplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should be not be Explicit", DataTypeManager.isExplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" transform should be avaialble", DataTypeManager.isTransformable(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ else if (c == 'C') {
+ assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should not be Implicit", DataTypeManager.isImplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should be Explicit", DataTypeManager.isExplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertTrue("src="+dataTypes[src]+" target="+dataTypes[tgt]+" transform should be avaialble", DataTypeManager.isTransformable(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ else if ( c == 'O' || c == 'N') {
+ assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should not be Implicit", DataTypeManager.isImplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" should not be Explicit", DataTypeManager.isExplicitConversion(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ assertFalse("src="+dataTypes[src]+" target="+dataTypes[tgt]+" No transform should be avaialble", DataTypeManager.isTransformable(dataTypes[src], dataTypes[tgt])); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ }
+ }
+
+ /** Test determine data type for a STRING object. */
+ @Test public void testDetermineDataType1() {
+ helpDetermineDataType("abc", DataTypeManager.DefaultDataClasses.STRING); //$NON-NLS-1$
+ }
+
+ /** Test determine data type for a NULL object. */
+ @Test public void testDetermineDataType2() {
+ helpDetermineDataType(null, DataTypeManager.DefaultDataClasses.NULL);
+ }
+
+ /** Test determine data type for an unknown object type - should be typed as an OBJECT. */
+ @Test public void testDetermineDataType3() throws Exception {
+ java.net.URL url = new java.net.URL("http://fake"); //$NON-NLS-1$
+ helpDetermineDataType(url, DataTypeManager.DefaultDataClasses.OBJECT);
+ }
+
+ @Test public void testCheckAllConversions() {
+ Set allTypes = DataTypeManager.getAllDataTypeNames();
+ Iterator srcIter = allTypes.iterator();
+ while(srcIter.hasNext()) {
+ String src = (String) srcIter.next();
+
+ Iterator tgtIter = allTypes.iterator();
+ while(tgtIter.hasNext()) {
+ String tgt = (String) tgtIter.next();
+
+ boolean isImplicit = DataTypeManager.isImplicitConversion(src, tgt);
+ boolean isExplicit = DataTypeManager.isExplicitConversion(src, tgt);
+
+ if(isImplicit && isExplicit) {
+ fail("Can't be both implicit and explicit for " + src + " to " + tgt); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ }
+ }
+
+ @Test public void testTimeConversions() {
+ Transform t = DataTypeManager.getTransform(DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.DATE);
+
+ assertEquals(DataTypeManager.DefaultDataClasses.DATE, t.getTargetType());
+
+ t = DataTypeManager.getTransform(DataTypeManager.DefaultDataTypes.TIME, DataTypeManager.DefaultDataTypes.TIMESTAMP);
+
+ assertEquals(DataTypeManager.DefaultDataClasses.TIMESTAMP, t.getTargetType());
+ }
+
+ @Test public void testJDBCSQLTypeInfo() {
+
+ String[] types = JDBCSQLTypeInfo.getMMTypeNames();
+
+ for (int i = 0; i < types.length; i++) {
+ String type = types[i];
+
+ assertEquals("Didn't get match for "+ type, JDBCSQLTypeInfo.getSQLType(type), JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.getDataTypeClass(type))); //$NON-NLS-1$
+
+ //the classnames will not match the runtime types for xml, clob, blob
+ if (!type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.XML) && !type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.CLOB) && !type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.BLOB)) {
+ assertEquals("Didn't get match for "+ type, JDBCSQLTypeInfo.getSQLType(type), JDBCSQLTypeInfo.getSQLTypeFromClass(DataTypeManager.getDataTypeClass(type).getName())); //$NON-NLS-1$
+ }
+ }
+
+ assertEquals(Types.TIMESTAMP, JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.TIMESTAMP));
+ //## JDBC4.0-begin ##
+ assertEquals(Types.SQLXML, JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.XML));
+ //## JDBC4.0-end ##
+ assertEquals(DataTypeManager.DefaultDataTypes.STRING, JDBCSQLTypeInfo.getTypeName(Types.CHAR));
+ assertEquals(Types.CHAR, JDBCSQLTypeInfo.getSQLTypeFromRuntimeType(DataTypeManager.DefaultDataClasses.CHAR));
+ }
+
+ @Test public void testRuntimeTypeConversion() throws Exception {
+ assertNull(DataTypeManager.convertToRuntimeType(null));
+
+ assertTrue(DataTypeManager.convertToRuntimeType(new SerialBlob(new byte[0])) instanceof BlobType);
+
+ //unknown type should return as same
+ Object foo = new Object();
+ assertEquals(foo, DataTypeManager.convertToRuntimeType(foo));
+
+ //known type should return as same
+ Integer bar = new Integer(1);
+ assertEquals(bar, DataTypeManager.convertToRuntimeType(bar));
+ }
+
+ @Test public void testObjectType() {
+ assertEquals(DataTypeManager.DefaultDataClasses.OBJECT, DataTypeManager.getDataTypeClass("foo")); //$NON-NLS-1$
+
+ assertEquals(DataTypeManager.DefaultDataTypes.OBJECT, DataTypeManager.getDataTypeName(TestDataTypeManager.class));
+ }
+
+ @Test public void testImplicitConversions() {
+ assertEquals(Arrays.asList(DataTypeManager.DefaultDataTypes.LONG,
+ DataTypeManager.DefaultDataTypes.BIG_INTEGER,
+ DataTypeManager.DefaultDataTypes.DOUBLE,
+ DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
+ 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$
+ }
+
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/TestSQLXMLImpl.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestSQLXMLImpl.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,109 @@
+/*
+ * 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.core.types;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.sql.SQLException;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.Streamable;
+import org.teiid.core.util.ObjectConverterUtil;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Basically we want to make sure that nobody has changed the fundamental contract
+ * of translator
+ */
+public class TestSQLXMLImpl extends TestCase {
+
+ String testStr = "<foo>test</foo>"; //$NON-NLS-1$
+
+ //## JDBC4.0-begin ##
+ public void testGetSource() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ assertTrue(xml.getSource(null) instanceof StreamSource);
+
+ StreamSource ss = (StreamSource)xml.getSource(null);
+ assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(ss.getInputStream()), Streamable.ENCODING));
+ }
+ //## JDBC4.0-end ##
+
+ public void testGetCharacterStream() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ assertEquals(testStr, getContents(xml.getCharacterStream()));
+ }
+
+ public void testGetBinaryStream() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(xml.getBinaryStream()), Streamable.ENCODING));
+ }
+
+ public void testGetString() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ assertEquals(testStr, xml.getString());
+ }
+
+ public void testSetBinaryStream() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ try {
+ xml.setBinaryStream();
+ fail("we do not support this yet.."); //$NON-NLS-1$
+ } catch (SQLException e) {
+ }
+ }
+
+ public void testSetCharacterStream() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ try {
+ xml.setCharacterStream();
+ fail("we do not support this yet.."); //$NON-NLS-1$
+ } catch (SQLException e) {
+ }
+ }
+
+ public void testSetString() throws Exception {
+ SQLXMLImpl xml = new SQLXMLImpl(testStr);
+ try {
+ xml.setString(testStr);
+ fail("we do not support this yet.."); //$NON-NLS-1$
+ } catch (SQLException e) {
+ }
+ }
+
+ private String getContents(Reader reader) throws IOException {
+ StringBuffer sb = new StringBuffer();
+ int chr = reader.read();
+ while(chr != -1) {
+ sb.append((char)chr);
+ chr = reader.read();
+ }
+ reader.close();
+ return sb.toString();
+ }
+
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/types/TestXMLStreamSourceTranslator.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLStreamSourceTranslator.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestXMLStreamSourceTranslator.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestXMLStreamSourceTranslator.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,101 @@
+/*
+ * 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.core.types;
+
+import java.io.StringReader;
+import java.util.StringTokenizer;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.teiid.core.types.StandardXMLTranslator;
+
+import junit.framework.TestCase;
+
+
+/**
+ * XML StreamSource Translator.
+ */
+public class TestXMLStreamSourceTranslator extends TestCase {
+
+ private static final String sourceXML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
+ "<Books:bookCollection xmlns:Books=\"http://www.metamatrix.com/XMLSchema/DataSets/Books\">\r\n" + //$NON-NLS-1$
+ " <book isbn=\"0-7356-0877-6\">\r\n" + //$NON-NLS-1$
+ " <title>After the Gold Rush</title>\r\n" + //$NON-NLS-1$
+ " <subtitle>Creating a True Profession of Software Engineering</subtitle>\r\n" + //$NON-NLS-1$
+ " <edition>1</edition>\r\n" + //$NON-NLS-1$
+ " <authors>\r\n" + //$NON-NLS-1$
+ " <author>McConnell</author>\r\n" + //$NON-NLS-1$
+ " </authors>\r\n" + //$NON-NLS-1$
+ " <publishingInformation>\r\n" + //$NON-NLS-1$
+ " <publisher>Microsoft Press</publisher>\r\n" + //$NON-NLS-1$
+ " <publishDate>1999</publishDate>\r\n" + //$NON-NLS-1$
+ " </publishingInformation>\r\n" + //$NON-NLS-1$
+ " </book>\r\n" + //$NON-NLS-1$
+ " <book isbn=\"1-55615-484-4\">\r\n" + //$NON-NLS-1$
+ " <title>Code Complete</title>\r\n" + //$NON-NLS-1$
+ " <subtitle>A Practical Handbook of Software Construction</subtitle>\r\n" + //$NON-NLS-1$
+ " <edition>1</edition>\r\n" + //$NON-NLS-1$
+ " <authors>\r\n" + //$NON-NLS-1$
+ " <author>McConnell</author>\r\n" + //$NON-NLS-1$
+ " </authors>\r\n" + //$NON-NLS-1$
+ " <publishingInformation>\r\n" + //$NON-NLS-1$
+ " <publisher>Microsoft Press</publisher>\r\n" + //$NON-NLS-1$
+ " <publishDate>1993</publishDate>\r\n" + //$NON-NLS-1$
+ " </publishingInformation>\r\n" + //$NON-NLS-1$
+ " </book>\r\n" + //$NON-NLS-1$
+ " <book isbn=\"1-556-15900-5\">\r\n" + //$NON-NLS-1$
+ " <title>Rapid Development</title>\r\n" + //$NON-NLS-1$
+ " <subtitle>Taming Wild Software Schedules</subtitle>\r\n" + //$NON-NLS-1$
+ " <edition>1</edition>\r\n" + //$NON-NLS-1$
+ " <authors>\r\n" + //$NON-NLS-1$
+ " <author>McConnell</author>\r\n" + //$NON-NLS-1$
+ " </authors>\r\n" + //$NON-NLS-1$
+ " <publishingInformation>\r\n" + //$NON-NLS-1$
+ " <publisher>Microsoft Press</publisher>\r\n" + //$NON-NLS-1$
+ " <publishDate>1996</publishDate>\r\n" + //$NON-NLS-1$
+ " </publishingInformation>\r\n" + //$NON-NLS-1$
+ " </book>\r\n" + //$NON-NLS-1$
+ "</Books:bookCollection>"; //$NON-NLS-1$
+
+ public void testStreamSourceWithStream() throws Exception {
+ StandardXMLTranslator translator = new StandardXMLTranslator(new StreamSource(new StringReader(sourceXML)));
+ compareDocuments(sourceXML, translator.getString());
+ }
+
+ private void compareDocuments(String expectedDoc, String actualDoc) {
+ StringTokenizer tokens1 = new StringTokenizer(expectedDoc, "\r\n"); //$NON-NLS-1$
+ StringTokenizer tokens2 = new StringTokenizer(actualDoc, "\n");//$NON-NLS-1$
+ while(tokens1.hasMoreTokens()){
+ String token1 = tokens1.nextToken().trim();
+ if(!tokens2.hasMoreTokens()){
+ fail("XML doc mismatch: expected=" + token1 + "\nactual=none");//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ String token2 = tokens2.nextToken().trim();
+ assertEquals("XML doc mismatch: ", token1, token2); //$NON-NLS-1$
+ }
+ if(tokens2.hasMoreTokens()){
+ fail("XML doc mismatch: expected=none\nactual=" + tokens2.nextToken().trim());//$NON-NLS-1$
+ }
+ }
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/TestXMLValue.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/types/TestXMLValue.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,78 @@
+/*
+ * 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.core.types;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.util.UnitTestUtil;
+
+
+import junit.framework.TestCase;
+
+
+public class TestXMLValue extends TestCase {
+
+ public void testXMLValue() throws Exception {
+ String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
+ SQLXMLImpl xml = new SQLXMLImpl(testString);
+
+ XMLType xv = new XMLType(xml);
+ assertEquals(testString, xv.getString());
+ }
+
+
+ public void testXMLValuePersistence() throws Exception {
+ String testString = "<foo>this is an xml value test</foo>"; //$NON-NLS-1$
+ SQLXMLImpl xml = new SQLXMLImpl(testString);
+
+ String key = "keytodata"; //$NON-NLS-1$
+ String pkey = "peresistkeytodata"; //$NON-NLS-1$
+ XMLType xv = new XMLType(xml);
+ xv.setReferenceStreamId(key);
+
+ // now force to serialize
+ File saved = new File(UnitTestUtil.getTestScratchPath()+"/xmlsaved.bin"); //$NON-NLS-1$
+ ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(saved));
+ out.writeObject(xv);
+ out.close();
+
+ // now read back the object from serilized state
+ ObjectInputStream in = new ObjectInputStream(new FileInputStream(saved));
+ XMLType read = (XMLType)in.readObject();
+
+ // make sure we have kept the reference stream id
+ assertEquals(key, read.getReferenceStreamId());
+
+ // and lost the original object
+ assertNull(read.getReference());
+
+ saved.delete();
+ }
+
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/types/basic (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/types/basic)
Modified: trunk/common-core/src/test/java/org/teiid/core/types/basic/TestStringToXmlTransform.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/basic/TestStringToXmlTransform.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/types/basic/TestStringToXmlTransform.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
//## JDBC4.0-begin ##
import static org.junit.Assert.*;
@@ -28,8 +28,9 @@
import java.sql.SQLXML;
import org.junit.Test;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.basic.StringToSQLXMLTransform;
-import com.metamatrix.common.types.TransformationException;
@SuppressWarnings("nls")
public class TestStringToXmlTransform {
Modified: trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/common/types/basic/TestTransforms.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/types/basic/TestTransforms.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.common.types.basic;
+package org.teiid.core.types.basic;
import static org.junit.Assert.*;
@@ -31,17 +31,18 @@
import java.sql.Timestamp;
import org.junit.Test;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.TestDataTypeManager;
+import org.teiid.core.types.Transform;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.types.DataTypeManager.DefaultDataClasses;
+import org.teiid.core.types.DataTypeManager.DefaultDataTypes;
+import org.teiid.core.types.basic.StringToSQLXMLTransform;
+import org.teiid.query.unittest.TimestampUtil;
-import com.metamatrix.common.types.ClobType;
-import com.metamatrix.common.types.DataTypeManager;
-import com.metamatrix.common.types.SQLXMLImpl;
-import com.metamatrix.common.types.TestDataTypeManager;
-import com.metamatrix.common.types.Transform;
-import com.metamatrix.common.types.TransformationException;
-import com.metamatrix.common.types.XMLType;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataClasses;
-import com.metamatrix.common.types.DataTypeManager.DefaultDataTypes;
-import com.metamatrix.query.unittest.TimestampUtil;
/**
Copied: trunk/common-core/src/test/java/org/teiid/core/util (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/core/util)
Copied: trunk/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/util/FakeInputStream.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,68 @@
+/*
+ * 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.core.util;
+
+import java.io.ByteArrayInputStream;
+
+/**
+ * This test input stream overrides the <code>available</code>
+ * to return "1" until <i>after</i> the {@link #read} method returns
+ * "-1" to indicate EOF, which is how java.util.zip.ZipInputStream
+ * works, which is what is used by ExtensionSourceManager to retrieve
+ * Class files from JAR files. The <code>available</code> method
+ * therefore can't be relied on by ByteArrayHelper to either
+ * indicate how many bytes can be read, or if more are
+ * available or not. In the latter case, ByteArrayHelper
+ * relies on the <code>read</code> method returning "-1".
+ */
+public class FakeInputStream extends ByteArrayInputStream {
+
+ private int available = 1;
+
+ public FakeInputStream(byte[] buf) {
+ super(buf);
+ }
+
+ /**
+ * Overriden to return "1" <i>until</i> the <code>read</code> method
+ * has returned "-1" to indicate EOF.
+ */
+ public int available(){
+ super.available();
+ return available;
+ }
+
+ /**
+ * Overriden - basically calls to super method, but checks returned
+ * number of bytes read; if "-1", then the next call to
+ * {@link #available} will return "0".
+ */
+ public int read(byte b[], int off, int len) {
+ int result = super.read(b, off, len);
+ if (result<0){
+ available = 0;
+ }
+ return result;
+ }
+
+}
Modified: trunk/common-core/src/test/java/org/teiid/core/util/SimpleMock.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/SimpleMock.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/SimpleMock.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import org.teiid.core.util.MixinProxy;
+
public class SimpleMock extends MixinProxy {
SimpleMock(Object[] baseInstances) {
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestAssertion.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestAssertion.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestAssertion.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,11 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
+import org.teiid.core.CorePlugin;
+import org.teiid.core.util.Assertion;
+
import junit.framework.TestCase;
-import com.metamatrix.core.CorePlugin;
/**
* TestAssertion
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestEquivalenceUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestEquivalenceUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestEquivalenceUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,8 +20,10 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
+import org.teiid.core.util.EquivalenceUtil;
+
import junit.framework.TestCase;
public class TestEquivalenceUtil extends TestCase {
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestExternalizeUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestExternalizeUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestExternalizeUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -29,6 +29,8 @@
import java.util.Arrays;
import java.util.List;
+import org.teiid.core.util.ExternalizeUtil;
+
import junit.framework.TestCase;
public class TestExternalizeUtil extends TestCase {
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestFileUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,9 +20,13 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.File;
+
+import org.teiid.core.util.FileUtil;
+import org.teiid.core.util.StringUtil;
+
import junit.framework.TestCase;
public class TestFileUtil extends TestCase {
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestFileUtils.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestFileUtils.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,15 +20,18 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.util.FileUtil;
+import org.teiid.core.util.FileUtils;
+
import junit.framework.TestCase;
-import com.metamatrix.core.MetaMatrixCoreException;
/**
* @since 4.0
@@ -140,7 +143,7 @@
try {
FileUtils.testDirectoryPermissions("fakeDir"); //$NON-NLS-1$
fail("Expected a MetaMatrixCoreException"); //$NON-NLS-1$
- } catch (MetaMatrixCoreException e) {
+ } catch (TeiidException e) {
}
}
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestMetaMatrixExceptionUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestMetaMatrixExceptionUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestMetaMatrixExceptionUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import javax.naming.ConfigurationException;
+
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.util.ExceptionUtil;
+
import junit.framework.TestCase;
-import com.metamatrix.core.MetaMatrixCoreException;
-import com.metamatrix.core.MetaMatrixRuntimeException;
public class TestMetaMatrixExceptionUtil extends TestCase {
@@ -35,32 +38,32 @@
public void testWithoutMessage() {
NullPointerException npe = new NullPointerException();
- MetaMatrixRuntimeException e = new MetaMatrixRuntimeException(npe);
- assertEquals("MetaMatrixRuntimeException->NullPointerException", MetaMatrixExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
- assertEquals("nullnull", MetaMatrixExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
+ TeiidRuntimeException e = new TeiidRuntimeException(npe);
+ assertEquals("TeiidRuntimeException->NullPointerException", ExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
+ assertEquals("nullnull", ExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
}
public void testWithMessage() {
NullPointerException npe = new NullPointerException("problem"); //$NON-NLS-1$
- MetaMatrixRuntimeException e = new MetaMatrixRuntimeException(npe);
- assertEquals("MetaMatrixRuntimeException-problem->NullPointerException", MetaMatrixExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
- assertEquals("problemproblem", MetaMatrixExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
+ TeiidRuntimeException e = new TeiidRuntimeException(npe);
+ assertEquals("TeiidRuntimeException-problem->NullPointerException", ExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
+ assertEquals("problemproblem", ExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
}
public void testWithAndWithoutMessage() {
NullPointerException npe = new NullPointerException();
- MetaMatrixCoreException ce = new MetaMatrixCoreException(npe, "problem"); //$NON-NLS-1$
- MetaMatrixRuntimeException e = new MetaMatrixRuntimeException(ce);
- assertEquals("MetaMatrixRuntimeException-problem->MetaMatrixCoreException->NullPointerException", MetaMatrixExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
- assertEquals("problemproblemnull", MetaMatrixExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
+ TeiidException ce = new TeiidException(npe, "problem"); //$NON-NLS-1$
+ TeiidRuntimeException e = new TeiidRuntimeException(ce);
+ assertEquals("TeiidRuntimeException-problem->TeiidException->NullPointerException", ExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
+ assertEquals("problemproblemnull", ExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
}
public void testConfigurationException() {
NullPointerException npe = new NullPointerException("problem1"); //$NON-NLS-1$
ConfigurationException configException = new ConfigurationException("problem2"); //$NON-NLS-1$
configException.setRootCause(npe);
- MetaMatrixCoreException e = new MetaMatrixCoreException(configException, "problem3"); //$NON-NLS-1$
- assertEquals("MetaMatrixCoreException-problem3->ConfigurationException-problem2->NullPointerException-problem1", MetaMatrixExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
- assertEquals("problem3problem2problem1", MetaMatrixExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
+ TeiidException e = new TeiidException(configException, "problem3"); //$NON-NLS-1$
+ assertEquals("TeiidException-problem3->ConfigurationException-problem2->NullPointerException-problem1", ExceptionUtil.getLinkedMessagesVerbose(e)); //$NON-NLS-1$
+ assertEquals("problem3problem2problem1", ExceptionUtil.getLinkedMessages(e)); //$NON-NLS-1$
}
}
Copied: trunk/common-core/src/test/java/org/teiid/core/util/TestPropertiesUtils.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/util/TestPropertiesUtils.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestPropertiesUtils.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestPropertiesUtils.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,567 @@
+/*
+ * 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.core.util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.teiid.core.util.PropertiesUtils;
+import org.teiid.core.util.PropertiesUtils.InvalidPropertyException;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests primarily the various cloning scenarios available with PropertiesUtils
+ */
+public class TestPropertiesUtils extends TestCase {
+
+ private final static String TEMP_FILE = UnitTestUtil.getTestScratchPath() + "/temp.properties"; //$NON-NLS-1$
+
+
+
+ // ################################## FRAMEWORK ################################
+
+ public TestPropertiesUtils(String name) {
+ super(name);
+ }
+
+ public void tearDown() throws Exception{
+ try {
+ File temp = new File(TEMP_FILE);
+ temp.delete();
+ } catch (Exception e) {
+ //ignore
+ }
+ }
+
+
+ //===================================================================
+ //ACTUAL TESTS
+ //===================================================================
+
+
+ /**
+ * Tests {@link com.metamatrix.common.utils.PropertiesUtils#print(String, Properties, String header)}
+ * and {@link org.teiid.core.util.utils.PropertiesUtils#load(String)}
+ * and {@link org.teiid.core.util.utils.PropertiesUtils#loadHeader(String)}
+ */
+ public void testPrintLoadWithHeader() throws Exception {
+ Properties props1 = make(MAP_C, null, !UNMODIFIABLE);
+
+ //print to file
+ PropertiesUtils.print(TEMP_FILE, props1, "header"); //$NON-NLS-1$
+
+ //load from file
+ Properties props2 = PropertiesUtils.load(TEMP_FILE);
+ assertEquals("Expected props1 to be equal to props2", 0, PropertiesUtils.compare(props1, props2)); //$NON-NLS-1$
+
+ String header = PropertiesUtils.loadHeader(TEMP_FILE);
+ assertEquals("header", header); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#print(String, Properties)}
+ * and {@link org.teiid.core.util.utils.PropertiesUtils#load(String)}
+ * and {@link org.teiid.core.util.utils.PropertiesUtils#loadHeader(String)}
+ */
+ public void testPrintLoadWithoutHeader() throws Exception {
+ Properties props1 = make(MAP_C, null, !UNMODIFIABLE);
+
+ //print to file
+ PropertiesUtils.print(TEMP_FILE, props1);
+
+ //load from file
+ Properties props2 = PropertiesUtils.load(TEMP_FILE);
+ assertEquals("Expected props1 to be equal to props2", 0, PropertiesUtils.compare(props1, props2)); //$NON-NLS-1$
+ }
+
+
+
+
+ // ################ putAll(Properties, Properties) ###########################
+
+ public void testPutAllWithDefaults(){
+ Properties c = make(MAP_C, null, !UNMODIFIABLE);
+ Properties ab = make(MAP_A, make(MAP_B, null, UNMODIFIABLE), UNMODIFIABLE);
+ PropertiesUtils.putAll(c, ab);
+ assertTrue(verifyProps(c, LIST_ABC));
+ }
+
+ // ##################### clone(Properties) ###################################
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties)}
+ */
+ public void testSimpleModifiableClone(){
+ Properties a = make(MAP_A, null, !UNMODIFIABLE);
+ a = PropertiesUtils.clone(a);
+ assertTrue(verifyProps(a, LIST_A));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties)}
+ */
+ public void testSimpleModifiableCloneWithUnmodifiableDefaults(){
+ Properties ab = make(MAP_A, make(MAP_B, null, UNMODIFIABLE), !UNMODIFIABLE);
+ ab = PropertiesUtils.clone(ab);
+ assertTrue(verifyProps(ab, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties)}
+ */
+ public void testSimpleModifiableCloneWithModifiableDefaults(){
+ Properties ab = make(MAP_A, make(MAP_B, null, !UNMODIFIABLE), !UNMODIFIABLE);
+ ab = PropertiesUtils.clone(ab);
+ assertTrue(verifyProps(ab, LIST_AB));
+ }
+
+ // ##################### clone(Properties, boolean) ##########################
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, boolean)}
+ */
+ public void testCloneModifiableAsModifiable(){
+ Properties a = make(MAP_A, null, !UNMODIFIABLE);
+ a = PropertiesUtils.clone(a);
+ assertTrue(verifyProps(a, LIST_A));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, boolean)}
+ */
+ public void testCloneUnmodifiableAsModifiable(){
+ Properties a = make(MAP_A, null, UNMODIFIABLE);
+ a = PropertiesUtils.clone(a);
+ assertTrue(verifyProps(a, LIST_A));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, boolean)}
+ */
+ public void testCloneModifiableWithModifiableAsModifiable(){
+ Properties ab = make(MAP_A, make(MAP_B, null, !UNMODIFIABLE), !UNMODIFIABLE);
+ ab = PropertiesUtils.clone(ab);
+ assertTrue(verifyProps(ab, LIST_AB));
+ }
+
+ // ######## clone(Properties, Properties, boolean, boolean) ##################
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testCloneModAndModAsMod(){
+ Properties a = make(MAP_A, null, !UNMODIFIABLE);
+ Properties b = make(MAP_B, null, !UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testDeepcloneModAndModAsMod(){
+ Properties a = make(MAP_A, null, !UNMODIFIABLE);
+ Properties b = make(MAP_B, null, !UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testCloneModAndUnmodAsMod(){
+ Properties a = make(MAP_A, null, !UNMODIFIABLE);
+ Properties b = make(MAP_B, null, UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testDeepcloneModAndUnmodAsMod(){
+ Properties a = make(MAP_A, null, !UNMODIFIABLE);
+ Properties b = make(MAP_B, null, UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testCloneUnmodAndModAsMod(){
+ Properties a = make(MAP_A, null, UNMODIFIABLE);
+ Properties b = make(MAP_B, null, !UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testDeepcloneUnmodAndModAsMod(){
+ Properties a = make(MAP_A, null, UNMODIFIABLE);
+ Properties b = make(MAP_B, null, !UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testCloneUnmodAndUnmodAsMod(){
+ Properties a = make(MAP_A, null, UNMODIFIABLE);
+ Properties b = make(MAP_B, null, UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, !DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ /**
+ * Tests {@link org.teiid.core.util.utils.PropertiesUtils#clone(Properties, Properties, boolean, boolean)}
+ */
+ public void testDeepcloneUnmodAndUnmodAsMod(){
+ Properties a = make(MAP_A, null, UNMODIFIABLE);
+ Properties b = make(MAP_B, null, UNMODIFIABLE);
+ a = PropertiesUtils.clone(a, b, DEEP_CLONE);
+ assertTrue(verifyProps(a, LIST_AB));
+ }
+
+ // ########################## ADVANCED #######################################
+
+ //===================================================================
+ //TESTS HELPERS
+ //===================================================================
+
+ /**
+ * Checks the Properties against the static test data defined in this Class.
+ * @param props Properties to check
+ * @param chainOfMappings a List of Map objects in order of defaults. That is,
+ * the first Map should represent the properties itself, the second Map the internal
+ * defaults of the properties, the third Map the defaults of the second Map, and so on...
+ * @return true or false for pass or fail
+ */
+ private static final boolean verifyProps(Properties props, List chainOfMappings){
+ boolean result = verifyAllPropsPresent(props, chainOfMappings);
+ if (result){
+ result = verifyCorrectMappings(props, chainOfMappings);
+ }
+ return result;
+ }
+
+ /**
+ * Check that the Set of all keys in the List<Map> chainOfMappings is present in props.
+ * @param props Properties to check
+ * @param chainOfMappings a List of Map objects in order of defaults. That is,
+ * the first Map should represent the properties itself, the second Map the internal
+ * defaults of the properties, the third Map the defaults of the second Map, and so on...
+ * @return true all keys are present, false otherwise
+ */
+ private static final boolean verifyAllPropsPresent(Properties props, List chainOfMappings){
+ Enumeration e = props.propertyNames();
+ HashSet propNames = new HashSet();
+ while (e.hasMoreElements()) {
+ propNames.add( e.nextElement());
+ }
+
+ HashSet testNames = new HashSet();
+ Iterator i = chainOfMappings.iterator();
+ while (i.hasNext()) {
+ Map aMapping = (Map) i.next();
+ testNames.addAll(aMapping.keySet());
+ }
+ return propNames.containsAll(testNames);
+ }
+
+ /**
+ * Verify that the Properties props correctly reflects the chain of mappings (which
+ * simulate an arbitrary chain of Properties and default Properties). For each
+ * property name, look in order through each Map in the List chainOfMappings to
+ * see if (a) that property name is there, and (b) that it is mapped to the same
+ * property. There are two conditions that will cause this method to returns
+ * false: (1) if a property name maps to an incorrect, non-null value the first
+ * time a mapping for that property name is found; (2) if no mapping is found at
+ * for a property name.
+ * @param props Properties to check
+ * @param chainOfMappings a List of Map objects in order of defaults. That is,
+ * the first Map should represent the properties itself, the second Map the internal
+ * defaults of the properties, the third Map the defaults of the second Map, and so on...
+ * @return true if props correctly reflects the chainOfMappings, false otherwise
+ */
+ private static final boolean verifyCorrectMappings(Properties props, List chainOfMappings){
+ Enumeration e = props.propertyNames();
+ boolean allGood = true;
+ while (e.hasMoreElements() && allGood) {
+ boolean foundKey = false;
+ String propName = (String) e.nextElement();
+ String propValue = props.getProperty(propName);
+ Iterator i = chainOfMappings.iterator();
+ while (i.hasNext() && !foundKey) {
+ Map aMapping = (Map) i.next();
+ Object value = aMapping.get(propName);
+ if (value != null){
+ foundKey = true;
+ allGood = propValue.equals(value);
+ }
+ }
+ }
+ return allGood;
+ }
+
+ /**
+ * Constructs a Properties object from the supplied Map of properties,
+ * the supplied defaults, and optionally wraps the returned Properties
+ * in an UnmodifiableProperties instance
+ * @param mappings Map of String propName to String propValue
+ * @param defaults optional default Properties; may be null
+ * @param makeUnmodifiable If true, the returned Properties object will be
+ * an instance of UnmodifiableProperties wrapping a Properties object
+ */
+ private static final Properties make(Map mappings, Properties defaults, boolean makeUnmodifiable){
+ Properties props = null;
+ if (defaults != null){
+ props = new Properties(defaults);
+ } else {
+ props = new Properties();
+ }
+ Iterator i = mappings.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry anEntry = (Map.Entry) i.next();
+ props.setProperty((String)anEntry.getKey(),(String)anEntry.getValue());
+ }
+ return props;
+ }
+
+ private static final boolean UNMODIFIABLE = true;
+ private static final boolean DEEP_CLONE = true;
+
+ private static final String PROP_NAME_1 = "prop1"; //$NON-NLS-1$
+ private static final String PROP_NAME_2 = "prop2"; //$NON-NLS-1$
+ private static final String PROP_NAME_3 = "prop3"; //$NON-NLS-1$
+ private static final String PROP_NAME_4 = "prop4"; //$NON-NLS-1$
+ private static final String PROP_NAME_5 = "prop5"; //$NON-NLS-1$
+ private static final String PROP_NAME_6 = "prop6"; //$NON-NLS-1$
+
+ //"a", "b", or "c" designates which of the test Properties
+ //the values will go in
+ private static final String PROP_VALUE_1A = "value1a"; //$NON-NLS-1$
+ private static final String PROP_VALUE_1B = "value1b"; //$NON-NLS-1$
+ private static final String PROP_VALUE_2A = "value2a"; //$NON-NLS-1$
+ private static final String PROP_VALUE_2C = "value2c"; //$NON-NLS-1$
+ private static final String PROP_VALUE_3A = "value3a"; //$NON-NLS-1$
+ private static final String PROP_VALUE_4B = "value4b"; //$NON-NLS-1$
+ private static final String PROP_VALUE_4C = "value4c"; //$NON-NLS-1$
+ private static final String PROP_VALUE_5B = "value5b"; //$NON-NLS-1$
+ private static final String PROP_VALUE_6C = "value6c"; //$NON-NLS-1$
+
+ private static final Map MAP_A;
+ private static final Map MAP_B;
+ private static final Map MAP_C;
+ private static final List LIST_A;
+// private static final List LIST_B;
+ private static final List LIST_AB;
+ private static final List LIST_ABC;
+ static{
+ //A
+ Map temp = new HashMap();
+ temp.put(PROP_NAME_1, PROP_VALUE_1A);
+ temp.put(PROP_NAME_2, PROP_VALUE_2A);
+ temp.put(PROP_NAME_3, PROP_VALUE_3A);
+ MAP_A = Collections.unmodifiableMap(temp);
+ //B
+ temp = new HashMap();
+ temp.put(PROP_NAME_1, PROP_VALUE_1B);
+ temp.put(PROP_NAME_4, PROP_VALUE_4B);
+ temp.put(PROP_NAME_5, PROP_VALUE_5B);
+ MAP_B = Collections.unmodifiableMap(temp);
+ //C
+ temp = new HashMap();
+ temp.put(PROP_NAME_2, PROP_VALUE_2C);
+ temp.put(PROP_NAME_4, PROP_VALUE_4C);
+ temp.put(PROP_NAME_6, PROP_VALUE_6C);
+ MAP_C = Collections.unmodifiableMap(temp);
+ //LISTS OF BINDINGS
+ List tempList = new ArrayList(1);
+ tempList.add(MAP_A);
+ LIST_A = Collections.unmodifiableList(tempList);
+ tempList = new ArrayList(1);
+ tempList.add(MAP_B);
+// LIST_B = Collections.unmodifiableList(tempList);
+ tempList = new ArrayList(2);
+ tempList.add(MAP_A);
+ tempList.add(MAP_B);
+ LIST_AB = Collections.unmodifiableList(tempList);
+ tempList = new ArrayList(3);
+ tempList.add(MAP_A);
+ tempList.add(MAP_B);
+ tempList.add(MAP_C);
+ LIST_ABC = Collections.unmodifiableList(tempList);
+ }
+
+ public void testNestedProperties() throws Exception {
+ System.setProperty("testdirectory", "c:/metamatrix/testdirectory"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Properties p = new Properties(System.getProperties());
+ p.setProperty("key1", "value1"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("key2", "${key1}/value2"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.put("key3", new Integer(-234)); //$NON-NLS-1$
+ p.setProperty("key4", "${key2}/value4"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("key5", "${testdirectory}/testdata"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("key7", "anotherdir/${testdirectory}/${key1}"); //$NON-NLS-1$ //$NON-NLS-2$
+ int currentSize = p.size();
+
+ Properties m = PropertiesUtils.resolveNestedProperties(p);
+ assertEquals("value1/value2", m.getProperty("key2")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(new Integer(-234), m.get("key3")); //$NON-NLS-1$
+ assertEquals("value1/value2/value4", m.getProperty("key4")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("c:/metamatrix/testdirectory/testdata", m.getProperty("key5")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("anotherdir/c:/metamatrix/testdirectory/value1", m.getProperty("key7")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(p == m); // no cloning.
+ assertTrue(currentSize == m.size());
+
+ p.setProperty("key6", "${foo}"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ try {
+ m = PropertiesUtils.resolveNestedProperties(p);
+ fail("must have failed to resovle as {foo} does not exist"); //$NON-NLS-1$
+ } catch(RuntimeException e) {
+ // pass
+ }
+
+
+ // JIRA: TEIID-909 - The resolveNestedProperties logic goes in a loop when the key is also in the value as ${key}.
+ Properties dups = new Properties();
+ dups.setProperty("usethis", "${usethis}");
+
+ dups = PropertiesUtils.resolveNestedProperties(dups);
+
+
+
+ }
+
+ public void testOverrideProperties() {
+ Properties p = new Properties();
+
+ p.setProperty("foo", "bar"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("foo1", "bar1"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("foo2", "bar2"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Properties p1 = new Properties(p);
+
+ p1.setProperty("foo", "x"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ PropertiesUtils.setOverrideProperies(p1, p);
+
+ assertEquals("bar", p1.getProperty("foo")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ assertEquals(1, p1.size());
+ }
+
+ public void testGetInvalidInt() {
+ Properties p = new Properties();
+ p.setProperty("x", "y"); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ PropertiesUtils.getIntProperty(p, "x", 1); //$NON-NLS-1$
+ fail("expected exception"); //$NON-NLS-1$
+ } catch (InvalidPropertyException e) {
+ assertEquals("Property 'x' with value 'y' is not a valid Integer.", e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ static class Bean {
+ private int prop;
+ private String prop1;
+ private double prop2;
+ private List<String> prop3;
+
+ public int getProp() {
+ return prop;
+ }
+ public void setProp(int prop) {
+ this.prop = prop;
+ }
+ public String getProp1() {
+ return prop1;
+ }
+ public void setProp1(String prop1) {
+ this.prop1 = prop1;
+ }
+ public double getProp2() {
+ return prop2;
+ }
+ public void setProp2(double prop2) {
+ this.prop2 = prop2;
+ }
+ public List<String> getProp3() {
+ return prop3;
+ }
+ public void setProp3(List<String> prop3) {
+ this.prop3 = prop3;
+ }
+ }
+
+ public void testSetBeanProperties() {
+ Bean bean = new Bean();
+ Properties p = new Properties();
+ p.setProperty("prop", "0"); //$NON-NLS-1$//$NON-NLS-2$
+ p.setProperty("prop1", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("prop2", "2"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty("prop3", "3"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ p = new Properties(p);
+ p.put("object", new Object()); //$NON-NLS-1$
+
+ PropertiesUtils.setBeanProperties(bean, p, null);
+
+ assertEquals(0, bean.getProp());
+ assertEquals("1", bean.getProp1()); //$NON-NLS-1$
+ assertEquals(2d, bean.getProp2());
+ assertEquals(Arrays.asList("3"), bean.getProp3()); //$NON-NLS-1$
+
+ p.setProperty("prop", "?"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ try {
+ PropertiesUtils.setBeanProperties(bean, p, null);
+ fail("expected exception"); //$NON-NLS-1$
+ } catch (InvalidPropertyException e) {
+
+ }
+ }
+
+ public void testGetInt() {
+ Properties p = new Properties();
+ p.setProperty("prop", "0 "); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(PropertiesUtils.getIntProperty(p, "prop", -1), 0); //$NON-NLS-1$
+ }
+}
Copied: trunk/common-core/src/test/java/org/teiid/core/util/TestReaderInputStream.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/util/TestReaderInputStream.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestReaderInputStream.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestReaderInputStream.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,70 @@
+/*
+ * 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.core.util;
+
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.StringReader;
+import java.nio.charset.Charset;
+
+import org.teiid.core.util.ReaderInputStream;
+
+import junit.framework.TestCase;
+
+
+public class TestReaderInputStream extends TestCase {
+
+ public void testUTF8() throws Exception {
+ FileInputStream fis = new FileInputStream(UnitTestUtil.getTestDataFile("legal_notice.xml")); //$NON-NLS-1$
+ ReaderInputStream ris = new ReaderInputStream(new FileReader(UnitTestUtil.getTestDataFile("legal_notice.xml")), Charset.forName("UTF-8")); //$NON-NLS-1$ //$NON-NLS-2$
+
+ int value;
+ while (true) {
+ value = fis.read();
+ assertEquals(value, ris.read());
+ if (value == -1) {
+ break;
+ }
+ }
+ }
+
+ //the encoding strategy is roughly equivalent to utf-16
+ public void testUTF16() throws Exception {
+ String actual = "!?abc"; //$NON-NLS-1$
+ ReaderInputStream ris = new ReaderInputStream(new StringReader(actual), Charset.forName("UTF-16"), 1); //$NON-NLS-1$
+ byte[] result = new byte[(actual.length()) * 2 + 2];
+ ris.read(result);
+ String resultString = new String(result, "UTF-16"); //$NON-NLS-1$
+ assertEquals(resultString, actual);
+ }
+
+ public void testASCII() throws Exception {
+ String actual = "!?abc"; //$NON-NLS-1$
+ ReaderInputStream ris = new ReaderInputStream(new StringReader(actual), Charset.forName("US-ASCII"), 1); //$NON-NLS-1$
+ byte[] result = new byte[actual.length()];
+ ris.read(result);
+ String resultString = new String(result, "US-ASCII"); //$NON-NLS-1$
+ assertEquals(resultString, actual);
+ }
+
+}
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestReflectionHelper.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestReflectionHelper.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,13 +20,15 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import org.teiid.core.util.ReflectionHelper;
+
import junit.framework.TestCase;
/**
Copied: trunk/common-core/src/test/java/org/teiid/core/util/TestSqlUtil.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/util/TestSqlUtil.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestSqlUtil.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestSqlUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -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.core.util;
+
+import org.teiid.core.util.SqlUtil;
+
+import junit.framework.TestCase;
+
+/**
+ */
+public class TestSqlUtil extends TestCase {
+
+ public TestSqlUtil(String name) {
+ super(name);
+ }
+
+ public void helpTest(String sql, boolean isUpdate) {
+ boolean actual = SqlUtil.isUpdateSql(sql);
+ assertEquals(isUpdate, actual);
+ }
+
+ public void testSelect() {
+ helpTest("SELECT x FROM y", false); //$NON-NLS-1$
+ }
+
+ public void testInsert() {
+ helpTest("Insert INTO g (a) VALUES (1)", true); //$NON-NLS-1$
+ }
+
+ public void testUpdate() {
+ helpTest("upDate x set a=5", true); //$NON-NLS-1$
+ }
+
+ public void testDelete() {
+ helpTest("delete FROM x", true); //$NON-NLS-1$
+ }
+
+ public void testInsertWithWhitespace() {
+ helpTest("\nINSERT INTO g (a) VALUES (1)", true); //$NON-NLS-1$
+ }
+
+ public void testExec() {
+ helpTest("exec sq1()", false); //$NON-NLS-1$
+ }
+
+ public void testXquery() {
+ helpTest("<i/>", false); //$NON-NLS-1$
+ }
+
+ public void testSelectInto1() {
+ helpTest("SELECT x INTO z FROM y", true); //$NON-NLS-1$
+ }
+
+ public void testSelectInto2() {
+ helpTest("SELECT x, INTOz FROM y", false); //$NON-NLS-1$
+ }
+
+ public void testSelectInto3() {
+ helpTest("SELECT x into z FROM y", true); //$NON-NLS-1$
+ }
+
+ public void testSelectInto4() {
+ helpTest("SELECT x into z", true); //$NON-NLS-1$
+ }
+
+ public void testCreate() {
+ helpTest(" create table x", true); //$NON-NLS-1$
+ }
+
+ public void testDrop() {
+ helpTest("/* */ drop table x", true); //$NON-NLS-1$
+ }
+
+}
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/TestStringUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,12 +20,14 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import org.teiid.core.util.StringUtil;
+
import junit.framework.TestCase;
/**
Copied: trunk/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/common/util/TestTimestampWithTimezone.java)
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java (rev 0)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestTimestampWithTimezone.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -0,0 +1,219 @@
+/*
+ * 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.core.util;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.teiid.core.util.TimestampWithTimezone;
+
+import junit.framework.TestCase;
+
+public class TestTimestampWithTimezone extends TestCase {
+
+ /**
+ * Constructor for TestTimestampWithTimezone.
+ *
+ * @param name
+ */
+ public TestTimestampWithTimezone(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("America/Chicago")); //$NON-NLS-1$
+ }
+
+ public void tearDown() {
+ TimestampWithTimezone.resetCalendar(null);
+ }
+
+ /**
+ * Ensures that the same calendar fields in different timezones (initially different UTC) can be converted to the same UTC in
+ * the local time zone
+ *
+ * @param startts
+ * @param startnanos
+ * @param starttz
+ * @param endtz
+ * @since 4.3
+ */
+ public void helpTestSame(String startts,
+ int startnanos,
+ String starttz,
+ String endtz) {
+ try {
+ Timestamp start = getTimestamp(startts, startnanos, starttz);
+ Timestamp end = getTimestamp(startts, startnanos, endtz);
+
+ assertFalse("Initial timestamps should be different UTC times", start.getTime() == end.getTime()); //$NON-NLS-1$
+
+ assertEquals(TimestampWithTimezone.createTimestamp(start, TimeZone.getTimeZone(starttz), Calendar.getInstance())
+ .getTime(), TimestampWithTimezone.createTimestamp(end,
+ TimeZone.getTimeZone(endtz),
+ Calendar.getInstance()).getTime());
+ } catch (ParseException e) {
+ fail(e.toString());
+ }
+ }
+
+ /**
+ * Assuming local time zone of -06:00, change ts to endtz and compare to expected
+ *
+ * @param ts
+ * @param endtz
+ * @since 4.3
+ */
+ public void helpTestChange(String ts,
+ String endtz,
+ String expected) {
+ Timestamp start = Timestamp.valueOf(ts);
+ Calendar target = Calendar.getInstance(TimeZone.getTimeZone(endtz));
+ assertEquals(expected,
+ TimestampWithTimezone.createTimestamp(start, TimeZone.getTimeZone("America/Chicago"), target).toString()); //$NON-NLS-1$
+ }
+
+ /**
+ * @param startts
+ * @param startnanos
+ * @param starttz
+ * @throws ParseException
+ * @since 4.3
+ */
+ private Timestamp getTimestamp(String startts,
+ int startnanos,
+ String starttz) throws ParseException {
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); //$NON-NLS-1$
+ df.setTimeZone(TimeZone.getTimeZone(starttz));
+
+ Timestamp ts = new Timestamp(df.parse(startts).getTime());
+ ts.setNanos(startnanos);
+ return ts;
+ }
+
+ public void testDST() {
+ helpTestSame("2005-10-30 02:39:10", 1, "America/Chicago", //$NON-NLS-1$ //$NON-NLS-2$
+ "GMT-05:00"); //$NON-NLS-1$
+
+ // ambiguous times are defaulted to standard time equivalent
+ helpTestSame("2005-10-30 01:39:10", 1, "America/Chicago", //$NON-NLS-1$ //$NON-NLS-2$
+ "GMT"); //$NON-NLS-1$
+
+ // test to ensure a time not representable in DST is converted correctly
+ helpTestSame("2005-04-03 02:39:10", 1, "GMT", //$NON-NLS-1$ //$NON-NLS-2$
+ "America/Chicago"); //$NON-NLS-1$
+
+ //expected is in DST
+ helpTestChange("2005-10-30 02:39:10.1", "GMT", "2005-10-29 21:39:10.1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ //expected is in standard time
+ helpTestChange("2005-10-30 10:39:10.1", "GMT", "2005-10-30 04:39:10.1"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ }
+
+ public void testTimezone() {
+ helpTestSame("2004-06-29 15:39:10", 1, "GMT-06:00", //$NON-NLS-1$ //$NON-NLS-2$
+ "GMT-05:00"); //$NON-NLS-1$
+ }
+
+ public void testTimezone2() {
+ helpTestSame("2004-06-29 15:39:10", 1, "GMT-08:00", //$NON-NLS-1$ //$NON-NLS-2$
+ "GMT-06:00"); //$NON-NLS-1$
+ }
+
+ public void testTimezone3() {
+ helpTestSame("2004-08-31 18:25:54", 1, "Europe/London", //$NON-NLS-1$ //$NON-NLS-2$
+ "GMT"); //$NON-NLS-1$
+ }
+
+ public void testTimezoneOverMidnight() {
+ helpTestSame("2004-06-30 23:39:10", 1, "America/Los_Angeles", //$NON-NLS-1$ //$NON-NLS-2$
+ "America/Chicago"); //$NON-NLS-1$
+ }
+
+ public void testCase2852() {
+ helpTestSame("2005-05-17 22:35:33", 508659, "GMT", //$NON-NLS-1$ //$NON-NLS-2$
+ "America/New_York"); //$NON-NLS-1$
+ }
+
+ public void testCreateDate() {
+ Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201"); //$NON-NLS-1$
+ Date date = TimestampWithTimezone.createDate(t);
+
+ Calendar cal = Calendar.getInstance();
+
+ cal.setTimeInMillis(date.getTime());
+
+ assertEquals(cal.get(Calendar.HOUR_OF_DAY), 0);
+ assertEquals(cal.get(Calendar.MINUTE), 0);
+ assertEquals(cal.get(Calendar.SECOND), 0);
+ assertEquals(cal.get(Calendar.MILLISECOND), 0);
+ assertEquals(cal.get(Calendar.YEAR), 2004);
+ assertEquals(cal.get(Calendar.MONTH), Calendar.JUNE);
+ assertEquals(cal.get(Calendar.DATE), 30);
+ }
+
+ public void testCreateTime() {
+ Timestamp t = Timestamp.valueOf("2004-06-30 23:39:10.1201"); //$NON-NLS-1$
+ Time date = TimestampWithTimezone.createTime(t);
+
+ Calendar cal = Calendar.getInstance();
+
+ cal.setTimeInMillis(date.getTime());
+
+ assertEquals(cal.get(Calendar.HOUR_OF_DAY), 23);
+ assertEquals(cal.get(Calendar.MINUTE), 39);
+ assertEquals(cal.get(Calendar.SECOND), 10);
+ assertEquals(cal.get(Calendar.MILLISECOND), 0);
+ assertEquals(cal.get(Calendar.YEAR), 1970);
+ assertEquals(cal.get(Calendar.MONTH), Calendar.JANUARY);
+ assertEquals(cal.get(Calendar.DATE), 1);
+ }
+
+ /**
+ * Even though the id of the timezones are different, this should not change the result
+ */
+ public void testDateToDateConversion() {
+ Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
+ Date converted = TimestampWithTimezone.createDate(t, TimeZone.getTimeZone("America/Chicago"), Calendar.getInstance(TimeZone.getTimeZone("US/Central"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+ assertEquals(t.getTime(), converted.getTime());
+ }
+
+ public void testDateToDateConversion1() {
+ Date t = Date.valueOf("2004-06-30"); //$NON-NLS-1$
+ Date converted = TimestampWithTimezone.createDate(t, TimeZone.getTimeZone("America/Chicago"), Calendar.getInstance(TimeZone.getTimeZone("GMT"))); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(converted);
+
+ assertEquals(0, cal.get(Calendar.MILLISECOND));
+ }
+
+}
\ No newline at end of file
Modified: trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/core/util/UnitTestUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/core/util/UnitTestUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -20,7 +20,7 @@
* 02110-1301 USA.
*/
-package com.metamatrix.core.util;
+package org.teiid.core.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Copied: trunk/common-core/src/test/java/org/teiid/query/unittest (from rev 2112, trunk/common-core/src/test/java/com/metamatrix/query/unittest)
Modified: trunk/common-core/src/test/java/org/teiid/query/unittest/TimestampUtil.java
===================================================================
--- trunk/common-core/src/test/java/com/metamatrix/query/unittest/TimestampUtil.java 2010-05-11 03:40:11 UTC (rev 2112)
+++ trunk/common-core/src/test/java/org/teiid/query/unittest/TimestampUtil.java 2010-05-11 21:39:07 UTC (rev 2115)
@@ -24,7 +24,7 @@
* Date: Jun 16, 2004
* Time: 1:47:51 PM
*/
-package com.metamatrix.query.unittest;
+package org.teiid.query.unittest;
import java.sql.Date;
import java.sql.Time;
Deleted: trunk/common-core/src/test/resources/test.jar
===================================================================
(Binary files differ)
More information about the teiid-commits
mailing list