net.sf.hajdbc.dialect.db2.DB2Dialect 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.db2;
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.IdentityColumnSupport;
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 DB2 (commercial).
* @author Paul Ferraro
* @since 1.1
*/
@SuppressWarnings("nls")
public class DB2Dialect extends StandardDialect
{
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#vendorPattern()
*/
@Override
protected String vendorPattern()
{
return "db2";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#executeFunctionFormat()
*/
@Override
protected String executeFunctionFormat()
{
return "VALUES {0}";
}
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#getSequenceSupport()
*/
@Override
public SequenceSupport getSequenceSupport()
{
return this;
}
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#getIdentityColumnSupport()
*/
@Override
public IdentityColumnSupport getIdentityColumnSupport()
{
return this;
}
@Override
public Collection getSequences(DatabaseMetaData metaData, SequencePropertiesFactory factory) throws SQLException
{
Statement statement = metaData.getConnection().createStatement();
try
{
ResultSet resultSet = statement.executeQuery("SELECT SEQSCHEMA, SEQNAME, INCREMENT FROM SYSCAT.SEQUENCES");
List sequences = new LinkedList();
while (resultSet.next())
{
sequences.add(factory.createSequenceProperties(resultSet.getString(1), resultSet.getString(2), resultSet.getInt(3)));
}
return sequences;
}
finally
{
Resources.close(statement);
}
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#sequencePattern()
*/
@Override
protected String sequencePattern()
{
return "(?:NEXT|PREV)VAL\\s+FOR\\s+'?([^',\\s\\(\\)]+)";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#nextSequenceValueFormat()
*/
@Override
protected String nextSequenceValueFormat()
{
return "NEXTVAL FOR {0}";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#dateLiteralFormat()
*/
@Override
protected String dateLiteralFormat()
{
return this.timestampLiteralFormat();
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#timeLiteralFormat()
*/
@Override
protected String timeLiteralFormat()
{
return this.timestampLiteralFormat();
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#timestampLiteralFormat()
*/
@Override
protected String timestampLiteralFormat()
{
return "''{0}''";
}
}