1 13 14 19 package org.ejbca.util.query; 20 21 import java.util.Date ; 22 23 24 35 public class TimeMatch extends BasicMatch { 36 38 public static final int MATCH_WITH_TIMECREATED = 0; 39 40 public static final int MATCH_WITH_TIMEMODIFIED = 1; 41 42 43 public static final int MATCH_WITH_REQUESTORAPPROVALTIME = 0; 44 45 public static final int MATCH_WITH_EXPIRETIME = 1; 46 47 private static final String [] MATCH_WITH_SQLNAMES = { 49 "time", "time", "timeCreated", "timeModified","requestdate","expiredate" 50 }; 52 54 63 public TimeMatch(int type, int matchwith, Date startdate, Date enddate) { 64 this.type = type; 65 this.matchwith = matchwith; 66 this.startdate = startdate; 67 this.enddate = enddate; 68 } 69 70 77 public TimeMatch(int type, Date startdate, Date enddate) { 78 this.type = type; 79 this.matchwith = 0; 80 this.startdate = startdate; 81 this.enddate = enddate; 82 } 83 84 89 public String getQueryString() { 90 String returnval = "( "; 91 92 if (startdate != null) { 93 returnval += (MATCH_WITH_SQLNAMES[(type * 2) + matchwith] + " >= " + 94 startdate.getTime() + " "); 95 96 if (enddate != null) { 97 returnval += " AND "; 98 } 99 } 100 101 if (enddate != null) { 102 returnval += (MATCH_WITH_SQLNAMES[(type * 2) + matchwith] + " <= " + enddate.getTime() + 103 " "); 104 } 105 106 returnval += " )"; 107 108 return returnval; 109 } 110 111 113 118 public boolean isLegalQuery() { 119 return !((startdate == null) && (enddate == null)); 120 } 121 122 private int matchwith; 124 private int type; 125 private Date startdate; 126 private Date enddate; 127 } 128 | Popular Tags |