001: /*
002: * HA-JDBC: High-Availability JDBC
003: * Copyright (c) 2004-2007 Paul Ferraro
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2.1 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: ferraro@users.sourceforge.net
020: */
021: package net.sf.hajdbc.dialect;
022:
023: import java.sql.DatabaseMetaData;
024: import java.sql.SQLException;
025: import java.util.Collection;
026: import java.util.Iterator;
027:
028: import net.sf.hajdbc.Dialect;
029: import net.sf.hajdbc.QualifiedName;
030:
031: import org.easymock.EasyMock;
032: import org.testng.annotations.DataProvider;
033: import org.testng.annotations.Test;
034:
035: /**
036: * @author Paul Ferraro
037: */
038: @SuppressWarnings("nls")
039: public class TestIngresDialect extends TestStandardDialect {
040: @Override
041: protected Dialect createDialect() {
042: return new IngresDialect();
043: }
044:
045: @Override
046: @Test(dataProvider="insert-table-sql")
047: public String parseInsertTable(String sql) throws SQLException {
048: this .replay();
049:
050: String table = this .dialect.parseInsertTable(sql);
051:
052: this .verify();
053:
054: assert table == null : table;
055:
056: return table;
057: }
058:
059: @Override
060: @Test(dataProvider="meta-data")
061: public Collection<QualifiedName> getSequences(
062: DatabaseMetaData metaData) throws SQLException {
063: EasyMock.expect(metaData.getConnection()).andReturn(
064: this .connection);
065: EasyMock.expect(this .connection.createStatement()).andReturn(
066: this .statement);
067: EasyMock
068: .expect(
069: this .statement
070: .executeQuery("SELECT seq_name FROM iisequence"))
071: .andReturn(this .resultSet);
072: EasyMock.expect(this .resultSet.next()).andReturn(true);
073: EasyMock.expect(this .resultSet.getString(1)).andReturn(
074: "sequence1");
075: EasyMock.expect(this .resultSet.next()).andReturn(true);
076: EasyMock.expect(this .resultSet.getString(1)).andReturn(
077: "sequence2");
078: EasyMock.expect(this .resultSet.next()).andReturn(false);
079:
080: this .statement.close();
081:
082: this .replay();
083:
084: Collection<QualifiedName> sequences = this .dialect
085: .getSequences(metaData);
086:
087: this .verify();
088:
089: assert sequences.size() == 2 : sequences.size();
090:
091: Iterator<QualifiedName> iterator = sequences.iterator();
092: QualifiedName sequence = iterator.next();
093: String schema = sequence.getSchema();
094: String name = sequence.getName();
095:
096: assert schema == null : schema;
097: assert name.equals("sequence1") : name;
098:
099: sequence = iterator.next();
100: schema = sequence.getSchema();
101: name = sequence.getName();
102:
103: assert schema == null : schema;
104: assert name.equals("sequence2") : name;
105:
106: return sequences;
107: }
108:
109: @Override
110: @DataProvider(name="sequence-sql")
111: Object[][] sequenceSQLProvider() {
112: return new Object[][] {
113: new Object[] { "SELECT NEXT VALUE FOR success" },
114: new Object[] { "SELECT CURRENT VALUE FOR success" },
115: new Object[] { "SELECT NEXT VALUE FOR success, * FROM table" },
116: new Object[] { "SELECT CURRENT VALUE FOR success, * FROM table" },
117: new Object[] { "INSERT INTO table VALUES (NEXT VALUE FOR success, 0)" },
118: new Object[] { "INSERT INTO table VALUES (CURRENT VALUE FOR success, 0)" },
119: new Object[] { "UPDATE table SET id = NEXT VALUE FOR success" },
120: new Object[] { "UPDATE table SET id = CURRENT VALUE FOR success" },
121: new Object[] { "SELECT success.nextval" },
122: new Object[] { "SELECT success.currval" },
123: new Object[] { "SELECT success.nextval, * FROM table" },
124: new Object[] { "SELECT success.currval, * FROM table" },
125: new Object[] { "INSERT INTO table VALUES (success.nextval, 0)" },
126: new Object[] { "INSERT INTO table VALUES (success.currval, 0)" },
127: new Object[] { "UPDATE table SET id = success.nextval" },
128: new Object[] { "UPDATE table SET id = success.currval" },
129: new Object[] { "SELECT * FROM table" }, };
130: }
131:
132: @Override
133: @DataProvider(name="current-date")
134: Object[][] currentDateProvider() {
135: java.sql.Date date = new java.sql.Date(System
136: .currentTimeMillis());
137:
138: return new Object[][] {
139: new Object[] { "SELECT CURRENT_DATE FROM success", date },
140: new Object[] { "SELECT DATE('TODAY') FROM success",
141: date },
142: new Object[] { "SELECT DATE ( 'TODAY' ) FROM success",
143: date },
144: new Object[] { "SELECT CURRENT_DATES FROM failure",
145: date },
146: new Object[] { "SELECT CCURRENT_DATE FROM failure",
147: date },
148: new Object[] { "SELECT DDATE('TODAY') FROM failure",
149: date },
150: new Object[] { "SELECT 1 FROM failure", date }, };
151: }
152:
153: @Override
154: @DataProvider(name="current-time")
155: Object[][] currentTimeProvider() {
156: java.sql.Time date = new java.sql.Time(System
157: .currentTimeMillis());
158:
159: return new Object[][] {
160: new Object[] { "SELECT CURRENT_TIME FROM success", date },
161: new Object[] { "SELECT LOCAL_TIME FROM success", date },
162: new Object[] { "SELECT CURRENT_TIMESTAMP FROM failure",
163: date },
164: new Object[] { "SELECT CCURRENT_TIME FROM failure",
165: date },
166: new Object[] { "SELECT LOCAL_TIMESTAMP FROM failure",
167: date },
168: new Object[] { "SELECT LLOCAL_TIME FROM failure", date },
169: new Object[] { "SELECT 1 FROM failure", date }, };
170: }
171:
172: @Override
173: @DataProvider(name="current-timestamp")
174: Object[][] currentTimestampProvider() {
175: java.sql.Timestamp date = new java.sql.Timestamp(System
176: .currentTimeMillis());
177:
178: return new Object[][] {
179: new Object[] { "SELECT CURRENT_TIMESTAMP FROM success",
180: date },
181: new Object[] { "SELECT LOCAL_TIMESTAMP FROM success",
182: date },
183: new Object[] { "SELECT DATE('NOW') FROM success", date },
184: new Object[] { "SELECT DATE( 'NOW' ) FROM success",
185: date },
186: new Object[] {
187: "SELECT CURRENT_TIMESTAMPS FROM failure", date },
188: new Object[] {
189: "SELECT CCURRENT_TIMESTAMP FROM failure", date },
190: new Object[] { "SELECT LOCAL_TIMESTAMPS FROM failure",
191: date },
192: new Object[] { "SELECT LLOCAL_TIMESTAMP FROM failure",
193: date },
194: new Object[] { "SELECT DDATE('NOW') FROM failure", date },
195: new Object[] { "SELECT 1 FROM failure", date }, };
196: }
197:
198: @Override
199: @DataProvider(name="random")
200: Object[][] randomProvider() {
201: return new Object[][] {
202: new Object[] { "SELECT RANDOMF() FROM success" },
203: new Object[] { "SELECT RANDOMF ( ) FROM success" },
204: new Object[] { "SELECT OPERANDOMF( ) FROM failure" },
205: new Object[] { "SELECT RAND() FROM failure" },
206: new Object[] { "SELECT 1 FROM failure" }, };
207: }
208: }
|