* @param ID The primary key of the Customer object
*/
Public Customer Loadcustomer (Integer id) throws Databasenotfoundexception,
persistenceexception {
Customer result = null;
Start a transaction
Db.begin ();
result = (Customer) db.load (Customer.class, id);
Complete transaction, close database
Db.commit ();
Db.close ();
return result;
}
/**
* Used to create user
* @param Customer Newcustomer New Object
*/
public void CreateCustomer (Customer newcustomer) throws
Databasenotfoundexception,
persistenceexception {
Customer result = null;
Db.begin ();
New Customer
Db.create (Newcustomer);
Db.commit ();
Db.close ();
}
/**
* Update Old objects
*/
Public Customer UpdateCustomer (customer UpdateCustomer) throws
Databasenotfoundexception,
persistenceexception {
Db.begin ();
Update Customer
Db.update (UpdateCustomer);
Db.commit ();
Db.close ();
return null;
}
public void Removecustomer (Customer removecustomer) throws
Databasenotfoundexception,
persistenceexception {
Db.begin ();
Delete Customer
Db.remove (Removecustomer);
Db.commit ();
Db.close ();
}
}
Executing queries on the Castor JDO object model
Castor implements a subset of the ODMG 3.0 specification of the Object Query Language (OQL). OQL syntax is similar to SQL syntax, but it allows you to query the object model rather than querying the database directly. This can be a powerful feature when multiple databases are supported. The OQL implementation of Castor transforms the OQL query internally into the appropriate SQL for the database. Use the bind () method to bind the parameters to the query. Here are some simple examples of OQL queries.
Castor's OQL implementation does not continue to use fully qualified object names throughout the query, instead it supports the use of object aliases. In the following queries, C is an alias like this.
If you want to query to find all of the Customer, you can execute the following query:
SELECT C from Demo.customer C
If you want to query to find the customer with the identity equal to 1234, you can:
SELECT c from Demo.customer C WHERE c.customerid= $
Start with, followed by:
Query.bind (1234)
To query for a Customer with a name similar to a special string, you can execute the following query:
SELECT c from Demo.customer C WHERE c.name like $
Followed by:
Query.bind ("%abcd%")
3, ObjectSpaces
ObjectSpaces is the R/O Mapping below Microsoft. Net, so far it is a beta version, I believe it will appear in Vs.net 2004 official version. NET under the R/O mapping is not as prosperous as Java, open source is not much, OJB. Net, Atomsframework, OPF. NET, and so on, are quite well-known, but still in the mature. Ado. NET function is powerful, and JDBC has a lot of different places, so. NET under the O ' mapping has a lot of its own characteristics.
Now a simple introduction to the use of objectspaces, you can compare with Hibernate and JDO.
ObjectSpaces also has a configuration Source.xml file:
We have hibernate the above example, I believe it is easy to understand this section of XML, many of which are similar. Similarly, a persistent class is required:
Public abstract class Customer
{
To define a primary key
[UniqueId] public abstract int CustomerID {get; set;}
Also define attributes
Public abstract string Name {get; set;}
public void OnCreate (int newId)
{
CustomerID = newId;
}
}
Examples of Use:
Mount Source.xml, build ObjectSpace factory
Iobjectspace OS = objectspacefactory.createobjectspace ("Source.xml");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.