phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
110 stars 36 forks source link

Concurrent Usage #141

Closed cemo closed 1 year ago

cemo commented 1 year ago

Hi @phax,

What is the recommended way of usage in a concurrent environment? Should I create a new ISchematronResource for each document to be validated?

I guess compiling is taking some time and you are already caching SCH schemas but I wanted to be sure that what is the recommended way.

phax commented 1 year ago

The recommended way is to compile the SCH to XSLT at build-time using e.g. the Maven plugin. Then in the code you are directly using SchematronXSLT as the basis for processing.

That spares the tedious compilation proces and usually saves a lot of execution time. Additionally you can rely on the concurrent usage rules for XSLT :)

cemo commented 1 year ago

How can I use concurrently XSLT? Because SchematronResourceXSLT seems not thread safe too.

Is there any other way than this?

 final ISchematronResource aResXSLT = SchematronResourceXSLT.fromClassPath("/schematron/my.xml");
phax commented 1 year ago

This is the correct way. Internally the precompiled XSLT "Templates" object is cached, so that it is reused automatically. So the instance itself is not thread-safe, the cache is thread-safe.

With aResXSLT.setUseCache (boolean) you can trigger the XSLT cache usage

cemo commented 1 year ago

Thank you so much.

phax commented 1 year ago

Btw. are you aware of my ph-ubl project that also has built-in support for UBLTR?

cemo commented 1 year ago

I am very surprised now. You have even tests with our invoice samples. I will try to learn more about it how can I use it.

cemo commented 1 year ago

@phax After many years I entered XML land again so please forgive my ignorance. Let me explain my use case first. We will take restful requests to communicate with government to create invoices and other related objects. We will not take XML requests from someone and validate them. We will just receive requests in a restful way to create invoices.

I see that UBL is used for 3 main purpose in the project. Write documents, read documents, validate documents. Read and Validate is not necessary my use case since I create them myself. What will be the benefit of using UBL?

By the way your projects are the greatest piece of thing in whole my way. Thank you again so much.

phax commented 1 year ago

Hi @cemo no worries. If you already have a solution to creating your UBL file, than my library is of no big use for you. I just thought it might be... Maybe it would make sense to include the UBLTR Schematrons in my phive-rules document validation library. Can you pls point me to the official website where I can download the official Schematrons??? Thx

cemo commented 1 year ago

I have sent an email regarding files. I can even contribute to projects if you want. I guess it is not so much difficult for you but If you need any help, please let me know.

phax commented 1 year ago

I assume the base link is https://ebelge.gib.gov.tr/efaturamevzuat.html and the main package can be taken from https://ebelge.gib.gov.tr/dosyalar/kilavuzlar/e-FaturaPaketi.zip ?

cemo commented 1 year ago

Yes exactly.

cemo commented 1 year ago

You had already use an old version of these files in UBL. I will be glad if you update them as well.

cemo commented 1 year ago

By the way there is also as fatura too. It is another kind of invoice but necessary as well.

https://ebelge.gib.gov.tr/earsivmevzuat.html