![]() |
Instroduction 1. Initialize configuration of frame environment The jar file of frame is excutable and users can initialize configuration of frame like this: java -jar D:\persistence.jar init config This command will create configuration files to default folder and users can edit these files then. If users want to learn more ,there is a java file'com.nonesole.persistence.main.Main' can give help. 2. Example of O-R Mapping (1) DataSource from JDBC : DriverProperties dp = new DriverProperties(); dp.setAssociateConnectionPool(false); dp.setDataSourceName("test"); dp.setDriverClass("com.mysql.jdbc.Driver"); dp.setUrl("jdbc:mysql://localhost:3306/test"); dp.setUser("root"); dp.setPwd("root"); DataSource ds = new DriverDataSource(dp); (2) Get sql operations : //sql operation ISQLOperations op = SQLOperationsFactory.getInstance().getSQLOperations(); //prepared sql operation which can deal with blob ISQLOperations op = SQLOperationsFactory.getInstance().getBlobOperations(); (3) Configuration for O-R Mapping <object-sql-mapping> <obj className="com.nonesole.persistence.example.bean.dao.User" tableName="system_user" primeryKey="id" /> </object-sql-mapping> (4) DML operations : User u = new User(); u.setId(100); u.setName("simple"); u.setPwd("sa"); try { op.insert(u, ds.getConnection()); } catch (OperationsException e) { e.printStackTrace(); } (5)DQL operations : List 3.Example of O-F Mapping (1) Initialize file operation: IFileOperations fo = null; try { fo = FileOperationsFactory.getInstance(). getOperation(FileOperationsFactory.TXT_OPERATION); } catch (OperationsException e) { e.printStackTrace(); } (2) Initialize url for O-F Mapping: URL url = null; try { url = new URI("file:/D:").toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } (3) Save object: try { fo.insert(u, url); } catch (OperationsException e) { e.printStackTrace(); } (4) Query objects: SearchConditions sc = new SearchConditions(); sc.setEndTime(new Date().getTime()+10); try { List<Object> os = fo.query(sc, url); System.out.println(((User)os.get(0)).getName()); } catch (OperationsException e) { e.printStackTrace(); } |