BatchUpdateSql in Application Platform

Hi!

I’m trying to call a BatchUpdateSQL adapter in my Application platform, as a POJO, however, I keep having my input variable as null (and hence I keep having an exception).

What am I doing wrong here?

PLS_UpdateDevicesToBPMSByBatchInput inputsPLS = new PLS_UpdateDevicesToBPMSByBatchInput();
UpdateDevicesToBPMSByBatchInput inputs = new UpdateDevicesToBPMSByBatchInput();

		Inputs[] input = new Inputs[10];
		int inputIndex = 0;
		for (String s : stringList)
		{
			try {
				Inputs _input = input[inputIndex];
				
				if (_input == null || input.length <= 0)
					throw new Exception("Input variable is null! Current size: " + input.length);


				

			} catch (Exception ex) 
			{
				throw ex;
			}
		}

The size is showing 10, but it keeps triggering the _input variable as being null.

Hi Rui,

I cannot follow your code.

Can you please provide the signature of the method please?
Where is the Inputs-array filled? I only see its initialization, but not where the data is added.
Additionally you should remember to increment the index for each iteration.

As you initialized the array to contain 10 elements its length is fixed to 10 (indexed 0 thru 9), so input.length will always show 10, but as the elements are never filled with any content the value of _input (equal to input[0], the first element of the array) will always be null (as expected obviously).

Therefore the first part of the if-statement is always true and the second part is never evaluated.
It would resolve to false anyway as “10<=0” can never be true.

Regards,
Holger

Hi

From the code snippet , its not clear on what you are trying to achieve. Below are my general review comments w.r.t to code snippet

  1. inputIndex is not incremented.
  2. Not sure on why you have defined a fixed array of Inputs , while you are iterating of stringList.

Thanks
Nagasrikrishna

1 Like

Hey!
Thanks for the input.

Sorry, but I didnt copy the whole code. I had definitely the inputIndex getting incremented : )

The way I solved this was to simply initialize the Inputs instance:

Inputs input = new Inputs[super.recordsToUpdate.entrySet().size()];
int inputIndex = 0;

START FOR LOOP
Inputs _input = new Inputs();
(…)
input[inputIndex] = _input;
inputIndex++;
END FOR LOOP

Anyway, since I am using the BatchUpdate adapter, I have to also start and commit transactions (LOCAL_TRANSACTION). Unfortunately, I keep having this error: “Unable to rollback transaction. A transaction name must be specified” in my application platform.

I have tried everything to make this work, which makes me assume the application platform does not support the art.pub.transaction services.

This is my current code layout:

String transactionName = “UpdateDevicesTable”;
< StartTransaction >(transactionName)
< Try >
< Loop records >
< Call BatchUpdate adapter >
< CommitTransaction >(transactionName)
< Catch >
< RollbackTransaction >(transactionName)
< End Try-Catch >

I am calling the “art.pub.transaction” services by creating manually the POJOs for the application platform, since we can’t use the wizard.

If this doesn’t work, is there a workaround for this? I still want to (have to) use Application platforms.

Thanks,
Rui Gomes

Hi

Can you try , by passing the same transactionName for the Start, Commit & Rollback services ?

Thanks for the reply Dasari.
Yes, I am doing that. I actually managed to workaround this by created a java conventional service that has all the transaction methods there and then my Application Platform calls this java conventional service. This is not ideal for sure, since I didn’t want to have an extra java conventional service to do this logic. This makes me assume the Application Platform does not support the Start, Commit and Rollback transaction services from the WMArt package.

Hi Rui,
the following lines can be combined into one line of code:

will become

input[inputIndex++] = _input;

Can you try to do the looping outside of the transaction and have only the BatchUpdate in the transaction?
When using LocalTransaction it is not really neccessary to use explicit transaction handling, you can rely on the implicit transaction handling of the LocalTransaction handler.

Regards,
Holger

Thanks Holger for the input.

I got the same error message after putting the loop before the start of the transaction : (

Thanks,
Rui

Hi Rui,

in this case this looks like you are entering the CATCH-Block even when there was no error and you are trying to rollback a transasction which has been already committed to the DB and therefore its transaction name is no longer valid.

Can you verify this, please?

BTW:
startTransaction does not require to specify the transaction name as input, just make sure you persist the output as input for commitTransaction and rollbackTransaction service invocations.

Regards,
Holger

Hi Holger,

Thanks for the input. I verified this and actually it’s the Commit Transaction method throwing the exception which then calls the Rollback Transaction. The error from the Commit Transaction is the same, where the transaction name doesn’t seem to be available.

Also, the transaction name is kept the same during the whole code block. I actually tried to hard code the transaction name in all transactions, but I keep having the same error message.