KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > util > query > ApprovalMatch


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 /*
15  * LogMatch.java
16  *
17  * Created on den 28 aug 2002, 23:20
18  */

19 package org.ejbca.util.query;
20
21 /**
22  * A class used by Query class to build a query for ejbca log module. Inherits BasicMatch. Main
23  * function is getQueryString which returns a fragment of SQL statment.
24  *
25  * @author TomSelleck
26  * @version $Id: ApprovalMatch.java,v 1.2.6.1 2007/05/04 09:10:26 anatom Exp $
27  *
28  * @see org.ejbca.util.query.BasicMatch
29  * @see org.ejbca.util.query.TimeMatch
30  * @see org.ejbca.util.query.ApprovalMatch
31  */

32 public class ApprovalMatch extends BasicMatch {
33     // Public Constants
34

35     public static final int MATCH_WITH_UNIQUEID = 0;
36     public static final int MATCH_WITH_APPROVALID = 1;
37     public static final int MATCH_WITH_APPROVALTYPE = 2;
38     public static final int MATCH_WITH_ENDENTITYPROFILEID = 3;
39     public static final int MATCH_WITH_CAID = 4;
40     public static final int MATCH_WITH_REQUESTADMINCERTISSUERDN = 5;
41     public static final int MATCH_WITH_REQUESTADMINCERTSERIALNUMBER = 6;
42     public static final int MATCH_WITH_STATUS = 7;
43     public static final int MATCH_WITH_REMAININGAPPROVALS = 8;
44
45     
46
47
48     // Private Constants.
49
static final String JavaDoc[] MATCH_WITH_SQLNAMES = {"id","approvalid", "approvaltype", "endentityprofileid", "caid"
50                                                          , "reqadmincertissuerdn", "reqadmincertsn", "status", "remainingapprovals"}; // Represents the column names in approvals table.
51

52     
53     // Public methods.
54

55     /**
56      * Creates a new instance of LogMatch.
57      *
58      * @param matchwith determines which field i logentry table to match with.
59      * @param matchtype determines how to match the field..
60      * @param matchvalue the value to match with.
61      *
62      * @throws NumberFormatException if matchvalue constains illegal numbervalue when matching
63      * number field.
64      */

65     public ApprovalMatch(int matchwith, int matchtype, String JavaDoc matchvalue)
66         throws NumberFormatException JavaDoc {
67         this.matchwith = matchwith;
68         this.matchtype = matchtype;
69         this.matchvalue = matchvalue;
70
71         // The row below does not do anthing but check that matchvalue contains
72
// a legal number value when matching number field. See @throws clause.
73
if (matchwith != MATCH_WITH_REQUESTADMINCERTISSUERDN &&
74             matchwith != MATCH_WITH_REQUESTADMINCERTSERIALNUMBER){
75             new Integer JavaDoc(matchvalue);
76         }
77     }
78
79     /**
80      * Returns a SQL statement fragment from the given data.
81      *
82      * @return DOCUMENT ME!
83      */

84     public String JavaDoc getQueryString() {
85         String JavaDoc returnval = "";
86
87         if (matchtype == BasicMatch.MATCH_TYPE_EQUALS) {
88             // Because some databases (read JavaDB/Derby) does not allow matching of integer with a string expression
89
// like "where status='10'" instead of "where status=10", we have to hav e some special handling here.
90
String JavaDoc stringChar = "'";
91             if ((matchwith >= MATCH_WITH_UNIQUEID && matchwith <= MATCH_WITH_CAID) || (matchwith == MATCH_WITH_STATUS) || (matchwith == MATCH_WITH_REMAININGAPPROVALS)) {
92                 stringChar = "";
93             }
94             returnval = MATCH_WITH_SQLNAMES[matchwith] + " = "+stringChar + matchvalue + stringChar;
95         }
96
97         if (matchtype == BasicMatch.MATCH_TYPE_BEGINSWITH) {
98             returnval = MATCH_WITH_SQLNAMES[matchwith] + " LIKE '" + matchvalue + "%'";
99         }
100
101         if (matchtype == BasicMatch.MATCH_TYPE_CONTAINS) {
102             returnval = MATCH_WITH_SQLNAMES[matchwith] + " LIKE '%" + matchvalue + "%'";
103         }
104
105         return returnval;
106     }
107
108     // getQueryString
109

110     /**
111      * Checks if query data is ok.
112      *
113      * @return DOCUMENT ME!
114      */

115     public boolean isLegalQuery() {
116         return !(matchvalue.trim().equals(""));
117     }
118
119     // Private Methods
120
// Private Fields.
121
private int matchwith;
122     private int matchtype;
123     private String JavaDoc matchvalue;
124 }
125
Popular Tags