Persist is a Java-based ORM/DAO tool. It provides only the minimal amount of functionalities necessary to map objects or maps from database queries and to statement parameters. Persist works around a java.sql.Connection object. This means that it does not care about customerquery languages, connection poolhandling, transaction handling, and so on. This also means it is very flexible, and can be integrated with any code that depends on JDBC. Persist does not require explicit mappings from POJOs to database tables. As long as there is some sort of naming conventions that relate database names with POJO names, Persist will require virtually no mappings. It can, however, be instructed to map Javaclasses and fields to database tables and columns using annotations. Persist supports several different mapping strategies: POJOs mapped to tables By default, if no annotations specify a given class should not be mapped to a table, Persist will try to find a table that matches that class and create a mapping between fields and columns. // Inserts a new customer persist.insert; // Reads a customer by its primary key Customer c = persist.readByPrimaryKey; // Retrieves customers using a custom query List list = persist.readList; // Fetch all customers and assign the ResultSet to an Iterator Iterator allCustomersIterator = persist.readIterator;
POJOs not mapped to tables If a class is annotated with @NoTable, Persist will not try to map it to a table, and the class will only be able to hold data produced by queries. @NoTable class QueryData QueryData qd1 = persist.read;
java.util.Map's Map's can be used to hold data from queries. Persist will convert values returned from the query to Java types. Keys in the table are the names of the columns returned in lower case. // Fetch a customer using a custom query and return the result as a map Map customerMap = persist.readMap; // Fetch all customers and result the results as Map instances in a List List Java primitive types If a query returns a single column, Persist can map data directly into primitive types : // Return customer name as String String name = persist.read; // Fetch all customer id's as a list of integers List ids = persist.readList;
Custom queries with no returning data Arbitrary queries that return no data can be easily executed. // Execute arbitrary SQL with parameters persist.executeUpdate;