This short tutorial allows a quick introduction into the general working
principles of PriDE, based on a simple example. It takes less than 15 minutes
to set up a primitive PriDE application which allows to perform basic operations
on a simple database table. The directory examples/quickstart contains
the complete source code für the tutorial example.
Setting up an application includes the following steps:
create table customer ( id integer not null primary key, name varchar(20), first_name varchar(30) ); |
java de.mathema.pride.util.CreateTableTemplate <driver class> <database url> <user> <password> customer Customer > Customer.java |
package quickstart; import de.mathema.pride.*; public class Customer extends MappedObject { private int id; private String name; private String firstname; public int getId() { return id; } public String getFirstname() { return firstname; } public String getName() { return name; } public void setId(int val) { id = val; } public void setFirstname(String val) { firstname = val; } public void setName(String val) { name = val; } public Customer(int id, String name, String firstname) { this.id = id; this.name = name; this.firstname = firstname; } public static RecordDescriptor red = new RecordDescriptor (Customer.class, "customer", null, new String[][] { { "id", "getId", "setId" }, { "first_name", "getFirstname", "setFirstname" }, { "name", "getName", "setName" }, }); public RecordDescriptor getDescriptor() { return red; } } |
Properties props = System.getProperties(); ResourceAccessorJ2SE accessor = new ResourceAccessorJ2SE(props); DatabaseFactory.setResourceAccessor(accessor); DatabaseFactory.setDatabaseName(props.getProperty("pride.db")); |
private void create(int id, String name, String firstName) throws SQLException { Customer c = new Customer(id, name, firstName); c.create(); } private void update(int id, String name, String firstName) throws SQLException { Customer c = new Customer(id, name, firstName); c.update(); } private void queryByName( String name ) throws SQLException { Customer c = new Customer(0, name, null); ResultIterator ri = c.query(new String[] { "name" }); do { System.out.println(c.getId() + ": " + c.getName() + "," + c.getFirstname()); } while(ri.next()); } |
The PriDE initialization above is based on system properties which must be passed in the application invokation. E.g. calling the interactive test client for a local MySQL 4 test database might look like this:
java -Dpride.driver=com.mysql.jdbc.Driver -Dpride.db=jdbc:mysql://localhost/test
quickstart.CustomerClient |
Home | Introduction | Javadoc |