original
Dao.Processor is a core class of data objectification and persistence of Java objects in multi-physical environments.
Summary is as follows:
First, binding with Entity;
For the DAO.Entity object, you can be compatible with the EJB.Entity settings. Typical use of Entity is:
Processor Pro = ProcessorFactory.getProcessorinstance (ENT);
or:
Processor Pro = Processor.getInstance (ENT);
or:
Processor Pro = Procesor.getInstance ();
Pro.sentity; or; prostentity (string ent);
The same is true;
The way is: prO.Open (); this time PRO will receive a specified database connection from the Entity's settings through DataSource or ConnectionManager;
Pro.Close (), turn off all data resources;
Second, bind to the DAO interface;
Pro can bind one or more DAO objects, then Hou Processor looks like a service SPI; however, each DAO object can only bind a Processor instance.
DAO objects can be obtained by find;
DAO DAO = Pro.FindBYID (In id) or Pro.FindByname (String Name) Gets an instance object of the corresponding Entity, each instance is equivalent to a line of records in the database;
DAO DAO = Pro.FindByValue (String Key, String Value); // Returns the DAO object according to a given condition;
DAO.INSERT (); DAO.UPDATE (); DAO.DELETE () and other methods Call Pro.Insert (DAO DAO) by interfaces; can manage these methods by containers, keep synchronization with the database Persistence.
DAO.isexist (), whether the object exists;
DAO DAO = Pro.getdao (String SQL); // actually gets DAO objects directly with SQL;
Third, bind Query;
Another way of use DAO.Processor is synchronized with the DAO.QUERY object. Query is a query container that contains SQL or other XML, typical settings as follows:
insert into bbsthread (author, sourceid, views, replys, authorid, pubdate, alias, topic, content, name, oldpath, oldsource) values ($ {author}, $ {sourceid}, $ {views}, $ {replys}, $ {authorid}, $ {pubdate}, $ {Topic}, $ {content}, $ {name}, $ {oldpath}, $ {oldsource})
Query gets a full SQL statement by query.addvarian (name, value) and then use query.getsqlstatement ();
Processor.SetQuery (Query Qry) is set to Query;
String msg = pro.execute (); // If you perform normal reverse, you will return an error message;
Or ArrayList Alist = Pro.executeQuery (); this requires returning to empty or the Entity's object query column (for SELECT type Query) if Entity is valid.
Or ResultSet RS = Pro.getResultSet (Query Qry); Direct SQL directly; DAO.Processor can perform SQL directly;
For queried statements, you can pass RSULTSET RS = Pro.getResultSet (SQL).
Or: string msg = pro.doupdate (SQL); directly execute SQL execution statement;
Require Entity not empty by arraylist alist = proprosultlist (string sql); // uses Entity settings
Or arraylist alist = propraylist (String SQL, String SCLSS); // DAO interface Class name;
Or ArrayList Alist (string SQL, CLASS CLS);
These overlapping methods get the corresponding query results object columns;
ArrayList Alist = Pro.getResultList (String [] Conditions, String Sord; // This method requires ENTY to return, returned to the sorted object column according to a given update Conditions condition set or Order statement;
V. Extension method:
ArrayList Alist = Pro.getstringList (query qry); // Returns the string type column;
Batchdelete (int [] IDS); BatchResume (int [] IDS); Batchclear (int [] IDS), several Batch methods, requires all records of the specified ID set on the basis of Entity has been set.
6. Get the method of connnection; mainly get database connections through ConnectionManager;
There are three possible ways; one is the connection name required by Entity; the second is to obtain the needed connection name through Query's getConn; third is to obtain a connection name directly through SetConnection;