JPMapper in the OSDays!

JPMapper in OSDays 2011! don't miss the event...
VERSION DOWNLOAD
The first beta-release 0.7.1 of JPMapper is now avalaible to download. Note that only MySQL DBMS is supported for now, if you are interested in the project, please feel free to contribute after getting the jpmapper code source from SVN Repository!
SIMPLE SELECT!
Download jpmapper and the mysql conncetor and place them in the class path!
You have also to download the dbinfo.properties
file configuration and make the needed changes: (only the "DB INFORMATION" section: host,username,password,dbname)
Get the user 3 from dataBase:
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
User user = new User();
user.setID(3);
jpmapper.get(user);
System.out.println("UserName:"+user.getName());
}
Get the user "jad" from dataBase:
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
User user = new User();
jpmapper.get(user,"name=' jad ' ");
System.out.println("UserName:"+user.getName());
}
Get all users from dataBase:
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
ArrayList<Users> users=new ArrayList<User>();
users=jpmapper.getAll(new User());
for(int i=0;i ≤users.size();i++)
System.out.println(users.get(i).getUserID()+users.get(i).getPassword());
}
INSERT INTO DATABASE!
two modes are available, if you are in a concurrency mode, use the transaction mode, if not, use the simple one!
insert a user://import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
User user = new User();
user.setName("jad");
jpmapper.put(user);
//close connection
jpmapper.close(); }insert a user:(transaction mode)
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
Transaction transaction=jpmapper.getNewTransaction();
transaction.begin();
User user = new User();
user.setName("jad");
transaction.put(user);
//commit changes
transaction.end();
//close connection
jpmapper.close(); }
DELETE FROM DATABASE!
delete the user 3 from database:
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
User user = new User();
user.setUserID(3);
jpmapper.delete(user);
}
delete the user 3 from dataBase:(transaction mode)
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
Transaction transaction=jpmapper.getNewTransaction();
transaction.begin();
User user = new User();
user.setUserID(3);
transaction.delete(user);
//commit changes
transaction.end();
//close connection
jpmapper.close(); }
UPDATE DATABASE!
update the user 3:
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
User user = new User();
user.setUserID(3);
user.setName("ahmed");
jpmapper.update(user);
//close connection
jpmapper.close(); }update the user 3:(transaction mode)
//import of classes.
import java.io.*; import jpmapper.core.JPMapperFacade;
//Main
public static void main ( String
args[] ) {JPMapperFacade jpmapper=JPMapperFacade.getInstance("dbinfo.properties");
Transaction transaction=jpmapper.getNewTransaction();
transaction.begin();
User user = new User();
user.setUserID(3);
user.setName("ahmed");
transaction.update(user);
//commit changes
transaction.end();
//close connection
jpmapper.close(); }