How to use Spring DataSource bean as data source for Log4j 2 JDBC appender

Posted in IT StuffTagged , ,

I would like to log log4j2 messages into a relational database using the datasource defined on application context and initialized using spring using log4j 2.10. One possibility is to add a JDBC appender inside log4j2 xml configuration but, Log4j is initialized before Spring so, dataSource won’t be available at runtime so the only solution is….

Parse an unknown JSON with Jquery

Posted in IT StuffTagged , , ,

Sometime it happens to receive a JSON string than need to be visualized without knowing the structure. Suppose we have an HTML table: <tbody id="reportTable"> </tbody><tbody id="reportTable"> </tbody> To populate this table with jQuery it’s possible to use this simple code: var rows = ${reportRows}; var html = $.each(rows, function(key, value){   $("#reportTable").append("<tr>");   $.each(value,….

MongoDB query with logical and condition in Java

Posted in IT StuffTagged , ,

Suppose you need to apply some filters to your MongoDB query, for example to extract some _ids that match a regex condition. This is the way to do that: Query query; query.addCriteria(Criteria.where("_id").in(IDs).and(query_field).regex(".*" + query_value + ".*", "i"));Query query; query.addCriteria(Criteria.where("_id").in(IDs).and(query_field).regex(".*" + query_value + ".*", "i")); In this example I used the Query (see here) and Criteria….