mybatis interceptor sql log process - mybatis

i make mybatis sqllog intercepor in my project.
in case. #{__frch_CUST_0} #{__frch_CUST_1} ~~~ #{__frch_CUST_N}
how can i get parameters value "__frch_CUST_n" ?
// mybatis interceptor sql log function
public String getSqlLog(StatementHandler handler)
{
String sql = handler.getBoundSql().getSql();
Object param = handler.getParameterHandler().getParameterObject();
List<ParameterMapping> paramMapping = handler.getBoundSql().getParameterMappings();
// change \? value to replace point
for(ParameterMapping mapping:paramMapping)
{
sql = sql.replaceFirst("\\?", "#{"+mapping.getProperty()+"}");
}
for(ParameterMapping mapping:paramMapping)
{
String sqlparam = "#{"+mapping.getProperty()+"}";
String sqlparamname = mapping.getProperty();
Object sqlparamvalue = ((Map) param).get(sqlparamname);
if( !sqlparamname.startsWith("__frch_") )
{
if(isNull(sqlparamvalue))
{
sql = sql.replace(sqlparam, "NULL");
}
else
{
if(sqlparamvalue instanceof String)
{
try
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
catch(Exception e)
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
}
else
{
sql = sql.replace(sqlparam, sqlparamvalue.toString());
}
}
}
else
{
**// HOW CAN I DO HERE?**
}
}
return sql;
}
thank you for read my question..

i resolve my self.
mybatis make new arrayList parameter. and use it.
example list value
DATE = ['20180101','20180102','20180103'];
STEP = ['PLAN', 'MAKE', 'SETUP'];
__frch_DATE_0
__frch_DATE_1
__frch_DATE_2
__frch_STEP_3
__frch_STEP_4
__frch_STEP_5
mybatis __frch_ = ['20180101','20180102','20180103','PLAN', 'MAKE', 'SETUP']
so i use it. my question is resolved..
public String getSqlLog(StatementHandler handler)
{
String sql = handler.getBoundSql().getSql();
Object param = handler.getParameterHandler().getParameterObject();
List<ParameterMapping> paramMapping = handler.getBoundSql().getParameterMappings();
List foreachlist = new ArrayList();
for(ParameterMapping mapping:paramMapping)
{
sql = sql.replaceFirst("\\?", "#{"+mapping.getProperty()+"}");
}
for(ParameterMapping mapping:paramMapping)
{
String sqlparam = "#{"+mapping.getProperty()+"}";
String sqlparamname = mapping.getProperty();
Object sqlparamvalue = ((Map) param).get(sqlparamname);
if( !sqlparamname.startsWith("__frch_") )
{
if(isNull(sqlparamvalue))
{
sql = sql.replace(sqlparam, "NULL");
}
else
{
if(sqlparamvalue instanceof String)
{
try
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
catch(Exception e)
{
sql = sql.replace(sqlparam, "'"+getSQLString(sqlparamvalue.toString())+"'");
}
}
else
{
sql = sql.replace(sqlparam, sqlparamvalue.toString());
}
}
}
else
{
if( foreachlist.size() == 0 )
{
Map parammap = (Map)param;
Iterator iterator = parammap.keySet().iterator();
while(iterator.hasNext())
{
String key = iterator.next().toString();
Object value = (Object)parammap.get(key);
if( value instanceof List )
{
List valuelist = (List)value;
for(int i=0;i<valuelist.size();i++)
{
foreachlist.add(valuelist.get(i));
}
}
}
}
String buff = sqlparamname.split("__frch_")[1];
int index = Integer.parseInt(buff.substring(buff.lastIndexOf("_")+1));
try
{
sql = sql.replace(sqlparam, "'"+getSQLString((String)foreachlist.get(index))+"'");
}
catch(Exception e)
{
;
}
}
}
return sql;
}

Related

SOAP service exception after second call

