From: <fab...@us...> - 2009-01-10 21:26:38
|
Revision: 3994 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3994&view=rev Author: fabiomaulo Date: 2009-01-10 21:26:34 +0000 (Sat, 10 Jan 2009) Log Message: ----------- Fix NH-1596 (Support Oracle Lite) by Alexandre Payment Modified Paths: -------------- trunk/nhibernate/src/NHibernate/NHibernate.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate/Dialect/OracleLiteDialect.cs trunk/nhibernate/src/NHibernate/Driver/OracleLiteDataClientDriver.cs Added: trunk/nhibernate/src/NHibernate/Dialect/OracleLiteDialect.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Dialect/OracleLiteDialect.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Dialect/OracleLiteDialect.cs 2009-01-10 21:26:34 UTC (rev 3994) @@ -0,0 +1,121 @@ +using System.Data; +using NHibernate.Dialect.Function; +using NHibernate.SqlCommand; +using Environment=NHibernate.Cfg.Environment; + +namespace NHibernate.Dialect +{ + /// <summary> + /// It's a immature version, it just work. + /// An SQL dialect for Oracle Lite + /// </summary> + /// <remarks> + /// The OracleLiteDialect defaults the following configuration properties: + /// <list type="table"> + /// <listheader> + /// <term>Property</term> + /// <description>Default Value</description> + /// </listheader> + /// <item> + /// <term>use_outer_join</term> + /// <description><see langword="true" /></description> + /// </item> + /// <item> + /// <term>connection.driver_class</term> + /// <description><see cref="NHibernate.Driver.OracleLiteDataClientDriver" /></description> + /// </item> + /// </list> + /// </remarks> + public class OracleLiteDialect : Oracle9Dialect + { + /// <summary></summary> + public OracleLiteDialect() + { + DefaultProperties[Environment.PrepareSql] = "false"; + DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.OracleLiteDataClientDriver"; + + RegisterColumnType(DbType.AnsiStringFixedLength, "CHAR(255)"); + RegisterColumnType(DbType.AnsiStringFixedLength, 2000, "CHAR($l)"); + RegisterColumnType(DbType.AnsiString, "VARCHAR2(255)"); + RegisterColumnType(DbType.AnsiString, 2000, "VARCHAR2($l)"); + RegisterColumnType(DbType.AnsiString, 2147483647, "CLOB"); // should use the IType.ClobType + RegisterColumnType(DbType.Binary, "RAW(2000)"); + RegisterColumnType(DbType.Binary, 2000, "RAW($l)"); + RegisterColumnType(DbType.Binary, 2147483647, "BLOB"); + RegisterColumnType(DbType.Boolean, "NUMBER(1,0)"); + RegisterColumnType(DbType.Byte, "NUMBER(3,0)"); + RegisterColumnType(DbType.Currency, "NUMBER(19,1)"); + RegisterColumnType(DbType.Date, "DATE"); + RegisterColumnType(DbType.DateTime, "TIMESTAMP(4)"); + RegisterColumnType(DbType.Decimal, "NUMBER(19,5)"); + RegisterColumnType(DbType.Decimal, 19, "NUMBER(19, $l)"); + // having problems with both ODP and OracleClient from MS not being able + // to read values out of a field that is DOUBLE PRECISION + RegisterColumnType(DbType.Double, "DOUBLE PRECISION"); //"FLOAT(53)" ); + //RegisterColumnType(DbType.Guid, "CHAR(38)"); + RegisterColumnType(DbType.Int16, "NUMBER(5,0)"); + RegisterColumnType(DbType.Int32, "NUMBER(10,0)"); + RegisterColumnType(DbType.Int64, "NUMBER(20,0)"); + RegisterColumnType(DbType.UInt16, "NUMBER(5,0)"); + RegisterColumnType(DbType.UInt32, "NUMBER(10,0)"); + RegisterColumnType(DbType.UInt64, "NUMBER(20,0)"); + RegisterColumnType(DbType.Single, "FLOAT(24)"); + RegisterColumnType(DbType.StringFixedLength, "NCHAR(255)"); + RegisterColumnType(DbType.StringFixedLength, 2000, "NCHAR($l)"); + RegisterColumnType(DbType.String, "VARCHAR2(255)"); + RegisterColumnType(DbType.String, 2000, "VARCHAR2($l)"); + RegisterColumnType(DbType.String, 1073741823, "CLOB"); + RegisterColumnType(DbType.Time, "DATE"); + + RegisterFunction("stddev", new StandardSQLFunction("stddev", NHibernateUtil.Double)); + RegisterFunction("variance", new StandardSQLFunction("variance", NHibernateUtil.Double)); + + RegisterFunction("round", new StandardSQLFunction("round")); + RegisterFunction("trunc", new StandardSQLFunction("trunc")); + RegisterFunction("ceil", new StandardSQLFunction("ceil")); + RegisterFunction("floor", new StandardSQLFunction("floor")); + + RegisterFunction("chr", new StandardSQLFunction("chr", NHibernateUtil.Character)); + RegisterFunction("initcap", new StandardSQLFunction("initcap")); + RegisterFunction("lower", new StandardSQLFunction("lower")); + RegisterFunction("ltrim", new StandardSQLFunction("ltrim")); + RegisterFunction("rtrim", new StandardSQLFunction("rtrim")); + RegisterFunction("upper", new StandardSQLFunction("upper")); + RegisterFunction("ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32)); + RegisterFunction("length", new StandardSQLFunction("length", NHibernateUtil.Int64)); + + RegisterFunction("to_char", new StandardSQLFunction("to_char", NHibernateUtil.String)); + RegisterFunction("to_date", new StandardSQLFunction("to_date", NHibernateUtil.Timestamp)); + + RegisterFunction("last_day", new StandardSQLFunction("last_day", NHibernateUtil.Date)); + RegisterFunction("sysdate", new NoArgSQLFunction("sysdate", NHibernateUtil.Date, false)); + RegisterFunction("user", new NoArgSQLFunction("user", NHibernateUtil.String, false)); + + // Multi-param string dialect functions... + RegisterFunction("concat", new StandardSQLFunction("concat", NHibernateUtil.String)); + RegisterFunction("instr", new StandardSQLFunction("instr", NHibernateUtil.String)); + RegisterFunction("instrb", new StandardSQLFunction("instrb", NHibernateUtil.String)); + RegisterFunction("lpad", new StandardSQLFunction("lpad", NHibernateUtil.String)); + RegisterFunction("replace", new StandardSQLFunction("replace", NHibernateUtil.String)); + RegisterFunction("rpad", new StandardSQLFunction("rpad", NHibernateUtil.String)); + RegisterFunction("substr", new StandardSQLFunction("substr", NHibernateUtil.String)); + RegisterFunction("substrb", new StandardSQLFunction("substrb", NHibernateUtil.String)); + RegisterFunction("translate", new StandardSQLFunction("translate", NHibernateUtil.String)); + + // Multi-param numeric dialect functions... + RegisterFunction("mod", new StandardSQLFunction("mod", NHibernateUtil.Int32)); + RegisterFunction("nvl", new StandardSQLFunction("nvl")); + + // Multi-param date dialect functions... + RegisterFunction("add_months", new StandardSQLFunction("add_months", NHibernateUtil.Date)); + RegisterFunction("months_between", new StandardSQLFunction("months_between", NHibernateUtil.Single)); + RegisterFunction("next_day", new StandardSQLFunction("next_day", NHibernateUtil.Date)); + } + + /// <summary></summary> + public override string GetCreateSequenceString(string sequenceName) + { + return "create sequence " + sequenceName + " INCREMENT BY 1 START WITH 1"; + } + } +} \ No newline at end of file Added: trunk/nhibernate/src/NHibernate/Driver/OracleLiteDataClientDriver.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Driver/OracleLiteDataClientDriver.cs (rev 0) +++ trunk/nhibernate/src/NHibernate/Driver/OracleLiteDataClientDriver.cs 2009-01-10 21:26:34 UTC (rev 3994) @@ -0,0 +1,68 @@ +using System.Data; +using NHibernate.AdoNet; +using NHibernate.SqlTypes; + +namespace NHibernate.Driver +{ + /// <summary> + /// A NHibernate Driver for using the Oracle.DataAccess.Lite DataProvider + /// </summary> + public class OracleLiteDataClientDriver : ReflectionBasedDriver, IEmbeddedBatcherFactoryProvider + { + /// <summary> + /// Initializes a new instance of <see cref="OracleLiteDataClientDriver"/>. + /// </summary> + /// <exception cref="HibernateException"> + /// Thrown when the <c>Oracle.DataAccess.Lite_w32</c> assembly can not be loaded. + /// </exception> + public OracleLiteDataClientDriver() + : base( + "Oracle.DataAccess.Lite_w32", + "Oracle.DataAccess.Lite.OracleConnection", + "Oracle.DataAccess.Lite.OracleCommand") + { + } + + /// <summary></summary> + public override bool UseNamedPrefixInSql + { + get { return true; } + } + + /// <summary></summary> + public override bool UseNamedPrefixInParameter + { + get { return true; } + } + + /// <summary></summary> + public override string NamedPrefix + { + get { return ":"; } + } + + /// <remarks> + /// This adds logic to ensure that a DbType.Boolean parameter is not created since + /// ODP.NET doesn't support it. + /// </remarks> + protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType) + { + // if the parameter coming in contains a boolean then we need to convert it + // to another type since ODP.NET doesn't support DbType.Boolean + if (sqlType.DbType == DbType.Boolean) + { + sqlType = SqlTypeFactory.Int16; + } + base.InitializeParameter(dbParam, name, sqlType); + } + + #region IEmbeddedBatcherFactoryProvider Members + + System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass + { + get { return typeof (OracleDataClientBatchingBatcherFactory); } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj =================================================================== --- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-01-10 20:36:28 UTC (rev 3993) +++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-01-10 21:26:34 UTC (rev 3994) @@ -445,11 +445,13 @@ <Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" /> <Compile Include="Dialect\InformixDialect0940.cs" /> <Compile Include="Dialect\InformixDialect1000.cs" /> + <Compile Include="Dialect\OracleLiteDialect.cs" /> <Compile Include="Dialect\Schema\SQLiteMetaData.cs" /> <Compile Include="Dialect\Schema\SybaseAnywhereMetaData.cs" /> <Compile Include="Dialect\SybaseASA10Dialect.cs" /> <Compile Include="Dialect\SybaseASA9Dialect.cs" /> <Compile Include="Driver\IfxDriver.cs" /> + <Compile Include="Driver\OracleLiteDataClientDriver.cs" /> <Compile Include="Exceptions\ReflectionBasedSqlStateExtracter.cs" /> <Compile Include="Exceptions\SqlStateExtracter.cs" /> <Compile Include="Exceptions\TemplatedViolatedConstraintNameExtracter.cs" /> @@ -1151,4 +1153,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project> +</Project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |