Change nhibernate config with nant xmlpoke - nhibernate

How can I change the connection string from nhibernate.config file using nant
the problem is that all examples are about changing attribute value, but nhibernate has inner text
eq:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data Source.\server;Database=UnitTestDb;UID=user;pwd=pass;</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="show_sql">true</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
....
I need to change property connection.connection_string
<xmlpoke file="${nhibernate.file}"
xpath="/hibernate-configuration/session-factory/add[#key='connection.connection_string']/#value"
value="${connection.string}">
</xmlpoke>
this does not work in this case.
Thanks

The sample xpath you're using refers to elements named add with attributes called key. In your case you are looking for property elements with attributes called name.
Next, since you want to change the inner text and not the #value attribute on the property element you should remove the trailing attribute reference.
And finally, since the NHibernate xml has a specific namespace you will have to inform xmlpoke to use the correct namespace.
So the task should look like this:
<xmlpoke file="${nhibernate.file}"
xpath="/nhc:hibernate-configuration/nhc:session-factory/nhc:property[#name='connection.connection_string']"
value="${connection.string}">
<namespaces>
<namespace prefix="nhc" uri="urn:nhibernate-configuration-2.2" />
</namespaces>
</xmlpoke>
Note: I've not tested this out, but general xml/xpath rules are in work here so I hope it works. Also, it could be that there is a way to indicate to xmlpoke that the specified namespace should be the default and thus eliminate the need to namespace prefix all the various parts in the xpath.
Good luck!

Related

Checking if the properties file exists

I need to check if the properties file exists. If it not exists build.xml must use itself property.
<property file="AntHW.properties"/>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="docdir" location="javadoc"/>
You don't need to check if it exists. Properties in ant are immutable, once set the values cannot be changed. So you want to import the properties file above your snippet, if the properties exist in that properties file the values are set and will not be overwritten by the snippet.
Maybe you can try
<available property="properties.available" file="path/to/properties/file" />
Now properties.available will tell you whether or on the properties file exists.

WSO2 esb access node from xml in property

i stored an XML document in a property:
<property expression="$body//*" name="InDoc"
scope="default" type="OM"/>
in a later step of the proxy a want to access the XML doucment.
This
<log level="custom">
<property name="InDoc" expression="get-property('InDoc')"/>
</log>
gives the whole XML document. But I would like to access only some parts of the XML e.g. only one value in a later step of the proxy. I already tried
<log level="custom">
<property name="InDoc" expression="get-property('InDoc')//AAA"/>
</log>
or this
<log level="custom">
<property name="InDoc" expression="$ctx:InDoc//AAA"/>
</log>
But both do not work. Is there another way?
Thanks in advance.
Roland
I think both way should work fine. The expression support XPath 1.0. You can run any XPath after the "get-property" in expression.
But you need check,
make sure you use the right XPath.
So you can log/copy the get-property('InDoc'), and then you can use any XPath tool to validate your XPath.
Namespace of the XPath in expression,
if your xml payload have namespace, make sure your XPath namespace is right, and declare right NS in property.
Through property mediator, you are not going to store XML file, you just retrieving content from it. As you have to retrieve part of it, you can give it through property mediator.
<property expression="$body//*" name="InDoc" scope="default" type="OM"/>
Through expression you should define it.
expression="$body//*"
You can change this and get required parts of xml. If you need few parts, you can add several properties for each and retrieve value from it.

Jackrabbit index boost configuration

I'm trying to understand the use of 'boosting' properties in the indexing configuration for CQ5. I thought I understood from http://wiki.apache.org/jackrabbit/IndexingConfiguration that setting a boost determined how far up the list an item would be returned as a search result. So I tried adding the following boost lines to my default CQ5 indexing configuration:
<index-rule nodeType="nt:base">
<property boost="5.0">jcr:title</property>
<property boost="5.0">history:title</property>
<property boost="3.0">history:description</property>
<property boost="3.0">history:caption</property>
<property boost="2.0">text</property>
<property nodeScopeIndex="false">analyticsProvider</property>
<property nodeScopeIndex="false">analyticsSnippet</property>
<property nodeScopeIndex="false">hideInNav</property>
<property nodeScopeIndex="false">offTime</property>
<property nodeScopeIndex="false">onTime</property>
:
:
<property isRegexp="true">.*:.*</property>
</index-rule>
The intent was that, in a full text search, text found in jcr:title or history:title properties would be the most relevant followed by history:description, history:caption and, finally, text.
I deleted the index information from the repository and from the workspace, then restarted CQ and let it rebuild all of the indexes.
Now when I do a full text search, I'm only getting results if the search text is in the nodename itself - nothing from description, caption, etc.
Obviously I've done something wrong but I'm not sure what. Any help would be greatly appreciated.

