Use DAO. Processor Manage Data Persistence objects

Source: Internet
Author: User
Tags bind insert interface query requires
Objects | data
Original

Dao. Processor is the core class of data object and persistence of Java object in multi-database multi-entity environment, its consumer

The law concludes as follows:

One, with entity binding;

For Dao.entity objects, can be compatible with ejb.entity settings. Typical ways to use entity compatibility are:

Processor Pro =processorfactory.getprocessorinstance (ENT);

Or:

Processor Pro =processor.getinstance (ENT);

Or:

Processor Pro =procesor.getinstance ();

Pro.setentity (entity); or; Pro.setentity (String ent);

Effect of the same;

The use is: Pro.open (), then Hou Pro will be from the entity settings through the DataSource or ConnectionManager to obtain the specified database connection;

Pro.close (), close clear all data resources;

binding with DAO interface;

Pro can bind one or more DAO objects, and Hou processor looks like a service SPI, but each DAO object can only bind to one processor instance.

You can get the DAO object by Find.

The DAO DAO =pro.findbyid (in ID) or pro.findbyname (String name) obtains the corresponding entity instance object, each equivalent to a row of records in the database;

DAO DAO =pro.findbyvalue (String key,string value);//Return DAO object based on given criteria;

Several methods, such as Pro.insert (dao Dao), are called by the Dao.insert ();d ao.update ();d ao.delete (), and can be managed by the container to maintain synchronization persistence with the database.

Dao.isexist (), whether the object exists;

DAO DAO =pro.getdao (String sql);//is actually getting the DAO object directly from SQL;

Third, with query binding;

Dao. Another way to use processor is to synchronize with Dao.query objects. Query is a query container that contains SQL that is defined by dao.xml or other XML, typically set as follows:

Insert into Bbsthread (Author,sourceid,views,replys,authorid,pubdate,alias,topic,content,name,oldpath,oldsource) VALUES (${author},${sourceid},${views},${replys},${authorid},${pubdate},${alias},${topic},${content},${name},${ Oldpath},${oldsource})

Query uses Query.getsqlstatement () to get the complete SQL statement through Query.addvarian (Name,value);

Processor.setquery (query qry) is set into query;

String msg =pro.execute ();//If normal anti-go home is performed, error message is returned;

or ArrayList alist =pro.executequery (), which requires a null return or an object query column for the entity (for select query) if the entity is valid;

or resultset Rs =pro.getresultset (Query qry), and execute SQL directly;

Dao. Processor can execute SQL directly;

For query-type statements can be directly through the ResultSet Rs =pro.getresultset (SQL);

Or: String msg =pro.doupdate (SQL); Execute SQL execution statement directly;

Entity is not null by ArrayList alist =pro.getresultlist (String sql)//using the class type set by entity

or ArrayList alist =pro.getresultlist (String sql,string SCLSS); The class name of the DAO interface;

or ArrayList alist =pro.getresultlist (String sql,class CLS);

These overlapping methods get the corresponding query result object columns;

ArrayList alist =pro.getresultlist (string[] conditions,string sord);//This method requires Enty to be set up, Returns the sorted object column by the given updated conditions conditional set or order statement;

V. Extension methods:

ArrayList alist =pro.getstringlist (Query qry);//Returns a string type of column;

Batchdelete (int[] IDs), Batchresume (int[] IDs); Batchclear (int[] IDs), several batch methods require all records of the specified set of IDs to be executed on the basis of the entity already set.

The method of acquiring connnection, mainly through ConnectionManager to obtain database connection;

There are three possible approaches; one is to obtain the required connection name by entity, the other is to obtain the necessary connection name through the getconn of query, and the third is to obtain the connection name directly through SetConnection;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.