SybaseSQLAnywhere12Dialect.cs
新しい名前に変更されたSybaseSQLAnywhere12Dialectクラスは、NHibernate 3.2.0ディストリビューションに含まれているSybaseSQLAnywhere11Dialectをベースにしています。SybaseSQLAnywhere12Dialectクラスは主として、現在SQL Anywhere 12でサポートされているISO標準SQLシーケンスに対するサポートを提供します。それ以外に小さな変更点が2つあります。1つは、TIMESTAMP WITH TIME ZONE
データ型(DATETIMEOFFSET
とも呼ばれます)のサポートです。そしてもう1つは、前述のように、修正されたメタデータクラスSybaseSQLAnywhere11DataBaseMetaDataを使用することです。次に、SybaseSQLAnywhere12Dialect.csのコードを紹介します。このコードはNHibernate/src/NHibernate/Dialectディレクトリに配置します。
using System; using System.Collections; using System.Data; using System.Data.Common; using System.Text.RegularExpressions; using NHibernate.Dialect.Function; using NHibernate.Dialect.Lock; using NHibernate.Dialect.Schema; using NHibernate.Engine; using NHibernate.Exceptions; using NHibernate.Mapping; using NHibernate.SqlCommand; using NHibernate.Type; using NHibernate.Util; using Environment = NHibernate.Cfg.Environment; namespace NHibernate.Dialect { /// <summary> /// SQL Dialect for SQL Anywhere 12 - for the NHibernate 3.2.0 distribution /// Copyright (C) 2011 Glenn Paulley /// Contact: http://iablog.sybase.com/paulley /// /// This NHibernate dialect for SQL Anywhere 12 is a contribution to the NHibernate /// open-source project. It is intended to be included in the NHibernate /// distribution and is licensed under LGPL. /// /// This library 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 2.1 of the License, or (at your option) any later version. /// /// This library 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 library; if not, write to the Free Software /// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /// /// </summary> /// /// <remarks> The SybaseSQLAnywhere12Dialect /// uses the SybaseSQLAnywhere11Dialect as its base class. /// SybaseSQLAnywhere12Dialect includes support for ISO SQL standard /// sequences, which are defined in the catalog table <tt>SYSSEQUENCE</tt>. /// The dialect uses the SybaseSQLAnywhere11MetaData class for metadata API /// calls, which correctly supports reserved words defined by SQL Anywhere. /// </remarks> public class SybaseSQLAnywhere12Dialect : SybaseSQLAnywhere11Dialect { /// <summary></summary> public SybaseSQLAnywhere12Dialect() { RegisterDateTimeTypeMappings(); RegisterKeywords(); } new protected void RegisterKeywords() { RegisterKeyword( "NEAR" ); RegisterKeyword( "LIMIT" ); RegisterKeyword( "OFFSET" ); RegisterKeyword( "DATETIMEOFFSET" ); } new protected void RegisterDateTimeTypeMappings() { RegisterColumnType(DbType.DateTimeOffset, "DATETIMEOFFSET"); } // DDL support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// <summary> /// SQL Anywhere supports <tt>SEQUENCES</tt> using a primarily SQL Standard /// syntax. Sequence values can be queried using the <tt>.CURRVAL</tt> identifier, and the next /// value in a sequence can be retrieved using the <tt>.NEXTVAL</tt> identifier. Sequences /// are retained in the SYS.SYSSEQUENCE catalog table. /// </summary> public override bool SupportsSequences { get { return true; } } /// <summary> /// Pooled sequences does not refer to the CACHE parameter of the <tt>CREATE SEQUENCE</tt> /// statement, but merely if the DBMS supports sequences that can be incremented or decremented /// by values greater than 1. /// </summary> public override bool SupportsPooledSequences { get { return true; } } /// <summary> Get the <tt>SELECT</tt> command used retrieve the names of all sequences.</summary> /// <returns> The <tt>SELECT</tt> command; or NULL if sequences are not supported. </returns> public override string QuerySequencesString { get { return "SELECT SEQUENCE_NAME FROM SYS.SYSSEQUENCE"; } } public override string GetSequenceNextValString( string sequenceName ) { return "SELECT " + GetSelectSequenceNextValString(sequenceName) + " FROM SYS.DUMMY"; } public override string GetSelectSequenceNextValString( string sequenceName ) { return sequenceName + ".NEXTVAL"; } public override string GetCreateSequenceString( string sequenceName ) { return "CREATE SEQUENCE " + sequenceName; // by default, is START WITH 1 MAXVALUE 2**63-1 } public override string GetDropSequenceString( string sequenceName ) { return "DROP SEQUENCE " + sequenceName; } // Informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public override IDataBaseSchema GetDataBaseSchema( DbConnection connection ) { return new SybaseSQLAnywhere11DataBaseMetaData( connection ); } } }
この方言ファイルについて最後に注意点を1つだけ補足しておきます。NHibernate 3.2.0ディストリビューションに含まれているSybaseSQLAnywhere10Dialect.csには、バイナリ型のマッピングに入力ミスが含まれています。つまり、このコードではLONG VARBINARY
という型を参照していますが、これは誤りで、正しくはLONG BINARY
です。これは私のミスでした。今後リリースされるNHibernateでは、(Julianを介して)この点が確実に修正されるようにします。