2
* HA-JDBC: High-Availability JDBC
3
* Copyright (c) 2004-2007 Paul Ferraro
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License as published by the
7
* Free Software Foundation; either version 2.1 of the License, or (at your
8
* option) any later version.
10
* This library is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library; if not, write to the Free Software Foundation,
17
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Contact: ferraro@users.sourceforge.net
21
package net.sf.hajdbc.dialect;
23
import java.sql.Connection;
24
import java.sql.DatabaseMetaData;
25
import java.sql.ResultSet;
26
import java.sql.SQLException;
27
import java.sql.Statement;
28
import java.util.Collection;
29
import java.util.Iterator;
31
import net.sf.hajdbc.QualifiedName;
32
import net.sf.hajdbc.SequenceProperties;
34
import org.easymock.EasyMock;
35
import org.testng.annotations.DataProvider;
36
import org.testng.annotations.Test;
39
* @author Paul Ferraro
42
@SuppressWarnings("nls")
44
public class TestFirebirdDialect extends TestStandardDialect
46
public TestFirebirdDialect()
48
super(new FirebirdDialect());
52
public void testGetAlterSequenceSQL() throws SQLException
54
SequenceProperties sequence = EasyMock.createStrictMock(SequenceProperties.class);
56
EasyMock.expect(sequence.getName()).andReturn("sequence");
58
EasyMock.replay(sequence);
60
String result = this.getAlterSequenceSQL(sequence, 1000L);
62
EasyMock.verify(sequence);
64
assert result.equals("SET GENERATOR sequence TO 1000") : result;
68
* @see net.sf.hajdbc.dialect.TestStandardDialect#testGetSequences()
71
public void testGetSequences() throws SQLException
73
DatabaseMetaData metaData = EasyMock.createStrictMock(DatabaseMetaData.class);
74
Connection connection = EasyMock.createStrictMock(Connection.class);
75
Statement statement = EasyMock.createStrictMock(Statement.class);
76
ResultSet resultSet = EasyMock.createStrictMock(ResultSet.class);
78
EasyMock.expect(metaData.getConnection()).andReturn(connection);
79
EasyMock.expect(connection.createStatement()).andReturn(statement);
80
EasyMock.expect(statement.executeQuery("SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS")).andReturn(resultSet);
81
EasyMock.expect(resultSet.next()).andReturn(true);
82
EasyMock.expect(resultSet.getString(1)).andReturn("sequence1");
83
EasyMock.expect(resultSet.next()).andReturn(true);
84
EasyMock.expect(resultSet.getString(1)).andReturn("sequence2");
85
EasyMock.expect(resultSet.next()).andReturn(false);
89
EasyMock.replay(metaData, connection, statement, resultSet);
91
Collection<QualifiedName> results = this.getSequences(metaData);
93
EasyMock.verify(metaData, connection, statement, resultSet);
95
assert results.size() == 2 : results;
97
Iterator<QualifiedName> iterator = results.iterator();
98
QualifiedName sequence = iterator.next();
99
String schema = sequence.getSchema();
100
String name = sequence.getName();
102
assert schema == null : schema;
103
assert name.equals("sequence1") : name;
105
sequence = iterator.next();
106
schema = sequence.getSchema();
107
name = sequence.getName();
109
assert schema == null : schema;
110
assert name.equals("sequence2") : name;
114
* @see net.sf.hajdbc.dialect.TestStandardDialect#testGetNextSequenceValueSQL()
117
public void testGetNextSequenceValueSQL() throws SQLException
119
SequenceProperties sequence = EasyMock.createStrictMock(SequenceProperties.class);
121
EasyMock.expect(sequence.getName()).andReturn("sequence");
123
EasyMock.replay(sequence);
125
String sql = this.getNextSequenceValueSQL(sequence);
127
EasyMock.verify(sequence);
129
assert sql.equals("SELECT GEN_ID(sequence, 1) FROM RDB$DATABASE") : sql;
133
* @see net.sf.hajdbc.dialect.TestStandardDialect#testGetSimpleSQL()
136
public void testGetSimpleSQL() throws SQLException
138
String result = this.getSimpleSQL();
140
assert result.equals("SELECT CURRENT_TIMESTAMP FROM RDB$DATABASE") : result;
144
@DataProvider(name = "select-for-update-sql")
145
Object[][] selectForUpdateProvider()
147
return new Object[][] {
148
new Object[] { "SELECT * FROM success WITH LOCK" },
149
new Object[] { "SELECT * FROM failure" },
154
@DataProvider(name = "sequence-sql")
155
Object[][] sequenceSQLProvider()
157
return new Object[][] {
158
new Object[] { "SELECT GEN_ID(success, 1) FROM RDB$DATABASE" },
159
new Object[] { "SELECT GEN_ID(success, 1), * FROM table" },
160
new Object[] { "INSERT INTO table VALUES (GEN_ID(success, 1), 0)" },
161
new Object[] { "UPDATE table SET id = GEN_ID(success, 1)" },
162
new Object[] { "SELECT * FROM table" },
167
* @see net.sf.hajdbc.dialect.TestStandardDialect#testParseInsertTable(java.lang.String)
170
@Test(dataProvider = "insert-table-sql")
171
public void testParseInsertTable(String sql) throws SQLException
173
String result = this.parseInsertTable(sql);
175
assert result == null : result;