|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
QueryBasic components handle information such as subscriber (SubscriberInfo) and location (RegistrationInfo) information. This information consists of attributes such as a user name, host name, CallID, and CSeq. Each attribute contains a pair of a key string to identify the attribute and a value. Each attribute also has type information about their values. Basic components have a function of retrieve subscriber and location information. The com.oki.sip.equips.query package provides APIs for the search. The user management and location management components define lookupCount, which returns the number of search results. Stateful session Beans for user and location search are deployed. When you perform a search, you can narrow the result by setting attribute conditions such as a user name and host name. You can also set a filter such as sort order to get a filtered result. This section describes how to write search conditions and filter the search result. Search StepsThe basic steps for a search are as follows:
Here is an example code: List 2.6.1 Sample Code import java.util.*; import com.oki.sip.equips.query.*; import com.oki.sip.equips.signal.BasicSipServlet; import com.oki.sip.equips.users.*; public SampleServlet extends BasicSipServlet { /** * Search all subscribers that match partially with the specified subscriber name alias and * get a list that contains OkiSubscriberAdminInfo. */ public List getOkiAdminInfos(String username, String alias) throws Exception { // 1. Create Query. Query q = EquipsLookupTemplate.createUsersQuery(); // 2. AND expression. LogicalExpression andE = q.createAnd(); // 3. Partial matching for username. ConditionalExpression likeE1 = q.createLike(OkiLookupUsers.USERNAME_KEY, "*" + username + "*"); // 4. Partial matching for alias. ConditionalExpression likeE2 = q.createLike(OkiLookupUsers.ALIAS_KEY, "*" + alias + "*"); // 5. AND username and alias conditions and set it in Query. andE.add(likeE1); andE.add(likeE2); q.setExpression(andE); // 6. Set descending sort by user name. SortKey skey = new SortKey(OkiLookupUsers.USERNAME_KEY, false); q.addSortKey(skey); // 7. Get QueryResult. QueryResult result = getUsersQueryResult(q); // 8. Return a result. List list = new Vector(); while(result.hasNext()){ OkiSubscriberAdminInfo info = (OkiSubscriberAdminInfo) result.next(); list.add(info); } return list; } }
Writing Search ConditionsThis section describes how to create search conditions. The Basic steps to do this are as follows:
Search conditions are expressed with operators. The Query class in the com.oki.sip.equips.query package defines create methods (such as createAnd and createEqual) to create search conditions using Java operators. Use these create methods to generate search conditions and set them in the Query object. If no condition is set, the query returns all data. Each operator has its own priority. When an expression with multiple operators is evaluated, the operator with a higher priority is evaluated first. If operators have the same priority, the preceding operator is evaluated first. A description and example of each operator is shown in Table 2.6.1, priority of each operator is shown in Table 2.6.2, and attribute keys and object types available for the search are shown in Table 2.6.3. Attribute keys used for a user search is defined in the OkiLookupUsers class in the com.oki.sip.equips.query package. Attribute keys used for a location search is defined in the OkiLookupUsers class in the com.oki.sip.equips.query package. Table 2.6.1 Description and Example of Each Operator Equal Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createEqual(OkiLookupUsers.USERNAME_KEY, "Oki")); NotEqual Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createNotEqual(OkiLookupUsers.USERNAME_KEY, "Oki")); GreaterThan Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createGreaterThan(OkiLookupUsers.AUTHFAILURE_KEY, new Integer(3))); LessThan Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createLessThan(OkiLookupUsers.AUTHFAILURE_KEY, new Integer(3))); GreaterEqual Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createGreaterEqual(OkiLookupUsers.AUTHFAILURE_KEY, new Integer(3))); LessEqual Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createLessEqual(OkiLookupUsers.AUTHFAILURE_KEY, new Integer(3))); Between Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createBetween(OkiLookupUsers.AUTHFAILURE_KEY, new Integer(1), new Integer(3))); Like Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createLike(OkiLookupUsers.USERNAME_KEY, "*user*")); NotLike Operator
Query q = EquipsLookupTemplate.createUsersQuery(); q.setExpression(q.createNotLike(OkiLookupUsers.USERNAME_KEY, "*user*")); And Operator
Query q = EquipsLookupTemplate.createUsersQuery(); LogicalExpression andE = q.createAnd(); andE.add(q.createLike(OkiLookupUsers.ALIAS_KEY, "Oki*")); andE.add(q.createEqual(OkiLookupUsers.HOST_KEY, "oki.com")); q.setExpression(andE); Or Operator
Query q = EquipsLookupTemplate.createUsersQuery(); LogicalExpression orE = q.createOr(); orE.add(q.createLike(OkiLookupUsers.ALIAS_KEY, "Oki*")); orE.add(q.createEqual(OkiLookupUsers.HOST_KEY, "oki.com")); q.setExpression(orE);
In expressions containing AND or OR, conditions can be nested as shown below: Query q = EquipsLookupTemplate.createUsersQuery(); LogicalExpression andE1 = q.createAnd(); LogicalExpression andE2 = q.createAnd(); LogicalExpression orE = q.createOr(); andE1.add(q.createLike(OkiLookupUsers.ALIAS_KEY, "Oki*")); andE1.add(q.createEqual(OkiLookupUsers.HOST_KEY, "oki.com")); andE2.add(q.createLike(OkiLookupUsers.ALIAS_KEY, "*user*")); andE2.add(q.createNotLike(OkiLookupUsers.SUBSCRIBER_KEY, "user*")); orE.add(andE1); orE.add(andE2); q.setExpression(orE); Table 2.6.2 Priority of Operator
You can use attribute keys that are defined in OkiLookupUsers (for a user search) and OkiLookupLocations (for a location search). Table 2.6.3 Attribute Keys and Object Types Available for a Search
Setting a FilterSetting a filter in the Query object enables you to get a result in a different form. Currently, a sorting filter is provided to sort the search result. The sorting filter sorts the result based on attribute values corresponding to each key. You must register these attributes with Query as a sort key. Any number of sort keys can be set in order of decreasing priority. If multiple sort keys are specified, when there are equivalent values corresponding to a key with a higher priority, a sort key with a lower priority is used for them. You can also set an ascending or descending order for each sort key. Specify true in the second constructor of SortKey to set an ascending order, specify false to set a descending order. Here is an example description of the sort key.
Sort by use name (Username). If equivalent values are found, sort them by alias (Alias). Query q = EquipsLookupTemplate.createUsersQuery(); q.addSortKey(new SortKey(OkiLookupUsers.USERNAME_KEY, true)); q.addSortKey(new SortKey(OkiLookupUsers.ALIAS_KEY, true));
Sort by authentication failure times (AuthFailure). If equivalent values are found, sort them by user name (Username) in ascending order, alias (Alias) in ascending order, and host name (Host) in ascending order. Query q = EquipsLookupTemplate.createUsersQuery(); q.addSortKey(new SortKey(OkiLookupUsers.AUTHFAILURE_KEY, false)); q.addSortKey(new SortKey(OkiLookupUsers.USERNAME_KEY, true)); q.addSortKey(new SortKey(OkiLookupUsers.ALIAS_KEY, true)); q.addSortKey(new SortKey(OkiLookupUsers.HOST_KEY, true)); NotesThe Search process is implemented using the search engine of your database. It may behave differently than when you write conditions in general Java language. NULL HandlingIf you specify a search condition "an attribute value of the specified key is not A" (A is any value other than null) such as NotEqual and NotLike, null is not included in the result. For example, if subscriber information X, Y, and Z are stored and their ALIAS_KEY values are as follows:
If a search condition "ALIAS_KEY value is not OKI" is specified, Y is returned but Z is not. If you want the search to return both Y and Z, you must explicitly specify "ALIAS_KEY value is either OKI or null". TipsYou can use the following ways to increase search speed.
Last Modified:Thu Mar 25 04:57:50 PM JST 2004 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|