Author: shawkins
Date: 2010-05-18 11:20:27 -0400 (Tue, 18 May 2010)
New Revision: 2137
Added:
trunk/adminshell/src/test/java/org/
trunk/adminshell/src/test/java/org/teiid/
trunk/adminshell/src/test/java/org/teiid/adminshell/
trunk/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java
trunk/adminshell/src/test/resources/foo/
trunk/adminshell/src/test/resources/foo/bar.txt
Modified:
trunk/adminshell/pom.xml
trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java
trunk/connectors/connector-ws/
trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java
Log:
TEIID-1088 ensuring that the vdb filename is set as just the filename and not the full
path.
Modified: trunk/adminshell/pom.xml
===================================================================
--- trunk/adminshell/pom.xml 2010-05-18 15:08:58 UTC (rev 2136)
+++ trunk/adminshell/pom.xml 2010-05-18 15:20:27 UTC (rev 2137)
@@ -18,6 +18,11 @@
</dependency>
<dependency>
<groupId>org.jboss.teiid</groupId>
+ <artifactId>teiid-common-core</artifactId>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.teiid</groupId>
<artifactId>teiid-client</artifactId>
<scope>provided</scope>
</dependency>
@@ -31,6 +36,12 @@
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
Modified: trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
===================================================================
--- trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2010-05-18
15:08:58 UTC (rev 2136)
+++ trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2010-05-18
15:20:27 UTC (rev 2137)
@@ -27,8 +27,6 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Reader;
-import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashMap;
import java.util.Properties;
@@ -50,7 +48,6 @@
import org.teiid.adminapi.WorkerPoolStatistics;
import org.teiid.adminshell.Help.Doc;
import org.teiid.core.util.ObjectConverterUtil;
-import org.teiid.core.util.ReaderInputStream;
/**
@@ -62,7 +59,7 @@
static Properties p;
private static int connectionCount = 1;
- private static Admin internalAdmin;
+ static Admin internalAdmin;
private static String currentName;
private static HashMap<String, Admin> connections = new HashMap<String,
Admin>();
private static Help help = new Help(AdminShell.class);
@@ -332,14 +329,6 @@
}
private static void writeFile(String deployedName, String fileName,
- Reader contents) throws IOException, AdminProcessingException {
- if (contents == null) {
- throw new AdminProcessingException(deployedName + " not found for
exporting");
- }
- ObjectConverterUtil.write(new ReaderInputStream(contents,
Charset.forName("UTF-8")), fileName); //$NON-NLS-1$
- }
-
- private static void writeFile(String deployedName, String fileName,
InputStream contents) throws IOException, AdminProcessingException {
if (contents == null) {
throw new AdminProcessingException(deployedName + " not found for
exporting");
@@ -359,9 +348,10 @@
@Doc(text = "Deploy a VDB from file")
public static void deployVDB(
@Doc(text = "file name") String vdbFile) throws AdminException,
FileNotFoundException {
- FileInputStream fis = new FileInputStream(new File(vdbFile));
+ File file = new File(vdbFile);
+ FileInputStream fis = new FileInputStream(file);
try {
- getAdmin().deployVDB(vdbFile, fis);
+ getAdmin().deployVDB(file.getName(), fis);
} finally {
try {
fis.close();
Added: trunk/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java
===================================================================
--- trunk/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java
(rev 0)
+++ trunk/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java 2010-05-18
15:20:27 UTC (rev 2137)
@@ -0,0 +1,55 @@
+/*
+ * 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 static
+ * 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 static License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General public static
+ * 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.adminshell;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.adminapi.Admin;
+import org.teiid.adminapi.AdminException;
+import org.teiid.core.util.UnitTestUtil;
+
+@SuppressWarnings("nls")
+public class TestAdminShell {
+
+ private static Admin admin;
+
+ @BeforeClass public static void oneTimeSetUp() {
+ admin = Mockito.mock(Admin.class);
+ AdminShell.internalAdmin = admin;
+ }
+
+ @AfterClass public static void oneTimeTearDown() {
+ AdminShell.internalAdmin = null;
+ }
+
+ @Test public void testDeployVDB() throws AdminException, FileNotFoundException {
+ AdminShell.deployVDB(UnitTestUtil.getTestDataPath() + "/foo/bar.txt");
+ Mockito.verify(admin).deployVDB(Mockito.eq("bar.txt"),
(InputStream)Mockito.anyObject());
+ }
+
+}
Property changes on:
trunk/adminshell/src/test/java/org/teiid/adminshell/TestAdminShell.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/adminshell/src/test/resources/foo/bar.txt
===================================================================
Property changes on: trunk/adminshell/src/test/resources/foo/bar.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2010-05-18
15:08:58 UTC (rev 2136)
+++ trunk/client/src/main/java/org/teiid/jdbc/PreparedStatementImpl.java 2010-05-18
15:20:27 UTC (rev 2137)
@@ -61,7 +61,6 @@
import org.teiid.core.types.InputStreamFactory;
import org.teiid.core.types.JDBCSQLTypeInfo;
import org.teiid.core.util.ArgCheck;
-import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.SqlUtil;
import org.teiid.core.util.TimestampWithTimezone;
@@ -294,11 +293,7 @@
}
public void setBinaryStream(int parameterIndex, java.io.InputStream in, int length)
throws SQLException {
- try {
- setObject(parameterIndex, new SerialBlob(ObjectConverterUtil.convertToByteArray(in,
length)));
- } catch (IOException e) {
- throw TeiidSQLException.create(e);
- }
+ setBlob(parameterIndex, in);
}
/**
@@ -330,7 +325,7 @@
* @throws SQLException, if parameter type/datatype do not match
*/
public void setByte(int parameterIndex, byte value) throws SQLException {
- setObject(parameterIndex, new Byte(value));
+ setObject(parameterIndex, Byte.valueOf(value));
}
/**
@@ -416,7 +411,7 @@
* @throws SQLException, if parameter type/datatype do not match
*/
public void setInt(int parameterIndex, int value) throws SQLException {
- setObject(parameterIndex, new Integer(value));
+ setObject(parameterIndex, Integer.valueOf(value));
}
/**
@@ -427,7 +422,7 @@
* @throws SQLException, if parameter type/datatype do not match
*/
public void setLong(int parameterIndex, long value) throws SQLException {
- setObject(parameterIndex, new Long(value));
+ setObject(parameterIndex, Long.valueOf(value));
}
/**
@@ -545,7 +540,7 @@
val = TimestampWithTimezone.create((java.util.Date)value,
getDefaultCalendar().getTimeZone(), serverCalendar, value.getClass());
} else val = value;
- parameterMap.put(new Integer(parameterIndex), val);
+ parameterMap.put(parameterIndex, val);
}
/**
@@ -556,7 +551,7 @@
* @throws SQLException, if there is an error setting the parameter value
*/
public void setShort(int parameterIndex, short value) throws SQLException {
- setObject(parameterIndex, new Short(value));
+ setObject(parameterIndex, value);
}
/**
Modified: trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java
===================================================================
---
trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java 2010-05-18
15:08:58 UTC (rev 2136)
+++
trunk/common-core/src/main/java/org/teiid/core/util/ObjectConverterUtil.java 2010-05-18
15:20:27 UTC (rev 2137)
@@ -33,7 +33,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
import java.sql.SQLException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -50,24 +53,7 @@
try {
// Open a stream to read the BLOB data
InputStream l_blobStream = data.getBinaryStream();
-
- // Open a file stream to save the BLOB data
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- BufferedOutputStream bos = new BufferedOutputStream(out);
-
- // Read from the BLOB data input stream, and write to the file output
stream
- byte[] l_buffer = new byte[1024]; // buffer holding bytes to be
transferred
- int l_nbytes = 0; // Number of bytes read
- while ((l_nbytes = l_blobStream.read(l_buffer)) != -1) // Read from BLOB
stream
- bos.write(l_buffer,0,l_nbytes); // Write to file stream
-
- // Flush and close the streams
- bos.flush();
- bos.close();
- l_blobStream.close();
-
- return out.toByteArray();
-
+ return convertToByteArray(l_blobStream);
} catch (IOException ioe) {
final Object[] params = new Object[]{data.getClass().getName()};
throw new
TeiidException(ioe,CorePlugin.Util.getString("ObjectConverterUtil.Error_translating_results_from_data_type_to_a_byte[]._1",params));
//$NON-NLS-1$
@@ -91,28 +77,65 @@
throw new
TeiidException(CorePlugin.Util.getString("ObjectConverterUtil.Object_type_not_supported_for_object_conversion._3",params));
//$NON-NLS-1$
}
-
public static byte[] convertToByteArray(final InputStream is) throws IOException {
+ return convertToByteArray(is, -1);
+ }
+
+ /**
+ * Returns the given input stream's contents as a byte array.
+ * If a length is specified (ie. if length != -1), only length bytes
+ * are returned. Otherwise all bytes in the stream are returned.
+ * Note this does close the stream, even if not all bytes are written,
+ * because the buffering does not guarantee the end position.
+ * @throws IOException if a problem occurred reading the stream.
+ */
+ public static byte[] convertToByteArray(final InputStream is, int length) throws
IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
- BufferedOutputStream bos = new BufferedOutputStream(out);
+ write(out, is, length);
+ return out.toByteArray();
+ }
+
+ public static void write(final OutputStream out, final InputStream is, int length)
throws IOException {
+ int writen = 0;
try {
- byte[] l_buffer = new byte[1024]; // buffer holding bytes to be transferred
+ byte[] l_buffer = new byte[DEFAULT_READING_SIZE]; // buffer holding bytes to be
transferred
int l_nbytes = 0; // Number of bytes read
- while ((l_nbytes = is.read(l_buffer)) != -1) // Read from BLOB stream
- bos.write(l_buffer,0,l_nbytes); // Write to file stream
+ while ((l_nbytes = is.read(l_buffer)) != -1) {
+ if (length != -1 && writen > length - l_nbytes) {
+ out.write(l_buffer, 0, writen + l_nbytes - length);
+ break;
+ }
+ out.write(l_buffer,0,l_nbytes);
+ writen += l_nbytes;
+ }
} finally {
- is.close();
- bos.close();
+ is.close();
+ out.close();
}
- byte[] data = out.toByteArray();
- return data;
}
+
+ public static void write(final Writer out, final Reader is, int length) throws
IOException {
+ int writen = 0;
+ try {
+ char[] l_buffer = new char[DEFAULT_READING_SIZE]; // buffer holding bytes to be
transferred
+ int l_nbytes = 0; // Number of bytes read
+ while ((l_nbytes = is.read(l_buffer)) != -1) {
+ if (length != -1 && writen > length - l_nbytes) {
+ out.write(l_buffer, 0, writen + l_nbytes - length);
+ break;
+ }
+ out.write(l_buffer,0,l_nbytes);
+ writen += l_nbytes;
+ }
+ } finally {
+ is.close();
+ out.close();
+ }
+ }
-
public static InputStream convertToInputStream(byte[] data) {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
InputStream isContent = new BufferedInputStream(bais);
-
return isContent;
}
@@ -126,47 +149,25 @@
public static void write(final InputStream is, final String fileName) throws
IOException {
File f = new File(fileName);
- f.delete();
-
write(is, f);
}
public static void write(final Reader reader, final String fileName) throws
IOException {
File f = new File(fileName);
- f.delete();
-
write(reader, f);
}
public static void write(final Reader reader, final File f) throws IOException {
- FileWriter fw = new FileWriter(f);
- try {
- char[] buff = new char[2048];
- int bytesRead;
-
- // Simple read/write loop.
- while (-1 != (bytesRead = reader.read(buff, 0, buff.length))) {
- fw.write(buff, 0, bytesRead);
- }
- } finally {
- fw.close();
- }
+ f.getParentFile().mkdirs();
+ FileWriter fw = new FileWriter(f);
+ write(fw, reader, -1);
}
public static void write(final InputStream is, final File f) throws IOException {
+ f.getParentFile().mkdirs();
FileOutputStream fio = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fio);
- try {
- byte[] buff = new byte[2048];
- int bytesRead;
-
- // Simple read/write loop.
- while (-1 != (bytesRead = is.read(buff, 0, buff.length))) {
- bos.write(buff, 0, bytesRead);
- }
- } finally {
- bos.close();
- }
+ write(bos, is, -1);
}
public static void write(byte[] data, final String fileName) throws Exception {
@@ -191,46 +192,25 @@
}
/**
* Returns the contents of the given file as a byte array.
- * @throws IOException if a problem occured reading the file.
+ * @throws IOException if a problem occurred reading the file.
*/
public static byte[] convertFileToByteArray(File file) throws IOException {
- InputStream stream = null;
- try {
- stream = new BufferedInputStream(new FileInputStream(file));
- return convertToByteArray(stream, (int) file.length());
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- }
+ return convertToByteArray(new FileInputStream(file), (int) file.length());
}
/**
* Returns the contents of the given file as a char array.
* When encoding is null, then the platform default one is used
- * @throws IOException if a problem occured reading the file.
+ * @throws IOException if a problem occurred reading the file.
*/
public static char[] convertFileToCharArray(File file, String encoding) throws
IOException {
- InputStream stream = null;
- try {
- stream = new BufferedInputStream(new FileInputStream(file));
- return convertToCharArray(stream, (int) file.length(), encoding);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- }
+ InputStream stream = new FileInputStream(file);
+ return convertToCharArray(stream, (int) file.length(), encoding);
}
/**
* Returns the contents of the given file as a string.
- * @throws IOException if a problem occured reading the file.
+ * @throws IOException if a problem occurred reading the file.
*/
public static String convertFileToString(final File file) throws IOException {
return new String(convertFileToCharArray(file,null));
@@ -239,161 +219,37 @@
/**
* Returns the contents of the given InputStream as a string.
- * @throws IOException if a problem occured reading the file.
+ * @throws IOException if a problem occurred reading the file.
*/
public static String convertToString(final InputStream stream) throws IOException {
return new String(convertToCharArray(stream, -1, null));
}
-
/**
- * Returns the given input stream's contents as a byte array.
- * If a length is specified (ie. if length != -1), only length bytes
- * are returned. Otherwise all bytes in the stream are returned.
- * Note this doesn't close the stream.
- * @throws IOException if a problem occured reading the stream.
- */
- public static byte[] convertToByteArray(InputStream stream, int length)
- throws IOException {
- byte[] contents;
- if (length == -1) {
- contents = new byte[0];
- int contentsLength = 0;
- int amountRead = -1;
- do {
- int amountRequested = Math.max(stream.available(), DEFAULT_READING_SIZE);
// read at least 8K
-
- // resize contents if needed
- if (contentsLength + amountRequested > contents.length) {
- System.arraycopy(
- contents,
- 0,
- contents = new byte[contentsLength + amountRequested],
- 0,
- contentsLength);
- }
-
- // read as many bytes as possible
- amountRead = stream.read(contents, contentsLength, amountRequested);
-
- if (amountRead > 0) {
- // remember length of contents
- contentsLength += amountRead;
- }
- } while (amountRead != -1);
-
- // resize contents if necessary
- if (contentsLength < contents.length) {
- System.arraycopy(
- contents,
- 0,
- contents = new byte[contentsLength],
- 0,
- contentsLength);
- }
- } else {
- contents = new byte[length];
- int len = 0;
- int readSize = 0;
- while ((readSize != -1) && (len != length)) {
- // See PR 1FMS89U
- // We record first the read size. In this case len is the actual read
size.
- len += readSize;
- readSize = stream.read(contents, len, length - len);
- }
- }
-
- return contents;
- }
-
- /**
* Returns the given input stream's contents as a character array.
* If a length is specified (ie. if length != -1), only length chars
* are returned. Otherwise all chars in the stream are returned.
* Note this doesn't close the stream.
- * @throws IOException if a problem occured reading the stream.
+ * @throws IOException if a problem occurred reading the stream.
*/
public static char[] convertToCharArray(InputStream stream, int length, String
encoding)
throws IOException {
- InputStreamReader reader = null;
- reader = encoding == null
- ? new InputStreamReader(stream)
- : new InputStreamReader(stream, encoding);
- char[] contents;
- if (length == -1) {
- contents = new char[0];
- int contentsLength = 0;
- int amountRead = -1;
- do {
- int amountRequested = Math.max(stream.available(), DEFAULT_READING_SIZE);
// read at least 8K
-
- // resize contents if needed
- if (contentsLength + amountRequested > contents.length) {
- System.arraycopy(
- contents,
- 0,
- contents = new char[contentsLength + amountRequested],
- 0,
- contentsLength);
- }
-
- // read as many chars as possible
- amountRead = reader.read(contents, contentsLength, amountRequested);
-
- if (amountRead > 0) {
- // remember length of contents
- contentsLength += amountRead;
- }
- } while (amountRead != -1);
-
- // resize contents if necessary
- if (contentsLength < contents.length) {
- System.arraycopy(
- contents,
- 0,
- contents = new char[contentsLength],
- 0,
- contentsLength);
- }
- } else {
- contents = new char[length];
- int len = 0;
- int readSize = 0;
- while ((readSize != -1) && (len != length)) {
- // See PR 1FMS89U
- // We record first the read size. In this case len is the actual read
size.
- len += readSize;
- readSize = reader.read(contents, len, length - len);
- }
- // See PR 1FMS89U
- // Now we need to resize in case the default encoding used more than one byte
for each
- // character
- if (len != length)
- System.arraycopy(contents, 0, (contents = new char[len]), 0, len);
- }
-
- return contents;
+ Reader r = null;
+ if (encoding == null) {
+ r = new InputStreamReader(stream);
+ } else {
+ r = new InputStreamReader(stream, encoding);
+ }
+ return convertToCharArray(r, length);
}
/**
* Returns the contents of the given zip entry as a byte array.
- * @throws IOException if a problem occured reading the zip entry.
+ * @throws IOException if a problem occurred reading the zip entry.
*/
public static byte[] convertToByteArray(ZipEntry ze, ZipFile zip)
throws IOException {
-
- InputStream stream = null;
- try {
- stream = new BufferedInputStream(zip.getInputStream(ze));
- return convertToByteArray(stream, (int) ze.getSize());
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- }
- }
- }
+ return convertToByteArray(zip.getInputStream(ze), (int) ze.getSize());
}
public static String convertToString(Reader reader) throws IOException {
@@ -401,11 +257,8 @@
}
public static char[] convertToCharArray(Reader reader, int length) throws IOException
{
- StringBuilder sb = new StringBuilder();
- int chr = -1;
- for (int i = 0; i < length && (chr = reader.read()) != -1; i ++) {
- sb.append((char)chr);
- }
+ StringWriter sb = new StringWriter();
+ write(sb, reader, length);
return sb.toString().toCharArray();
}
Property changes on: trunk/connectors/connector-ws
___________________________________________________________________
Name: svn:ignore
+ target
.settings
.classpath
.project
Modified: trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-05-18
15:08:58 UTC (rev 2136)
+++ trunk/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2010-05-18
15:20:27 UTC (rev 2137)
@@ -233,7 +233,6 @@
else {
Map<String, String> configProps = new HashMap<String, String>();
configProps.put(propertyName, propertyValue);
- configProps.put(propertyValue+".type", "java.lang.String");
//$NON-NLS-1$ //$NON-NLS-2$
MetaValue metaValue = ManagedUtil.compositeValueMap(configProps);
mc.getProperty("translator-property").setValue(metaValue); //$NON-NLS-1$
}
Modified:
trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java
===================================================================
---
trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java 2010-05-18
15:08:58 UTC (rev 2136)
+++
trunk/runtime/src/test/java/com/metamatrix/dqp/service/buffer/TestLocalBufferService.java 2010-05-18
15:20:27 UTC (rev 2137)
@@ -29,7 +29,7 @@
import junit.framework.TestCase;
-
+@SuppressWarnings("nls")
public class TestLocalBufferService extends TestCase {
public TestLocalBufferService(String name) {