Persist

Persist

Infobox_Software
name = Persist
logo=


caption =
developer =
latest_release_version =
latest_release_date =
operating_system = Cross-platform
genre = Persistence Framework
license = GNU Lesser General Public License
website = http://code.google.com/p/persist/
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 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 ORM/DAO tool).

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 Java classes 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 (the class Customer is mapped to the table customer automatically) persist.insert(customer); // reads a customer by its primary key Customer c = persist.readByPrimaryKey(Customer.class, 42); // retrieves customers using a custom query (note the usage of varargs) List list = persist.readList(Customer.class, "select * from customer where id > ?", 10); // fetch all customers and assign the ResultSet to an Iterator 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.

@NoTable class QueryData { private int count; private String concatName; public long getCount() { return count; } public void setCount(long count) { this.count = count; } public String getConcatName() { return concatName; } public void setConcatName(String concatName) { this.concatName = concatName; } }

QueryData qd1 = persist.read(QueryData.class, "select 1 as count, 'hello' as concat_name from dual");

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 customer
> customerMapList = persist.readMapList("select * from customer"); // fetch all customers and assign the ResultSet to an Iterator which maps rows to Map instances Iterator allCustomersIterator = persist.readMapIterator("select * from customer");

Java primitive types

If a query returns a single column, Persist can map data directly into primitive types (either single values or lists):

// return customer name as String String name = persist.read(String.class, "select name from customer where id=?", 55); // fetch all customer id's as a list of integers List ids = persist.readList(Integer.class, "select id from customer");

Custom queries with no returning data

Arbitrary queries that return no data can be easily executed.

// execute arbitrary SQL with parameters persist.executeUpdate("delete from customer where id in (?,?)", 10, 20);

ee also

*Hibernate
*iBATIS

External links

* [http://code.google.com/p/persist/ Persist @ Google Code]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую
Synonyms:

Look at other dictionaries:

  • Persist — Per*sist , v. i. [imp. & p. p. {Persisted}; p. pr. & vb. n. {Persisting}.] [L. persistere; per + sistere to stand or be fixed, fr. stare to stand: cf. F. persister. See {Per }, and {Stand}.] To stand firm; to be fixed and unmoved; to stay; to… …   The Collaborative International Dictionary of English

  • persist in — index adhere (persist), bear (tolerate) Burton s Legal Thesaurus. William C. Burton. 2006 …   Law dictionary

  • persist — I verb abide, be determined, be obstinate, be resolute, be steadfast, be steady, be tenacious, be unyielding, bide, carry on, cling to, continue, drag on, endure, go forward, go on, hold fast, hold on, hold out, insist, keep at, keep on, last,… …   Law dictionary

  • persist — 1530s, from M.Fr. persister (14c.), from L. persistere continue steadfastly, from per thoroughly + sistere come to stand, cause to stand still (see ASSIST (Cf. assist)) …   Etymology dictionary

  • persist — 1 *persevere Antonyms: desist Contrasted words: discontinue, cease, *stop, quit 2 *continue, last, endure, abide Antonyms: desist Contrasted words: *stop, cease, discont …   New Dictionary of Synonyms

  • persist — [v] carry on, carry through abide, be resolute, be stubborn, continue, endure, follow through*, follow up*, go all the way*, go on, go the limit*, grind, hold on, insist, keep up*, last, leave no stone unturned*, linger, obtain, perdure,… …   New thesaurus

  • persist — ► VERB 1) continue doing something in spite of difficulty or opposition. 2) continue to exist. ORIGIN Latin persistere continue steadfastly …   English terms dictionary

  • persist — [pər sist′, pərzist′] vi. [MFr persister < L persistere < per, through + sistere, to cause to stand, redupl. of base of stare, to STAND] 1. to refuse to give up, esp. when faced with opposition or difficulty; continue firmly or steadily 2.… …   English World dictionary

  • persist */*/ — UK [pə(r)ˈsɪst] / US [pərˈsɪst] verb [intransitive] Word forms persist : present tense I/you/we/they persist he/she/it persists present participle persisting past tense persisted past participle persisted 1) to continue to do or say something in… …   English dictionary

  • persist — verb 1 continue doing sth ADVERB ▪ doggedly, stubbornly PREPOSITION ▪ in ▪ If you persist in upsetting her, I will have to punish you. ▪ with …   Collocations dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”