用Spring的Converter API生成VoltDB的資料物件

jieforest發表於2012-06-24
Mapping one type to another is a pretty common task. Hibernate and other ORM’s map a result from a data source’s native representation to an application specific representation.
In English, I want to convert a JDBC result set, or data objects, into a collection of POJOs (plain old Java objects) using some kind of data mapping tool or API.

Spring exposes a low level service provider interface that makes it very easy to convert one data type to another with either built-in converters or customer converters, allowing a developer to support just about any conversion one can think of.

Today I am writing about how to convert VoltDB's VoltTable result object into an application specific POJO using the Spring Converter API.Why even have a converter API in any application? A fairly common pattern in any database backed application is the value object (VO) to data access object (DAO) mapping.

A similar pattern is the transfer object to entity pattern. The data layer object is generally a mapping of fields to database table columns or query results.  That data layer object may contain additional objects that map to other tables too.

It may also expose methods, either explicitly or implicitly, to perform. the usual CRUD operations or it can rely on a service to accomplish those operations.The application layer object may include some or all of the data layer fields as well as application layer specific fields.

A data layer object may represent a student and the grades she got on all her tests while the application layer object may represent the student, the grades and then additional fields like the average, highest and lowest grades for each of those tests.

The importance of the converter API is that it makes it possible to abstract the link between the data access layer and the application layer objects such that either layer can be swapped out or updated without impacting the other layer.

Further, changes to the application layer object may not need to be persisted to the database while changes to the DAO are often persisted to the database.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-733664/,如需轉載,請註明出處,否則將追究法律責任。

相關文章