polyforms--Reduce DAO Code duplication

Source: Internet
Author: User

The goal of the POLYFORMS project is to eliminate duplicate code for binding data access objects and the underlying persistence APIs. The approach to this framework is to automate the implementation of service methods on repository interfaces defined by developers. The method defined in the interface is connected to the database operation by default through a naming convention. For example, the project Wiki discusses how to implement a storage for the user entity object. First, the stored APIs must be defined as:

public interface UserRepository extends EntityRepository<User, String> {

  @Finder
  List<User> findByCreator(User creator);
}

@Finder Annotations mark the Polyforms method. Next, do not implement Userrepostiory, but provide a matching hibernate query in the user entity with additional annotations.

@NamedQueries({
  @NamedQuery(name = "User.findByCreator", query = "select u from User u where u.creator = :creator"),
})
public class User {
 ...
}

According to the document, the naming convention used to find query statements is based on the method name and the entity name:

The mapping rule for a named query is [name of Named query] = [name of Entity]. [Name of method]. You can specify the name of the named query by @finder, such as @finder ("Finduserbyname"), and then the name of the query will be "User.finduserbyname".

In addition to @finder annotations, there are @updater and @counter that provide support for large-scale updates and query counts, respectively.

Entityrepository

The parent interface already supports the ability to save a single entity, delete, and get through identifiers.

All of these connections are through

Spring Framework

Completed, and relies on spring's slice to provide dynamic implementation of the API.

Other features supported by Polyforms include:

Automatic management of trace information (creator, creation date, modifier, modified date)

Transparent paging support

Defining transaction boundaries through annotations

Domain event model, separating persistent events and application functionality.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.