How to generate Model layer, Persistence layer and service layer from a single configuration file - spring

I am using hibernate to persist data on a MySql database.
Now I am already configuring what my business model is in the hibernate configuration file.
What I am looking for is, are there any tools that on building/deploying the application will generate the Model Layer (POJOs), Persistence Layer and the Service Layer (Business logic) for the controllers to communicate with the database server. In short I wish to generated all the basic essentials from a single configuration point.
Ant or Spring or combination of other frameworks, anything that can achieve the solution.
Any reference to an existence thread or a handful document would be highly appreciated.
Thanks in advance.

Your closest bet is Grails.
I'm not a fan of what you'd like to do. Code generation can result in a brittle system.

spring roo can be also good option to look at as your stack is based on spring framework.
Another option which can be used is MyEclipse IDE for Spring this supports code generation based on domain/table.

Related

Hexagonal Architecture with Hibernate Reactive and Quarkus

I am using Hexagonal Architecture, Hibernate Reactive with Panache and Quarkus in a Kotlin Project.
Transaction boundaries are set using #ReactiveTransactional annotation.
The problem is that I had to add the whole Hibernate Reactive with Panache dependency in the domain and application layers just to make this annotation available.
Is there a way to avoid this?
I was hoping it would be possible to create a domain annotation and then in the adapters layer replace it with the #ReactiveTransactional somehow.
You could remove the annotation from the class, and wrap it into a service, and implement this service in the adapter layer using the annotation.
Don't use database related dependencies inside the hexagon.
The idea is to decouple the business logic from the user interface and infrastructure. Database logic should be placed into an adapter.
It theory it sounds great, in practice that means tons of mappers i.e. boilerplate code. On the bright side you have a Kotlin, and not a Java project so this should be a bit less tedious than the alternative. Bear in mind that there are projects such as Dozer, MapStruct that can make the mapping process easier.

Spring design pattern for common update service or module

