JDO learning notes (1)
Query your data
There are two interfaces related to the Query in the JDO API (their specific implementation by JDO products):
Java.jdo.Query
=========================
The instance of this interface is created by another interface PersistenceManager. In the JDO, PersistenceManager is a more important interface, and all of our transactions are defined by this interface.
The PersistenceManager interface has a set of newqury methods to generate an instance of Query:
Public query newquery ()
Public Query NewQuery (Java.lang.class CLS)
Public Query NewQuery (java.lang.class cls, java.util.collection CLN)
Public Query NewQuery (java.lang.class CLS,
Java.util.collection CLN,
Java.lang.string filter)
Public Query NewQuery (Java.lang.class CLS, Java.lang.String Filter)
Public Query NewQuery (Extent CLN)
Public Query NewQuery (Extent CLN, Java.lang.String Filter)
Public Query NewQuery (java.lang.Object Compiled)
Public Query NewQuery (java.lang.string language, java.lang.object query)
If you have a query, you have to have a return result. A set of Execute methods in the query interface to return the query:
Public Object Execute ()
Public Object Execute (java.lang.Object P1)
Public Object Execute (java.lang.object p1, java.lang.object P2)
Public Object Execute (java.lang.Object P1,
Java.lang.Object P2,
Java.lang.Object P3)
Usually I don't have to have the next method, especially when I am inquiry, I prefer the following two ways to return to the query results:
Public Object Excutewitharray (java.lang.Object [] parameters)
Public Object ExcutewithMap (Java.util.map Parameters)
Of course, if it is a very simple condition, the four methods on the upper side can not be used, and the latter methods should be constructed or collections themselves.
Personally think that the above execution query is similar to java.sql. PreparedStatement is almost assumed to assign a value for the specified "parameter"; such as P1, P2, P3, Array, Map, all stored, the value of the parameters required, follow PreparedStatement The order in which they are in order to define the order of the parameters.
To be careful of
l The order of arrays in the array parameter set is highly defined in the order of the parameters.
l The name of the key in the MAP parameter collection, the value of the parameter, value is the value of the parameter.
The upper side has begun to mention the query with parameters, yes, the Query interface defines the method of introducing parameters: Public void DeclareParameters (java.lang.string parameters)
If you have more parameters, you should be separated by a comma.
JDO's query method can be introduced into the parameters, and can introduce variables and other classes. The following is the introduction variable and introduction, its syntax and general java syntax have no difference:
Introducing variables, when the introduction of multiple variables is separated by semicolons
Public void Declarevariables (java.lang.string variables)
Example: Public Void Declarevariables ("Student Students; Teacher Teacher1);
Introducing class, when introducing multiple classes, the connection of the string is similar, bad, see example:
Public void DeclareImports (java.lang.string imports)
Example: Public void DeclareImports ("Import Java.util.date;" "Import com.Yourname.student");
Since the query is required to exist, the Query interface defines the method of filtering conditions: Serfilter ()
Public void setfilter (java.lang.string filter)
Filter's way of writing should be the same as the condition of the WHERE statement in SQL. If the query condition is: find out the surname of the student, then the writing is as follows:
Query.Setfilter ("Name.startSwith");
At the same time, it is found that gender is equal to the woman, and it is changed to:
Query.Setfilter ("Name.startSwith && Sex == IT_SEX");
JDO's operation function, how do I only see StartSwith and Endswith, how do you make a more vague query against a string? Hope to advise?
The sorting method is also provided in the JDO inquiry, and setORDERING is as follows:
Public void setORDERING (Java.lang.String ORDERING)
Such as sorting according to the age of students:
Query.setOrdering ("age ascending"); ascending
Query.SetOrdering ("age descending"); descending order
If multiple sort conditions, such as the size of the age, the height is high:
Query.SetOrdering ("Age Ascending," "stature descending");
Java.jdo.extend
=========================
The instance of the interface represents all kinds of class objects existing in the current database. It is also created by interface personcemanager, as follows:
Public Extent getExtent (Class Persistencecapableclass, Boolean Subclasses)
The true and false parameters Subclass indicates a subclass containing the first parameter class: true, representing a subclass; false, not including a subclass.
There may be two places to use the Extend instance L to get a collection of specific persistent classes.
l For all specific persistent classes in the database for query