alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (Ingres9Dialect.java)

This example Hibernate source code file (Ingres9Dialect.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

ingres9dialect, ingres9dialect, ingresdialect, jdbc, noargsqlfunction, noargsqlfunction, sql, string, string, stringbuffer, stringbuffer, varargssqlfunction

The Hibernate Ingres9Dialect.java source code

/*
 * 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 java.sql.Types;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.type.StandardBasicTypes;

/**
 * A SQL dialect for Ingres 9.3 and later versions.
 * <p />
 * Changes:
 * <ul>
 * <li>Support for the SQL functions current_time, current_timestamp and current_date added
 * <li>Type mapping of Types.TIMESTAMP changed from "timestamp with time zone" to "timestamp(9) with time zone"
 * <li>Improved handling of "SELECT...FOR UPDATE" statements
 * <li>Added support for pooled sequences
 * <li>Added support for SELECT queries with limit and offset
 * <li>Added getIdentitySelectString
 * <li>Modified concatination operator
 * </ul>
 * 
 * @author Enrico Schenk
 * @author Raymond Fan
 */
public class Ingres9Dialect extends IngresDialect {
    public Ingres9Dialect() {
        super();
        registerDateTimeFunctions();
        registerDateTimeColumnTypes();
        registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "(", "||", ")" ) );
    }

	/**
	 * Register functions current_time, current_timestamp, current_date
	 */
	protected void registerDateTimeFunctions() {
		registerFunction("current_time", new NoArgSQLFunction("current_time", StandardBasicTypes.TIME, false));
		registerFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", StandardBasicTypes.TIMESTAMP, false));
		registerFunction("current_date", new NoArgSQLFunction("current_date", StandardBasicTypes.DATE, false));
	}

	/**
	 * Register column types date, time, timestamp
	 */
	protected void registerDateTimeColumnTypes() {
		registerColumnType(Types.DATE, "ansidate");
		registerColumnType(Types.TIMESTAMP, "timestamp(9) with time zone");
	}

	// lock acquisition support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	/**
	 * Does this dialect support <tt>FOR UPDATE in conjunction with outer
	 * joined rows?
	 * 
	 * @return True if outer joined rows can be locked via <tt>FOR UPDATE.
	 */
	public boolean supportsOuterJoinForUpdate() {
		return false;
	}

	/**
	 * Is <tt>FOR UPDATE OF syntax supported?
	 * 
	 * @return True if the database supports <tt>FOR UPDATE OF syntax;
	 *         false otherwise.
	 */
	public boolean forUpdateOfColumns() {
		return true;
	}

	// SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    /**
     * Get the select command used to retrieve the last generated sequence
     * value.
     *
     * @return Statement to retrieve last generated sequence value
     */
    public String getIdentitySelectString() {
         return "select last_identity()";
    }

	/**
	 * Get the select command used retrieve the names of all sequences.
	 * 
	 * @return The select command; or null if sequences are not supported.
	 * @see org.hibernate.tool.hbm2ddl.SchemaUpdate
	 */
	public String getQuerySequencesString() {
		return "select seq_name from iisequences";
	}

	/**
	 * Does this dialect support "pooled" sequences. Not aware of a better name
	 * for this. Essentially can we specify the initial and increment values?
	 * 
	 * @return True if such "pooled" sequences are supported; false otherwise.
	 * @see #getCreateSequenceStrings(String, int, int)
	 * @see #getCreateSequenceString(String, int, int)
	 */
	public boolean supportsPooledSequences() {
		return true;
	}

	// current timestamp support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	/**
	 * Should the value returned by {@link #getCurrentTimestampSelectString} be
	 * treated as callable. Typically this indicates that JDBC escape sytnax is
	 * being used...
	 * 
	 * @return True if the {@link #getCurrentTimestampSelectString} return is
	 *         callable; false otherwise.
	 */
	public boolean isCurrentTimestampSelectStringCallable() {
		return false;
	}

	/**
	 * Does this dialect support a way to retrieve the database's current
	 * timestamp value?
	 * 
	 * @return True if the current timestamp can be retrieved; false otherwise.
	 */
	public boolean supportsCurrentTimestampSelection() {
		return true;
	}

	/**
	 * Retrieve the command used to retrieve the current timestammp from the
	 * database.
	 * 
	 * @return The command.
	 */
	public String getCurrentTimestampSelectString() {
		return "select current_timestamp";
	}

	/**
	 * Expression for current_timestamp
	 */
	public String getCurrentTimestampSQLFunctionName() {
		return "current_timestamp";
	}

	// union subclass support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	/**
	 * Does this dialect support UNION ALL, which is generally a faster variant
	 * of UNION?
	 * 
	 * @return True if UNION ALL is supported; false otherwise.
	 */
	public boolean supportsUnionAll() {
		return true;
	}

	// Informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	/**
	 * For the underlying database, is READ_COMMITTED isolation implemented by
	 * forcing readers to wait for write locks to be released?
	 * 
	 * @return true
	 */
	public boolean doesReadCommittedCauseWritersToBlockReaders() {
		return true;
	}

	/**
	 * For the underlying database, is REPEATABLE_READ isolation implemented by
	 * forcing writers to wait for read locks to be released?
	 * 
	 * @return true
	 */
	public boolean doesRepeatableReadCauseReadersToBlockWriters() {
		return true;
	}

	// limit/offset support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	/**
	 * Does this dialect's LIMIT support (if any) additionally support
	 * specifying an offset?
	 * 
	 * @return true
	 */
	public boolean supportsLimitOffset() {
		return true;
	}

	/**
	 * Does this dialect support bind variables (i.e., prepared statememnt
	 * parameters) for its limit/offset?
	 * 
	 * @return false
	 */
	public boolean supportsVariableLimit() {
		return false;
	}

	/**
	 * Does the <tt>LIMIT clause take a "maximum" row number instead
	 * of a total number of returned rows?
	 */
	public boolean useMaxForLimit() {
		return false;
	}

	/**
	 * Add a <tt>LIMIT clause to the given SQL SELECT
	 * 
	 * @return the modified SQL
	 */
	public String getLimitString(String querySelect, int offset, int limit) {
        StringBuffer soff = new StringBuffer(" offset " + offset);
        StringBuffer slim = new StringBuffer(" fetch first " + limit + " rows only");
		StringBuffer sb = new StringBuffer(querySelect.length() +
            soff.length() + slim.length()).append(querySelect);
		if (offset > 0) {
			sb.append(soff);
		}
        if (limit > 0) {
            sb.append(slim);
        }
		return sb.toString();
	}
}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Ingres9Dialect.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.