diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java new file mode 100644 index 0000000000..f2066ad401 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java @@ -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); + } + +} \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java index d1908e96fb..00f3d35db9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL9Dialect.java @@ -28,7 +28,7 @@ package org.hibernate.dialect; * * @author edalquist */ -public class PostgreSQL9Dialect extends PostgreSQL81Dialect { +public class PostgreSQL9Dialect extends PostgreSQL82Dialect { @Override public boolean supportsIfExistsBeforeConstraintName() { return true; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQL2008StandardLimitHandler.java b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQL2008StandardLimitHandler.java new file mode 100644 index 0000000000..c9f75cd9e7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/dialect/pagination/SQL2008StandardLimitHandler.java @@ -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; + } + } + +} \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDialectResolver.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDialectResolver.java index 89b861e62b..44ea2a8fb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDialectResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/StandardDialectResolver.java @@ -42,6 +42,7 @@ import org.hibernate.dialect.IngresDialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.Oracle12cDialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.Oracle9iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; @@ -204,7 +205,7 @@ public class StandardDialectResolver implements DialectResolver { switch ( majorVersion ) { case 12: - // fall through + return new Oracle12cDialect(); case 11: // fall through case 10: diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java index 7f6a67c400..b19193b02e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/StatementPreparerImpl.java @@ -121,7 +121,7 @@ class StatementPreparerImpl implements StatementPreparer { jdbcCoordinator.executeBatch(); return new StatementPreparationTemplate( sql ) { public PreparedStatement doPrepare() throws SQLException { - return connection().prepareStatement( sql, autoGeneratedKeys ); + return connection().prepareStatement( sql, new int[]{ 1 } ); } }.prepareStatement(); } diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java index 0e62f2fbf4..05b614a2ad 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java @@ -118,9 +118,14 @@ public final class IdentifierGeneratorHelper { 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(); - if (rs.getMetaData().getColumnCount() == 1) { + if (columnCount == 1) { if ( clazz == Long.class ) { return rs.getLong( 1 ); }