net.sf.hajdbc.dialect.oracle.OracleDialect Maven / Gradle / Ivy
/*
* HA-JDBC: High-Availability JDBC
* Copyright (C) 2012 Paul Ferraro
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package net.sf.hajdbc.dialect.oracle;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import net.sf.hajdbc.SequenceProperties;
import net.sf.hajdbc.SequencePropertiesFactory;
import net.sf.hajdbc.SequenceSupport;
import net.sf.hajdbc.dialect.StandardDialect;
import net.sf.hajdbc.util.Resources;
/**
* Dialect for Oracle (commercial).
* @author Paul Ferraro
*/
@SuppressWarnings("nls")
public class OracleDialect extends StandardDialect
{
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#vendorPattern()
*/
@Override
protected String vendorPattern()
{
return "oracle";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#dummyTable()
*/
@Override
protected String dummyTable()
{
return "DUAL";
}
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#getSequenceSupport()
*/
@Override
public SequenceSupport getSequenceSupport()
{
return this;
}
@Override
public Collection getSequences(DatabaseMetaData metaData, SequencePropertiesFactory factory) throws SQLException
{
Statement statement = metaData.getConnection().createStatement();
try
{
ResultSet resultSet = statement.executeQuery("SELECT SEQUENCE_NAME, INCREMENT_BY FROM USER_SEQUENCES");
List sequences = new LinkedList();
while (resultSet.next())
{
sequences.add(factory.createSequenceProperties(null, resultSet.getString(1), resultSet.getInt(2)));
}
return sequences;
}
finally
{
Resources.close(statement);
}
}
@Override
protected String schemaPattern(DatabaseMetaData metaData) throws SQLException
{
return metaData.getUserName();
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#truncateTableFormat()
*/
@Override
protected String truncateTableFormat()
{
return "TRUNCATE TABLE {0}";
}
/**
* ON UPDATE and deferrability clauses are not supported.
* @see net.sf.hajdbc.dialect.StandardDialect#createForeignKeyConstraintFormat()
*/
@Override
protected String createForeignKeyConstraintFormat()
{
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}";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#sequencePattern()
*/
@Override
protected String sequencePattern()
{
return "'?(\\w+)'?\\.(?:CURR|NEXT)VAL";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#nextSequenceValueFormat()
*/
@Override
protected String nextSequenceValueFormat()
{
return "{0}.NEXTVAL";
}
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#alterSequenceFormat()
*/
@Override
protected String alterSequenceFormat()
{
return "DROP SEQUENCE {0}; CREATE SEQUENCE {0} START WITH {1} INCREMENT BY {2}";
}
@Override
protected boolean indicatesFailure(String sqlState)
{
// 66 class SQLStates indicate SQL*Net driver errors
// 69 class SQLStates indicate SQL*Connect errors
return super.indicatesFailure(sqlState) || sqlState.startsWith("66") || sqlState.startsWith("69");
}
}