summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java
blob: db77f41acc0044417a592461b8248388635d71c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.request;

import java.util.*;
import java.io.*;
import java.math.*;
import com.netscape.certsrv.dbs.EDBException;
import com.netscape.certsrv.dbs.IDBSubsystem;
import com.netscape.certsrv.dbs.*;
import com.netscape.certsrv.request.*;
import com.netscape.certsrv.base.*;
import com.netscape.certsrv.apps.*;
import com.netscape.cmscore.dbs.*;


/**
 * TODO: what does this class provide beyond the Repository
 * base class??
 * <p>
 * @author thayes
 * @version $Revision$ $Date$
 */
class RequestRepository
    extends Repository {

     IDBSubsystem mDB = null;
     IRequestQueue mRequestQueue = null;
    /**
     * Create a request repository that uses the LDAP database
     * <p>
     * @param name
     *    the name of the repository.  This String is used to
     *    construct the DN for the repository's LDAP entry.
     * @param db
     *    the LDAP database system.
     */
    public RequestRepository(String name, int increment, IDBSubsystem db)
        throws EDBException {
        super(db, increment, "ou=" + name + ",ou=requests," + db.getBaseDN());

        CMS.debug("RequestRepository: constructor 1");
        mBaseDN = "ou=" + name + ",ou=requests," + db.getBaseDN();

        // Let RequestRecord class register its
        // database mapping and object mapping values
        RequestRecord.register(db);
        mDB = db;
    }

    public RequestRepository(String name, int increment, IDBSubsystem db,IRequestQueue requestQueue)
        throws EDBException {
        super(db, increment, "ou=" + name + ",ou=requests," + db.getBaseDN());

        CMS.debug("RequestRepository: constructor2.");
        mRequestQueue = requestQueue;
        mBaseDN = "ou=" + name + ",ou=requests," + db.getBaseDN();

        // Let RequestRecord class register its
        // database mapping and object mapping values
        RequestRecord.register(db);
        mDB = db;
    }

    /**
     * get the LDAP base DN for this repository.  This
     * value can be used by the request queue to create the
     * name for the request records themselves.
     * <p>
     * @return
     *    the LDAP base DN.
     */
    public String getBaseDN() {
        return mBaseDN;
    }

    /**
     * Resets serial number.
     */
    public void resetSerialNumber(BigInteger serial) throws EBaseException
    {
        setTheSerialNumber(serial);
    }
                                                                                
    /**
     * Removes all objects with this repository.
     */
    public void removeAllObjects() throws EBaseException
    {
        IDBSSession s = mDB.createSession();
        try {
            Enumeration e = s.search(getBaseDN(), 
                               "(" + RequestRecord.ATTR_REQUEST_ID + "=*)");
            while (e.hasMoreElements()) {
              RequestRecord r = (RequestRecord)e.nextElement();
              String name = "cn" + "=" +
                r.getRequestId().toString() + "," + getBaseDN();
               s.delete(name);
            }       
        } finally {
            if (s != null)
                s.close();
        }
    }

    public BigInteger getLastSerialNumberInRange(BigInteger min, BigInteger max)
    {

        CMS.debug("RequestRepository: in getLastSerialNumberInRange: min " + min + " max " + max);

        CMS.debug("RequestRepository: mRequestQueue " + mRequestQueue);

        BigInteger ret = null;

        if(mRequestQueue == null)  {

            CMS.debug("RequestRepository:  mRequestQueue is null.");

        }  else  {
       
            CMS.debug("RequestRepository: about to call mRequestQueue.getLastRequestIdInRange"); 
            ret = mRequestQueue.getLastRequestIdInRange(min,max);

        }

        return ret;

    }
    /**
     * the LDAP base DN for this repository
     */
    protected String mBaseDN;
}