SmartPersistencelayer 2.0 (6) --- Condition

xiaoxiao2021-03-06  46

SMARTPERSISISTENCELAYER 2.0 CONDition

principle

The powerful condition function is a feature of the SPL. You can use the CONDITION to complete the conditions definition, the use is also the most widely used, such as Retrievecriteria, Updatecriteria, DeleteCriteria, Query, etc., as long as you use the query criteria, you will use this CONDITION class. .

Condition's instantiation method:

Retrievecriteria rc = new retrievecriteria (TypeEOf (Studentent));

Condition C = rc.getnewcondition ();

or

Updatecriteria uc = new updatecriteria (TypeEntent);

Condition c = uc.getnewcondition ();

or

Deletecriteria DC = New DeleteCriteria (TypeEntent);

Condition C = dc.getnewcondition ();

or

Query Q = New Query (TypeEntent));

Condition C = q. GetQueryCondition ();

Inside the Condition is the AND relationship, between the condition, is combined with "OR"

Such as:

Retrievecriteria rc = new retrievecriteria (TypeEOf (Studentent));

Condition C = rc.getnewcondition ();

C.ADDEQUALTO (Studententity.Name, "Tintown");

C.Addnotequalto (studEntentity.sex, 'male');

CONDition C2 = rc.getnewcondition ();

C2.Addequalto (Studententity.ID, "1");

This will result in "(Name = 'Tintown' and SEX <> Men ') OR ID = 1".

Common condition

The following takes Retrievecriteria RC = New RetrieveCriteria (TypeEntent);

Condition C = rc.getnewcondition ();

Addequalto (=)

Equally comparison: A statement similar to "where name = 'tintown'" is generated, for example:

C.Addequalto ("Name", "Tintown");

Addgreaterthan (>)

More than comparison: will generate a statement similar to "Where price> 1000"

C.Addgreaterthan ("Price", 1000);

Addgreaterthanorequalto (> =)

Coner than or equal to comparison: a statement similar to "where price> = 1000" will generate

C.AddgreartERTHANOREQUALTO ("Price", 1000);

AddNotequalto (<>)

Not equal to comparison: will generate a statement similar to "Where name <> tintown '"

C.AddNotequalto ("Name", "TINTOWN");

AddLessthan (<)

Small than comparison: A statement like "WHERE PRICE <1000" will be generated

C.Addlessthan ("Price", 1000);

AddLesSthanorequalto (<=)

It is less than or equal to comparison: a statement like "WHERE PRICE <= 1000" C. ADDLESSSTHANOREQUALTO ("Price", 1000);

Addmatch (Like '% a%')

Matching comparison: will generate a statement similar to "where name like '% Liu%'"

C.Addmatch ("Name", "Liu");

AddmatchPrefix (Like 'a%')

Front match comparison: will generate a "WHERE Name Like%" statement

C.addmatchPrefix ("Name", "Liu");

Addin (in (a))

In comparison: A statement similar to "WHERE NAME IN ('K', 'I')" is generated

String [] where = new string [] {"k", "i"}

C.Addin ("Name", where);

Orgroup condition class [2.0 new features]

In convention, we noticed that it is difficult to implement A and B And (C OR D) effect, so add a Orgroup class here.

Orgroup refers to the group of OR, in Orgroup, the relationship is OR, so you can implement the following code:

Retrievecriteria rc = new retrievecriteria (TypeEOf (Studentent));

Condition C = rc.getnewcondition ();

C.Addequalto (....) // Condition a

C.ADDEQUALTO (....) / / Condition B

Orgroup og = rc. GetNeworgroup (); // instance an orgroup

Og.addequalto (...); // Condition C

ig.addequalto (...); // Condition D

C and D form an OR group so that A and B AND (C OR D)

More standard definitions can be achieved by the above way

Fields and fields Compare [2.0 new features]

For this comparison of fields and fields, the query criteria is extended.

Pictures between Fields, etc. Addequaltofield

C.Addequaltofield ("Field1", Field2);

This will generate similar "where field1 = field2"

Fields are larger than addgreaterthanfield

c. AddgreatertHanfield ("Field1", Field2);

This will generate similar "where field1> field2"

Fields are greater than equals Addgreatertlthanorequaltofield

c. Addgreaterthanorequaltofield ("Field1", Field2);

This will generate similar "where field1> = field2"

Fields are not equal to AddNotequaltofield

c. Addnotequaltofield ("Field1", Field2);

This will generate similar "where field1 <> field2"

Fields are less than addLessthanfield

c. AddLesSthanfield ("Field1", Field2);

This will generate similar "where field1

The field is less than or equal to addLesSthanorequaltofield

c. AddLesSthanorequaltofield ("Field1", Field2);

This will generate similar "where field1 <= field2"

to sum up

Although SPL provides a strong conditional definition feature, if you encounter a particularly complex condition, you still need your own handwritten SQL statement for query.

Listen to

November 2004

转载请注明原文地址:https://www.9cbs.com/read-80660.html

New Post(0)