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.ResultSet;
025: import java.sql.SQLException;
026: import java.sql.Statement;
027: import java.util.Collection;
028: import java.util.LinkedList;
029: import java.util.List;
030:
031: import net.sf.hajdbc.QualifiedName;
032:
033: /**
034: * Dialect for Oracle (commercial).
035: * @author Paul Ferraro
036: */
037: @SuppressWarnings("nls")
038: public class OracleDialect extends StandardDialect {
039: /**
040: * @see net.sf.hajdbc.dialect.StandardDialect#dummyTable()
041: */
042: @Override
043: protected String dummyTable() {
044: return "DUAL";
045: }
046:
047: /**
048: * @see net.sf.hajdbc.dialect.StandardDialect#getSequences(java.sql.DatabaseMetaData)
049: */
050: @Override
051: public Collection<QualifiedName> getSequences(
052: DatabaseMetaData metaData) throws SQLException {
053: List<QualifiedName> sequenceList = new LinkedList<QualifiedName>();
054:
055: Statement statement = metaData.getConnection()
056: .createStatement();
057:
058: ResultSet resultSet = statement
059: .executeQuery("SELECT SEQUENCE_NAME FROM USER_SEQUENCES");
060:
061: while (resultSet.next()) {
062: sequenceList.add(new QualifiedName(resultSet.getString(1)));
063: }
064:
065: statement.close();
066:
067: return sequenceList;
068: }
069:
070: /**
071: * @see net.sf.hajdbc.dialect.StandardDialect#parseInsertTable(java.lang.String)
072: */
073: @Override
074: public String parseInsertTable(String sql) {
075: return null;
076: }
077:
078: /**
079: * @see net.sf.hajdbc.dialect.StandardDialect#truncateTableFormat()
080: */
081: @Override
082: protected String truncateTableFormat() {
083: return "TRUNCATE TABLE {0}";
084: }
085:
086: /**
087: * ON UPDATE and deferrability clauses are not supported.
088: * @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat()
089: */
090: @Override
091: protected String createForeignKeyConstraintFormat() {
092: return "ALTER TABLE {1} ADD CONSTRAINT {0} FOREIGN KEY ({2}) REFERENCES {3} ({4}) ON DELETE {5,choice,0#CASCADE|1#RESTRICT|2#SET NULL|3#NO ACTION|4#SET DEFAULT}";
093: }
094:
095: /**
096: * @see net.sf.hajdbc.dialect.StandardDialect#sequencePattern()
097: */
098: @Override
099: protected String sequencePattern() {
100: return "'?(\\w+)'?\\.(?:CURR|NEXT)VAL";
101: }
102:
103: /**
104: * @see net.sf.hajdbc.dialect.StandardDialect#nextSequenceValueFormat()
105: */
106: @Override
107: protected String nextSequenceValueFormat() {
108: return "{0}.NEXTVAL";
109: }
110: }
|