Skip to content

NH-4062 - Oracle Unicode support dual model. #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 7, 2017

Conversation

fredericDelaporte
Copy link
Member

@fredericDelaporte fredericDelaporte commented Aug 1, 2017

NH-4062 - Properly handle Oracle Unicode support dual model

And reverting NH-3620: this was a workaround for a now obsolete bug in ODP.Net managed driver. Its test still pass without it now. It should probably have been solved as "external issue" with instruction on how to extend the driver for working around the bug till Oracle fixes it. Removing this workaround causes another test to fail: BinaryBlobTypeFixture.ReadWriteZeroLen. Without it, the blob come back as null.

Managed and un-managed drivers require the same code, but it was duplicated. Now it is refactored in a single base class.

@fredericDelaporte fredericDelaporte force-pushed the NH-4062 branch 3 times, most recently from fc66069 to cdf4d5d Compare August 1, 2017 14:24
[Explicit]
public void NoBooleanParameters()
[Theory]
public void NoBooleanParameters(bool managed)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted for it to no more fail in case the driver could not be loaded.

@@ -772,7 +772,7 @@ public void GroupByComputedValueInObjectArrayWithJoinOnId()
Assert.AreEqual(2155, orderGroups.Sum(g => g.Count));
}

[Test(Description = "NH-3801")]
[Test(Description = "NH-3801, NH-4062")]
Copy link
Member Author

@fredericDelaporte fredericDelaporte Aug 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #666 is merged first, will need to re-base then re-enabled Oracle in this test, since #666 disable it.

Edit: done.

/// <param name="settings">The configuration settings.</param>
public virtual void Configure(IDictionary<string, string> settings)
{
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a way to configure the dialect.

/// https://docs.oracle.com/database/121/ODPNT/featOraCommand.htm#i1007557
/// This setting applies only to Oracle dialects and ODP.Net managed or unmanaged driver.
/// </remarks>
public const string OracleUseNPrefixedTypesForUnicode = "oracle.use_n_prefixed_types_for_unicode";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New setting just for Oracle.

base.Configure(settings);

// If changing the default value, keep it in sync with Oracle8iDialect.Configure.
UseNPrefixedTypesForUnicode = PropertiesHelper.GetBoolean(Cfg.Environment.OracleUseNPrefixedTypesForUnicode, settings, false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value false avoid a possible breaking change for queries, by keeping the default typing of the ODP.Net provider.


// If changing the default value, keep it in sync with OracleDataClientDriverBase.Configure.
UseNPrefixedTypesForUnicode = PropertiesHelper.GetBoolean(Environment.OracleUseNPrefixedTypesForUnicode, settings, false);
RegisterCharacterTypeMappings();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Moving the comment on non-outdated file version.)
Possible breaking change for those using hbm2ddl: now Unicode string types will be mapped by default to non N prefixed types, while NH 4 was mapping to N prefixed one.

Doing it the other way round would be a possible breaking change for queries instead, because they would start using NVarchar2 for Unicode string parameters instead of Varchar2 (NH 4 currently maps that to Varchar2).

Other possible breaking change, character types will not be registered if the dialect is not configured, which may happen if not getting it through Dialect.GetDialect.

@hazzik hazzik modified the milestone: 5.0 Aug 3, 2017
@fredericDelaporte fredericDelaporte force-pushed the NH-4062 branch 2 times, most recently from 3a0489d to 9b72bef Compare August 25, 2017 11:27
@fredericDelaporte fredericDelaporte force-pushed the NH-4062 branch 2 times, most recently from 78f63cb to 006caa7 Compare September 2, 2017 10:36
@fredericDelaporte
Copy link
Member Author

Rebased with async regeneration embedded in "NH-4062 - Oracle Unicode support dual model." commit. (It does just alter one async test.)

/// </exception>
protected OracleDataClientDriverBase(bool managed)
: this(
managed ? _managedProviderInvariantName : _unmanagedProviderInvariantName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these back to the constructor instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not get it.

Would you like this to be removed and having manage and un-managed classes providing these values themselves? Or should the ReflectionBasedDriver be changed for allowing specifying these values without a constructor call (which forces to put that inside : this(...) or : base(...)), by example with some protected settable properties or a protected initialize method?
Or something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is to receive these strings from the child constructor instead of a bool argument. Eg. move this constructor down the inheritance chain:

public OracleManagedDataClientDriver : base(_managedProviderInvariantName, ...)

Also, it seems that we need to have only 2 variable strings: "Oracle.ManagedDataAccess" and "Oracle.DataAccess", all other are derivatives

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, with only assembly name as a parameter. My previous idea was to be able to adapt to eventual weird naming changes done on Oracle side for some future version. But well, they may not do same than Sap with its Sybase drivers.


var prefix = UseNPrefixedTypesForUnicode ? "N" : string.Empty;
RegisterColumnType(DbType.StringFixedLength, prefix + "CHAR(255)");
RegisterColumnType(DbType.StringFixedLength, 2000, prefix + "CHAR($l)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is 2000.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well me too... I am not sufficiently experimented with Oracle for knowing of any past reason, whether this should be overridden in newer dialects or not, ... So I have just kept the previous value.

_oracleCommandBindByName = oracleCommandType.GetProperty("BindByName");

var parameterType = ReflectHelper.TypeFromAssembly(clientNamespace + ".OracleParameter", driverAssemblyName, true);
_oracleDbType = parameterType.GetProperty("OracleDbType");
Copy link
Member

@hazzik hazzik Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we build delegates for these properties? Like in MySqlClientSqlCommandSet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about it, you are right.

_commandBindByNameSetter = DelegateHelper.BuildPropertySetter<bool>(oracleCommandType, "BindByName");

var parameterType = ReflectHelper.TypeFromAssembly(clientNamespace + ".OracleParameter", driverAssemblyName, true);
_parameterOracleDbTypeSetter = DelegateHelper.BuildPropertySetter<object>(parameterType, "OracleDbType");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can not use the actual set type here for the delegate. This has required adapting DelegateHelper.

var valueParameter = Expression.Parameter(typeof (T), "value");
Expression value = valueParameter;
// Cast value if required
if (!property.Type.IsAssignableFrom(typeof(T)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes required for supporting setting without being able to provide the actual property type as a generic parameter.

@fredericDelaporte fredericDelaporte force-pushed the NH-4062 branch 2 times, most recently from e5701dc to 4bf7d13 Compare September 6, 2017 23:32
hazzik
hazzik previously approved these changes Sep 6, 2017
@fredericDelaporte fredericDelaporte merged commit 05bac51 into nhibernate:master Sep 7, 2017
@fredericDelaporte fredericDelaporte deleted the NH-4062 branch September 7, 2017 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants