The tutorial Spring Data JPA Entity Auditing using EntityListeners will show you how you persist the audit log using JPA’s built-in functionality. Spring Data JPA provides sophisticated support to transparently keep track of who created or changed an entity and at what time. To benefit from this functionality you have to equip your entity classes with auditing metadata that can be defined either using annotations or by implementing an interface.
Spring Data JPA Batch Insertion will show you how we can insert a large dataset into a database at once using Spring Data JPA. For this tutorial we will create a Spring Boot project in Eclipse. We will also see how Spring @Transactional annotation works. Spring transaction required in order to rollback the inserted data at any point if your application fails for any reason.
Sometimes we need to insert or update large number of records in the database. It’s not a good idea to insert multiple records into database one by one in a traditional approach. It will hit the application’s performance. Spring provides batch operations with the help of JpaRepository or CrudRepository, it inserts or updates records into database in one shot. You can also use JDBC API to insert multiple records or batch insertion into database but here we will use Spring JPA’s built-in functionality to get benefits of Spring API.
By default Spring does not save your data into database when you call save() method with multiple entities (a list of objects) passed as argument, hence you have to save entities one by one, which is time consuming and performance gets affected. For this there are few properties that need to be configured to let Spring Data JPA work on batch insertion into database. We will see how these properties set during creation of database configuration class below.
Generic way of reading Excel file using Apache POI is a way of reading excel file in a dynamic configurable way to read an excel file where in future if you add more columns or remove columns from excel then you don’t need to almost touch the Java source code but you change the configurations that makes your life easier. Here we will see how we can define configurations in JSON file and read the excel file using Apache POI to establish mapping between JSON and Java POJO.
We have also seen Generic way of Excel file writing using Apache POI.
Obviously whenever you want to read or write to excel file you need to use Java Reflection API though it is not recommended to use Java Reflection API but in rare situations you may need to use Reflection.
You may also like to read:
The Apache POI is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft’s OLE 2 Compound Document format (OLE2). You can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. Apache POI is the Java Excel solution (for Excel 97-2008).
In Hibernate UserType Example using Spring Data JPA we will see how Hibernate allows us to implement and use custom types when built-in types do not satisfy an application’s requirements, or when we want to change the default behavior of a built-in type. As you will see, you can easily implement a custom-type class and then use it in the same way as a built-in one.
Hibernate provides an abstraction of database SQL types to prevent an application from getting mapped to underlying actual database column types. This allow us to develop an application without thinking about the target database column types that the target database supports and we easily develop our application and get involved with mapping Java types to Hibernate types. The database dialect which is a part of Hibernate responsible for mapping Java types to target database column types. If we write HQSL (hibernate query language) then we can easily switch to different database by changing the dialect without changing the application code.
For most of the mappings, Hibernate’s built-in types are enough but, in some situations, you may need to define a custom type. These situations generally happen when we want Hibernate to treat basic Java types or persistent classes differently than Hibernate normally treats them.
Spring EnableEncryptableProperties with Jasypt shows an example how to avoid putting clear text password for database connection credentials in properties file. Jasypt means Java simplified encryption. Here we are going to use Spring version 4 with Jasypt (Java simplified encryption). Here we are also going to use Spring Data JPA to perform the data layer activities with database.
If you put clear text password in properties file then everybody even people who should not see password would gain access to your database and may change database tables values, structure or even may delete without your consent. So it is always better to put the password in an encypted way to avoid such unwanted issues.
Here we will create Gradle based Spring Boot application with Spring Data JPA and apply Jasypt (Java simplified encryption) to extra layer of security for your password.
Jasypt Spring Boot provides Encryption support for property sources in Spring Boot Applications. There are 3 ways to integrate Jasypt in your spring boot project:
Simply adding the starter jar jasypt-spring-boot-starter to your classpath if using @SpringBootApplication or @EnableAutoConfiguration will enable encryptable properties across the entire Spring Environment
Adding jasypt-spring-boot-starter to your classpath and adding @EnableEncryptableProperties to your main Configuration class to enable encryptable properties across the entire Spring Environment
Adding jasypt-spring-boot-starter to your classpath and declaring individual encryptable property sources with @EncrytablePropertySource
This tutorial will show you Hackerrank 1D Array Part 2 using Kotlin.
Let’s play a game on an array! You’re standing at index 0 of an n-element array named game. From some index i (where 0 <= i < n), you can perform one of the following moves:
Move Backward: If cell i-1 exists and contains a 0, you can walk back to cell i-1.
If cell i+1 contains a zero, you can walk to cell i+1.
If cell i+leap contains a zero, you can jump to cell i+leap.
If you’re standing in cell n-1 or the value of i+leap >= n, you can walk or jump off the end of the array and win the game.
In other words, you can move from index i to index i+1, i-1, or i+leap as long as the destination index is a cell containing a 0. If the destination index is greater than n-1, you win the game.
Given leap and game, complete the function in the editor below so that it returns true if you can win the game (or false if you cannot).
This tutorial will show you an example on starting mule apps from main class. You can use any IDE for building your mule apps. Here we will see how to build and start mule apps in Eclipse. You can also use Mule or Anypoint Studio to build your mule apps.
In our previous tutorial we have seen an example on building mule apps with Gradle in Eclipse. Here we will use the previous tutorial to show example on starting mule apps from main class. So basically if you don’t have Anypoint or Mule studio then also you can build your mule apps outside Mule or Anypoint studio.
Building Mule Apps with Gradle in Eclipse, i.e., you are going to create Mule project outside Mule Studio. We will build the Mule project in Eclipse using Gradle script. Gradle is becoming more and more popularity as a build system. It combines the power of scripting with the simplicity of conventions, where customization does not end up in tons of messy configurations. Over the times we have done building Mule apps through Mule Studio using Maven plugin. Here you will create build.gradle script with your own hand to build the Mule project in Eclipse.
Spring Boot Internationalization Example will show you how to make an web based application in different languages. Internationalization or Localization will show you the web page content based on your choosen language in which you want to view the page.
I will show here how we can switch in different langugaes like Bengali, Hindi, English, Dutch and French. You don’t need to change the language settings from the browser for switching to different languages. You are given an option to choose a language in a dropdown where the langugaes are displayed in Bengali, Hindi, English, Dutch and French. If you want you can add more languages or remove languages and accordingly you need to create separate properties file for each language and put them under classpath directory.
This application shows title, welcome message, choose language option and copyright information in Bengali, Hindi, English, Dutch and French languages. By default the selected language is English.
You may also would like to read JSF 2 Internationalisation Example
The tutorial, SOAP over HTTPS with client certificate authentication, will show you how we can use client certificate to handshake with server along with basic authentication for consuming the service. We have also seen how to authenticate by sending authentication information over http headers in SOAP web service but here we will use client certificate (jks file) as a security mechanism. Even you can use header authentication along with client certificate to make more secure.
I will show here both server side code or service and client side code so that server expects client to establish communication through certificate authentication. Here to consume the service you will be given client certificate (extention might be .crt or .der or .p12 or anything else), password for this certificate and username/password for basic authentication (in case if you need also header authentication).