Java Doc for Store.java in  » Database-ORM » beankeeper » hu » netmind » persistence » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » beankeeper » hu.netmind.persistence 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   hu.netmind.persistence.Store

Store
public class Store (Code)
This store class is the entry point to the persistence library. To store, remove or select given objects, just use the appropriate method.
author:
   Brautigam Robert
version:
   Revision: $Revision$



Constructor Summary
public  Store(String driverClass, String url)
     Instantiate a store.
public  Store(DataSource dataSource)
     Instantiate a store.

Method Summary
public  voidclose()
     Close the store, and release all resources.
 voidcommit(Transaction transaction)
     Commit a transaction.
public  Listfind(String statement)
     Query an object from the datastore.
public  Listfind(String statement, Object[] parameters)
     Same as find(statement).
 Listfind(String statement, Object[] parameters, TimeControl timeControl, Map unmarshalledObjects)
     This method in addition to all usual parameters can define the exact time of the query with the timeControl parameter.
 SearchResultfind(Transaction transaction, QueryStatement stmt, Limits limits)
     Internal raw loading.
 SearchResultfind(QueryStatement rawStmt, Limits limits, Map unmarshalledObjects)
     Internal loading.
public  ObjectfindSingle(String statement, Object[] parameters)
     Same as find(statement,parameters), but the result should be a single object.
Parameters:
  statement - The query statement to execute.
Parameters:
  parameters - The parameters to the statement.
public  ObjectfindSingle(String statement)
     Same as find(statement), but the result should be a single object.
Parameters:
  statement - The query statement to execute.
protected  StoreContextgetContext()
     Get context.
public  EventDispatchergetEventDispatcher()
     Get the event dispatcher in which the caller may register listeners.
public  LockTrackergetLockTracker()
     Get the lock tracker.
public  LonggetPersistenceId(Object obj)
     Get the persistence id for an object.
public  PersistenceMetaDatagetPersistenceMetaData(Object obj)
     Get the persistence meta-data object for a given object.
public  TransactionTrackergetTransactionTracker()
     Get the transaction tracker associated with this store.
public  voidremove(Object obj)
     Remove the object given.
 voidrollback(Transaction transaction)
     Rollback a transaction.
public  voidsave(Object obj)
     Save the given object to the store.


Constructor Detail
Store
public Store(String driverClass, String url)(Code)
Instantiate a store. Note that you should only make one store instance for each datasource you might want to use, all methods are thread-safe, so you can use the single instance in more threads.
Parameters:
  driverClass - The driver class to register.
Parameters:
  url - The driver's jdbc url (including username and password).



Store
public Store(DataSource dataSource)(Code)
Instantiate a store. Note that you should only make one store instance for each datasource you might want to use, all methods are thread-safe, so you can use the single instance in more threads.




Method Detail
close
public void close()(Code)
Close the store, and release all resources. This method is automatically invoked as a JVM shutdown hook, so it does not have to be called at all.



commit
void commit(Transaction transaction)(Code)
Commit a transaction. This method is necessary, because on the end of a transaction, the store must set all persistence_start and persistence_end date/serials to the actual close-serial of transaction.



