I have an XML which has multiple nodes and sub-nodes from which am consuming data as input for multiple functions from the main function.
I have a basic question on optimized code here.
Is it good to pass the XML object as an input to multiple function which consumes some data from the XML?
Is it good to pass the XML path to the function and instantiate XML object inside each function?
Is there a way to pass just the node which is required for a particular function? ( In-case i have 10 nodes and 10 functions - where each function requires just one particular node for consuming data)
Thanks
I would argue that it's better to pass only specific arguments to each function. The less broad your input, the simpler your input validation. Also, I'd strongly recommend to avoid repeatedly reading/parsing the same data. There's no benefit at all in doing that.
Related
I am new to spring batch. I want to understand how the data is passed from Reader to Processor and from processor to Writer? So basically in Reader we will be having read() method which will return some kind of data, say String.. this return type will be used as an input parameter in process() method in Processor.
So what I want to understand is once read() method returns a String data, until it reaches process() method, how this transfer is handled? Does spring stores this data somewhere and then passes to the next phase? How it happens?
Any pointers to understand this or some good links to readup on the same are welcome.
Thanks in advance!
Spring Batch uses chunk-oriented processing as explained here: https://docs.spring.io/spring-batch/4.0.x/reference/html/step.html#chunkOrientedProcessing
The idea is to read/process items one at a time until a chunk (of a predefined size) is created. This design choice avoids loading the whole data source in memory which is very efficient when dealing with large amounts of data. The writing on the other hand operates on a chunk of items (and not a single item) in order to optimize writes (like jdbc batch inserts or elastic search bulk inserts).
If you want more details on what's happening behind the scene, I invite you to take a look at the code of the ChunkOrientedTasklet class which uses basically two collaborators:
A ChunkProvider which provides chunks of items (delegating item reading to an ItemReader)
A ChunkProcessor which processes chunks (delegating processing and writing respectively to an ItemProcessor/ItemWriter)
Here is a simplified version of the code:
Chunk inputs = chunkProvider.provide(contribution);
chunkProcessor.process(contribution, inputs);
The contribution object is used to add the chunk contribution to the step. So to answer your question:
"how this transfer is handled? Does spring stores this data somewhere and then passes to the next phase?"
Items are actually handed between these two collaborators through the inputs variable of type Chunk.
Hope this helps!
You seem to be thinking about this as WAY more complicated than it is. This is no different than any other object oriented method call.
When the read() method completes it returns a (hopefully defined generics typed) object(s) which then is passed as an argument to the process() method which then when it completes passes that object(s) the write() method. It all takes place effective instantly, in memory (which is why jobs are chucked) just the same way you pass any object to a method.
Object someData = read();
process(someData);
write(someData);
I'm new to Matlab and I need some suggestions on how to deal with having many inputs to a function.
The program reads data from multiple elements and stores them in an array, which I'm doing in a loop. The problem is that if I input the wrong information about one element, I must re-input the data all over again. I believe that there must exist a better way to input these data, like reading it from a external file, for example.
The problem with the external file would be, as far as I know, with the reading of multiple arrays from a single file, hence the need of multiple external files - and I believe also that must exist some better way.
As noted by #beaker, you can use save and load to store the data. You can store multiple variables in a given file without a problem.
We are working in a very complex solution using drools 6 (Fusion) and I would like your opinion about best way to read Objects created during the correlation results over time.
My first basic approach was to read Working Memory every certain time, looking for new objects and reporting them to external Service (REST).
AgendaEventListener does not seems to be the "best" approach beacuse I dont care about most of the objects being inserted in working memory, so maybe, best approach would be to inject particular "object" in some sort of service inside DRL. Is this a good approach?
You have quite a lot of options. In decreasing order of my preference:
AgendaEventListener is probably the solution requiring the smallest amount of LOC. It might be useful for other tasks as well; all you have on the negative side is one additional method call and a class test per inserted fact. Peanuts.
You can wrap the insert macro in a DRL function and collect inserted fact of class X in a global List. The problem you have here is that you'll have to pass the KieContext as a second parameter to the function call.
If the creation of a class X object is inevitably linked with its insertion into WM, you could add the registry of new objects into a static List inside class X, to be done in a factory method (or the constructor).
I'm putting your "basic approach" last because it requires much more cycles than the listener (#1) and tons of overhead for maintaining the set of X objects that have already been put to REST.
I want to use record type as parameter but I got message that function cannot have record type parameters. I have a Dao function which perform various operation on a Arraylist passed through parameter and I need to implement it in stored procedure. So any help will be greatly appreciated. thanks!
The function m looking for is something like:
CREATE OR REPLACE FUNCTION est_fn_get_emp_report(rec record,...)
I am new using postgresql but have used stored functions before but never have to use record type parameters.
The simple issue is you can't specify a record. You can specify some polymorphic types (ANYARRAY, ANYELEMENT) as an input of a function but it needs to have a structure known at planning time and this can lead to issues with polymorphic types as input args on even on a good day. The problem with a record is that PostgreSQL wont necessarily know what the internal structure is when it is passed in. ROW(1, 'test') is not useful in a functional context.
Instead you want to specify complex types. You can actually take this very far in terms of relying on PostgreSQL. This allows you to specify a specific type of record when passing it in.
I am having to pass a fairly large object/file to a workflow when it starts (in the order of hundreds of MBs). I am using secondary storage to dump the object and have as little of it as possible in the RAM at one time on Workflow side. Is there another way to pass and handle the object which is more efficient. Does WF provide any built in function to handle such situations?
what about passing the URI to that object instead ?