summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2011-12-08 21:15:59 -0500
committerAde Lee <alee@redhat.com>2011-12-08 21:15:59 -0500
commit171aaece4f23709d33d180cf36eb3af5e454b0c9 (patch)
tree1485f9f0a7bd10de4ff25030db575dbb8dafae74 /pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
parentadad2fcee8a29fdb82376fbce07dedb11fccc182 (diff)
downloadpki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.gz
pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.tar.xz
pki-171aaece4f23709d33d180cf36eb3af5e454b0c9.zip
Revert "Formatting"
This reverts commit 32150d3ee32f8ac27118af7c792794b538c78a2f.
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.java293
1 files changed, 151 insertions, 142 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 1b6633dc..efdbceec 100644
--- a/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
+++ b/pki/base/common/src/com/netscape/cmscore/dbs/DBSSession.java
@@ -17,6 +17,7 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.dbs;
+
import java.util.Enumeration;
import netscape.ldap.LDAPAttribute;
@@ -46,12 +47,14 @@ 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$
*/
@@ -63,7 +66,7 @@ public class DBSSession implements IDBSSession {
/**
* Constructs a database session.
- *
+ *
* @param system the database subsytem
* @param c the ldap connection
*/
@@ -72,7 +75,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) {
}
}
@@ -94,40 +97,39 @@ public class DBSSession implements IDBSSession {
/**
* Adds object to backend database. For example,
- *
* <PRE>
- * session.add(&quot;cn=123459,o=certificate repository,o=airius.com&quot;, certRec);
+ * session.add("cn=123459,o=certificate repository,o=airius.com",
+ * 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);
+ LDAPAttributeSet attrs = mDBSystem.getRegistry(
+ ).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", name + " " + e.toString()));
+ throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
+ name + " " + e.toString()));
}
}
/**
- * 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 {
@@ -135,52 +137,50 @@ 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 {
+ public IDBObj read(String name, String attrs[])
+ throws EBaseException {
try {
String ldapattrs[] = null;
if (attrs != null) {
- ldapattrs = mDBSystem.getRegistry().getLDAPAttributes(attrs);
+ ldapattrs = mDBSystem.getRegistry(
+ ).getLDAPAttributes(attrs);
}
- /*
- * LogDoc
- *
+ /*LogDoc
+ *
* @phase local ldap read
- *
* @message DBSSession: begin LDAP read <entry>
*/
- LDAPSearchResults res = mConn.search(name, LDAPv2.SCOPE_BASE,
- "(objectclass=*)", ldapattrs, false);
+ LDAPSearchResults res = mConn.search(name,
+ LDAPv2.SCOPE_BASE, "(objectclass=*)",
+ ldapattrs, false);
LDAPEntry entry = (LDAPEntry) res.nextElement();
- return mDBSystem.getRegistry()
- .createObject(entry.getAttributeSet());
+ return mDBSystem.getRegistry().createObject(
+ 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)
+ mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_INFO, "DBSSession: " + e.toString());
+ 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", name + " " + e.toString()));
+ throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
+ name + " " + e.toString()));
}
}
@@ -191,50 +191,52 @@ 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", name + " " + e.toString()));
+ throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
+ name + " " + e.toString()));
}
}
/**
* Modify an object in the database.
*/
- public void modify(String name, ModificationSet mods) throws EBaseException {
+ public void modify(String name, ModificationSet mods)
+ throws EBaseException {
try {
- LDAPModificationSet ldapMods = new LDAPModificationSet();
+ LDAPModificationSet ldapMods = new
+ LDAPModificationSet();
Enumeration e = mods.getModifications();
while (e.hasMoreElements()) {
- Modification mod = (Modification) e.nextElement();
+ Modification mod = (Modification)
+ e.nextElement();
LDAPAttributeSet attrs = new LDAPAttributeSet();
- mDBSystem.getRegistry().mapObject(null, mod.getName(),
- mod.getValue(), attrs);
+ mDBSystem.getRegistry().mapObject(null,
+ 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", name + " " + e.toString()));
+ throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
+ name + " " + e.toString()));
}
}
@@ -250,120 +252,128 @@ public class DBSSession implements IDBSSession {
return LDAPModification.REPLACE;
}
throw new EBaseException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
- Integer.toString(modOp)));
+ Integer.toString(modOp)));
}
/**
- * 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);
+ String ldapfilter =
+ mDBSystem.getRegistry().getFilter(filter);
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setMaxResults(maxSize);
- LDAPSearchResults res = mConn.search(base, LDAPv2.SCOPE_ONE,
- ldapfilter, ldapattrs, false, cons);
+ LDAPSearchResults res = mConn.search(base,
+ LDAPv2.SCOPE_ONE, ldapfilter, ldapattrs, false, cons);
- return new DBSearchResults(mDBSystem.getRegistry(), res);
+ 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
- throw new EDBException(CMS.getUserMessage(
- "CMS_DBS_LDAP_OP_FAILURE", e.toString()));
+ // 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 {
+ public IDBSearchResults search(String base, String filter, int maxSize, int timeLimit)
+ throws EBaseException {
try {
String ldapattrs[] = null;
- String ldapfilter = mDBSystem.getRegistry().getFilter(filter);
+ String ldapfilter =
+ mDBSystem.getRegistry().getFilter(filter);
LDAPSearchConstraints cons = new LDAPSearchConstraints();
cons.setMaxResults(maxSize);
cons.setServerTimeLimit(timeLimit);
- LDAPSearchResults res = mConn.search(base, LDAPv2.SCOPE_ONE,
- ldapfilter, ldapattrs, false, cons);
+ LDAPSearchResults res = mConn.search(base,
+ LDAPv2.SCOPE_ONE, ldapfilter, ldapattrs, false, cons);
- return new DBSearchResults(mDBSystem.getRegistry(), res);
+ 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
- throw new EDBException(CMS.getUserMessage(
- "CMS_DBS_LDAP_OP_FAILURE", e.toString()));
+ // 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 {
+ public IDBSearchResults search(String base, String filter,
+ String attrs[]) throws EBaseException {
try {
String ldapattrs[] = null;
if (attrs != null) {
- ldapattrs = mDBSystem.getRegistry().getLDAPAttributes(attrs);
+ ldapattrs = mDBSystem.getRegistry(
+ ).getLDAPAttributes(attrs);
}
- String ldapfilter = mDBSystem.getRegistry().getFilter(filter);
+ String ldapfilter =
+ mDBSystem.getRegistry().getFilter(filter);
- /*
- * LogDoc
- *
+ /*LogDoc
+ *
* @phase local ldap add
- *
* @message DBSSession: begin LDAP search <filter>
*/
LDAPSearchConstraints cons = new LDAPSearchConstraints();
- cons.setMaxResults(0);
-
- LDAPSearchResults res = mConn.search(base, LDAPv2.SCOPE_ONE,
- ldapfilter, ldapattrs, false, cons);
+ cons.setMaxResults(0);
+
+ LDAPSearchResults res = mConn.search(base,
+ LDAPv2.SCOPE_ONE, ldapfilter, ldapattrs, false, cons);
- return new DBSearchResults(mDBSystem.getRegistry(), res);
+ 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
- throw new EDBException(CMS.getUserMessage(
- "CMS_DBS_LDAP_OP_FAILURE", e.toString()));
+ // 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 {
+ public LDAPSearchResults persistentSearch(String base, String filter, String attrs[])
+ throws EBaseException {
try {
String ldapattrs[] = null;
if (attrs != null) {
- ldapattrs = mDBSystem.getRegistry().getLDAPAttributes(attrs);
+ ldapattrs = mDBSystem.getRegistry(
+ ).getLDAPAttributes(attrs);
}
- String ldapfilter = mDBSystem.getRegistry().getFilter(filter);
+ String ldapfilter =
+ 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));
}
@@ -373,24 +383,25 @@ public class DBSSession implements IDBSSession {
boolean changesOnly = true;
boolean returnControls = true;
boolean isCritical = true;
- LDAPPersistSearchControl persistCtrl = new LDAPPersistSearchControl(
- op, changesOnly, returnControls, isCritical);
+ LDAPPersistSearchControl persistCtrl = new
+ 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);
+ 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
- throw new EDBException(CMS.getUserMessage(
- "CMS_DBS_LDAP_OP_FAILURE", e.toString()));
+ // XXX error handling, should not raise exception if
+ // entry not found
+ throw new EDBException(CMS.getUserMessage("CMS_DBS_LDAP_OP_FAILURE",
+ e.toString()));
}
}
@@ -398,59 +409,57 @@ public class DBSSession implements IDBSSession {
* Retrieves a list of objects.
*/
public IDBVirtualList createVirtualList(String base, String filter,
- String attrs[]) throws EBaseException {
- return new DBVirtualList(mDBSystem.getRegistry(), mConn, base, filter,
- attrs);
+ String attrs[]) throws EBaseException {
+ return new DBVirtualList(mDBSystem.getRegistry(), mConn, base,
+ filter, attrs);
}
/**
* Retrieves a list of objects.
*/
public IDBVirtualList createVirtualList(String base, String filter,
- String attrs[], String sortKey[]) throws EBaseException {
- return new DBVirtualList(mDBSystem.getRegistry(), mConn, base, filter,
- attrs, sortKey);
+ String attrs[], String sortKey[]) throws EBaseException {
+ return new DBVirtualList(mDBSystem.getRegistry(), mConn, base,
+ filter, attrs, sortKey);
}
/**
* Retrieves a list of objects.
*/
public IDBVirtualList createVirtualList(String base, String filter,
- String attrs[], String sortKey) throws EBaseException {
- return new DBVirtualList(mDBSystem.getRegistry(), mConn, base, filter,
- attrs, sortKey);
+ String attrs[], String sortKey) throws EBaseException {
+ return new DBVirtualList(mDBSystem.getRegistry(), mConn, base,
+ filter, attrs, sortKey);
}
/**
* Retrieves a list of objects.
*/
public IDBVirtualList createVirtualList(String base, String filter,
- String attrs[], String sortKey[], int pageSize)
- throws EBaseException {
- return new DBVirtualList(mDBSystem.getRegistry(), mConn, base, filter,
- attrs, sortKey, pageSize);
+ String attrs[], String sortKey[], int pageSize) throws EBaseException {
+ return new DBVirtualList(mDBSystem.getRegistry(), mConn, base,
+ filter, attrs, sortKey, pageSize);
}
/**
* Retrieves a list of objects.
*/
public IDBVirtualList createVirtualList(String base, String filter,
- String attrs[], String sortKey, int pageSize) throws EBaseException {
- return new DBVirtualList(mDBSystem.getRegistry(), mConn, base, filter,
- attrs, sortKey, pageSize);
+ String attrs[], String sortKey, int pageSize) throws EBaseException {
+ return new DBVirtualList(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 {
- return new DBVirtualList(mDBSystem.getRegistry(), mConn, base, filter,
- attrs, startFrom, sortKey, pageSize);
+ String attrs[], String startFrom, String sortKey, int pageSize) throws EBaseException {
+ return new DBVirtualList(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