summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-01-09 23:32:31 -0500
committerAde Lee <alee@redhat.com>2012-01-09 23:32:31 -0500
commit466533710c179f62865e08b3031748072a0247a3 (patch)
tree4c04c20d50239be26ba8319076de90226526a542 /pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
parentc9e3c48de53fce6908f625f40ac2b2f75d66b5a1 (diff)
downloadpki-466533710c179f62865e08b3031748072a0247a3.tar.gz
pki-466533710c179f62865e08b3031748072a0247a3.tar.xz
pki-466533710c179f62865e08b3031748072a0247a3.zip
Formatting (no wrap)
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java')
-rw-r--r--pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java169
1 files changed, 87 insertions, 82 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java b/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
index 5b081d6c..b2a3b17f 100644
--- a/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
+++ b/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.dbs;
-
import java.util.Enumeration;
import netscape.ldap.LDAPAttribute;
@@ -47,14 +46,12 @@ import com.netscape.certsrv.dbs.Modification;
import com.netscape.certsrv.dbs.ModificationSet;
import com.netscape.certsrv.logging.ILogger;
-
/**
- * A class represents the database session. Operations
- * can be performed with a session.
- *
- * Transaction and Caching support can be integrated
- * into session.
- *
+ * A class represents the database session. Operations can be performed with a
+ * session.
+ *
+ * Transaction and Caching support can be integrated into session.
+ *
* @author thomask
* @version $Revision$, $Date$
*/
@@ -66,7 +63,7 @@ public class DBSSession implements IDBSSession {
/**
* Constructs a database session.
- *
+ *
* @param system the database subsytem
* @param c the ldap connection
*/
@@ -75,7 +72,7 @@ public class DBSSession implements IDBSSession {
mConn = c;
try {
// no limit
- mConn.setOption(LDAPv2.SIZELIMIT, Integer.valueOf(0));
+ mConn.setOption(LDAPv2.SIZELIMIT, Integer.valueOf(0));
} catch (LDAPException e) {
}
}
@@ -97,28 +94,31 @@ public class DBSSession implements IDBSSession {
/**
* Adds object to backend database. For example,
+ *
* <PRE>
- * session.add("cn=123459,o=certificate repository,o=airius.com",
- * certRec);
+ * session.add(&quot;cn=123459,o=certificate repository,o=airius.com&quot;,
+ * certRec);
* </PRE>
- *
+ *
* @param name the name of the ldap entry
* @param obj the DBobj that can be mapped to ldap attrubute set
*/
public void add(String name, IDBObj obj) throws EBaseException {
try {
LDAPAttributeSet attrs = mDBSystem.getRegistry(
- ).createLDAPAttributeSet(obj);
+ ).createLDAPAttributeSet(obj);
LDAPEntry e = new LDAPEntry(name, attrs);
- /*LogDoc
- *
+ /*
+ * LogDoc
+ *
* @phase local ldap add
+ *
* @message DBSSession: begin LDAP add <entry>
*/
mConn.add(e);
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
@@ -127,9 +127,8 @@ public class DBSSession implements IDBSSession {
}
/**
- * Reads an object from the database.
- * all attributes will be returned
- *
+ * Reads an object from the database. all attributes will be returned
+ *
* @param name the name of the ldap entry
*/
public IDBObj read(String name) throws EBaseException {
@@ -137,14 +136,14 @@ public class DBSSession implements IDBSSession {
}
/**
- * Reads an object from the database, and only populates
- * the selected attributes.
- *
+ * Reads an object from the database, and only populates the selected
+ * attributes.
+ *
* @param name the name of the ldap entry
* @param attrs the attributes to be selected
*/
public IDBObj read(String name, String attrs[])
- throws EBaseException {
+ throws EBaseException {
try {
String ldapattrs[] = null;
@@ -153,9 +152,11 @@ public class DBSSession implements IDBSSession {
).getLDAPAttributes(attrs);
}
- /*LogDoc
- *
+ /*
+ * LogDoc
+ *
* @phase local ldap read
+ *
* @message DBSSession: begin LDAP read <entry>
*/
LDAPSearchResults res = mConn.search(name,
@@ -167,16 +168,18 @@ public class DBSSession implements IDBSSession {
entry.getAttributeSet());
} catch (LDAPException e) {
- /*LogDoc
- *
+ /*
+ * LogDoc
+ *
* @phase local ldap read
+ *
* @message DBSSession: <exception thrown>
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_INFO, "DBSSession: " + e.toString());
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
- if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT)
+ if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT)
throw new EDBRecordNotFoundException(
CMS.getUserMessage("CMS_DBS_RECORD_NOT_FOUND"));
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
@@ -191,7 +194,7 @@ public class DBSSession implements IDBSSession {
try {
mConn.delete(name);
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
@@ -203,36 +206,38 @@ public class DBSSession implements IDBSSession {
* Modify an object in the database.
*/
public void modify(String name, ModificationSet mods)
- throws EBaseException {
+ throws EBaseException {
try {
LDAPModificationSet ldapMods = new
- LDAPModificationSet();
+ LDAPModificationSet();
Enumeration<?> e = mods.getModifications();
while (e.hasMoreElements()) {
Modification mod = (Modification)
- e.nextElement();
+ e.nextElement();
LDAPAttributeSet attrs = new LDAPAttributeSet();
mDBSystem.getRegistry().mapObject(null,
- mod.getName(), mod.getValue(), attrs);
+ mod.getName(), mod.getValue(), attrs);
Enumeration<?> e0 = attrs.getAttributes();
while (e0.hasMoreElements()) {
ldapMods.add(toLdapModOp(mod.getOp()),
- (LDAPAttribute)
- e0.nextElement());
+ (LDAPAttribute)
+ e0.nextElement());
}
}
- /*LogDoc
- *
+ /*
+ * LogDoc
+ *
* @phase local ldap add
+ *
* @message DBSSession: begin LDAP modify <entry>
*/
mConn.modify(name, ldapMods);
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
@@ -256,20 +261,19 @@ public class DBSSession implements IDBSSession {
}
/**
- * Searchs for a list of objects that match the
- * filter.
+ * Searchs for a list of objects that match the filter.
*/
public IDBSearchResults search(String base, String filter)
- throws EBaseException {
+ throws EBaseException {
return search(base, filter, null);
}
public IDBSearchResults search(String base, String filter, int maxSize)
- throws EBaseException {
+ throws EBaseException {
try {
String ldapattrs[] = null;
String ldapfilter =
- mDBSystem.getRegistry().getFilter(filter);
+ mDBSystem.getRegistry().getFilter(filter);
LDAPSearchConstraints cons = new LDAPSearchConstraints();
@@ -281,22 +285,22 @@ public class DBSSession implements IDBSSession {
return new DBSearchResults(mDBSystem.getRegistry(),
res);
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
- // XXX error handling, should not raise exception if
- // entry not found
+ // XXX error handling, should not raise exception if
+ // entry not found
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
e.toString()));
}
}
public IDBSearchResults search(String base, String filter, int maxSize, int timeLimit)
- throws EBaseException {
+ throws EBaseException {
try {
String ldapattrs[] = null;
String ldapfilter =
- mDBSystem.getRegistry().getFilter(filter);
+ mDBSystem.getRegistry().getFilter(filter);
LDAPSearchConstraints cons = new LDAPSearchConstraints();
@@ -309,22 +313,21 @@ public class DBSSession implements IDBSSession {
return new DBSearchResults(mDBSystem.getRegistry(),
res);
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
- // XXX error handling, should not raise exception if
- // entry not found
+ // XXX error handling, should not raise exception if
+ // entry not found
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
e.toString()));
}
}
/**
- * Retrieves a list of object that satifies the given
- * filter.
+ * Retrieves a list of object that satifies the given filter.
*/
public IDBSearchResults search(String base, String filter,
- String attrs[]) throws EBaseException {
+ String attrs[]) throws EBaseException {
try {
String ldapattrs[] = null;
@@ -333,35 +336,37 @@ public class DBSSession implements IDBSSession {
).getLDAPAttributes(attrs);
}
String ldapfilter =
- mDBSystem.getRegistry().getFilter(filter);
+ mDBSystem.getRegistry().getFilter(filter);
- /*LogDoc
- *
+ /*
+ * LogDoc
+ *
* @phase local ldap add
+ *
* @message DBSSession: begin LDAP search <filter>
*/
LDAPSearchConstraints cons = new LDAPSearchConstraints();
- cons.setMaxResults(0);
-
+ cons.setMaxResults(0);
+
LDAPSearchResults res = mConn.search(base,
LDAPv2.SCOPE_ONE, ldapfilter, ldapattrs, false, cons);
return new DBSearchResults(mDBSystem.getRegistry(),
res);
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
- // XXX error handling, should not raise exception if
- // entry not found
+ // XXX error handling, should not raise exception if
+ // entry not found
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
e.toString()));
}
}
public LDAPSearchResults persistentSearch(String base, String filter, String attrs[])
- throws EBaseException {
+ throws EBaseException {
try {
String ldapattrs[] = null;
if (attrs != null) {
@@ -369,11 +374,11 @@ public class DBSSession implements IDBSSession {
).getLDAPAttributes(attrs);
}
String ldapfilter =
- mDBSystem.getRegistry().getFilter(filter);
+ mDBSystem.getRegistry().getFilter(filter);
- Integer version = (Integer)(mConn.getOption(LDAPv2.PROTOCOL_VERSION));
+ Integer version = (Integer) (mConn.getOption(LDAPv2.PROTOCOL_VERSION));
- // Only version 3 protocol supports persistent search.
+ // Only version 3 protocol supports persistent search.
if (version.intValue() == 2) {
mConn.setOption(LDAPv2.PROTOCOL_VERSION, Integer.valueOf(3));
}
@@ -384,22 +389,22 @@ public class DBSSession implements IDBSSession {
boolean returnControls = true;
boolean isCritical = true;
LDAPPersistSearchControl persistCtrl = new
- LDAPPersistSearchControl( op, changesOnly,
- returnControls, isCritical );
+ LDAPPersistSearchControl(op, changesOnly,
+ returnControls, isCritical);
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setBatchSize(0);
- cons.setServerControls( persistCtrl );
+ cons.setServerControls(persistCtrl);
LDAPSearchResults res = mConn.search(base,
LDAPv2.SCOPE_ONE, ldapfilter, ldapattrs, false, cons);
return res;
} catch (LDAPException e) {
- if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
+ if (e.getLDAPResultCode() == LDAPException.UNAVAILABLE)
throw new EDBNotAvailException(
CMS.getUserMessage("CMS_DBS_INTERNAL_DIR_UNAVAILABLE"));
- // XXX error handling, should not raise exception if
- // entry not found
+ // XXX error handling, should not raise exception if
+ // entry not found
throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
e.toString()));
}
@@ -409,7 +414,7 @@ public class DBSSession implements IDBSSession {
* Retrieves a list of objects.
*/
public <T> IDBVirtualList<T> createVirtualList(String base, String filter,
- String attrs[]) throws EBaseException {
+ String attrs[]) throws EBaseException {
return new DBVirtualList<T>(mDBSystem.getRegistry(), mConn, base,
filter, attrs);
}
@@ -418,7 +423,7 @@ public class DBSSession implements IDBSSession {
* Retrieves a list of objects.
*/
public <T> IDBVirtualList<T> createVirtualList(String base, String filter,
- String attrs[], String sortKey[]) throws EBaseException {
+ String attrs[], String sortKey[]) throws EBaseException {
return new DBVirtualList<T>(mDBSystem.getRegistry(), mConn, base,
filter, attrs, sortKey);
}
@@ -427,7 +432,7 @@ public class DBSSession implements IDBSSession {
* Retrieves a list of objects.
*/
public IDBVirtualList<?> createVirtualList(String base, String filter,
- String attrs[], String sortKey) throws EBaseException {
+ String attrs[], String sortKey) throws EBaseException {
return new DBVirtualList<Object>(mDBSystem.getRegistry(), mConn, base,
filter, attrs, sortKey);
}
@@ -436,7 +441,7 @@ public class DBSSession implements IDBSSession {
* Retrieves a list of objects.
*/
public IDBVirtualList<?> createVirtualList(String base, String filter,
- String attrs[], String sortKey[], int pageSize) throws EBaseException {
+ String attrs[], String sortKey[], int pageSize) throws EBaseException {
return new DBVirtualList<Object>(mDBSystem.getRegistry(), mConn, base,
filter, attrs, sortKey, pageSize);
}
@@ -445,21 +450,21 @@ public class DBSSession implements IDBSSession {
* Retrieves a list of objects.
*/
public IDBVirtualList<?> createVirtualList(String base, String filter,
- String attrs[], String sortKey, int pageSize) throws EBaseException {
+ String attrs[], String sortKey, int pageSize) throws EBaseException {
return new DBVirtualList<Object>(mDBSystem.getRegistry(), mConn, base,
filter, attrs, sortKey, pageSize);
}
public IDBVirtualList<?> createVirtualList(String base, String filter,
- String attrs[], String startFrom, String sortKey, int pageSize) throws EBaseException {
+ String attrs[], String startFrom, String sortKey, int pageSize) throws EBaseException {
return new DBVirtualList<Object>(mDBSystem.getRegistry(), mConn, base,
filter, attrs, startFrom, sortKey, pageSize);
}
/**
- * Releases object to this interface. This allows us to
- * use memory more efficiently.
+ * Releases object to this interface. This allows us to use memory more
+ * efficiently.
*/
public void release(Object obj) {
// not implemented