Mybatis update xml return affected rows count - mybatis

What's the problem:
I hope get a procedure return value which only has a few update sql like below.
<update id="updateSingleW11MeetingKeyTmp" parameterType="com.cisco.wbx11.db.meetingmigration.wbx11.migrationmeeting.vo.MappingVO">
{call
declare
begin
update mtgconference <set> meetingtoolsid= #{w11mkTmp,jdbcType=NUMERIC} </set>
where siteid=#{w11SiteId,jdbcType=NUMERIC} and hostid=#{w11Uid,jdbcType=NUMERIC} and meetingtoolsid=#{wbxmk,jdbcType=NUMERIC};
update wbxcalendar <set> confkey= #{w11mkTmp,jdbcType=NUMERIC} </set>
where siteid=#{w11SiteId,jdbcType=NUMERIC} and hostid=#{w11Uid,jdbcType=NUMERIC} and confkey=#{wbxmk,jdbcType=NUMERIC};
update wbxconferencekey <set> confkey= #{w11mkTmp,jdbcType=NUMERIC} </set>
where siteid=#{w11SiteId,jdbcType=NUMERIC} and confkey=#{wbxmk,jdbcType=NUMERIC};
update WBXREPEATEREXCEPTION set CONFKEY = #{w11mkTmp,jdbcType=NUMERIC}
where siteid=#{w11SiteId,jdbcType=NUMERIC} and CONFKEY=#{wbxmk,jdbcType=NUMERIC};
end
}
</update>
I called this with mapper in Java code, but the return is not expected
public Integer updateSingleW11MeetingKeyTmp(MappingVO vo) {
return mapper().updateSingleW11MeetingKeyTmp(vo);
}

Related

Executing PostgreSQL Stored Procedure using Spring Data - JdbcTemplate

I am trying to call a PostgreSQL Stored Procedure from Spring Data JdbcTemplate. The following are the error and code block. Appreciate if any one can help.
Stored procedure
CREATE or replace PROCEDURE getRecord (
IN in_id INTEGER,
OUT out_name VARCHAR(20),
OUT out_age INTEGER)
language plpgsql
as $$
BEGIN
SELECT name, age
INTO out_name, out_age
FROM Student where id = in_id;
END
$$
Springboot Code
SimpleJdbcCall simpleJdbcCall;
dataSource = jdbcTemplate.getDataSource();
simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName("getrecord");
SqlParameterSource in = new MapSqlParameterSource().addValue("in_id",24);
try {
Map<String, Object> out = simpleJdbcCall.execute(in);
if (out != null){
System.out.println("A record found");
}
else
{
System.out.println("No record found");
}
}
catch (Exception e){
System.out.println(e.getMessage());
}
Error
CallableStatementCallback; bad SQL grammar [{call getrecord(?, ?, ?)}]; nested exception is org.postgresql.util.PSQLException: ERROR: getrecord(integer) is a procedure
Hint: To call a procedure, use CALL.
Position: 15
Note:
The stored procedure is having three parameters - one IN and two Out Parameters.
After going through few tutorials, I had observed that, only in parameter is being passed to the stored procedure call rather than all 3 parameters, because only the first parameter is IN and the rest of two are OUT parameters.
For example:
https://www.tutorialspoint.com/springjdbc/springjdbc_stored_procedure.htm
https://mkyong.com/spring-boot/spring-boot-jdbc-stored-procedure-examples/

How to tranverse through the SOAP response in eSQL

I am new to ESQL programming language, I need bit a small help in writing it.
I have a requirement in IIB where in I receive SOAP response from SOAP Request node and send the transformed message to MQ queue.
Below is the sample input
<Response xmlns="http://www.xyz.fr/Retail/1.0">
<Result xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Output>
<Element>
<Notification>{ "employee": { "name": "sonoo", "salary": 56000, "married": true } } </Notification>
<collegeID>345</collegeID>
</Element>
<Element>
<Notification> { "employee": { "name": "sonoo", "salary": 56000, "married": true } }</Notification>
<collegeID>123</collegeID>
</Element>
</Output>
</Result>
</Response>
Below is the code which I have written
CREATE COMPUTE MODULE Compute1
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
DECLARE myref REFERENCE TO InputRoot.XMLNSC.Response.Result.Output;
DECLARE Count INT CARDINALITY(myref.Element[]);
DECLARE i INT 1;
WHILE (i<=Count)DO
SET OutputRoot.JSON.Data = FIELDVALUE(myref.Element[i].Notification);
SET i = i + 1;
PROPAGATE TO TERMINAL 'out' DELETE NONE;
END WHIlE;
RETURN TRUE;
END;
CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = CARDINALITY(InputRoot.*[]);
WHILE I < J DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I = I + 1;
END WHILE;
END;
CREATE PROCEDURE CopyEntireMessage() BEGIN
SET OutputRoot = InputRoot;
PROPAGATE TO TERMINAL 'out1' DELETE NONE;
END;
END MODULE;
In 'Count' variable I am not able to see the value, it is always showing '0'.
Count =0 but it should be 2 as per the input message.
In the input from 'Notification' field, I need to send JSON message to MQ queue using MQ Output node.
Could you please suggest is it because of namespace tagged with 'Response' field tag which I am not able to retrieve the count?

System.QueryException: List has no rows for assignment to SObject

I want update list of opportunities using visualforce page.In visualforce page I want to update Amount,close date and Stage.The visulaforce page should only show all open opportunities(STAGE NOT EQUALS TO CLOSED WON AND CLOSED LOST).
Anyone help me to fix this error and update only all open opportunities.
Here is my code:
Apex
public class UpdateListofOppty {
public Opportunity opportunities {get;set;}
public Id recId{get;set;}
public UpdateListofOpporunity(ApexPages.StandardSetController sc){
recId = ApexPages.CurrentPage().getParameters().get('id');
opportunities = [SELECT Name,Amount,StageName FROM opportunity WHERE Id = :recId AND StageName NOT IN ('Closed Lost', 'Closed Won')];
}
public Opportunity getOpptyDetail(){
return opportunities;
}
public PageReference Save() {
try{
update(opportunities);
}
catch(System.DmlException e){
ApexPages.addMessages(e);
return null;
}
PageReference view = new ApexPages.StandardController(opportunities).view();
return (view);
}
}
VF Page
<apex:page standardController="Opportunity" extensions="UpdateListofOppty" recordSetVar="opportunities" tabStyle="Opportunity" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!opportunities}" var="opp">
<apex:column value="{!opp.name}"/>
<apex:column headerValue="Amount">
<apex:inputField value="{!opp.Amount}"/>
</apex:column>
<apex:column headerValue="Close Date">
<apex:inputField value="{!opp.CloseDate}"/>
</apex:column>
<apex:column headerValue="Stage">
<apex:inputField value="{!opp.stageName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
ERROR:
System.QueryException: List has no rows for assignment to SObject
Error shown in this line:
opportunities = [SELECT Name,Amount,StageName FROM opportunity WHERE Id = :recId AND StageName NOT IN ('Closed Lost', 'Closed Won')];
I suspect your id parameter is not passed through so it's a null. Querying Opportunities WHERE Id = null will always return zero results. Or maybe it's being passed but it's useless. If you have StandardSetController the Id value in the page URL might be used as filter id (listview), not an id of any particular record. Meaning query will still return 0 rows.
What were you trying to do? Maybe just removing that part of condition will help although this list can grow very fast. You might want to put a LIMIT statement in the query or read about StandardSetController and pagination.

Contructor MongoDB.Bson.ObjectId() does not work in .NET Core 2

I have a first project who tries to get a value from mongodb using MongoDB.Driver. I can connect to the database and "GetAll" but when make a request who need ObjectId i receive that Exception:
Exception has occurred: CLR/System.IndexOutOfRangeException
An exception of type 'System.IndexOutOfRangeException' occurred in MongoDB.Bson.dll but was not handled in user code: 'Index was outside the bounds of the array.'
being more specific:
at MongoDB.Bson.ObjectId.FromByteArray(Byte[] bytes, Int32 offset, Int32& a, Int32& b, Int32& c)
at MongoDB.Bson.ObjectId..ctor(String value)
at TodoApi.Controllers.TodoController.GetById(String id) ...
Method GetById:
[HttpGet("{id}", Name = "GetTodo")]
public IActionResult GetById(string id)
{
var objId = new ObjectId(id); << this line exceptions occures
var item = objds.GetTodoItem(objId);
if (item == null) { return NotFound(); }
return new ObjectResult(item);
}
Methodo GetTodoItem from DataAcess:
public TodoItem GetTodoItem(ObjectId id)
{
var res = Query<TodoItem>.EQ(p=>p.Id,id);
return _db.GetCollection<TodoItem>("TodoApi").FindOne(res);
}
.csproj
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver.Core" Version="2.5.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.5.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="mongocsharpdriver" Version="2.5.0" />
</ItemGroup>
You can generate a new ObjectId like this:
ObjectId.GenerateNewId();
But most likely you will not find any document in your database with that id. Usually, you generate an ObjectId when you want to do an Insert and do not want Mongo to assign a random id to your newly inserted document (let's say you want to return that id back to the user).
Now, assuming you are looking for a specific document with id = 5a71ae10a41e1656a4a50902, you can do as follows:
var id = "5a71ae10a41e1656a4a50902";
var context = new YourContext();
var builder = Builders<TodoItem>.Filter;
var filter = builder.Eq(x => x.Id, ObjectId.Parse(id));
var result = await context.TodoItemCollection.FindAsync(filter);
The problem is the line about create new objectID. mongoDB supplies default document IDs automatically, and you just first, find the ID then query the collection using that.
Off course you can change the default behaviour - see
http://codingcanvas.com/using-mongodb-_id-field-with-c-pocos/
Change this line:
var objId = new ObjectId(id);
To something like this (you have to change the objectid.Parse() argument to your values.
var query_id = Query.EQ("_id",
ObjectId.Parse("50ed4e7d5baffd13a44d0153"));
var entity = dbCollection.FindOne(query_id);
return entity.ToString();
Also, this line has typo, did you meant objId after the = sign?
var item = objds.GetTodoItem(objId)
Credits:
Query MongoDB Using 'ObjectId'

Entity Framework Procedure Error - Silverlight, EF, Oracle

Error Message:
The data reader returned by the store data provider does not have enough columns for the query requested.
public ObjectResult<global::System.String> P_GET_MST_CODE(global::System.String i_RES_TYPE, ObjectParameter v_RESULT)
{
ObjectParameter i_RES_TYPEParameter;
if (i_RES_TYPE != null)
{
i_RES_TYPEParameter = new ObjectParameter("I_RES_TYPE", i_RES_TYPE);
}
else
{
i_RES_TYPEParameter = new ObjectParameter("I_RES_TYPE", typeof(global::System.String));
}
return base.ExecuteFunction<global::System.String>("P_GET_MST_CODE", i_RES_TYPEParameter, v_RESULT);
}
Below is the definition of the stored procedure.
<Function Name="P_GET_MST_CODE" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="LEGACY">
<Parameter Name="I_RES_TYPE" Type="varchar2" Mode="In" />
<Parameter Name="V_RESULT" Type="varchar2" Mode="Out" />
</Function>
Can anyone help me to solve this problem?
I've solved this by avoiding entity connection object. :-)
Until now, It seems to be unsupported for OUT Parameter of ORACLE Database.
Below is the changed code example.
using System.Data;
using System.Data.Common;
using System.Data.EntityClient;
using System.ServiceModel.DomainServices.EntityFramework;
using System.ServiceModel.DomainServices.Server;
using Oracle.DataAccess.Client;
.......
[Invoke]
public string method(string OTL)
{
DbCommand cmd = (((EntityConnection)this.ObjectContext.Connection).StoreConnection).CreateCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "LoveMe";
OracleParameter ep = new OracleParameter("I_RES_TYPE", OTL);
ep.OracleDbType = OracleDbType.Varchar2;
ep.Direction = ParameterDirection.Input;
OracleParameter epV_RESULT = new OracleParameter("V_RESULT", null);
epV_RESULT.OracleDbType = OracleDbType.Varchar2;
epV_RESULT.Size = 30;
epV_RESULT.Direction = ParameterDirection.Output;
cmd.Parameters.Add(ep);
cmd.Parameters.Add(epV_RESULT);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
string result = cmd.Parameters[1].Value.ToString(); //What I want to get.
cmd.Connection.Close();
return result;
}