ParameterizedRowMapper is recommended or RowMapper - spring

I am very new to Spring JDBC and working on a given task, looking at the codes we already have my teammates have used RowMapper, but I was doing some Googling and saw some tutorials are using ParameterizedRowMapper , so I was wondering if there is any benefit or good practice in using one rather than the other one and your technical thoughts behind that...
thanks.

Right from the javadoc of ParameterizedRowMapper:
Extension of the RowMapper interface, adding type parameterization. As
of Spring 3.0, this is equivalent to using the RowMapper interface
directly.

Prior to Spring 3.0, most APIs did not use generics because Java 1.5 wasn't a requirement. As a result, there was a RowMapper, that didn't support generics and ParameterizedRowMapper that did support generics by extending RowMapper and adding the generic parameter. As of Spring 3.0, most APIs were updated to support generics. If you actually look at the current (3.0 or greater) definition of ParameterizedRowMapper, it just simply extends RowMapper and adds nothing to the definition to allow for backward compatibility. Therefore, you can pretty much use RowMapper either parameterized or not and no need to use ParameterizedRowMapper.

Related

Spring persistent framework which supports data class of kotlin

the question is simple, but I can't find any of answer about this.
After searching, I realize that kotlin data class is not suitable for Spring JPA because data class is immutable and does not support inheritance.
So, I wonder are there any alternatives for JPA which support data class.
Thanks,
I find two kotlin-based ORM, ktorm and exposed.
It seems both are very good for start, and it supports data class.
But, at some point, I thought that I need to move to ktor rather than Spring boot when I wanna use kotlin more kotlin-tic way..

How to know what implementation of graphics 2d my spring boot project is using

As stated in the title. I have a project that uses Graphics 2d. While debugging I am able to see that my project uses SunGraphics2d implementation of the graphics 2d abstract class. How do I find out without going into debug mode and moreover how do I find the same about other abstract classes?
As an example, hibernate implementation of JPA interface is provided by default in spring. How to find what implementation is provided in spring by default and how to change the default.
Spring/Spring boot doesn't manage anything related to graphics. So you don't have any spring related tools to help you out here.
In a plain java world, reflection is probably the best choice then

Where is this class "HttpContext" exist in glassfish jersey 2.9?

Where is this class "HttpContext" exist in glassfish jersey 2.9 . I was using jersey 1.17.1 to use HttpContext where it was exist in package com.sun.jersey.api.core.HttpContext.
But i did't find it in jersey 2.9.
The direct replacement for HttpContext is not available in Jersey 2.x versions and unfortunately, this breaking change detail hasn't been mentioned anywhere in the migration guide. Instead of searching for direct replacement, if we dig deeper into the interface HttpContext, based on the following method summary refer
we can infer that instead of using HttpContext, we can simply use the following out-of-the-box alternatives.
Instead of HttpContext#getRequest use #Context ContainerRequestContext crc
Instead of HttpContext#getResponse use #Context ContainerResponseContext crc
Instead of HttpContext#getUriInfo use #Context UriInfo uriInfo
Instead of HttpContext#getProperties use ContainerRequestContext#getProperty
Jersey 2.x had a lot of breaking changes, which partly caused by the fact that JAX-RS standard incorporated a lot of things in Jersey 1.x.
To quote https://jersey.java.net/documentation/latest/migration.html#mig-1.x
This chapter is a migration guide for people switching from Jersey 1.x. Since many of the Jersey 1.x features became part of JAX-RS 2.0 standard which caused changes in the package names, we decided it is a good time to do a more significant incompatible refactoring, which will allow us to introduce some more interesting new features in the future. As the result, there are many incompatibilities between Jersey 1.x and Jersey 2.0. This chapter summarizes how to migrate the concepts found in Jersey 1.x to Jersey/JAX-RS 2.0 concepts.
The migration chapter does not indicate what happened to HttpContext, but it no longer exists in its old form.

Use of Spring oxm

I am new to spring. I was looking into spring-oxm's XStreamMarshaller. I was hoping to find a way to convert my objects into xml using this. The spring site tells me clearly how to do it but it still needs me to add a XStream dependency in my POM. I don't understand what the use of spring-oxm is? If i had to add the xstream dependency anyway then i can directly use xstreams toXml operation and be done with it? I would really appreciate any help I could get in understanding the use of spring-oxm.
Thanks a lot in advance!
Spring provides a higher level abstraction for you by eliminating the scaffolding code you need to write. For e.g. in case of OXM you will be working with Marshaller and Unmarshaller abstractions irrespective of the underlying implementations uses (XStream, JAXB, Castor, XmlBeans etc). Moreover it lets you use DI for injecting marshalling/unmarshalling services to your own services. Another advantage is consistent exception hierarchy irrespective of the underlying implementation. All these are well explained on their reference documentation.
If you have very simple needs and doesn't already use Spring then I suggest you stick to JAXB that comes with JDK 6.

Up to date, JPA compliant GenericDAO Implementation

I read this article:
http://www.ibm.com/developerworks/java/library/j-genericdao.html
several times and believe I understand what it is saying. However, it is 4 years old and I have a JPA compliant Java application to contend with. In addition, I see that there is a JPATemplate in Spring that has some good functionality, but the Spring documentation says it is already deprecated!
Can anybody point me to a solid, modern, JPA compliant, Spring based, working example of a GenericDAOImpl that proxies an Interface to provide generic finder execution?
Nowadays JPA 2 in itself has become a decent implementation of a DAO layer since its responsibility (or contract if you wish) is the same as for the traditional "crafted" DAO, that is an isolation of a business logic from a storage mechanism. An important implication out of this is that you may need an explicit DAO only when working with non-DBMS storages like spreadsheet files, web-services, etc.
I've created a generic DAO mixing different approaches that I shared on SO in this question. I use these 2 approaches: DDD: The Generic Repository and JPA implementation patterns: Data Access Objects.
Please feel free to comment/edit if you think it can be improved.

Resources