Skip to content

Commit

Permalink
Allow any cache.* property in NHibernate configuration (#1656)
Browse files Browse the repository at this point in the history
Fixes #1650
  • Loading branch information
hazzik authored and fredericDelaporte committed Apr 15, 2018
1 parent 469d79f commit 92de0b7
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 143 deletions.
4 changes: 3 additions & 1 deletion src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ public void Properties()
<session-factory>
<property name='connection.provider'>Value of connection.provider</property>
<property name='default_schema'>Value of default_schema</property>
<property name='cache.some_category.setting_name'>Some cache configuration</property>
</session-factory>
</hibernate-configuration>";

XmlTextReader xtr = new XmlTextReader(xml, XmlNodeType.Document, null);
HibernateConfiguration hc = new HibernateConfiguration(xtr);
Assert.AreEqual(2, hc.SessionFactory.Properties.Count);
Assert.AreEqual(3, hc.SessionFactory.Properties.Count);
Assert.IsTrue(hc.SessionFactory.Properties.ContainsKey("connection.provider"));
Assert.IsTrue(hc.SessionFactory.Properties.ContainsKey("default_schema"));
Assert.AreEqual("Value of connection.provider", hc.SessionFactory.Properties["connection.provider"]);
Assert.AreEqual("Value of default_schema", hc.SessionFactory.Properties["default_schema"]);
Assert.AreEqual("Some cache configuration", hc.SessionFactory.Properties["cache.some_category.setting_name"]);
}

[Test]
Expand Down
293 changes: 151 additions & 142 deletions src/NHibernate/nhibernate-configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -70,149 +70,158 @@
<xs:extension base="xs:string">
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="connection.provider" />
<xs:enumeration value="connection.driver_class" />
<xs:enumeration value="connection.connection_string" />
<xs:enumeration value="connection.isolation" />
<xs:enumeration value="connection.release_mode" />
<xs:enumeration value="connection.connection_string_name" />
<xs:enumeration value="dialect" />
<xs:enumeration value="default_schema" />
<xs:enumeration value="show_sql" />
<xs:enumeration value="max_fetch_depth" />
<xs:enumeration value="current_session_context_class" />
<xs:enumeration value="transaction.factory_class" />
<xs:enumeration value="cache.provider_class" />
<xs:enumeration value="cache.use_query_cache" />
<xs:enumeration value="cache.query_cache_factory" />
<xs:enumeration value="cache.use_second_level_cache" />
<xs:enumeration value="cache.region_prefix" />
<xs:enumeration value="cache.use_minimal_puts" />
<xs:enumeration value="cache.default_expiration" />
<xs:enumeration value="query.substitutions" />
<xs:enumeration value="query.factory_class" />
<xs:enumeration value="query.linq_provider_class" />
<xs:enumeration value="query.imports" />
<xs:enumeration value="hbm2ddl.auto" />
<xs:enumeration value="hbm2ddl.keywords" />
<xs:enumeration value="sql_exception_converter" />
<xs:enumeration value="adonet.wrap_result_sets" />
<xs:enumeration value="prepare_sql" />
<xs:enumeration value="command_timeout">
<xs:annotation>
<xs:documentation>
Set the default timeout in seconds for ADO.NET queries.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="adonet.batch_size" />
<xs:enumeration value="use_proxy_validator" />
<xs:enumeration value="xml.output_stylesheet" />
<xs:enumeration value="generate_statistics" />
<xs:enumeration value="query.startup_check" />
<xs:enumeration value="default_catalog" />
<xs:enumeration value="proxyfactory.factory_class" />
<xs:enumeration value="adonet.factory_class" />
<xs:enumeration value="default_batch_fetch_size" />
<xs:enumeration value="default_entity_mode" />
<xs:enumeration value="default_flush_mode" />
<xs:enumeration value="use_sql_comments" />
<xs:enumeration value="format_sql" />
<xs:enumeration value="collectiontype.factory_class" />
<xs:enumeration value="order_inserts" />
<xs:enumeration value="order_updates" />
<xs:enumeration value="query.query_model_rewriter_factory" />
<xs:enumeration value="linqtohql.generatorsregistry" />
<xs:enumeration value="odbc.explicit_datetime_scale" />
<xs:enumeration value="adonet.batch_versioned_data" />
<xs:enumeration value="transaction.system_completion_lock_timeout">
<xs:annotation>
<xs:documentation>
Timeout duration in milliseconds for the system transaction completion lock.
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="connection.provider" />
<xs:enumeration value="connection.driver_class" />
<xs:enumeration value="connection.connection_string" />
<xs:enumeration value="connection.isolation" />
<xs:enumeration value="connection.release_mode" />
<xs:enumeration value="connection.connection_string_name" />
<xs:enumeration value="dialect" />
<xs:enumeration value="default_schema" />
<xs:enumeration value="show_sql" />
<xs:enumeration value="max_fetch_depth" />
<xs:enumeration value="current_session_context_class" />
<xs:enumeration value="transaction.factory_class" />
<xs:enumeration value="cache.provider_class" />
<xs:enumeration value="cache.use_query_cache" />
<xs:enumeration value="cache.query_cache_factory" />
<xs:enumeration value="cache.use_second_level_cache" />
<xs:enumeration value="cache.region_prefix" />
<xs:enumeration value="cache.use_minimal_puts" />
<xs:enumeration value="cache.default_expiration" />
<xs:enumeration value="query.substitutions" />
<xs:enumeration value="query.factory_class" />
<xs:enumeration value="query.linq_provider_class" />
<xs:enumeration value="query.imports" />
<xs:enumeration value="hbm2ddl.auto" />
<xs:enumeration value="hbm2ddl.keywords" />
<xs:enumeration value="sql_exception_converter" />
<xs:enumeration value="adonet.wrap_result_sets" />
<xs:enumeration value="prepare_sql" />
<xs:enumeration value="command_timeout">
<xs:annotation>
<xs:documentation>
Set the default timeout in seconds for ADO.NET queries.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="adonet.batch_size" />
<xs:enumeration value="use_proxy_validator" />
<xs:enumeration value="xml.output_stylesheet" />
<xs:enumeration value="generate_statistics" />
<xs:enumeration value="query.startup_check" />
<xs:enumeration value="default_catalog" />
<xs:enumeration value="proxyfactory.factory_class" />
<xs:enumeration value="adonet.factory_class" />
<xs:enumeration value="default_batch_fetch_size" />
<xs:enumeration value="default_entity_mode" />
<xs:enumeration value="default_flush_mode" />
<xs:enumeration value="use_sql_comments" />
<xs:enumeration value="format_sql" />
<xs:enumeration value="collectiontype.factory_class" />
<xs:enumeration value="order_inserts" />
<xs:enumeration value="order_updates" />
<xs:enumeration value="query.query_model_rewriter_factory" />
<xs:enumeration value="linqtohql.generatorsregistry" />
<xs:enumeration value="odbc.explicit_datetime_scale" />
<xs:enumeration value="adonet.batch_versioned_data" />
<xs:enumeration value="transaction.system_completion_lock_timeout">
<xs:annotation>
<xs:documentation>
Timeout duration in milliseconds for the system transaction completion lock.

