All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.dialect.SybaseASE157Dialect Maven / Gradle / Ivy

There is a newer version: 6.6.2.Final
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.dialect;

import java.sql.SQLException;
import java.util.Map;

import org.hibernate.JDBCException;
import org.hibernate.LockOptions;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.SybaseASE157LimitHandler;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.LockTimeoutException;
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.sql.ForUpdateFragment;
import org.hibernate.type.StandardBasicTypes;

/**
 * An SQL dialect targeting Sybase Adaptive Server Enterprise (ASE) 15.7 and higher.
 * 

* * @author Junyan Ren */ public class SybaseASE157Dialect extends SybaseASE15Dialect { private static final SybaseASE157LimitHandler LIMIT_HANDLER = new SybaseASE157LimitHandler(); /** * Constructs a SybaseASE157Dialect */ public SybaseASE157Dialect() { super(); registerFunction( "create_locator", new SQLFunctionTemplate( StandardBasicTypes.BINARY, "create_locator(?1, ?2)" ) ); registerFunction( "locator_literal", new SQLFunctionTemplate( StandardBasicTypes.BINARY, "locator_literal(?1, ?2)" ) ); registerFunction( "locator_valid", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "locator_valid(?1)" ) ); registerFunction( "return_lob", new SQLFunctionTemplate( StandardBasicTypes.BINARY, "return_lob(?1, ?2)" ) ); registerFunction( "setdata", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "setdata(?1, ?2, ?3)" ) ); registerFunction( "charindex", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "charindex(?1, ?2, ?3)" ) ); } @Override public String getTableTypeString() { //HHH-7298 I don't know if this would break something or cause some side affects //but it is required to use 'select for update' return " lock datarows"; } @Override public boolean supportsExpectedLobUsagePattern() { return true; } @Override public boolean supportsLobValueChangePropogation() { return false; } @Override public boolean forUpdateOfColumns() { return true; } @Override public String getForUpdateString() { return " for update"; } @Override public String getForUpdateString(String aliases) { return getForUpdateString() + " of " + aliases; } @Override public String appendLockHint(LockOptions mode, String tableName) { return tableName; } @Override public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map keyColumnNames) { return sql + new ForUpdateFragment( this, aliasedLockOptions, keyColumnNames ).toFragmentString(); } @Override public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() { return new SQLExceptionConversionDelegate() { @Override public JDBCException convert(SQLException sqlException, String message, String sql) { final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException ); final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException ); if("JZ0TO".equals( sqlState ) || "JZ006".equals( sqlState )){ throw new LockTimeoutException( message, sqlException, sql ); } if ( 515 == errorCode && "ZZZZZ".equals( sqlState ) ) { // Attempt to insert NULL value into column; column does not allow nulls. final String constraintName = getViolatedConstraintNameExtracter().extractConstraintName( sqlException ); return new ConstraintViolationException( message, sqlException, sql, constraintName ); } return null; } }; } @Override public boolean supportsLimit() { return true; } @Override public boolean supportsLimitOffset() { return false; } @Override public LimitHandler getLimitHandler() { return LIMIT_HANDLER; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy