Trying to read mutiple cursor values in MyBatis and setting these values in DTO but getting error - ibatis

I am trying to read multiple cursor values in MyBatis and setting these values in DTO but getting an error. My SP returns 3 cursors and each cursor value I am trying to map with one DTO. Code follows
AccountDSSpMapper.xml
<resultMap type="com.Role_Test" id="Role">
<result property="roleID" column="Role_ID" />
<result property="accountID" column="Account_ID" />
<result property="roleName" column="Role_Name" />
<result property="roleDesc" column="Description" />
</resultMap>
<resultMap type="com.Feature_Test" id="Feature">
<result property="featureID" column="Feature_ID" />
<result property="featureName" column="Feature_Name" />
</resultMap>
<resultMap type="com.Privilege_Test" id="Privilege">
<result property="privilegeID" column="Privilege_ID" />
<result property="privilegeName" column="Privilege_Name" />
</resultMap>
<select id="roleResults" resultMap="Role,Feature,Privilege" statementType="CALLABLE">
{ call Get_RoleDetails(#{accountID, mode=IN, jdbcType=INTEGER}, #{roleID, mode=IN, jdbcType=INTEGER})}
</select>
AccountDSSpMapper.java
#MapKey("roleResults")
public List<List<ArrayList<Object>>> getRoleDetails(Integer accountID, Integer roleID);
Exception - java.lang.IllegalArgumentException: Mapped Statements
collection does not contain value for
com.AccountDSSpMapper.getRoleDetails
Can someone please suggest what's wrong here or correct way to deal with multiple cursor values in MyBatis.

Got this working with
<select id="getRoleDetails" resultMap="Role,Feature,Privilege" statementType="CALLABLE">
{ call Get_RoleDetails(#{accountID, mode=IN, jdbcType=INTEGER}, #{roleID, mode=IN, jdbcType=INTEGER})}
</select>
public List<List<ArrayList<Object>>> getRoleDetails(Integer accountID, Integer roleID);

Related

Searching a nested structure. Can not retrieve parents with all corresponding childs

The data is imported with the data import handler:
<dataConfig>
<dataSource
...
/>
<!-- product import -->
<document>
<!-- entity = table -->
<entity name="skn" pk="SKN" rootEntity="true" query="select * from skn">
<field column="SKN" name="id" />
<field column="root" name="root" />
<field column="SEARCHDESCRIPTION" name="SEARCHDESCRIPTION" />
<entity name="sku" child="true" query="select * from sku where SKN = '${skn.SKN}'">
<field column="SKU" name="id" />
<field column="variant1" name="variant1" />
<field column="variant2" name="variant2" />
<field column="v1_long" name="v1_long" />
<field column="v2_long" name="v2_long" />
<field column="v1_type" name="v1_type" />
<field column="v2_type" name="v2_type" />
</entity>
</entity>
<propertyWriter
dateFormat="yyyy-MM-dd HH:mm:ss"
type="SimplePropertiesWriter"
directory="conf"
filename="dataimport.properties"
locale="de-DE"
/>
</document>
</dataConfig>
I can get all childs for a certain parent or all parents for a certain child (so the nested structure is working). But I cannot retrive parents with the corresponding childs.
I tried the following query:
q={!parent which="id:1"}&fl=*,[child]&rows=200
It returns the parent document but not the corresponding child. I dont't get any error message. I also checked the log file.
Can anybody help?

Mybatis 3.1 returning only one row in XPATH SQL query

Mybatis 3.1 returning only one row as result of XPATH SQL query, but when running same query in Sql tools like DataGrip/SQLServerManagementStudio its giving 2 rows. I have verified that there are two matching rows as confirmed by running same query in DataGrip. I think there is some issue with mapping to data object or Mybatis not handling XPATH sql correctly.
Mapper Interface:
List<PIIData> getResponseContactInfoPII(#Param("accountIdVal") Long accountIdVal,
#Param("emailVal") String emailVal,
#Param("fNameVal") String fNameVal,
#Param("lNameVal") String lNameVal) throws SQLException;
Mapper query:
<select id="getResponseContactInfoPII" statementType="CALLABLE" resultMap="piiData" resultType="java.util.List">
SELECT
N.x.value('#firstname', 'nvarchar(60)') AS firstName,
N.x.value('#lastname', 'nvarchar(60)') AS lastName,
N.x.value('#title', 'nvarchar(60)') AS title,
N.x.value('#email', 'nvarchar(90)') AS email,
N.x.value('#phone', 'nvarchar(40)') AS phone,
'RFP_RESPONSE_CONTACT' as entityName,
'REF_RFP_OFFERING' as reference,
CAST(acct_id AS VARCHAR(100)) AS pkCol1,
CAST(rfp_stub AS VARCHAR(100)) AS pkCol2,
CAST(ofrg_stub AS VARCHAR(100)) AS pkCol3
FROM
(SELECT * FROM dbo.RFP_OFFERING WHERE ofrg_acct_id = #{accountIdVal}) AS RO
CROSS APPLY
<choose>
<when test="fNameVal != null and lNameVal != null">
RO.response_contact_info_xml.nodes('/ROOT/FIELD[#email="${emailVal}" and #firstname="${fNameVal}" and #lastname="${lNameVal}"]') AS N(x)
</when>
<when test="fNameVal != null and lNameVal == null">
RO.response_contact_info_xml.nodes('/ROOT/FIELD[#email="${emailVal}" and #firstname="${fNameVal}"]') AS N(x)
</when>
<when test="fNameVal == null and lNameVal != null">
RO.response_contact_info_xml.nodes('/ROOT/FIELD[#email="${emailVal}" and #lastname="${lNameVal}"]') AS N(x)
</when>
<otherwise>
RO.response_contact_info_xml.nodes('/ROOT/FIELD[#email="${emailVal}"]') AS N(x)
</otherwise>
</choose>
</select>
ResultMap:
<resultMap id="piiData" type="com.cvent.csngdpr.dbEntity.PIIData">
<result property = "firstName" column="firstName"/>
<result property = "lastName" column = "lastName" />
<result property = "address1" column = "address1" />
<result property = "address2" column = "address2" />
<result property = "address3" column = "address3" />
<result property = "cityName" column = "cityName" />
<result property = "email" column = "email" />
<result property = "stateName" column = "stateName" />
<result property = "countryName" column = "countryName" />
<result property = "stateCode" column = "stateCode" />
<result property = "postalCode" column = "postalCode" />
<result property = "countryCode" column = "countryCode" />
<result property = "title" column = "title" />
<result property = "phone" column = "phone" />
<result property = "mobile" column = "mobile" />
<result property = "fax" column = "fax" />
<result property = "ipAddress" column = "ipAddress" />
<result property = "additionalInfo" column = "additionalInfo" />
<result property = "zip" column = "zip" />
<result property = "entityName" column = "entityName" />
<result property = "reference" column = "reference" />
<association property="primaryKeys" resultMap="primaryKeysMap"/>
</resultMap>
<resultMap id="primaryKeysMap" type="map">
<result column="pkCol1" property="pkCol1"/>
<result column="pkCol2" property="pkCol2"/>
<result column="pkCol3" property="pkCol3"/>
<result column="pkCol4" property="pkCol4"/>
<result column="pkCol5" property="pkCol5"/>
</resultMap>
Data Model Object:
public class PIIData {
private String firstName;
private String lastName;
private String email;
private String address1;
private String address2;
private String address3;
private String cityName;
private String stateName;
private String countryName;
private String ipAddress;
private String entityName;
private String phone;
private String mobile;
private String title;
private String stateCode;
private String postalCode;
private String countryCode;
private String additionalInfo;
private String fax;
private String reference;
private String zip;
private Map<String, String> primaryKeys;
}
Luckily, I found this link that explains the issue. If all the columns except the association have same values then Mybatis de-duplicates the collection, thats why it was returning only one record.
I just changed resultMap configuration as
Replaced
<association property="primaryKeys" resultMap="primaryKeysMap"/>
with
<result property = "primaryKeys.pkCol1" column = "pkCol1" />
<result property = "primaryKeys.pkCol2" column = "pkCol2" />
<result property = "primaryKeys.pkCol3" column = "pkCol3" />
<result property = "primaryKeys.pkCol4" column = "pkCol4" />
<result property = "primaryKeys.pkCol5" column = "pkCol5" />
And removed
<resultMap id="primaryKeysMap" type="map">
<result column="pkCol1" property="pkCol1"/>
<result column="pkCol2" property="pkCol2"/>
<result column="pkCol3" property="pkCol3"/>
<result column="pkCol4" property="pkCol4"/>
<result column="pkCol5" property="pkCol5"/>
</resultMap>
Final configuration:
<resultMap id="piiData" type="com.cvent.csngdpr.dbEntity.PIIData">
<result property = "firstName" column="firstName"/>
<result property = "lastName" column = "lastName" />
<result property = "address1" column = "address1" />
<result property = "address2" column = "address2" />
<result property = "address3" column = "address3" />
<result property = "cityName" column = "cityName" />
<result property = "email" column = "email" />
<result property = "stateName" column = "stateName" />
<result property = "countryName" column = "countryName" />
<result property = "stateCode" column = "stateCode" />
<result property = "postalCode" column = "postalCode" />
<result property = "countryCode" column = "countryCode" />
<result property = "title" column = "title" />
<result property = "phone" column = "phone" />
<result property = "mobile" column = "mobile" />
<result property = "fax" column = "fax" />
<result property = "ipAddress" column = "ipAddress" />
<result property = "additionalInfo" column = "additionalInfo" />
<result property = "zip" column = "zip" />
<result property = "entityName" column = "entityName" />
<result property = "reference" column = "reference" />
<result property = "primaryKeys.pkCol1" column = "pkCol1" />
<result property = "primaryKeys.pkCol2" column = "pkCol2" />
<result property = "primaryKeys.pkCol3" column = "pkCol3" />
<result property = "primaryKeys.pkCol4" column = "pkCol4" />
<result property = "primaryKeys.pkCol5" column = "pkCol5" />
</resultMap>

DeltaImport fetches all the data

I'm indexing data from database. I'm using delta import to fetch the recently updated data. However, I find that it is fetching the whole data twice and processing it once though the changes are applicable to only one row.
My config.xml where deltaquery is given:
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.github.cassandra.jdbc.CassandraDriver" url="jdbc:c*://127.0.0.1:9042/test" autoCommit="true" rowLimit = '-1' batchSize="-1"/>
<document name="content">
<entity name="test" query="SELECT * from person" deltaImportQuery="select * from person where seq=${dataimporter.delta.seq}" deltaQuery="select seq from person where last_modified > '${dataimporter.last_index_time}' ALLOW FILTERING" autoCommit="true">
<field column="seq" name="id" />
<field column="last" name="last_s" />
<field column="first" name="first_s" />
<field column="city" name="city_s" />
<field column="zip" name="zip_s" />
<field column="street" name="street_s" />
<field column="age" name="age_s" />
<field column="state" name="state_s" />
<field column="dollar" name="dollar_s" />
<field column="pick" name="pick_s" />
</entity>
</document>
</dataConfig>
There are about 2100000 rows. So it always cause a large memory consumption resulting in Running Out of Memory. What could be the problem? Or does it work in this way only?
If solr is running out of memory then it is time to add more memory to the solr box. Adding more RAM will help alleviate the issue.

How to call a stored procedure with parameter from dataimporthandler

Hi can anybody tell me how to call a stored procedure with parameter in db-config.xml file.
I have a stored procedure which takes date time as a parameter and it returns me the rows which are created or modified after the specified parameter.
While trying to call that stored procedure from dataimporthandler i am not getting success.
My db-config.xml is like below
<dataConfig>
<dataSource type="JdbcDataSource" name="ds-1" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://DataBaseURL;databaseName=DBtest" user="sa" password="MyPassword" readOnly="True" />
<document>
<entity dataSource="ds-1" name="JobSeekerDetails" query="exec [SP_GetAllJobSeekerDetails] '${dih.last_index_time}'"
deltaImportQuery="exec [SP_GetAllJobSeekerDetails] '${dih.last_index_time}'"
deltaQuery="exec [SP_GetAllJobSeekerDetails] '${dih.last_index_time}'">
<field column="FName" name="FName" />
<field column="LName" name="LName" />
<field column="Exp_year" name="Exp_year" />
<field column="Exp_Month" name="Exp_Month" />
<field column="INDUSTRY" name="INDUSTRY" />
<field column="DESIREDPOSITION" name="DESIREDPOSITION" />
<field column="ROLE_NAME" name="ROLE_NAME" />
<field column="PHONE_NUMBER" name="PHONE_NUMBER" />
<field column="COUNTRY_NAME" name="COUNTRY_NAME" />
<field column="STATE_NAME" name="STATE_NAME" />
<field column="CITY_NAME" name="CITY_NAME" />
<field column="POSTAL_CODE" name="POSTAL_CODE" />
</entity>
</document>
</dataConfig>
Please help me to find out where i am doing mistakes.
Also i have tried without using exec key word inside query parameter.
Thanks in advance.

How to generate an Id using DataImportHandler?

I'm new in Solr and I'm struggling to import some XML Data which does not contain a ID field, although It's required as it says my schema.xml:
An XML example:
<results>
<estacions>
<estacio id="72400" nom="Aeroport"/>
<estacio id="79600" nom="Arenys de Mar"/>
...
</estacions>
</results>
Schema.xml:
<uniqueKey>id</uniqueKey>
At this point, I need to import this xml from http fetch, then I use DataimportHandler.
This is my data-config.xml
<dataConfig>
<dataSource type="URLDataSource" />
<document>
<entity name="renfe"
url="http://host_url/myexample.xml"
processor="XPathEntityProcessor"
forEach="/results/estacions/estacio"
transformer="script:generateCustomId">
<field column="idestacio" xpath="/results/estacions/estacio/#id" commonField="true" />
<field column="nomestacio" xpath="/results/estacions/estacio/#nom" commonField="true" />
</entity>
</document>
Then, it seems to work properly, but I got the following error:
org.apache.solr.common.SolrException: [doc=null] missing required field: id
This makes me think that I should generate an automatic id while importing, and by using the data-config.xml, but I don't reach to see how to do it.
How should I do? Using a ScriptTransformer? Any idea is grateful
And another question: Can I force a value during the import ?
For ex: <field column="site" value="estacions"/> (obviously this does not work)
You can use code below to generate ID:
<dataConfig>
<script><![CDATA[
id = 1;
function GenerateId(row) {
row.put('id', (id ++).toFixed());
return row;
}
]]></script>
<dataSource type="URLDataSource" />
<document>
<entity name="renfe"
url="http://host_url/myexample.xml"
processor="XPathEntityProcessor"
forEach="/results/estacions/estacio"
transformer="script:GenerateId">
<field column="idestacio" xpath="/results/estacions/estacio/#id" commonField="true" />
<field column="nomestacio" xpath="/results/estacions/estacio/#nom" commonField="true" />
</entity>
</document>

Resources