In this post under Spring Batch, I will explain the purpose and how to use JsonRecordSeparatorPolicy class with an example. JsonRecordSeparatorPolicy class is a concrete implementation of org.springframework.batch.item.file.separator.RecordSeparatorPolicy interface. In one of my previous post I have explained the purpose of RecordSeparatorPolicy and how to use it. For recap, RecordSeparatorPolicy interface is used to tell…… Continue reading JsonRecordSeparatorPolicy example
Month: March 2019
Deleting a persisted object
In this post under hibrenate, I will explain how to delete a persisted object. We can delete a persisted object using Session interface delete method. Below is the complete code Main Class 1 import org.hibernate.Session; 2 import org.hibernate.SessionFactory; 3 4 public class HibernateDemo9 { 5 public static void main(String[] args) { 6 SessionFactory sessionFactory =…… Continue reading Deleting a persisted object
Session’s load vs get method
In this post under hibernate, I will introduce you to Session’s load and get method and explain their difference. Similarity 1) Both methods are used to load persistent object from the database 2) Both needs primary key id as a parameter Difference 1) If the persistent object identified by primary key is not there, then…… Continue reading Session’s load vs get method
Loading a Persistent Object
In this post under hibernate, I will explain how to load a persistent object from the database. We load a persistent object using Session interface “load” method. Several overloadded version of the “load” method exists, all these methods require the primary key id of the object to be loaded. Below is the complete code Main…… Continue reading Loading a Persistent Object
Custom Error Handling when parsing xml through SAX api
In this post under JAXP, I will explain how to add custom error handler when parsing xml document through SAX api. To provie a custom error handler, we need to implement the interface org.xml.sax.ErrorHandler as shown below package sax; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class CustomErrorHandler implements ErrorHandler { @Override public void error(SAXParseException…… Continue reading Custom Error Handling when parsing xml through SAX api
Rotating File Handler
In this post under logging, I will show how to create a rotating file handler. A rotating file handler create a set of files, with each file having a count in the file name indicating the total number of files created. Each file has a size limit, which when reached a new file is created…… Continue reading Rotating File Handler
Java Util Logging ErrorManager example
In this post under java logging, I will explain the purpose of ErrorManager and how we can use it. Whenever we write the below code logger.info(“Hello my name is Sumanth1”); We are requesting the Handler to log the message to a destination. What if an error happens at the Handler level when an attempt is…… Continue reading Java Util Logging ErrorManager example
JsonLineMapper Example
In this post under Spring Batch, I will explain the purpose of JsonLineMapper with an example. JsonLineMapper is used with reader bean for reading file containing JSON input as shown below JsonFileInput.txt {“id”:”id0″,”name”:”name0″,”status”:”status0″,”salary”:0}{“id”:”id1″,”name”:”name1″,”status”:”status1″,”salary”:1}{“id”:”id2″,”name”:”name2″,”status”:”status2″,”salary”:2}{“id”:”id3″,”name”:”name3″,”status”:”status3″,”salary”:3}{“id”:”id4″,”name”:”name4″,”status”:”status4″,”salary”:4}{“id”:”id5″,”name”:”name5″,”status”:”status5″,”salary”:5}{“id”:”id6″,”name”:”name6″,”status”:”status6″,”salary”:6}{“id”:”id7″,”name”:”name7″,”status”:”status7″,”salary”:7}{“id”:”id8″,”name”:”name8″,”status”:”status8″,”salary”:8}{“id”:”id9″,”name”:”name9″,”status”:”status9″,”salary”:9} Each line in the file is interpreted as a JSON object by JsonLineMapper. So each line must start with “{” and end…… Continue reading JsonLineMapper Example
Formatting batch file output
In this post under Spring Batch, I will show how to create batch files with formatted output. The example I use will generate output file where the width of the each fields are fixed. In all my previous posts under Spring Batch, the output of the examples generated will be as shown below Current Output…… Continue reading Formatting batch file output