NHibernate - Trying to get it to use a SQL Server Row version

As per the StackOverflow question 'NHibernate and sql timestamp columns as version', I use the following mapping:
<version name="RowNumber" generated="always" unsaved-value="null" type="BinaryBlob">
<column name="RowNumber" not-null="false" sql-type="timestamp" />
</version>
<property name="CreateDate" column="CreateDate" type="DateTime" update="false" insert="false" />
(Other properties after this last).
But when I run my ASP.MVC app I get:
[Path]\Clients.hbm.xml(7,90): XML validation error: The element 'urn:nhibernate-mapping-2.2:version' cannot contain child element 'urn:nhibernate-mapping-2.2:column' because the parent element's content model is empty.
But as far as I can see 2.2 is the latest version of the mapping, so how can anyone put a column element inside the version element?
Sorry if this is really basic,
In case anyone else has this problem:
It works as Ayende Rahien specifies in this blog on NHibernate - but only (AFAIK) on version 2.1.n; I was using 2.0.n. I also think you need the object's field/property to be byte[], not System.Linq.Binary as that type has no default constructor (but I am not sure about this - I seemed to have to do this)
Example (excuse the names):
<version name="RowKludge" type="BinaryBlob" generated="always" unsaved-value="null" >
<column name="RowNumber"
not-null="false"
sql-type="timestamp"/>
</version>
A SQL server 'timestamp' is not your regular timestamp, hence the requirement that the type should be a binary blob.
Note that if you do migrate you will need to change the NHibernate configuration in Web/App config - most tutorials currently available seem to be for v.2.0 (or earlier) - you need an uptodate reference or tutorial for 2.1
A quick look in the documentation reveals that your mapping is not correct. It should be something like this:
<version name="RowNumber" column="RowNumber"
generated="always" unsaved-value="null"
type="Timestamp" />
Best Regards,
Oliver Hanappi

How do I set the xmlns attribute when using XMLFile in Wix 3

I am adding elements to an XML file during installation using the XmlFile element:
<util:XmlFile Id="SetOracleDialectProperty"
Action="createElement"
ElementPath="//hibernate-configuration/session-factory"
Name="property"
Sequence="9"
File="[INSTALLLOCATION]Config\hibernate.config"
Value="NHibernate.Dialect.Oracle10gDialect"/>
The empty file I am writing to looks like this:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
</session-factory>
</hibernate-configuration>
After running the installer I end up with this:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property xmlns="">NHibernate.Dialect.Oracle10gDialect</property>
</session-factory>
</hibernate-configuration>
The problem is that the empty xmlns attribute is overriding the xmlns specified in the root node of the file so the property element is not recognised correctly by nhibernate.
How can I either set the value to match the root node or remove the xmlns attribute?
I have spent some time searching for an answer and the closest I've found is "do what you would do in MSXML" which doesn't help me as it doesn't say how to do it in WiX (e.g. what attribute on XmlFile to use).
EDIT
To explain Rob's answer slightly, in a place where I can use nice formatting:
You add a document fragment by setting Node="document" on the XmlConfig element.
You have to explicitly set the namespace otherwise you get the default one again.
Also although you're adding a "document" it doesn't seem to work if you specify more than one element. You get a mysterious and thoroughly unhelpful "Setup wizard ended prematurely" runtime error.
So my fixed code looks like this:
<util:XmlConfig Id="MsSqlDialect"
Action="create"
ElementPath="//hibernate-configuration/session-factory"
File="[INSTALLLOCATION]Config\hibernate.config"
Node="document">
<![CDATA[
<property xmlns="urn:nhibernate-configuration-2.2" name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
]]>
</util:XmlConfig>
I know this is years later but if anyone else comes across this I think the true solution is this:
<util:XmlFile Id="SetOracleDialectProperty"
Action="createElement"
ElementPath="//hibernate-configuration/session-factory"
Name="urn:nhibernate-configuration-2.2:property"
Sequence="9"
File="[INSTALLLOCATION]Config\hibernate.config"
Value="NHibernate.Dialect.Oracle10gDialect"/>
change is from Name="property" to Name="urn:nhibernate-configuration-2.2:property" - when config is written it will apprear as just as it will recognize it is the default namespace. I had the same problem adjusting manifest files and this approach sorted it.
The problem here is that MSXML states that createElement will always give you the default namespace (just as you are seeing). I think you'll need to switch to the more complex but more powerful XmlConfig. In this case, try using a document fragment to add the entire element with correct namespace instead of depending on MSXML to create it for you.