ibatis - where to place the <cacheModel> tag? - ibatis

I have the map config file like this
<sqlMap ..............>
<alias>
<typeAlias ......../>
</alias>
<statements>
....
<sql>....</sql>
<select cacheModel="cache-select-all">....</select>
<update>...</update>
<procedure>...</procedure>
.....
</statements>
<parameterMaps>
<parameterMap>....</parameterMap>
</parameterMaps>
<cacheModel id="cache-select-all" type="LRU" readOnly="true" serialize="false">
<flushInterval hours="24"/>
<flushOnExecute statement="InsertIOs"/>
<!--<property name="CacheSize" value="1000"/>-->
</cacheModel>
</sqlMap>
I am using ibatis (.net, if that matters) and i have one question: where to place the tags? is There a or because placing it like i did, in the statements seems not to work. What am i doing wrong?

You must reference the cacheModel you defined inside a statement tag as shown in the following link:
http://ibatis.apache.org/docs/dotnet/datamapper/ch03s08.html

Before you use it in the select statement. Order does matter here. Otherwise sql map parser wouldn't be able to validate your sql map.

Related

Azure Logic App outputs XML all in single line

I'm trying to convert a CSV to XML, which works perfectly fine when I test the map file in Visual Studio as I made sure the XSLT1.0 contains indent="yes". But for some reason when I repeat the steps in my Azure Logic App everything gets exported to one line:
<?xml version="1.0" encoding="utf-8"?><enfinity xsi:schemaLocation="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex bc_pricing.xsd" major="6" minor="1" family="enfinity" branch="enterprise" build="build" xmlns="http://www.fakewebsite.com/xml/ns/enfinity/7.1/bc_pricing/impex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.fakewebsite.com/xml/ns/enfinity/6.5/core/impex-dt"><product-price-list id="DEMarkdown" priceType="ES_SalePrice" import-mode="UPDATE"><display-name>DE Markdown</display-name><description /><enabled>true</enabled><priority>1</priority><target-groups><customer-segments><customer-segment id="Everyone" repository-id="WhiteStuff-DE-Anonymous" /><customer-segment id="IG_RegisteredUsers" repository-id="WhiteStuff-DE-Anonymous" /></customer-segments></target-groups><product-price-list-entry sku="433493126" import-mode="REPLACE"><price-scale-table type-code="1" currency="EUR"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>44.95</value></fixed-price-entry></price-scale-entries></price-scale-table><price-scale-table type-code="1" currency="GBP"><valid-from>2021-07-06T00:00:00+00:00</valid-from><valid-to>2099-07-13T00:00:00+00:00</valid-to><price-scale-entries><fixed-price-entry quantity="1" unit=""><value>39.50</value></fixed-price-entry></price-scale-entries></price-scale-table></product-price-list-entry></product-price-list></enfinity>
I have 2 ways for this
WAY-1
You can use the XML Validation connector before the process which parses the content into the right format.
WAY-2
Just for viewing purposes, you can do a request-response method using Postman then use XML format in order to achieve your requirement.
For those interested, I've found a setting within the Logic App, simply select Apply XSLT output attributes and that's it, no validation needed either!

Get the values from the <xd:doc/>

I want to access the version information which I store in the
<xsl:stylesheet>
<xd:doc scope="stylesheet">
<xd:ul>
<xd:li>
<xd:i>Updates</xd:i>: <xd:ul>
<xd:li>20.11.2018, version: <xd:i>1.1.0</xd:i></xd:li>
<xd:li>08.03.2019, version: <xd:i>2.0.0</xd:i></xd:li>
<xd:li>11.03.2019, version: <xd:i>2.0.1</xd:i></xd:li>
</xd:ul>
</xd:li>
</xd:ul>
</xd:doc>
</xsl:stylesheet>
Normally the XPath of the #select is evaluated to the xml-file which is currently transforming. But how refer XPath to the (main) XSL-stylesheet?
Another option would be to use fn:doc(). But I want to place the version-writing-functionality in an external module, so there will be dynamic file names and I don't know how to get the xsl-file name
I use oXygen XML editor 20.1 where I define the transformation scenarios.
#MartinHonnen Thank you. I updated the code in the question. As you may see I store the version in the docs of the stylesheet.
The document('') / doc('') was what I needed. So I implemented the following:
I put the document-node of the main stylesheet in the variable which is placed in this stylesheet:
<xsl:variable name="currentStylesheet" select="doc('')"/>
then refer to it in the external module
<xsl:variable as="xs:string" name="versionXSLT" select="$currentStylesheet//xd:li[xd:i = 'Updates']/xd:ul/xd:li[last()]/xd:i/string()"/>
I also use it to get the name of the stylesheet:
<xsl:variable as="xs:string" name="currentStylesheetName" select="tokenize(document-uri($currentStylesheet), '/')[last()]"/>
Are there maybe better solutions?

Magento - possible to have multiple tables for a single model?

