Content deleted Content added
another persist |
m Infobox Software: 2-clause BSD License, source https://github.com/r5v9/persist/tree/master |
||
(30 intermediate revisions by 21 users not shown) | |||
Line 1:
{{No footnotes|date=June 2023}}
{{Infobox Software
|name = Persist
|logo =
|screenshot =
|caption =
Line 10:
|operating_system = [[Cross-platform]]
|genre = [[Persistence Framework]]
|license = [[BSD_licenses#2-clause_license_("Simplified_BSD_License"_or_"FreeBSD_License")|2-clause BSD License]]
|website =
}}
'''Persist''' is a [[Java (programming language)|Java]]-based [[Object-relational mapping|ORM]]/[[Data Access Object|DAO]] tool. It provides only the minimal amount of functionalities necessary to map objects or maps from database queries and to statement parameters.▼
▲Persist is a [[Java (programming language)|Java]]-based [[Object-relational mapping|ORM]]/[[Data Access Object|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 customer query languages (it uses plain [[SQL]] with placeholders, as PreparedStatement objects use), connection pool handling, transaction handling (for the most part), and so on. This also means it is very flexible, and can be integrated with any code that depends on [[JDBC]] (including code that already use another [[Object-relational mapping|ORM]]/[[Data Access Object|DAO]] tool).
Line 25 ⟶ 24:
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.
<syntaxhighlight lang="java">
▲ // inserts a new customer (the class Customer is mapped to the table customer automatically)
Customer c = persist.readByPrimaryKey(Customer.class, 42);
▲ persist.insert(customer);
▲ // reads a customer by its primary key
</syntaxhighlight>
Iterator allCustomersIterator = persist.readIterator(Customer.class, "select * from customer");▼
'''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.
<syntaxhighlight lang="java">
private int count;
private String concatName;
Line 52:
public String getConcatName() { return concatName; }
public void setConcatName(String concatName) { this.concatName = concatName; }
</syntaxhighlight>
'''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.
<syntaxhighlight lang="java">
// Fetch a customer using a custom query and return the result as a map
Map<String,Object> customerMap = persist.readMap("select * from customer where id=?", 10);
// Fetch all customers and result the results as Map instances in a List
▲ // fetch a customer using a custom query and return the result as a map
</syntaxhighlight>
'''Java primitive types'''
If a query returns a single column, Persist can map data directly into primitive types (either single values or lists):
<syntaxhighlight lang="java">
// Return customer name as String
▲
</syntaxhighlight>
'''Custom queries with no returning data'''
Arbitrary queries that return no data can be easily executed.
<syntaxhighlight lang="java">
</syntaxhighlight>
==See also==
* [[Hibernate (Java)|Hibernate]]
* [[iBATIS]]
==
{{Reflist}}
*[http://code.google.com/p/persist/ Persist @ Google Code]▼
==External links==
[[Category:Articles with example Java code]]
[[Category:Java (programming language)]]
|