HHH-9044 created Oracle12cDialect, SQL2008StandardLimitHandler, minor tweaks for identity generation
This commit is contained in:
parent
a9f867fede
commit
1e5444f07d
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* 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 distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.dialect;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.dialect.pagination.LimitHandler;
|
||||||
|
import org.hibernate.dialect.pagination.SQL2008StandardLimitHandler;
|
||||||
|
import org.hibernate.engine.spi.RowSelection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An SQL dialect for Oracle 12c.
|
||||||
|
*
|
||||||
|
* @author zhouyanming (zhouyanming@gmail.com)
|
||||||
|
*/
|
||||||
|
public class Oracle12cDialect extends Oracle10gDialect {
|
||||||
|
|
||||||
|
public Oracle12cDialect() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerDefaultProperties() {
|
||||||
|
super.registerDefaultProperties();
|
||||||
|
getDefaultProperties().setProperty( Environment.USE_GET_GENERATED_KEYS, "true" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsIdentityColumns() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsInsertSelectIdentity() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentityColumnString() {
|
||||||
|
return "generated as identity";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LimitHandler buildLimitHandler(String sql, RowSelection selection) {
|
||||||
|
return new SQL2008StandardLimitHandler(sql, selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ package org.hibernate.dialect;
|
||||||
*
|
*
|
||||||
* @author edalquist
|
* @author edalquist
|
||||||
*/
|
*/
|
||||||
public class PostgreSQL9Dialect extends PostgreSQL81Dialect {
|
public class PostgreSQL9Dialect extends PostgreSQL82Dialect {
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsIfExistsBeforeConstraintName() {
|
public boolean supportsIfExistsBeforeConstraintName() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Inc.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* 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 distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.dialect.pagination;
|
||||||
|
|
||||||
|
import org.hibernate.engine.spi.RowSelection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LIMIT clause handler compatible with ISO and ANSI SQL:2008 standard.
|
||||||
|
*
|
||||||
|
* @author zhouyanming (zhouyanming@gmail.com)
|
||||||
|
*/
|
||||||
|
public class SQL2008StandardLimitHandler extends AbstractLimitHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a SQL2008StandardLimitHandler
|
||||||
|
*
|
||||||
|
* @param sql
|
||||||
|
* The SQL
|
||||||
|
* @param selection
|
||||||
|
* The row selection options
|
||||||
|
*/
|
||||||
|
public SQL2008StandardLimitHandler(String sql, RowSelection selection) {
|
||||||
|
super(sql, selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsLimit() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getProcessedSql() {
|
||||||
|
if (LimitHelper.useLimit(this, selection)) {
|
||||||
|
return sql
|
||||||
|
+ (LimitHelper.hasFirstRow(selection) ? " offset ? rows fetch next ? rows only"
|
||||||
|
: " fetch first ? rows only");
|
||||||
|
} else {
|
||||||
|
// or return unaltered SQL
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ import org.hibernate.dialect.IngresDialect;
|
||||||
import org.hibernate.dialect.MySQL5Dialect;
|
import org.hibernate.dialect.MySQL5Dialect;
|
||||||
import org.hibernate.dialect.MySQLDialect;
|
import org.hibernate.dialect.MySQLDialect;
|
||||||
import org.hibernate.dialect.Oracle10gDialect;
|
import org.hibernate.dialect.Oracle10gDialect;
|
||||||
|
import org.hibernate.dialect.Oracle12cDialect;
|
||||||
import org.hibernate.dialect.Oracle8iDialect;
|
import org.hibernate.dialect.Oracle8iDialect;
|
||||||
import org.hibernate.dialect.Oracle9iDialect;
|
import org.hibernate.dialect.Oracle9iDialect;
|
||||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||||
|
@ -195,6 +196,8 @@ public class StandardDialectResolver implements DialectResolver {
|
||||||
final int majorVersion = info.getDatabaseMajorVersion();
|
final int majorVersion = info.getDatabaseMajorVersion();
|
||||||
|
|
||||||
switch ( majorVersion ) {
|
switch ( majorVersion ) {
|
||||||
|
case 12:
|
||||||
|
return new Oracle12cDialect();
|
||||||
case 11:
|
case 11:
|
||||||
return new Oracle10gDialect();
|
return new Oracle10gDialect();
|
||||||
case 10:
|
case 10:
|
||||||
|
|
|
@ -121,7 +121,7 @@ class StatementPreparerImpl implements StatementPreparer {
|
||||||
jdbcCoordinator.executeBatch();
|
jdbcCoordinator.executeBatch();
|
||||||
return new StatementPreparationTemplate( sql ) {
|
return new StatementPreparationTemplate( sql ) {
|
||||||
public PreparedStatement doPrepare() throws SQLException {
|
public PreparedStatement doPrepare() throws SQLException {
|
||||||
return connection().prepareStatement( sql, autoGeneratedKeys );
|
return connection().prepareStatement( sql, new int[]{ 1 } );
|
||||||
}
|
}
|
||||||
}.prepareStatement();
|
}.prepareStatement();
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,9 +118,14 @@ public final class IdentifierGeneratorHelper {
|
||||||
return ( (ResultSetIdentifierConsumer) customType.getUserType() ).consumeIdentifier( rs );
|
return ( (ResultSetIdentifierConsumer) customType.getUserType() ).consumeIdentifier( rs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int columnCount = 1;
|
||||||
|
try{
|
||||||
|
columnCount = rs.getMetaData().getColumnCount();
|
||||||
|
}catch(Exception e){
|
||||||
|
//Oracle driver will throw NPE
|
||||||
|
}
|
||||||
Class clazz = type.getReturnedClass();
|
Class clazz = type.getReturnedClass();
|
||||||
if (rs.getMetaData().getColumnCount() == 1) {
|
if (columnCount == 1) {
|
||||||
if ( clazz == Long.class ) {
|
if ( clazz == Long.class ) {
|
||||||
return rs.getLong( 1 );
|
return rs.getLong( 1 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue