summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-01-11 12:57:53 -0500
committerAde Lee <alee@redhat.com>2012-01-11 13:49:04 -0500
commit10cfe7756e967ac91c66d33b392aeab9cf3780fb (patch)
treed5ac9b58442265d2ce5ef60e31f041ddacba1b4f /pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
parentedcb24f65cc3700e75d0a1d14dc2483f210b0ee4 (diff)
downloadpki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.gz
pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.tar.xz
pki-10cfe7756e967ac91c66d33b392aeab9cf3780fb.zip
Formatting (no line wrap in comments or code)
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java')
-rw-r--r--pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java215
1 files changed, 108 insertions, 107 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java b/pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
index ddec63cef..b9f338c43 100644
--- a/pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
+++ b/pki/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.dbs;
-
import java.util.Arrays;
import java.util.Vector;
@@ -38,12 +37,11 @@ import com.netscape.certsrv.dbs.IDBVirtualList;
import com.netscape.certsrv.dbs.IElementProcessor;
import com.netscape.certsrv.logging.ILogger;
-
/**
* A class represents a virtual list of search results.
* Note that this class must be used with DS4.0.
- *
- * @author thomask
+ *
+ * @author thomask
* @author mzhao
* @version $Revision$, $Date$
*/
@@ -71,17 +69,17 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
// the index of the first entry returned
private int mSelectedIndex = 0;
private int mJumpToIndex = 0;
- private int mJumpToInitialIndex = 0; // Initial index hit in jumpto operation
- private int mJumpToDirection = 1; // Do we proceed forward or backwards
- private String mJumpTo = null; // Determines if this is the jumpto case
+ private int mJumpToInitialIndex = 0; // Initial index hit in jumpto operation
+ private int mJumpToDirection = 1; // Do we proceed forward or backwards
+ private String mJumpTo = null; // Determines if this is the jumpto case
private ILogger mLogger = CMS.getLogger();
/**
- * Constructs a virtual list.
+ * Constructs a virtual list.
* Be sure to setPageSize() later if your pageSize is not the default 10
* Be sure to setSortKey() before fetchs
- *
+ *
* param registry the registry of attribute mappers
* param c the ldap connection. It has to be version 3 and upper
* param base the base distinguished name to search from
@@ -89,18 +87,18 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* param attrs list of attributes that you want returned in the search results
*/
public DBVirtualList(IDBRegistry registry, LDAPConnection c,
- String base, String filter, String attrs[]) throws EBaseException {
+ String base, String filter, String attrs[]) throws EBaseException {
mRegistry = registry;
mFilter = filter;
mBase = base;
mAttrs = attrs;
- CMS.debug( "In DBVirtualList filter attrs filter: " + filter
- + " attrs: " + Arrays.toString( attrs ) );
+ CMS.debug("In DBVirtualList filter attrs filter: " + filter
+ + " attrs: " + Arrays.toString(attrs));
mPageControls = new LDAPControl[2];
try {
mConn = (LDAPConnection) c.clone();
} catch (Exception e) {
- throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()));
}
}
@@ -108,7 +106,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* Constructs a virtual list.
* Be sure to setPageSize() later if your pageSize is not the default 10
- *
+ *
* param registry the registry of attribute mappers
* param c the ldap connection. It has to be version 3 and upper
* param base the base distinguished name to search from
@@ -117,17 +115,17 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* param sortKey the attributes to sort by
*/
public DBVirtualList(IDBRegistry registry, LDAPConnection c,
- String base, String filter, String attrs[], String sortKey[])
- throws EBaseException {
+ String base, String filter, String attrs[], String sortKey[])
+ throws EBaseException {
- CMS.debug( "In DBVirtualList filter attrs sotrKey[] filter: " + filter
- + " attrs: " + Arrays.toString( attrs ) );
+ CMS.debug("In DBVirtualList filter attrs sotrKey[] filter: " + filter
+ + " attrs: " + Arrays.toString(attrs));
mRegistry = registry;
mFilter = filter;
try {
mConn = (LDAPConnection) c.clone();
} catch (Exception e) {
- throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()));
}
mBase = base;
@@ -139,7 +137,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* Constructs a virtual list.
* Be sure to setPageSize() later if your pageSize is not the default 10
- *
+ *
* param registry the registry of attribute mappers
* param c the ldap connection. It has to be version 3 and upper
* param base the base distinguished name to search from
@@ -148,16 +146,16 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* param sortKey the attribute to sort by
*/
public DBVirtualList(IDBRegistry registry, LDAPConnection c,
- String base, String filter, String attrs[], String sortKey)
- throws EBaseException {
+ String base, String filter, String attrs[], String sortKey)
+ throws EBaseException {
- CMS.debug( "In DBVirtualList filter attrs sortKey filter: " + filter + " attrs: " + Arrays.toString( attrs ) );
+ CMS.debug("In DBVirtualList filter attrs sortKey filter: " + filter + " attrs: " + Arrays.toString(attrs));
mRegistry = registry;
mFilter = filter;
try {
mConn = (LDAPConnection) c.clone();
} catch (Exception e) {
- throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()));
}
mBase = base;
@@ -168,7 +166,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* Constructs a virtual list.
- *
+ *
* param registry the registry of attribute mappers
* param c the ldap connection. It has to be version 3 and upper
* param base the base distinguished name to search from
@@ -176,21 +174,21 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* param attrs list of attributes that you want returned in the search results
* param sortKey the attributes to sort by
* param pageSize the size of a page. There is a 3*pageSize buffer maintained so
- * pageUp and pageDown won't invoke fetch from ldap server
+ * pageUp and pageDown won't invoke fetch from ldap server
*/
public DBVirtualList(IDBRegistry registry, LDAPConnection c,
- String base, String filter, String attrs[], String sortKey[],
- int pageSize) throws EBaseException {
+ String base, String filter, String attrs[], String sortKey[],
+ int pageSize) throws EBaseException {
- CMS.debug( "In DBVirtualList filter attrs sortKey[] pageSize filter: "
- + filter + " attrs: " + Arrays.toString( attrs )
- + " pageSize " + pageSize );
+ CMS.debug("In DBVirtualList filter attrs sortKey[] pageSize filter: "
+ + filter + " attrs: " + Arrays.toString(attrs)
+ + " pageSize " + pageSize);
mRegistry = registry;
mFilter = filter;
try {
mConn = (LDAPConnection) c.clone();
} catch (Exception e) {
- throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()));
}
mBase = base;
@@ -202,7 +200,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* Constructs a virtual list.
- *
+ *
* param registry the registry of attribute mappers
* param c the ldap connection. It has to be version 3 and upper
* param base the base distinguished name to search from
@@ -210,15 +208,15 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* param attrs list of attributes that you want returned in the search results
* param sortKey the attribute to sort by
* param pageSize the size of a page. There is a 3*pageSize buffer maintained so
- * pageUp and pageDown won't invoke fetch from ldap server
+ * pageUp and pageDown won't invoke fetch from ldap server
*/
public DBVirtualList(IDBRegistry registry, LDAPConnection c,
- String base, String filter, String attrs[], String sortKey,
- int pageSize) throws EBaseException {
+ String base, String filter, String attrs[], String sortKey,
+ int pageSize) throws EBaseException {
- CMS.debug( "In DBVirtualList filter attrs sortKey pageSize filter: "
- + filter + " attrs: " + Arrays.toString( attrs )
- + " pageSize " + pageSize );
+ CMS.debug("In DBVirtualList filter attrs sortKey pageSize filter: "
+ + filter + " attrs: " + Arrays.toString(attrs)
+ + " pageSize " + pageSize);
mRegistry = registry;
mFilter = filter;
try {
@@ -235,20 +233,20 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
}
public DBVirtualList(IDBRegistry registry, LDAPConnection c,
- String base, String filter, String attrs[],
- String startFrom, String sortKey,
- int pageSize) throws EBaseException {
-
- CMS.debug( "In DBVirtualList filter attrs startFrom sortKey pageSize "
- + "filter: " + filter
- + " attrs: " + Arrays.toString( attrs )
- + " pageSize " + pageSize + " startFrom " + startFrom );
+ String base, String filter, String attrs[],
+ String startFrom, String sortKey,
+ int pageSize) throws EBaseException {
+
+ CMS.debug("In DBVirtualList filter attrs startFrom sortKey pageSize "
+ + "filter: " + filter
+ + " attrs: " + Arrays.toString(attrs)
+ + " pageSize " + pageSize + " startFrom " + startFrom);
mRegistry = registry;
mFilter = filter;
try {
mConn = (LDAPConnection) c.clone();
} catch (Exception e) {
- throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
+ throw new EBaseException(CMS.getUserMessage("CMS_BASE_CONN_FAILED",
e.toString()));
}
mBase = base;
@@ -260,7 +258,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
if (pageSize < 0) {
mJumpToDirection = -1;
- }
+ }
mPageSize = pageSize;
mBeforeCount = 0;
@@ -291,7 +289,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* set the sort key
- *
+ *
* @param sortKey the attribute to sort by
*/
public void setSortKey(String sortKey) throws EBaseException {
@@ -303,7 +301,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* set the sort key
- *
+ *
* @param sortKey the attributes to sort by
*/
public void setSortKey(String[] sortKeys) throws EBaseException {
@@ -326,20 +324,20 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* @message DBVirtualList: <exception thrown>
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_FAILURE,
- CMS.getLogMessage("OPERATION_ERROR", e.toString()));
+ CMS.getLogMessage("OPERATION_ERROR", e.toString()));
}
// Paged results also require a sort control
if (mKeys != null) {
mPageControls[0] =
new LDAPSortControl(mKeys, true);
- }else {
+ } else {
throw new EBaseException("sort keys cannot be null");
}
}
/**
* Retrieves the size of this virtual list.
- * Recommend to call getSize() before getElementAt() or getElements()
+ * Recommend to call getSize() before getElementAt() or getElements()
* since you'd better check if the index is out of bound first.
*/
public int getSize() {
@@ -368,7 +366,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
if (mPageSize < 0) {
mBeforeCount = mPageSize * -1;
- mAfterCount = 0;
+ mAfterCount = 0;
}
cont = new LDAPVirtualListControl(mJumpTo,
mBeforeCount,
@@ -382,21 +380,21 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
return mSize;
}
- public int getSizeBeforeJumpTo() {
+ public int getSizeBeforeJumpTo() {
if (!mInitialized || mJumpTo == null)
return 0;
int size = 0;
-
- if (mJumpToDirection < 0) {
+
+ if (mJumpToDirection < 0) {
size = mTop + mEntries.size();
} else {
size = mTop;
}
- return size;
+ return size;
}
@@ -410,7 +408,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
return size;
}
-
+
private synchronized boolean getEntries() {
// Specify necessary controls for vlist
// LDAPSearchConstraints cons = mConn.getSearchConstraints();
@@ -461,7 +459,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
try {
//maintain mEntries as vector of LDAPEntry
@SuppressWarnings("unchecked")
- E o = (E)mRegistry.createObject(entry.getAttributeSet());
+ E o = (E) mRegistry.createObject(entry.getAttributeSet());
mEntries.addElement(o);
} catch (Exception e) {
@@ -475,12 +473,12 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* @message DBVirtualList: <exception thrown>
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_FAILURE,
- CMS.getLogMessage("CMSCORE_DBS_VL_ADD", e.toString()));
+ CMS.getLogMessage("CMSCORE_DBS_VL_ADD", e.toString()));
// #539044
damageCounter++;
if (damageCounter > 100) {
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_FAILURE,
- CMS.getLogMessage("CMSCORE_DBS_VL_CORRUPTED_ENTRIES", Integer.toString(damageCounter)));
+ CMS.getLogMessage("CMSCORE_DBS_VL_CORRUPTED_ENTRIES", Integer.toString(damageCounter)));
return false;
}
}
@@ -496,7 +494,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
CMS.debug("getEntries: exception " + e);
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_FAILURE,
- CMS.getLogMessage("OPERATION_ERROR", e.toString()));
+ CMS.getLogMessage("OPERATION_ERROR", e.toString()));
}
//System.out.println( "Returning " + mEntries.size() +
// " entries" );
@@ -515,10 +513,10 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
if (!getEntries())
return false;
- // Check if we have a control returned
+ // Check if we have a control returned
LDAPControl[] c = mConn.getResponseControls();
LDAPVirtualListResponse nextCont =
- LDAPVirtualListResponse.parseResponse(c);
+ LDAPVirtualListResponse.parseResponse(c);
if (nextCont != null) {
mSelectedIndex = nextCont.getFirstPosition() - 1;
@@ -536,7 +534,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
//System.out.println( "Virtual window: " + mTop +
// ".." + (mTop+mEntries.size()-1) +
// " of " + mSize );
- } else {
+ } else {
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_DBS_VL_NULL_RESPONSE"));
}
return true;
@@ -546,14 +544,15 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
}
}
- /** Get a page starting at "first" (although we may also fetch
+ /**
+ * Get a page starting at "first" (although we may also fetch
* some preceding entries)
- * Recommend to call getSize() before getElementAt() or getElements()
+ * Recommend to call getSize() before getElementAt() or getElements()
* since you'd better check if the index is out of bound first.
- *
+ *
* @param first the index of the first entry of the page you want to fetch
*/
- public boolean getPage(int first) {
+ public boolean getPage(int first) {
CMS.debug("getPage " + first);
if (!mInitialized) {
LDAPVirtualListControl cont = new LDAPVirtualListControl(0,
@@ -568,17 +567,18 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
return getPage();
}
- /** Fetch a buffer
+ /**
+ * Fetch a buffer
*/
- private boolean getPage() {
+ private boolean getPage() {
// Get the actual entries
if (!getEntries())
return false;
- // Check if we have a control returned
+ // Check if we have a control returned
LDAPControl[] c = mConn.getResponseControls();
LDAPVirtualListResponse nextCont =
- LDAPVirtualListResponse.parseResponse(c);
+ LDAPVirtualListResponse.parseResponse(c);
if (nextCont != null) {
mSelectedIndex = nextCont.getFirstPosition() - 1;
@@ -598,38 +598,39 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
* @phase local ldap search
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB, ILogger.LL_FAILURE,
- CMS.getLogMessage("CMSCORE_DBS_VL_NULL_RESPONSE"));
+ CMS.getLogMessage("CMSCORE_DBS_VL_NULL_RESPONSE"));
}
return true;
}
- /** Called by application to scroll the list with initial letters.
+ /**
+ * Called by application to scroll the list with initial letters.
* Consider text to be an initial substring of the attribute of the
* primary sorting key(the first one specified in the sort key array)
* of an entry.
* If no entries match, the one just before(or after, if none before)
* will be returned as mSelectedIndex
- *
+ *
* @param text the prefix of the first entry of the page you want to fetch
*/
public boolean getPage(String text) {
mPageControls[1] =
new LDAPVirtualListControl(text,
- mBeforeCount,
- mAfterCount);
+ mBeforeCount,
+ mAfterCount);
//System.out.println( "Setting requested start to " +
// text + ", -" + mBeforeCount + ", +" +
// mAfterCount );
return getPage();
}
- /**
+ /**
* fetch data of a single list item
- * Recommend to call getSize() before getElementAt() or getElements()
+ * Recommend to call getSize() before getElementAt() or getElements()
* since you'd better check if the index is out of bound first.
* If the index is out of range of the virtual list, an exception will be thrown
* and return null
- *
+ *
* @param index the index of the element to fetch
*/
public E getElementAt(int index) {
@@ -643,36 +644,36 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
if (!mInitialized)
mSize = getSize();
- CMS.debug("getElementAt: " + index + " mTop " + mTop);
-
+ CMS.debug("getElementAt: " + index + " mTop " + mTop);
+
//System.out.println( "need entry " + index );
if ((index < 0) || (index >= mSize)) {
CMS.debug("returning null");
return null;
}
- if (mJumpTo != null) { //Handle the explicit jumpto case
+ if (mJumpTo != null) { //Handle the explicit jumpto case
if (index == 0)
- mJumpToIndex = 0; // Keep a running jumpto index for this page of data
+ mJumpToIndex = 0; // Keep a running jumpto index for this page of data
else
mJumpToIndex++;
-
- //CMS.debug("getElementAtJT: " + index + " mTop " + mTop + " mEntries.size() " + mEntries.size());
-
- if ((mJumpToDirection > 0) && (mJumpToInitialIndex + index >= mSize)) // out of data in forward paging jumpto case
+
+ //CMS.debug("getElementAtJT: " + index + " mTop " + mTop + " mEntries.size() " + mEntries.size());
+
+ if ((mJumpToDirection > 0) && (mJumpToInitialIndex + index >= mSize)) // out of data in forward paging jumpto case
{
CMS.debug("mJumpTo virtual list exhausted mTop " + mTop + " mSize " + mSize);
return null;
}
-
- if (mJumpToIndex >= mEntries.size()) // In jumpto case, page of data has been exhausted
+
+ if (mJumpToIndex >= mEntries.size()) // In jumpto case, page of data has been exhausted
{
- mJumpToIndex = 0; // new page will be needed reset running count
+ mJumpToIndex = 0; // new page will be needed reset running count
- if (mJumpToDirection > 0) { //proceed in positive direction past hit point
- getPage(index + mJumpToInitialIndex + 1);
- } else { //proceed backwards from hit point
+ if (mJumpToDirection > 0) { //proceed in positive direction past hit point
+ getPage(index + mJumpToInitialIndex + 1);
+ } else { //proceed backwards from hit point
if (mTop == 0) {
getPage(0);
CMS.debug("asking for a page less than zero in reverse case, return null");
@@ -681,15 +682,15 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
CMS.debug("getting page reverse mJumptoIndex " + mJumpToIndex + " mTop " + mTop);
getPage(mTop);
-
+
}
}
- if (mJumpToDirection > 0) // handle getting entry in forward direction
+ if (mJumpToDirection > 0) // handle getting entry in forward direction
{
return mEntries.elementAt(mJumpToIndex);
- } else { // handle getting entry in reverse direction
+ } else { // handle getting entry in reverse direction
int reverse_index = mEntries.size() - mJumpToIndex - 1;
CMS.debug("reverse direction getting index " + reverse_index);
@@ -704,7 +705,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
//CMS.debug("getElementAt noJumpto: " + index);
- if ((index < mTop) || (index >= mTop + mEntries.size())) { // handle the non jumpto case
+ if ((index < mTop) || (index >= mTop + mEntries.size())) { // handle the non jumpto case
//fetch a new page
//System.out.println( "fetching a page starting at " +
// index );
@@ -727,10 +728,10 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
/**
* This function processes elements as soon as it arrives. It is
- * more memory-efficient.
+ * more memory-efficient.
*/
public void processElements(int startidx, int endidx, IElementProcessor ep)
- throws EBaseException {
+ throws EBaseException {
/* mSize may not be init at this time! Bad !
* the caller should really check the index is within bound before this
@@ -739,7 +740,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
if (!mInitialized)
mSize = getSize();
- // short-cut the existing code ... :(
+ // short-cut the existing code ... :(
if (mJumpTo != null) {
for (int i = startidx; i <= endidx; i++) {
Object element = getJumpToElementAt(i);
@@ -753,7 +754,7 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
//guess this is what you really mean to try to improve performance
if (startidx >= endidx) {
throw new EBaseException("startidx must be less than endidx");
- }else {
+ } else {
setPageSize(endidx - startidx);
getPage(startidx);
}
@@ -766,14 +767,14 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
}
}
- /**
+ /**
* get the virutal selected index
*/
public int getSelectedIndex() {
return mSelectedIndex;
}
- /**
+ /**
* get the top of the buffer
*/
public int getFirstIndex() {