-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NHibernate.Dialect.SAPDBDialect
PostPosted: Tue Jun 12, 2007 7:49 am 
Newbie

Joined: Tue Jun 12, 2007 7:39 am
Posts: 1
Hello,


take a look at this:

Code:
using System;
using System.Data;
using NHibernate;
using NHibernate.SqlCommand;
using Environment=NHibernate.Cfg.Environment;
using System.Text;
using NHibernate.Util;
namespace NHibernate.Dialect
{
   /// <summary>
   /// An SQL dialect compatible with SAP DB.
   /// </summary>
   public class SAPDBDialect:NHibernate.Dialect.Dialect
   {
      public SAPDBDialect():base()
      {
         #region RegisterColumnTypes
         RegisterColumnType( DbType.Boolean, "BOOLEAN" );
         
         RegisterColumnType( DbType.Int64, "FIXED(19,0)" );
         RegisterColumnType( DbType.Int16, "SMALLINT" );
         RegisterColumnType( DbType.Int32, "FIXED(10,0)" );
         
         RegisterColumnType( DbType.Double, "DOUBLE PRECISION" );
         RegisterColumnType( DbType.Single, "FLOAT" );
         RegisterColumnType( DbType.Currency, "DECIMAL(16,4)" );
         
         RegisterColumnType( DbType.DateTime, "TIMESTAMP" );
         RegisterColumnType( DbType.Date, "DATE" );
         RegisterColumnType( DbType.Time, "TIME" );
         
         RegisterColumnType( DbType.Binary, "LONG BYTE" );
         RegisterColumnType( DbType.Binary,2147483647, "LONG BYTE" );
         
         
         RegisterColumnType( DbType.AnsiStringFixedLength,"CHAR(255)" );
         RegisterColumnType( DbType.AnsiStringFixedLength,8000,"CHAR($1)" );
         
         RegisterColumnType( DbType.AnsiString,"VARCHAR(255)" );
         RegisterColumnType( DbType.AnsiString,8000,"VARCHAR($1)" );
         RegisterColumnType( DbType.AnsiString,2147483647, "LONG VARCHAR" );
         
         RegisterColumnType( DbType.StringFixedLength,"CHAR(255)" );
         RegisterColumnType( DbType.StringFixedLength,4000,"CHAR($1)" );
         
         RegisterColumnType( DbType.String,"VARCHAR(255)" );
         RegisterColumnType( DbType.String,4000,"VARCHAR($1)" );
         RegisterColumnType( DbType.String,1073741823,"LONG VARCHAR" );
         #endregion
         
         
         RegisterColumnType( DbType.Byte, "FIXED(3,0)" );//?
         
         
         RegisterColumnType( DbType.Decimal, "FIXED(19,5)" );
         RegisterColumnType( DbType.Decimal, 19, "FIXED(18, $1)" );
      
         #region RegisterFunctions
         RegisterFunction( "abs", new StandardSQLFunction() );
         RegisterFunction( "sign", new StandardSQLFunction(NHibernateUtil.Int32) );
      
         RegisterFunction( "exp", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "ln", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "log", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "pi", new NoArgSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "power", new StandardSQLFunction() );
         RegisterFunction( "acos", new StandardSQLFunction( NHibernateUtil.Double) );
         RegisterFunction( "asin", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "atan", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "cos", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "cosh", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "cot", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "sin", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "sinh", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "tan", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "tanh", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "radians", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "degrees", new StandardSQLFunction(NHibernateUtil.Double) );
         RegisterFunction( "atan2", new StandardSQLFunction(NHibernateUtil.Double) );
   
         RegisterFunction( "round", new StandardSQLFunction() );
         RegisterFunction( "trunc", new StandardSQLFunction() );
         RegisterFunction( "ceil", new StandardSQLFunction() );
         RegisterFunction( "floor", new StandardSQLFunction() );
         RegisterFunction( "greatest", new StandardSQLFunction() );
         RegisterFunction( "least", new StandardSQLFunction() );
   
         RegisterFunction("time", new StandardSQLFunction(NHibernateUtil.Time) );
         RegisterFunction("timestamp", new StandardSQLFunction(NHibernateUtil.Timestamp) );
         RegisterFunction("date", new StandardSQLFunction(NHibernateUtil.Date) );
         RegisterFunction("microsecond", new StandardSQLFunction(NHibernateUtil.Int32) );
   
         RegisterFunction("dayname", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction("monthname", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction("dayofmonth", new StandardSQLFunction(NHibernateUtil.Int32) );
         RegisterFunction("dayofweek", new StandardSQLFunction(NHibernateUtil.Int32) );
         RegisterFunction("dayofyear", new StandardSQLFunction(NHibernateUtil.Int32) );
         RegisterFunction("weekofyear", new StandardSQLFunction(NHibernateUtil.Int32) );
   
         RegisterFunction( "replace", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "translate", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "lpad", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "rpad", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "substr", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "initcap", new StandardSQLFunction( NHibernateUtil.String) );
         RegisterFunction( "lower", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "ltrim", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "rtrim", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "lfill", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "rfill", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "soundex", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "upper", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "ascii", new StandardSQLFunction(NHibernateUtil.String) );
         RegisterFunction( "index", new StandardSQLFunction(NHibernateUtil.Int32) );
   
         RegisterFunction( "value", new StandardSQLFunction() );
         
         RegisterFunction( "concat", new StandardSQLFunction(NHibernateUtil.String ) );
         RegisterFunction( "substring", new StandardSQLFunction(NHibernateUtil.String ) );
         RegisterFunction( "locate", new StandardSQLFunction(NHibernateUtil.Int32) );
         RegisterFunction( "coalesce", new StandardSQLFunction() );
         #endregion
      
         DefaultProperties[ Environment.UseOuterJoin ] = "true";
         DefaultProperties[Environment.PrepareSql] = "true";
         DefaultProperties[Environment.ConnectionDriver] = "NHibernateUtil.Driver.OdbcDriver";
      }
            
      public override string GetAddForeignKeyConstraintString(string constraintName, string[] foreignKey, string referencedTable, string[] primaryKey)
      {
         return new StringBuilder(30).Append(" FOREIGN KEY ")
            .Append(constraintName)
            .Append(" (")
            .Append(string.Join(StringHelper.CommaSpace, foreignKey))
            .Append(") REFERENCES ")
            .Append(referencedTable).ToString();
      }
      
      public override string GetAddPrimaryKeyConstraintString(string constraintName)
      {
         return " PRIMARY KEY ";
      }
      public string GetQuerySequencesString() {
         return "SELECT sequence_name FROM domain.sequences";
      }
      public override string GetSequenceNextValString(string sequenceName)
      {
         return string.Concat("SELECT ",sequenceName,".NEXTVAL FROM dual");
      }
      
      public override string GetCreateSequenceString(string sequenceName)
      {
         return string.Concat("CREATE SEQUENCE ",sequenceName);
      }
      
      public override string GetDropSequenceString(string sequenceName)
      {
         return string.Concat("DROP SEQUENCE ",sequenceName);
      }
      
      public override CaseFragment CreateCaseFragment()
      {
         return new DecodeCaseFragment(this);
      }
      
      public override JoinFragment CreateOuterJoinFragment()
      {
         return new OracleJoinFragment();
      }
      
      public override string AddColumnString
      {
         get { return "ADD"; }
      }
      
      public override bool DropConstraints {
         get { return false; }
      }
      
      public override string NullColumnString {
         get { return " NULL"; }
      }
      
      public override bool SupportsSequences {
         get { return true; }
      }   
   }
}



Regards

Konstantin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.