I created a SOAP service that fetches some data from a remote server.
After second call I always get an exception:
stackTrace: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
Any ideas what could be wrong?
function getInstance () {
return LocalServiceRegistry.createService('SaveNewCustomerService', new SaveNewCustomerServiceObject());
}
function SaveNewCustomerServiceObject() {};
SaveNewCustomerServiceObject.prototype.initServiceClient = function() {
this.webReference = webreferences.CustomerWS;
return this.webReference.getDefaultService();
}
SaveNewCustomerServiceObject.prototype.createRequest = function(svc, params) {
return params;
}
SaveNewCustomerServiceObject.prototype.execute = function(svc, requestObject) {
var customerRequestObjTest = new webreferences.CustomerWS.SaveNewCustomer();
if (requestObject != null) {
setObj(); //reduced
}
var result;
try{
result = svc.serviceClient.saveNewCustomer(customerRequestObjTest);
var a =result;
}catch(ex){
var e = ex; //
if(e.faultString == "Import error"){
log.info("Import error" + e.faultDetail);
}else{
log.info(e.faultDetail);
}
}
return result;
}
SaveNewCustomerServiceObject.prototype.parseResponse = function(svc, responseObject) {
return responseObject;
}

DB2ResultSet.Read(). ERROR [24000] [IBM] CLI0115E Invalid cursor state. SQLSTATE=24000

We have problem with the application run DB2ResultSet.Read(). Sometime will get ERROR :
[24000] [IBM] CLI0115E Invalid cursor state. SQLSTATE=24000.
Database : DB2 for Linux, UNIX and Windows V10.5
Client: Windows 7 64bit
Method:
public int EventGetEvSegmentCnt(string SegmentID, string strEvntGroup)
{
int strGroupCnt = 0;
string strSQL = string.Empty;`enter code here`
DB2ResultSet objRs;
if (string.IsNullOrEmpty(SegmentID) || string.IsNullOrEmpty(strEvntGroup))
{
strGroupCnt = 0;
}
else
{
strSQL = " SELECT COUNT(EVNT_CODE) AS EVNT_GROUP_COUNT FROM E_SEGMENT_EVENT WHERE C_SEGMENT_ID = " + SegmentID + " AND EVNT_GROUP = " + strEvntGroup;
Common.DatabaseHelper helper = new Common.DatabaseHelper();
objRs = helper.ExecuteResultSet(strSQL);
if (objRs.Read())
{
strGroupCnt = 0;
}
else
{
strGroupCnt = int.Parse(objRs["EVNT_GROUP_COUNT"].ToString());
}
}
return strGroupCnt;
}
Error Message:
[Information] System.Web.HttpUnhandledException (0x80004005):
Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> IBM.Data.DB2.DB2Exception (0x80004005): ERROR [24000] [IBM] CLI0115E Invalid cursor state. SQLSTATE=24000
at IBM.Data.DB2.DB2DataBuffer.FetchScroll(FetchType fetchType, Int64 offset, Int32 numRows)
at IBM.Data.DB2.DB2DataBuffer.FetchNext()
at IBM.Data.DB2.DB2DataReader.Fetch(FetchDirection direction, Int64 offset, Boolean& isDeleted)
at IBM.Data.DB2.DB2ResultSet.Read()
Please help.
DatabaseHelper:
public class DatabaseHelper
{
public DatabaseHelper()
{
}
public DataSet ExecuteDataSet(string commandText, List<DB2Parameter> parameters = null)
{
var command = GetCommand(commandText, parameters);
var adapter = new DB2DataAdapter();
adapter.SelectCommand = command;
var ds = new DataSet();
adapter.Fill(ds);
adapter.Dispose();
return ds;
}
public DB2DataReader ExecuteReader(string commandText, List<DB2Parameter> parameters = null)
{
var command = GetCommand(commandText, parameters);
return command.ExecuteReader(CommandBehavior.CloseConnection);
}
public DB2ResultSet ExecuteResultSet(string commandText, List<DB2Parameter> parameters = null)
{
var command = GetCommand(commandText, parameters);
//DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.Default, DB2CursorType.Dynamic);
DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.CloseConnection, DB2CursorType.Dynamic);
return result;
}
public DB2ResultSet ExecuteResultSetStatic(string commandText, List<DB2Parameter> parameters = null)
{
var command = GetCommand(commandText, parameters);
// DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.Default, DB2CursorType.Static);
DB2ResultSet result = command.ExecuteResultSet(CommandBehavior.CloseConnection, DB2CursorType.Static);
return result;
}
public int ExecuteNonQuery(string commandText, List<DB2Parameter> parameters = null)
{
var command = GetCommand(commandText, parameters);
int result = command.ExecuteNonQuery();
command.Connection.Close();
return result;
}
public void ExecuteSQLArray(string[] arrSQL)
{
var command = new DB2Command();
command.Connection = GetConnection();
command.CommandType = CommandType.Text;
command.CommandTimeout = 600;
command.Transaction = command.Connection.BeginTransaction();
try
{
foreach (string strSQL in arrSQL)
{
if (!string.IsNullOrEmpty(strSQL))
{
command.CommandText = strSQL;
command.ExecuteNonQuery();
}
}
command.Transaction.Commit();
}
catch (Exception)
{
command.Transaction.Rollback();
throw;
}
command.Connection.Close();
command.Dispose();
}
public DB2Connection GetConnection()
{
var conn = new DB2Connection(System.Configuration.ConfigurationManager.ConnectionStrings["DB2_Conn"].ConnectionString);
conn.Open();
return conn;
}
public DB2Command GetCommand(string commandText, List<DB2Parameter> parameters)
{
var command = new DB2Command(commandText);
command.Connection = GetConnection();
command.CommandTimeout = 600;
if (parameters != null)
{
foreach (var parameter in parameters)
{
command.Parameters.Add(parameter);
}
}
return command;
}
}
try this :
public int EventGetEvSegmentCnt(string SegmentID, string strEvntGroup)
{
if (string.IsNullOrEmpty(SegmentID) || string.IsNullOrEmpty(strEvntGroup)) return 0;
int strGroupCnt = 0;
DataSet objDS=null;
string strSQL = string.Format(" SELECT COUNT(EVNT_CODE) AS EVNT_GROUP_COUNT FROM E_SEGMENT_EVENT WHERE C_SEGMENT_ID ={0} AND EVNT_GROUP = {0}", SegmentID, strEvntGroup);
try
{
Common.DatabaseHelper helper = new Common.DatabaseHelper();
objDS = helper.ExecuteDataSet(strSQL);
if (objRs.Table[0].Rows.Count > 0)
{
strGroupCnt = int.Parse(objDS.Tables[0].Rows[0]["EVNT_GROUP_COUNT"].ToString());
}
}
finally
{
if (objDS != null) objDS.Dispose()
return strGroupCnt;
}
}

