net.sf.hajdbc.dialect.sybase.SybaseDialect 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.sybase;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import net.sf.hajdbc.IdentityColumnSupport;
import net.sf.hajdbc.dialect.StandardDialect;
import net.sf.hajdbc.util.Resources;
/**
* Dialect for Sybase (commercial).
* @author Paul Ferraro
*/
@SuppressWarnings("nls")
public class SybaseDialect extends StandardDialect
{
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#getIdentityColumnSupport()
*/
@Override
public IdentityColumnSupport getIdentityColumnSupport()
{
return this;
}
/**
* {@inheritDoc}
* @see net.sf.hajdbc.dialect.StandardDialect#vendorPattern()
*/
@Override
protected String vendorPattern()
{
return "sybase";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#truncateTableFormat()
*/
@Override
protected String truncateTableFormat()
{
return "TRUNCATE TABLE {0}";
}
/**
* Deferrability clause is 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} ON UPDATE {6,choice,0#CASCADE|1#RESTRICT|2#SET NULL|3#NO ACTION|4#SET DEFAULT}";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#currentDatePattern()
*/
@Override
protected String currentDatePattern()
{
return "(?<=\\W)CURRENT\\s+DATE(?=\\W)|(?<=\\W)TODAY\\s*\\(\\s*\\*\\s*\\)";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#currentTimePattern()
*/
@Override
protected String currentTimePattern()
{
return "(?<=\\W)CURRENT\\s+TIME(?=\\W)";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#currentTimestampPattern()
*/
@Override
protected String currentTimestampPattern()
{
return "(?<=\\W)CURRENT\\s+TIMESTAMP(?=\\W)|(?<=\\W)GETDATE\\s*\\(\\s*\\)|(?<=\\W)NOW\\s*\\(\\s*\\*\\s*\\)";
}
/**
* @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}''";
}
/**
* @see net.sf.hajdbc.dialect.StandardDialect#randomPattern()
*/
@Override
protected String randomPattern()
{
return "(?<=\\W)RAND\\s*\\(\\s*\\d*\\s*\\)";
}
/**
* jTDS does not implement Connection.isValid(...)
*/
@Override
public boolean isValid(Connection connection) throws SQLException
{
Statement statement = connection.createStatement();
try
{
statement.executeQuery("SELECT GETDATE()");
return true;
}
finally
{
Resources.close(statement);
}
}
}