When a system transaction completes, it may have its completion events running on concurrent threads,
after scope disposal. This occurs when the transaction is distributed.
This notably concerns ISessionImplementor.AfterTransactionCompletion(bool, ITransaction).
NHibernate protects the session from being concurrently used by the code following the scope disposal
with a lock. To prevent any application freeze, this lock has a default timeout of five seconds. If the
application appears to require longer (!) running transaction completion events, this setting allows to
raise this timeout. -1 disables the timeout.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="transaction.use_connection_on_system_prepare">
<xs:annotation>
<xs:documentation>
When a system transaction is being prepared/prepared, is using connection during this process enabled?
Default is true, for supporting FlushMode.Commit with transaction factories
supporting system transactions. But this requires enlisting additional connections, retaining disposed
sessions and their connections till transaction end, and may trigger undesired transaction promotions to
distributed. Set to false for disabling using connections from system
transaction preparation, while still benefiting from FlushMode.Auto on querying.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="oracle.use_n_prefixed_types_for_unicode">
<xs:annotation>
<xs:documentation>
Oracle has a dual Unicode support model.
Either the whole database use an Unicode encoding, and then all string types
will be Unicode. In such case, Unicode strings should be mapped to non N prefixed
types, such as Varchar2. This is the default.
Or N prefixed types such as NVarchar2 are to be used for Unicode strings.
See https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch6unicode.htm#CACHCAHF
https://docs.oracle.com/database/121/ODPNT/featOraCommand.htm#i1007557
This setting applies only to Oracle dialects and ODP.Net managed or unmanaged driver.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="sql_types.keep_datetime">
<xs:annotation>
<xs:documentation>
Disable switching built-in NHibernate date-time types from DbType.DateTime to DbType.DateTime2
for dialects supporting datetime2.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="query.default_cast_length">
<xs:annotation>
<xs:documentation>
Set the default length used in casting when the target type is length bound and
does not specify it. 4000 by default, automatically trimmed down according to dialect type registration.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="query.default_cast_precision">
<xs:annotation>
<xs:documentation>
Set the default precision used in casting when the target type is decimal and
does not specify it. 29 by default, automatically trimmed down according to dialect type registration.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="query.default_cast_scale">
<xs:annotation>
<xs:documentation>
Set the default scale used in casting when the target type is decimal and
does not specify it. 10 by default, automatically trimmed down according to dialect type registration.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="track_session_id">
<xs:annotation>
<xs:documentation>
Set whether tracking the session id or not. When true, each session will have an unique Guid
that can be retrieved by ISessionImplementor.SessionId, otherwise ISessionImplementor.SessionId will
always be Guid.Empty. Session id is used for logging purpose that can be also retrieved in a static
context by SessionIdLoggingContext.SessionId, where the current session id is stored, when tracking
is enabled. In case the current session id won't be used, it is recommended to disable it, in order
to increase performance.
True by default.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
When a system transaction completes, it may have its completion events running on concurrent threads,
after scope disposal. This occurs when the transaction is distributed.
This notably concerns ISessionImplementor.AfterTransactionCompletion(bool, ITransaction).
NHibernate protects the session from being concurrently used by the code following the scope disposal
with a lock. To prevent any application freeze, this lock has a default timeout of five seconds. If the
application appears to require longer (!) running transaction completion events, this setting allows to
raise this timeout. -1 disables the timeout.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="transaction.use_connection_on_system_prepare">
<xs:annotation>
<xs:documentation>
When a system transaction is being prepared/prepared, is using connection during this process enabled?
Default is true, for supporting FlushMode.Commit with transaction factories
supporting system transactions. But this requires enlisting additional connections, retaining disposed
sessions and their connections till transaction end, and may trigger undesired transaction promotions to
distributed. Set to false for disabling using connections from system
transaction preparation, while still benefiting from FlushMode.Auto on querying.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="oracle.use_n_prefixed_types_for_unicode">
<xs:annotation>
<xs:documentation>
Oracle has a dual Unicode support model.
Either the whole database use an Unicode encoding, and then all string types
will be Unicode. In such case, Unicode strings should be mapped to non N prefixed
types, such as Varchar2. This is the default.
Or N prefixed types such as NVarchar2 are to be used for Unicode strings.
See https://docs.oracle.com/cd/B19306_01/server.102/b14225/ch6unicode.htm#CACHCAHF
https://docs.oracle.com/database/121/ODPNT/featOraCommand.htm#i1007557
This setting applies only to Oracle dialects and ODP.Net managed or unmanaged driver.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="sql_types.keep_datetime">
<xs:annotation>
<xs:documentation>
Disable switching built-in NHibernate date-time types from DbType.DateTime to DbType.DateTime2
for dialects supporting datetime2.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="query.default_cast_length">
<xs:annotation>
<xs:documentation>
Set the default length used in casting when the target type is length bound and
does not specify it. 4000 by default, automatically trimmed down according to dialect type registration.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="query.default_cast_precision">
<xs:annotation>
<xs:documentation>
Set the default precision used in casting when the target type is decimal and
does not specify it. 29 by default, automatically trimmed down according to dialect type registration.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="query.default_cast_scale">
<xs:annotation>
<xs:documentation>
Set the default scale used in casting when the target type is decimal and
does not specify it. 10 by default, automatically trimmed down according to dialect type registration.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="track_session_id">
<xs:annotation>
<xs:documentation>
Set whether tracking the session id or not. When true, each session will have an unique Guid
that can be retrieved by ISessionImplementor.SessionId, otherwise ISessionImplementor.SessionId will
always be Guid.Empty. Session id is used for logging purpose that can be also retrieved in a static
context by SessionIdLoggingContext.SessionId, where the current session id is stored, when tracking
is enabled. In case the current session id won't be used, it is recommended to disable it, in order
to increase performance.
True by default.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="cache\.[\w._]+"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>
</xs:extension>
Expand Down

0 comments on commit 92de0b7

Please sign in to comment.