|
| 1 | +/* |
| 2 | + * Copyright 2004-2010 the Seasar Foundation and the Others. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 13 | + * either express or implied. See the License for the specific language |
| 14 | + * governing permissions and limitations under the License. |
| 15 | + */ |
| 16 | +package org.seasar.doma.jdbc.dialect; |
| 17 | + |
| 18 | +import java.sql.Date; |
| 19 | +import java.sql.Time; |
| 20 | +import java.sql.Timestamp; |
| 21 | +import java.text.SimpleDateFormat; |
| 22 | + |
| 23 | +import org.seasar.doma.expr.ExpressionFunctions; |
| 24 | +import org.seasar.doma.internal.jdbc.sql.ConvertToLogFormatFunction; |
| 25 | +import org.seasar.doma.jdbc.SqlLogFormattingVisitor; |
| 26 | +import org.seasar.doma.wrapper.DateWrapper; |
| 27 | +import org.seasar.doma.wrapper.TimeWrapper; |
| 28 | +import org.seasar.doma.wrapper.TimestampWrapper; |
| 29 | +import org.seasar.doma.wrapper.UtilDateWrapper; |
| 30 | + |
| 31 | +import junit.framework.TestCase; |
| 32 | + |
| 33 | +/** |
| 34 | + * @author taedium |
| 35 | + * |
| 36 | + */ |
| 37 | +public class Oracle11DialectTest extends TestCase { |
| 38 | + |
| 39 | + public void testExpressionFunctions_prefix() throws Exception { |
| 40 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 41 | + ExpressionFunctions functions = dialect.getExpressionFunctions(); |
| 42 | + assertEquals("a$$a$%a$_a$%a$_%", functions.prefix("a$a%a_a%a_")); |
| 43 | + } |
| 44 | + |
| 45 | + public void testExpressionFunctions_prefix_escape() throws Exception { |
| 46 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 47 | + ExpressionFunctions functions = dialect.getExpressionFunctions(); |
| 48 | + assertEquals("a!!a!%a!_a!%a!_%", functions.prefix("a!a%a_a%a_", '!')); |
| 49 | + } |
| 50 | + |
| 51 | + public void testExpressionFunctions_prefix_escapeWithBackslash() |
| 52 | + throws Exception { |
| 53 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 54 | + ExpressionFunctions functions = dialect.getExpressionFunctions(); |
| 55 | + assertEquals("a\\\\a\\%a\\_a\\%a\\_%", |
| 56 | + functions.prefix("a\\a%a_a%a_", '\\')); |
| 57 | + } |
| 58 | + |
| 59 | + public void testDateFormat() throws Exception { |
| 60 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 61 | + SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor(); |
| 62 | + DateWrapper wrapper = new DateWrapper(Date.valueOf("2009-01-23")); |
| 63 | + assertEquals("date'2009-01-23'", wrapper.accept(visitor, |
| 64 | + new ConvertToLogFormatFunction(), null)); |
| 65 | + } |
| 66 | + |
| 67 | + public void testTimeFormat() throws Exception { |
| 68 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 69 | + SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor(); |
| 70 | + TimeWrapper wrapper = new TimeWrapper(Time.valueOf("01:23:45")); |
| 71 | + assertEquals("time'01:23:45'", wrapper.accept(visitor, |
| 72 | + new ConvertToLogFormatFunction(), null)); |
| 73 | + } |
| 74 | + |
| 75 | + public void testTimestampFormat() throws Exception { |
| 76 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 77 | + SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor(); |
| 78 | + TimestampWrapper wrapper = new TimestampWrapper( |
| 79 | + Timestamp.valueOf("2009-01-23 01:23:45.123456789")); |
| 80 | + assertEquals("timestamp'2009-01-23 01:23:45.123456789'", wrapper |
| 81 | + .accept(visitor, new ConvertToLogFormatFunction(), null)); |
| 82 | + } |
| 83 | + |
| 84 | + public void testUtilDateFormat() throws Exception { |
| 85 | + Oracle11Dialect dialect = new Oracle11Dialect(); |
| 86 | + SqlLogFormattingVisitor visitor = dialect.getSqlLogFormattingVisitor(); |
| 87 | + UtilDateWrapper wrapper = new UtilDateWrapper( |
| 88 | + new SimpleDateFormat("yyyy-MM-dd HH:mm:sss.SSS") |
| 89 | + .parse("2009-01-23 12:34:56.789")); |
| 90 | + assertEquals("timestamp'2009-01-23 12:34:56.789'", wrapper |
| 91 | + .accept(visitor, new ConvertToLogFormatFunction(), null)); |
| 92 | + } |
| 93 | +} |
0 commit comments