I have a use case where I would like build a common interface or service which can update entities of application. Example case is shown as below:
Now every application has to handle update functionality of entities. Rather than implementing update functionality in n application module. I would like to build a common interface or server in spring boot.
Service will be like below:
My question is how to design service/interface which can used for above scenario. Any api or tool which can help me to achieve this. I dont want to write code for update in every application module.
Thanks in advance.
Last year I was thinking about the similar concept to yours, but in Apache Camel framework context. I haven't got enough time and motivation to do so, but your post encouraged me to give it a try - perhaps mostly because I've found your concept very similar to mine.
This is how I see it:
So basically I considered an environment with application that might uses N modules/plugins that enriches application's features, i.e. processing feature etc. Application uses module/plugin when it is available in the classpath - considering Java background. When the module is not available application works without its functionality like it was never there. Moreover I wanted to implement it purely using framework capabilities - in this case Spring - without ugly hacks/ifs in the source code.
Three solutions come to my mind:
- using request/response interceptors and modifying(#ControllerAdvice)
- using Spring AOP to intercept method invocations in *Service proxy classes
- using Apache Camel framework to create a routes for processing entities
Here's the brief overview of POC that I implemented:
I've chosen Spring AOP because I've never been using it before on my own.
simple EmployeeService that simulates saving employee - EmployeeEntity
3 processors that simulates Processing Modules that could be located outside the application. These three modules change properties of EmployeeEntity in some way.
one Aspect that intercepts "save" method in EmployeeService and handles invocation of available processors
In the next steps I'd like to externalize these Processors so these are some kind of pluggable jar files.
I'm wondering if this is something that you wanted to achieve?
link to Spring AOP introduction here: https://docs.spring.io/spring/docs/5.0.5.RELEASE/spring-framework-reference/core.html#aop
link to repository of mentioned POC: https://github.com/bkpawlowski/spring-aop

Hybris sap use Spring?

I all,
I have experience with oracle atg and now i want to merge to hybris sap, so i have some questions about hybris.
For development, does hybris uses spring, that means when i develop an hybris application do i use spring ioc, spring mvc and spring security (#autowired, #controller, #service...) or just like atg the usage of spring is done in the background and when i use angular with hybris do i have to use spring (#RESTController) and for data access do i have to use hibernate or does it have his own methods? And do we have to use spring boot and spring data with it?
I haven't got knowledge about oracle ATG. Hybris is a platform which has a lot of module. Some modules developed with spring (xml based config), for example web services and customer ui (store front). Hybris has own ORM, so spring data not used. Hybris using a lot of technologies, some of them:
Spring
Apache Solr
ZK Framework
Apache Ant
Apache Tomcat
Junit
JQuery
Also we use a lot of languages for this technologies:
Html
Java
Javascript
Flex Query
Bean shell
Groovy
Jsp
Lucene
Cron
You can use other frameworks look like React for store front with developing custom controls. But hybris has a lot of out of the box functions for managing ui and customization on the fly. These functionalities may be not usable with different framework or it needs a lot of work.
I don't know about ATG, but in hybris there are many modules using which you can quickly setup a live production website within 4-6 months.
Front-End:
JSP, JSTL, EL
Javascript, HTML, CSS
Bootstrap
jQuery
Backend:
Java for handling and writing the logic
Spring Core, Spring MVC, Spring Security
Spring EL
Database:
More than 6 databases are supported:
- SAP
- HANA
- HSQLDB
- MySQL
- SQL Server
- Oracle
- PostgreSQL and many are added
For searching:
Hybris has its own search engine.
Lucene, Apache Solr
Now you can use Google cloud search as well.
For scripting:
beanshell
JavaScript
Groovy
Please keep an eye on the Hybris Commerce roadmap. Thin Angular.JS based UI is probably the future.
UI development is typically done in Hybris Commerce using the Hybris Commerce WCMS framework, and extending or creating new pages, widgets, etc. The stuff provided out-of-the-box in accelerators and extensions is very feature rich. Angular is already in there, if you know where to look.
Hybris Commerce also provides OCC (Omni Commerce Connect) REST API extension. REST endpoints are automatically generated at compile time. This is very mature, and has been the primary integration strategy for native mobile commerce apps and separate digital asset management (DAM) tools.
More ideas:
https://hybrismart.com/2016/09/03/angularjs-v-2-and-hybris/
The basis of Hybris is mostly spring mvc, so yes, you can use spring mvc annotations for mapping, mostly all the code in hybris is done using the spring standard, including autowiring, annotations and xml files.
Unlike ATG where you have formhandlers, droplets etc to deal with UI and backend connection, Hybris uses the facade design pattern. That is,
You have a facade layer that acts as a sort of barrier between your request handling logic and your service logic.
Therefore, variables used in the service layer (Model Objects) are not carried forward to the request handling layer and separate variables are used (Data Objects)
Regarding database, Hybris has its own ORM, and they are called as Models and items, the concept is similar to repositories in ATG. For example, to create a new item entry, add the same to an items.xml file, providing the name of the model, the table used for persisting and the various attributes (corresponding to the fields in the table). So when you run ant all for building your application, Hybris uses this mapping to create a model class for your item, this is basically a pojo class, that has getters and setters for all your attributes. So if you save a model object, you will be persisting the data in the database.
To query the data, there is a special query language called as flexible search,it is nearly same as sql but with a few syntax differences, so instead of querying tables, you query items, much like using RQL in ATG.
You can also access data using model objects.
Relations too can be created using items.
Hope this gives you a more clearer picture.
to Start with Hybris, you need to be good at java,jsp,html,css.
And framework such as Spring and Hibernate.
Last but not the least:you should good in any Query language,which helps you lot while coding in Hybris, because hybris have there own language called as Flexible Search Query.

When to use default Spring Data REST behavior?

I recently worked on a project which uses Spring Data REST with Spring Boot. While it is GREAT to harness the power of Spring Data REST and build a powerful web service in no time, I have come to regret one thing: how tightly coupled the "presentation" layer (JSON returns) is to the underlying data structure.
Sure, I have used Projections and ResourceProcessors to manipulate the JSON, but that still does not completely sever ties with the database structure.
I want to introduce Controllers to the project, to integrate some of the "old" ways of building a web service in Spring. But how should I draw the line? I don't want to eradicate Spring Data REST from my project.
I am sure many of you have faced similar decisions, so any advice would be most appreciated!

Spring data alternatives

Currently We have an enterprise application that works with spring and JPA.
Today we are planning our next generation server.
We are debating whether to use spring-data in our project? It seems to increase productivity and development times.
Are there any alternatives to spring-data to consider? Why not using spring and JPA alone?
What do you suggest?
Bear in mind we are starting to develop from scratch so no constraints are available other than:
we use mysql and mongoDB
we code in java
we will develop client side code in GWT.
Currently we have a layered architecture.
We have a Service layer and a manager layer, which takes care for persisting and business logic. Whoever built that didn't see a good reason to insert the third DAO layer.
There are some technical benefits of Spring Data over Spring + JPA, which in a pure SQL environment, I think give Spring Data an advantage:
Spring Data uses the same CrudRepository interface for all implementations, so you'll have less effort to switch between JPA to MongoDB
Spring Data saves you writing the same methods again and again. You just add the method to the interface and it'll generate it for you (e.g. UserRepository.findByUsername())
You can save boilerplate on REST implementations for JPA, MongoDB and others (see http://projects.spring.io/spring-data-rest/)
If you wanted to experiment with other persistence or indexing services, then there are Spring Data implementations for both mature and newer technologies such as for Neo4j, Hadoop, Solr, ElasticSearch, fuzzydb.
Given that you use MySQL and MongoDB, I think Spring Data is a strong candidate, as it allows developers to code to a single data access API (Spring Data) instead of two (JPA and the MongoDB Java Client).
Regarding the existing architecture, it sounds as though your manager layer is implementing either a Rich Domain pattern, or Active Record.
Spring Data is in my view very well suited to Rich Domain when combined with injection of services using Spring's #Configurable.
Lastly, I'd say that Spring Data also gives a significant advantage when needing to implement services for things like Spring Security and Spring Social, which use MongoDB or others instead of SQL.
We did this in the fuzzydb sample webapp that can be found here. (Disclaimer: I'm the currently sole recent committer on fuzzydb, and haven't touched it for a number of years, but we did have a live service, www.fridgemountain.com, based on that code, but neglected to promote it)

Resources