Removes semicolon from end of the SQL file.
@@ -110,9 +110,23 @@ | ||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | + * Removing semicolon. | |
114 | + */ | |
115 | + public void testRemoveSemicolon() throws Exception { | |
116 | + MirageTestContext.initMirageTestContext(); | |
117 | + MockSqlManager sqlManager = new MockSqlManager(); | |
118 | + | |
119 | + sqlManager.getResultList( | |
120 | + Book.class, SQL_PREFIX + "SqlManagerImplTest_removeSemicolon.sql"); | |
121 | + | |
122 | + MirageTestContext.verifySqlNumber(1); | |
123 | + ExecutedSQLInfo info = MirageTestContext.getExecutedSQLInfo(0); | |
124 | + assertEquals("SELECT BOOK_ID, BOOK_NAME, AUTHOR, PRICE FROM BOOK", info.getSql()); | |
125 | + } | |
126 | + /** | |
113 | 127 | * for Oracle hint |
114 | 128 | * <p> |
115 | - * TODO Should it be written as SqlParserImplTest? | |
129 | + * TODO Should it be written in SqlParserImplTest? | |
116 | 130 | */ |
117 | 131 | public void testIOracleHint1() throws Exception { |
118 | 132 | MirageTestContext.initMirageTestContext(); |
@@ -129,7 +143,7 @@ | ||
129 | 143 | /** |
130 | 144 | * for Oracle hint |
131 | 145 | * <p> |
132 | - * TODO Should it be written as SqlParserImplTest? | |
146 | + * TODO Should it be written in SqlParserImplTest? | |
133 | 147 | */ |
134 | 148 | public void testIOracleHint2() throws Exception { |
135 | 149 | MirageTestContext.initMirageTestContext(); |
@@ -0,0 +1,2 @@ | ||
1 | + SELECT BOOK_ID, BOOK_NAME, AUTHOR, PRICE FROM BOOK; | |
2 | + |
@@ -1,6 +1,5 @@ | ||
1 | 1 | package jp.sf.amateras.mirage; |
2 | 2 | |
3 | -import java.io.ByteArrayOutputStream; | |
4 | 3 | import java.io.InputStream; |
5 | 4 | import java.util.ArrayList; |
6 | 5 | import java.util.List; |
@@ -24,6 +23,7 @@ | ||
24 | 23 | import jp.sf.amateras.mirage.provider.ConnectionProvider; |
25 | 24 | import jp.sf.amateras.mirage.type.DefaultValueType; |
26 | 25 | import jp.sf.amateras.mirage.type.ValueType; |
26 | +import jp.sf.amateras.mirage.util.IOUtil; | |
27 | 27 | import jp.sf.amateras.mirage.util.MirageUtil; |
28 | 28 | |
29 | 29 | public class SqlManagerImpl implements SqlManager { |
@@ -105,19 +105,16 @@ | ||
105 | 105 | |
106 | 106 | String sql = null; |
107 | 107 | try { |
108 | - byte[] buf = new byte[1024 * 8]; | |
109 | - int length = 0; | |
110 | - ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
111 | - while((length = in.read(buf)) != -1){ | |
112 | - out.write(buf, 0, length); | |
113 | - } | |
114 | - | |
115 | - sql = new String(out.toByteArray(), "UTF-8"); | |
116 | - | |
108 | + sql = new String(IOUtil.readStream(in), "UTF-8"); | |
117 | 109 | } catch(Exception ex){ |
118 | 110 | throw new RuntimeException(String.format("Failed to load SQL from: %s", sqlPath)); |
119 | 111 | } |
120 | 112 | |
113 | + sql = sql.trim(); | |
114 | + if(sql.endsWith(";")){ | |
115 | + sql = sql.substring(0, sql.length() - 1); | |
116 | + } | |
117 | + | |
121 | 118 | Node node = new SqlParserImpl(sql).parse(); |
122 | 119 | |
123 | 120 | if(cacheMode){ |