E4X to JSON conversion fails for duplicate xml elements

Kindly see below code I am using to convert Mirth xml to JSON.
function E4XtoJSON(xml, ignored) {
var r, children = xml.*, attributes = xml.#*, length = children.length();
if(length == 0) {
r = xml.toString();
} else if(length == 1) {
var text = xml.text().toString();
if(text) {
r = text;
}
}
if(r == undefined) {
r = {};
for each (var child in children) {
var name = child.localName();
var json = E4XtoJSON(child, ignored);
var value = r[name];
if(value) {
if(value.length) {
value.push(json);
} else {
r[name] = [value, json]
}
} else {
r[name] = json;
}
}
}
if(attributes.length()) {
var a = {}, c = 0;
for each (var attribute in attributes) {
var name = attribute.localName();
if(ignored && ignored.indexOf(name) == -1) {
a["_" + name] = attribute.toString();
c ++;
}
}
if(c) {
if(r) a._ = r;
return a;
}
}
return r;
}
My concern is
<AdditionalMessageInformationCount AdditionalMessageInformationCount="02"><AdditionalMessageInformationQualifier>01</AdditionalMessageInformationQualifier><AdditionalMessageInformation>MEMBER MUST USE MAIL ORDER.</AdditionalMessageInformation><AdditionalMessageInformationQualifier>02</AdditionalMessageInformationQualifier><AdditionalMessageInformation>PLAN LIMITATIONS EXCEEDED</AdditionalMessageInformation></AdditionalMessageInformationCount>
Here AdditionalMessageInformation elemt is used two times so function fails to create JSON.
Kindly help if anyone have converted XML in json usingg javascript code not any API
We've had success with this version:
function E4XtoJSON(xml, ignored){
var r, children = xml.*,
attributes = xml.# * ,
length = children.length();
if (length == 0)
{
r = xml.toString();
}
else if (length == 1)
{
var text = xml.text().toString();
if (text)
{
r = text;
}
}
if (r == undefined)
{
r = {};
for each(var child in children)
{
var name = child.localName();
var json = E4XtoJSON(child, ignored);
var value = r[name];
if (value)
{
if (value instanceof Array)
{
value.push(json);
}
else
{
r[name] = [value, json]
}
}
else
{
r[name] = json;
}
}
}
if (attributes.length())
{
var a = {},
c = 0;
for each(var attribute in attributes)
{
var name = attribute.localName();
if (ignored && ignored.indexOf(name) == -1)
{
a["_" + name] = attribute.toString();
c++;
}
}
if (c)
{
if (r) a._ = r;
return a;
}
}
return r;
}
With the release of Mirth Connect version 3.3.0, you can use Mirth Connect to set your channel's interior data type to JSON. This will all be done for you.

