Research based project for Database applications
- Goals of this project
- Connection Poolin
- Support all known Database – driver required for java
- Easy to use
- Easy to create Object Relations
- No need to write DDL statements
- No Need to write DML statements
- XML-RPC service over http
- New Fields
- Object Pooling
- Easy to add New Service
SQLObject - subversion
http://sqlobject-java.svn.sourceforge.net/viewvc/sqlobject-java/
Examples
public class Category extends SQLObject {
private Char name = new Char("Name",64,true);
private Char code = new Char("Code",4,false);
private Many2One parent_ids = newMany2One(
"Parent",0,false,"modules.base.res.Category");
}
public class Country extends SQLObject {
private Char name = new Char("Name",32,true);
private Char code = new Char("Code",4,true);
}
public class State extends SQLObject {
private Char name = new Char("Name",32,true);
private Char code = new Char("Code",4,true);
private Many2One country_id = new
Many2One("Country",0,true,"modules.base.res.Country");
}
public class Address extends SQLObject {
private Many2One partner_id = new
Many2One("Partner",0,true,"modules.base.res.Partner");
private Char name = new Char("Name",64,false);
private Char street = new Char("Stree2",64,false);
private Char street2 = new Char("Street2",64,false);
private Char zip = new Char("Pin Code",64,false);
private Char city = new Char("City",64,false);
private Many2One state = new
Many2One("State",0,true,"modules.base.res.State");
private Many2One country = new
Many2One("Country",0,true,"modules.base.res.Country");
private Char mobile = new Char("Mobile",64,false);
private Char phone = new Char("Phone",64,false);
private Char fax = new Char("Fax",64,false);
}
public class Partner extends SQLObject {
private Char name = new Char("Name",64,false);
private Char email = new Char("Name",64,false);
private Char age = new Char("Age",64,false);
private One2Many address = new
One2Many("Address",false,"modules.base.res.Address");
}
Above 5 classes will result in following just by running application using SQLObject framework
As i have using PostgreSQL as Database it shows the view of PostgreSQL, also look at Object Diagram
These all class extends SQLObject so in that already methods defined like, create, write, search, unlink, read, so now no need to write the methods for data reading from and writing to databse
Client Application - connect to XML-RPC server that provides Object Service for all SQLObjects
defined in SQLObject framework
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.*;
import java.util.HashMap;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
try {
config.setServerURL(new URL("http://127.0.0.1:5050"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
try {
HashMap<String, Object> vals = new HashMap<String, Object>();
vals.put("name", "Mantavya Gajjar");
vals.put("email", "mantavyagajjar@gmail.com");
vals.put("vatcode", "VAT-GJ/25");
HashMap<String, Object> address1 = new HashMap<String, Object>();
address1.put("name", "M Gajjar");
address1.put("state", "Gujarat");
vals.put("address", address1);
vals.put("category_ids", new Integer[]{1,2,3});
Object[] params = new Object[]{"modules.base.res.Partner",vals};
client.execute("obj.create", params);
} catch (XmlRpcException e) {
System.out.println(e.getMessage());
}
This will create a record in Partner Object and also add an record in database with all related records line, address, category
- Thank's to Amit to deliverd a interesting link
http://www.sqlalchemy.org/