trying to set up a config file for a custom module - do I need to have a unique model for each 'resourceModel', or is it possible to have multiple table entities per model?
Is it possible to get something like this to work:
<config>...
<model>
<namespace>
<class>Namespace_Module_Model</class>
<resourceModel>module_mysq4</resourceModel>
</namespace>
<module_mysql4>
<class>Namespace_Module_Model_Mysql4</class>
<entities>
<table_1>
<table>table_1</table>
</table_1>
<table_2>
<table>table_2</table>
</table_2>
<table_3>
<table>table_3</table>
</table_3>
...
</entities>
</module_mysql4>
..</config>
and then dynamically switch between the tables through the model?
and related: Anyone know what the possible children of the are and their properites? I've seen 'entities', 'associations' and 'items' - thx
It's not really clear what you're asking here. Magento has a basic one resource to one table resource, and a one resource to many tables constructed in a specific manner resource for EAV style models.
The scenario you're describing above isn't directly supported by the system, but if you wanted to implement something like it there's nothing stopping you from implementing a resource that works any way you want.
As for the possible children, create the simple config viewer described here to get a dump of the entire merged config, and then use an xpath viewer to examine all the nodes (and their children) that you're interested in
Thx for the response & apologies if the question was unclear. After a few hours of debugging, I have it working with the following structure:
<models>
<modulename>
<class>Namespace_Modulename_Model</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename>
<modulename_type1>
<class>Namespace_Modulename_Model_Type1</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename_type1>
<modulename_type2>
<class>Namespace_Modulename_Model_Type2</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename_type2>
<modulename_mysql4>
<class>Namespace_Modulename_Model_Mysql4</class>
<entities>
<modulename>
<table>modulename</table>
</modulename>
<modulename_type1>
<table>modulename_type1</table>
</modulename_type1>
<modulename__type2>
<table>modulename_type2</table>
</modulename_type2>
</entities>
</modulename_mysql4>
</models>
So yes - there is a single table entity for each model declared (one model, one resource) but I would have assumed that each additional model/resourceModel combination would require it's own separate Model_Mysql class in it's own modulename_mysql4 node, ala:
<models>
<modulename>
<class>Namespace_Modulename_Model</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename>
<modulename_type1>
<class>Namespace_Modulename_Model_Type1</class>
<resourceModel>modulename_mysql4_type1</resourceModel>
</modulename_type1>
<modulename_type2>
<class>Namespace_Modulename_Model_Type2</class>
<resourceModel>modulename_mysql4_type2</resourceModel>
</modulename_type2>
<modulename_mysql4>
<class>Namespace_Modulename_Model_Mysql4</class>
<entities>
<modulename>
<table>modulename</table>
</modulename>
</entities>
</modulename_mysql4>
<modulename_mysql4_type1>
<class>Namespace_Modulename_Model_Mysql4_Type1</class>
<entities>
<modulename_type1>
<table>modulename_type1</table>
</modulename_type1>
</entities>
</modulename_mysql4_type1>
<modulename_mysql4_type2>
<class>Namespace_Modulename_Model_Mysql_Type2</class>
<entities>
<modulename_type2>
<table>modulename_type2</table>
</modulename_type2>
</entities>
</modulename_mysql4_type2>
</models>
but that is not the case. Would love to hear a play by play explanation. Thx for the help!
Or:
<resources>
<modulename_setup>
<setup>
<module>modulename</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</modulename_setup>
<modulename_write>
<connection>
<use>core_write</use>
</connection>
</modulename_write>
<modulename_read>
<connection>
<use>core_read</use>
</connection>
</modulename_read>
</resources>

Is it possible to put myBatis (iBatis) xml mappers outside the project?

According to the user guide i am able to use file path instead of
resource:
// Using classpath relative resources
<mappers>
<mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
</mappers>
// Using url fully qualified paths
<mappers>
<mapper url="file:///var/sqlmaps/AuthorMapper.xml"/>
</mappers>
in my project I'm trying to put my mapper xml "outside" the project
and i'm doing this:
<mapper url="file://D:/Mappers/ComponentMapper1.xml" />
The output of my log4j console:
Error building SqlSession.
The error may exist in file://D:/Mappers/ComponentMapper1.xml
Cause: org.apache.ibatis.builder.BuilderException: Error parsing
SQL Mapper Configuration. Cause: java.net.UnknownHostException: D
Is it bug or it's me doing something wrong?
You just need an additional forward slash before the drive letter.
Sql Map Config looks for mapping files relatively to the classpath, so just try adding your ComponentMapper1.xml somewhere to the classpath.
set CLASSPATH=%CLASSPATH%;D:/Mappers/
...
<mapper resource="ComponentMapper1.xml" />
You must use
<mapper url="file:///usr/local/ComponentMapper1.xml" />
Where file:///usr/local/ComponentMapper1.xmlis the path to your XML File, instead of the resource if you want use mappers outside resource dir.

how to insert html tag inside sql in Liquibase migration?

I need to update my data that have html tag inside so wrote this on liquibase
<sql> update table_something set table_content = " something <br/> in the next line " </sql>
it apparently doesn't work on liquibase ( i got loooong errors .. and meaningless). I tried to remove <br/> and it works.
my question is, is it possible to insert / update something that contains xml tag in Liquibase ?
I am using liquibase 1.9.3 with Grails 1.1.1
edited: forgot to set code sample tag in my examples.
As the liquibase author mentions here you'll need to add CDATA section inside <sql>.
In your particular example that would become:
<sql><![CDATA[ update table_something set table_content = " something <br/> in the next line " ]]></sql>
Even better not to use a <sql> tag at all (I added the where clause ...):
<changeSet author="author" id="table_something_1">
<update tableName="table_something">
<column name="table_content"><![CDATA[ something <br/> in the next line ]]></column>
<where>id=1</where>
</update>
<rollback />
</changeSet>

Resources