Add OR condition to query

I am wondering how it is possible to add an OR condition to the Envers criteria api:
public IEnumerable<Guid> GetHistory(object id, params string[] props)
{
var auditQuery = AuditReaderFactory.Get(Session).CreateQuery()
.ForRevisionsOfEntity(typeof(T), false, true);
foreach (var prop in props)
{
auditQuery.Add(AuditEntity.RelatedId(prop).Eq(id)); // <-- adds AND, while OR is required!
}
return auditQuery
.GetResultList<object[]>()
.Select(i => ((T)i[0]).ID)
.Distinct();
}
Use AuditEntity.Disjunction().
In your example, something like...
[..]
var disjunction = AuditEntity.Disjunction();
foreach (var prop in props)
{
disjunction.Add(AuditEntity.RelatedId(prop).Eq(id));
}
auditQuery.Add(disjunction);
[..]
I did like this in Java as #Roger mentioned above. (Just in case if anybody needs)
public List<Employee> getAuditHistory(Session session, int id, String property) {
AuditReader auditReader = AuditReaderFactory.get(session);
List<Employee> employeeHistory = new ArrayList<>();
if (auditReader != null) {
AuditQuery auditQuery = auditReader.createQuery().forRevisionsOfEntity(Employee.class, true, false)
.add(AuditEntity.property(ResultsConstants.Employee_ID).eq(id));
AuditDisjunction auditDisjunction = null;
if (property.equalsIgnoreCase("FULL_NAME")) {
auditDisjunction = AuditEntity.disjunction().add(AuditEntity.property("FIRST_NAME".toUpperCase()).hasChanged())
.add(AuditEntity.property("LAST_NAME".toUpperCase()).hasChanged());
} else {
auditQuery = auditQuery.add(AuditEntity.property(property.toUpperCase()).hasChanged());
}
auditQuery = auditQuery.addOrder(AuditEntity.property("MODIFIED_DATE").desc());
if(null != auditDisjunction){
auditQuery = auditQuery.add(auditDisjunction);
}
if (auditQuery != null) {
if (auditQuery.getResultList().isEmpty()) {
// Log here or throw it back to caller
}
employeeHistory.addAll(auditQuery.getResultList());
}
}
return employeeHistory;
}

Selecting a value from a database an check if it is true or false

This code always returns true can some please help me out
public boolean plselct(String sqd)
{
try{
String player ;
pm = conn.prepareStatement("SELECT playertype FROM playerdetails where idplayeratrr = ?");
pm.setString(1,sqd );
h= pm.executeQuery();
player = h.getString("playertype");
if ("Goal keeper".equals(player))
{ return true; }
else
return false;
}catch (Exception e)
{}
return false;
}
SelectQu p = new SelectQu();
p.plselct("77");
if(true)
{ System.out.println("Yes"); }
else
{ System.out.println("No"); }
You are checking for if(true)? Did you mean this instead:
SelectQu p = new SelectQu();
if(p.plselct("77"))
{
System.out.println("Yes");
}
else
{
System.out.println("No");
}