Mule - getting primary key back after insert - jdbc

From the below article, i understand that Mule won't return the auto-generated Primary key after insert statement. Is there any work-around to get the PrimaryKey? I don't prefer going for mybatis as mentioned in this article.
Any help is appreciated!
http://ricston.com/blog/rant-mule-jdbc-transport-introduction-mule-module-mybatis/

try using new DB module availabe in 3.5.0-M4 or wait a few weeks for Mule ESB 3.5.0. Here is a usage example of this new feature:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<flow name="insertWithAutoGeneratedKeys">
<inbound-endpoint address="vm://insertWithAutoGeneratedKeys" exchange-pattern="request-response"/>
<db:insert config-ref="dbConfig" autoGeneratedKeys="true" autoGeneratedKeysColumnIndexes="1">
<db:parameterized-query>INSERT INTO PLANET(POSITION, NAME) VALUES (777, 'Mercury')</db:parameterized-query>
</db:insert>
</flow>

Alternative: Use UUIDs for primary key and generate the UUID in Mule before the insert.

Related

How to extract values (list and unique tags) from xml in Nifi?

I have a xml file that contains some tags, one is unique other are same tags. I'd like to get values from these tags and convert them to another xml tag. Here is example of xml file:
<?xml version="1.0" encoding="UTF-8"?>
<entry dataset="Swiss-Prot" created="2005-04-26" modified="2019-11-13" version="158" xmlns="http://uniprot.org/uniprot" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<accession>Q96IY4</accession>
<accession>A8K464</accession>
<accession>Q15114</accession>
<accession>Q5T9K1</accession>
<accession>Q5T9K2</accession>
<accession>Q9P2Y6</accession>
<name>CBPB2_HUMAN</name>
<protein>
<recommendedName>
<fullName>Carboxypeptidase B2</fullName>
<ecNumber evidence="7">3.4.17.20</ecNumber>
</recommendedName>
<alternativeName>
<fullName>Carboxypeptidase U</fullName>
<shortName>CPU</shortName>
</alternativeName>
<alternativeName>
<fullName>Plasma carboxypeptidase B</fullName>
<shortName>pCPB</shortName>
</alternativeName>
<alternativeName>
<fullName>Thrombin-activable fibrinolysis inhibitor</fullName>
<shortName>TAFI</shortName>
</alternativeName>
</protein>...other tags
</entry>
I though of using EvaluateXQuery processor and EvaluateXPath. EvaluateXQuery is using for getting accession and alternativeName tags. EvaluateXPath is using for getting name, recommendedName (fullName) tags.
Is it possible to use both and combine them to only xml or hust necessary to use EvaluateXQuery processor, like this:
<accessions>Q96IY4, A8K464, Q15114,...</accessions>
<name>CBPB2_HUMAN</name>
<recommendedName>Carboxypeptidase B2</recommendedName>
<alternativeNames>Carboxypeptidase U-CPU, Plasma carboxypeptidase B-pCPB,...</alternativeNames>
Can you help me, please?
Thank you!
Hi you may use processor execute groovy script and parse xml with a script to get your values and put them into attributes.

Visual Studio truncates message in Test Detail Summary window