find
public List find(String statement)(Code)
Query an object from the datastore. The List returned is a lazy list, the implementation tries to limit the communication with the database layer, as much as possible and pratical. Only parts of the list will be loaded when an item is referenced, not the whole list. Some features of the query language:
find book where book.name='Snow Crash'
The statement always starts with the keyword 'find', and all keywords and parts of the statement not between apostrophs are case in-sensitive.
The second word of the statement determines the class you are trying to find. You can abbreviate the classname (strip the package) if it is unique, but you can use the full name (com.acme.book) if you wish, but then you MUST provide an alias name (see below)
The following parts are all optional. First, there can be a select statement, to specify which objects to select which are instances of given class. If you want to have a where part, the third word should be 'where'. After it there should be an expression almost as in SQL. Parts of the expression can be:
  • Member attributes of classes. The class given previously (the target of statement) is always available as declared. If you wish to use other classes, they can be referenced by class (abbreviated or fully declared). For example
    find book where book.author=author and author.birthdate=1959
    Of course Book, and Author classes must exits in the store with given attributes. Note also, that the above statement can be simply written:
    find book where book.author.birthdate=1959
    You can name the classes you are referencing for later use (handy if you must "join" the class with itself):
    find book where book.author=otherbook(book).author and otherbook.name='Snow Crash'
    Here, the "otherbook" does not refer to a class, it is only another name for the class book, and means, that is should be not the same instance as the one referenced with "book".
  • "Now" constant: For easy use the current date/time is represented with the special word 'now'. So you can write:
    find movie where movie.startdate > now
    This also means, that attributes named 'now' must be escaped (prefixed with it's table name).
  • Constants: Numbers and strings, see examples above. Dates and objects can be given by using the question mark (?), and adding the object as parameters (same as in jdbc).
  • The operators: <, >, =, !=, like, is null, not null, is not null. Note however, that not all database backends are required to support all of these. If they are not supported, an exception will be thrown.
  • Logical operators: or, and, not. See examples above.
  • Grouping with parenthesis. As usual in expressions, you can use grouping:
    find book where ((book.author.firstname='Neal') and (book.author.lastname='Stephenson'))
  • Special container operator: contains. These are used in conjunction with container types such as Map and List:
    find book where book.genres contains genre and genre.name='postcyberpunk'
    find author where author.books contains book and book.name='Snow Crash'
    A container operator can not be negated, an exception will be thrown, if the expression would try to do that.
  • Special map operator: [, ]. These are used when referencing a Map. Note also, that [] can only contain strings.
    find book where book.metadata['author']=author and author.name='Neal Stephenson
    However, if after a map operator an attribute is referenced, there is a mandatory class specifier:
    find book where book.metadata['author'](author).name='Neal Stephenson

You can also sort the result list with the 'order by' command:
find book order by book.name asc
The order by command takes attributes as aguments. You can give more than one attribute separated by commas. Also you can append 'asc' (ascending) or 'desc' (descending) to mark the direction of sort.
find book order by book.author.name asc, book.name desc
Note, that method will silently return an empty list, if the specified table or one specified in where clause does not exist.
For more detailed information, check the documentation.
Parameters:
  statement - The query statement to select.



find
public List find(String statement, Object[] parameters)(Code)
Same as find(statement). When a statement contains the question mark (?), the object which should be in the place of the mark should be given as parameters (parameters are usually of Date, or custom classes).
Parameters:
  statement - The query statement to execute.
Parameters:
  parameters - The parameters.



find
List find(String statement, Object[] parameters, TimeControl timeControl, Map unmarshalledObjects)(Code)
This method in addition to all usual parameters can define the exact time of the query with the timeControl parameter. If the query is a historical query, this control will be overridden.
Parameters:
  statement - The query statement to execute.
Parameters:
  parameters - The parameters.
Parameters:
  timeControl - The exact default time of the query.



find
SearchResult find(Transaction transaction, QueryStatement stmt, Limits limits)(Code)
Internal raw loading. All finder methods sooner or later call into this method to get real results in form of attribute name-value maps.



find
SearchResult find(QueryStatement rawStmt, Limits limits, Map unmarshalledObjects)(Code)
Internal loading.



findSingle
public Object findSingle(String statement, Object[] parameters)(Code)
Same as find(statement,parameters), but the result should be a single object.
Parameters:
  statement - The query statement to execute.
Parameters:
  parameters - The parameters to the statement. The object selected, or null if no such object exists. Ifthe result contains more objects, an arbitrary one is selected.



findSingle
public Object findSingle(String statement)(Code)
Same as find(statement), but the result should be a single object.
Parameters:
  statement - The query statement to execute. The object selected, or null if no such object exists. Ifthe result contains more objects, an arbitrary one is selected.



getContext
protected StoreContext getContext()(Code)
Get context.



getEventDispatcher
public EventDispatcher getEventDispatcher()(Code)
Get the event dispatcher in which the caller may register listeners.



getLockTracker
public LockTracker getLockTracker()(Code)
Get the lock tracker. This tracker can be used to lock and unlock objects for exclusive operations.



getPersistenceId
public Long getPersistenceId(Object obj)(Code)
Get the persistence id for an object. This method always returns a valid id, even if the object is not saved, or otherwise has no persistence id. If the object is later saved, this persistence id is always preserved.
Same as: getPersistenceMetaData(obj).getPersistenceId(). A persistence id, and never null.



getPersistenceMetaData
public PersistenceMetaData getPersistenceMetaData(Object obj)(Code)
Get the persistence meta-data object for a given object. Metadata is always available, even for non-saved objects.



getTransactionTracker
public TransactionTracker getTransactionTracker()(Code)
Get the transaction tracker associated with this store. The transaction tracker can be used to create transactions, and listen for transactional events. The transaction tracker.



remove
public void remove(Object obj)(Code)
Remove the object given. If the object is not stored yet, no operation will take place.
Parameters:
  obj - The object to remove.
throws:
  StoreException - If remove is not successfull.



rollback
void rollback(Transaction transaction)(Code)
Rollback a transaction. Rollback has to only unlock objects the transaction carries, and call the database rollback.



save
public void save(Object obj)(Code)
Save the given object to the store. The given object's all private non-transient fields will be saved. If the object was not selected from the store, and not yet saved, it will be created in the store, and a unique id will be assigned, so all subsequent calls to save the given object will only modify the already existing instance in store. A few tips:
  • Use simple beans. Although this library does not scan methods to determine the attributes to save, it is a good idea to simplify work with them.
  • If you do not use simple beans, watch out that your object does not reference unnecessary objects, because if it does, all will be saved/inserted and tracked.
  • You CAN use objects which reference other beans though. But beware, that all objects which are directly referenced will be loaded when the parent object loads.
  • You CAN use Map, and List types in your beans. Check the documentation.
Note:A save operation is not recursive. It does not traverse the object hierarchy, only saves the object given, and does not save objects referenced, except when referenced object does not exist yet. If a referenced object does not yet exist, it will be inserted into database (and recursively all referenced objects of that object). Implementation note:This class is the intelligent part of the framework, an intentionally so. This is the class that coordinates all other classes, trackers and functions together.
Parameters:
  obj - The object to save.
throws:
  StoreException - If save is not successfull.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.