KickJava   Java API By Example, From Geeks To Geeks.

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


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: LogMatch.java,v 1.2 2006/08/09 07:29:48 herrvendil Exp $
27  *
28  * @see org.ejbca.util.query.BasicMatch
29  * @see org.ejbca.util.query.TimeMatch
30  * @see org.ejbca.util.query.LogMatch
31  */

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

35     public static final int MATCH_WITH_USERNAME = 0;
36     public static final int MATCH_WITH_ADMINCERTIFICATE = 1;
37     public static final int MATCH_WITH_IP = 2;
38     public static final int MATCH_WITH_SPECIALADMIN = 3;
39     public static final int MATCH_WITH_CERTIFICATE = 4;
40     public static final int MATCH_WITH_COMMENT = 5;
41     public static final int MATCH_WITH_EVENT = 6; // Value must the number representation.
42
public static final int MATCH_WITH_MODULE = 7;
43     public static final int MATCH_WITH_CA = 8;
44
45
46     // Private Constants.
47
static final String JavaDoc[] MATCH_WITH_SQLNAMES = {"username", "adminData", "adminData", "adminType"
48                                                          , "certificateSNR", "comment", "event", "module", "caid"}; // Represents the column names in ra userdata table.
49

50     
51     // Public methods.
52

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

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

81     public String JavaDoc getQueryString() {
82         String JavaDoc returnval = "";
83
84         if (matchtype == BasicMatch.MATCH_TYPE_EQUALS) {
85             returnval = MATCH_WITH_SQLNAMES[matchwith] + " = '" + matchvalue + "'";
86         }
87
88         if (matchtype == BasicMatch.MATCH_TYPE_BEGINSWITH) {
89             returnval = MATCH_WITH_SQLNAMES[matchwith] + " LIKE '" + matchvalue + "%'";
90         }
91
92         if (matchtype == BasicMatch.MATCH_TYPE_CONTAINS) {
93             returnval = MATCH_WITH_SQLNAMES[matchwith] + " LIKE '%" + matchvalue + "%'";
94         }
95
96         return returnval;
97     }
98
99     // getQueryString
100

101     /**
102      * Checks if query data is ok.
103      *
104      * @return DOCUMENT ME!
105      */

106     public boolean isLegalQuery() {
107         return !(matchvalue.trim().equals(""));
108     }
109
110     // Private Methods
111
// Private Fields.
112
private int matchwith;
113     private int matchtype;
114     private String JavaDoc matchvalue;
115 }
116
Popular Tags