I have test which compares two json objects. If test fails then I print those json objects.
Assert.That(
json1,
Is.EqualTo( json2 ).Using<JToken>( JToken.DeepEquals ),
"Jsons are not equal\n{0}\n{1}", json1.ToString(), json2.ToString() );
But Visual Studio truncates my message :( Message from TestContext.Out is also truncated.
How can I increase message length limit?
I have temporarily solved this problem by saving the test's result to an xml file.
To achieve it you should create .runsettings file.
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<ResultsDirectory>ResultsDirectory</ResultsDirectory>
</RunConfiguration>
<NUnit>
<TestDirectory>TestDirectory</TestDirectory>
<WorkDirectory>WorkDirectory</WorkDirectory>
<TestOutputXml>TestOutputXml</TestOutputXml>
<InternalTraceLevel>Info</InternalTraceLevel>
</NUnit>
</RunSettings>

Loading multiple packages in a single kie session?

I have two packages a and b having different rule files. Right now I am using two sessions to load the rules. Is there a way I can load rules from both the packages in a single session?
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rules_a" packages="rules_a">
<ksession name="ksession1"/>
</kbase>
<kbase name="rules_b" packages="rules_b">
<ksession name="ksession2"/>
</kmodule>
Can I pass something like: packages = {"rules_a", "rules_b"} ??
As stated in this section of the documentation, you can pass a comma separated list of packages when building a KieBase.
Another possibility is to create a KieBase that includes others. That same section of the documentation shows how to do it.
Hope it helps,
There is a packages attribute of kiebase, below is an example of how to include the packages rules1, rules2 in kiebase.
<kbase name="rules_12" packages="rules1,rules2">
From drools documentation:

Create Exchange Message Items with EWS and mark them for deletion

I am using EWS to create items in an Exchange mailbox. I am using the CreateItems method. I am also setting an extended property on the items I create so that it is deleted when that date is reached. The items are created correctly, but they are not deleted at the specified date.
I read that there is a timer job in Exchange that does the actual processing based on the extended property set on an item and that I could use "Start-ManagedFolderAssistant -Identity user#example.com" in Powershell to force that job, but this didn't work either.
Here is the message I am sending:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
</soap:Header>
<soap:Body>
<m:CreateItem MessageDisposition="SaveOnly">
<m:SavedItemFolderId>
<t:DistinguishedFolderId Id="root" />
</m:SavedItemFolderId>
<m:Items>
<t:Message>
<t:ItemClass>IPM.Blabla</t:ItemClass>
<t:Subject>ToDelete</t:Subject>
<t:Body BodyType="Text">Todelete</t:Body>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertySetId="c11ff724-aa03-4555-9952-8fa248a11c3e"
PropertyName="Expiration Date" PropertyType="String" />
<t:Value>6/4/2015 2:39:04 PM</t:Value>
</t:ExtendedProperty>
</t:Message>
</m:Items>
</m:CreateItem>
</soap:Body>
</soap:Envelope>
Is there something missing with in the message so that the job deletes it? Is there something that I misunderstood in the way the system works?
That property your setting won't do anything it looks like you have pulled the sample from https://msdn.microsoft.com/en-us/library/office/dd633654%28v=exchg.80%29.aspx which is just a sample of creating a custom property for your own use. There is no back-end process that would use this property you just created.
There are two ways of doing expiry in Outlook/Exchange the first is using the PidtagExpirytime https://msdn.microsoft.com/en-us/library/ee237103%28v=exchg.80%29.aspx . This is a client mechanism and there is still no server process to delete the expired messages see http://www.msoutlook.info/question/automatically-delete-message-at-set-date . The Server side method is to stamp the messages with a Retention tag that will specify when the message will be deleted eg http://blogs.msdn.com/b/akashb/archive/2011/08/11/stamping-retention-policy-tag-using-ews-managed-api-1-1-from-powershell-exchange-2010.aspx and in 2013 you can do this via https://msdn.microsoft.com/en-us/library/office/jj220500%28v=exchg.80%29.aspx#ret
Cheers
Glen

Generating OData $metadata with the schema http://schemas.microsoft.com/ado/2007/06/edmx

When I use ODataLib 5.6.1 to generate an OData metadata document like this:
var eModel = new Microsoft.Data.Edm.Library.EdmModel();
....
...WriteMetadataDocument()
....
I get the following xml:
edmx document 1:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx" Version="3.0">
...
</edmx:Edmx>
However this metadata (http://services.odata.org/V3/OData/OData.svc/$metadata) has a different schema:
edmx document 2:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" Version="1.0">
...
</edmx:Edmx>
How can I generate metadata looking like the document 2? My motivation is that many OData clients (e.g. Visual Studio's "Add Service Reference") don't seem to recognize the document 1.
After a while I figured out the trick (using SetEdmVersion):
var eModel = new Microsoft.Data.Edm.Library.EdmModel();
...
eModel.SetEdmVersion(new Version(1, 0));

Resources