Package com.netscape.cmscore.dbs
Class Repository
- java.lang.Object
-
- com.netscape.cmscore.dbs.Repository
-
- All Implemented Interfaces:
IRepository
- Direct Known Subclasses:
CertificateRepository,ReplicaIDRepository,RequestRepository
public abstract class Repository extends java.lang.Object implements IRepository
A class represents a generic repository. It maintains unique serial number within repository.To build domain specific repository, subclass should be created.
- Version:
- $Revision: 1.4 $, $Date$
- Author:
- galperin, thomask
-
-
Field Summary
Fields Modifier and Type Field Description protected DBSubsystemdbSubsystemstatic org.slf4j.Loggerloggerprotected java.lang.StringmaxSerialNameprotected java.lang.StringmBaseDNprotected java.math.BigIntegermCounterprotected booleanmEnableRandomSerialNumbersprotected java.math.BigIntegermIncrementNoprotected java.lang.StringminSerialNameprotected java.math.BigIntegermLowWaterMarkNoprotected java.math.BigIntegermMaxSerialNoprotected java.math.BigIntegermMinSerialNoprotected java.math.BigIntegermNextMaxSerialNoprotected java.math.BigIntegermNextMinSerialNoprotected intmRadixprotected java.lang.StringnextMaxSerialNameprotected java.lang.StringnextMinSerialNameprotected java.lang.StringrangeDNprotected java.util.Hashtable<java.lang.String,java.lang.String>repositoryConfig
-
Constructor Summary
Constructors Constructor Description Repository(DBSubsystem dbSubsystem, int radix)Constructs a repository.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckRange()Checks if the given number is in the current range.voidcheckRanges()Checks to see if a new range is needed, or if we have reached the end of the current range, or if a range conflict has occurred.java.lang.StringgetBaseDN()Get the LDAP base DN for this repository.abstract java.math.BigIntegergetLastSerialNumberInRange(java.math.BigInteger serial_low_bound, java.math.BigInteger serial_upper_bound)java.math.BigIntegergetMaxSerial()Get the maximum serial number.java.math.BigIntegergetMinSerial()Get the minimum serial number.java.math.BigIntegergetNextMaxSerial()Get the maximum serial number in next range.java.lang.StringgetNextRange()Gets start of next range from database.java.math.BigIntegergetNextSerialNumber()Retrieves the next serial number, and also increase the serial number by one.intgetRadix()booleanhasRangeConflict()Determines if a range conflict has been observed in database.protected voidinitCacheIfNeeded()java.math.BigIntegerpeekNextSerialNumber()Peek at the next serial number in cache (does not consume the number).voidsetEnableSerialMgmt(boolean value)Sets whether serial number management is enabled for certs and requests.protected voidsetLastSerialNo(java.math.BigInteger lastSN)voidsetMaxSerial(java.math.BigInteger serial)Set the maximum serial number.voidsetMaxSerialConfig()Sets maximum serial number limit in config filevoidsetMinSerialConfig()Sets minimum serial number limit in config filevoidsetNextMaxSerial(java.math.BigInteger serial)Set the maximum serial number in next rangevoidsetNextMaxSerialConfig()Sets maximum serial number limit for next range in config filevoidsetNextMinSerialConfig()Sets minimum serial number limit for next range in config filevoidsetTheSerialNumber(java.math.BigInteger num)Updates the serial number to the specified in db and cache.
-
-
-
Field Detail
-
logger
public static org.slf4j.Logger logger
-
minSerialName
protected java.lang.String minSerialName
-
mMinSerialNo
protected java.math.BigInteger mMinSerialNo
-
maxSerialName
protected java.lang.String maxSerialName
-
mMaxSerialNo
protected java.math.BigInteger mMaxSerialNo
-
nextMinSerialName
protected java.lang.String nextMinSerialName
-
mNextMinSerialNo
protected java.math.BigInteger mNextMinSerialNo
-
nextMaxSerialName
protected java.lang.String nextMaxSerialName
-
mNextMaxSerialNo
protected java.math.BigInteger mNextMaxSerialNo
-
mEnableRandomSerialNumbers
protected boolean mEnableRandomSerialNumbers
-
mCounter
protected java.math.BigInteger mCounter
-
mIncrementNo
protected java.math.BigInteger mIncrementNo
-
mLowWaterMarkNo
protected java.math.BigInteger mLowWaterMarkNo
-
dbSubsystem
protected DBSubsystem dbSubsystem
-
mBaseDN
protected java.lang.String mBaseDN
-
rangeDN
protected java.lang.String rangeDN
-
mRadix
protected int mRadix
-
repositoryConfig
protected java.util.Hashtable<java.lang.String,java.lang.String> repositoryConfig
-
-
Constructor Detail
-
Repository
public Repository(DBSubsystem dbSubsystem, int radix)
Constructs a repository.
-
-
Method Detail
-
getBaseDN
public java.lang.String getBaseDN()
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.- Returns:
- the LDAP base DN.
-
getRadix
public int getRadix()
-
getMaxSerial
public java.math.BigInteger getMaxSerial()
Get the maximum serial number.- Returns:
- maximum serial number
-
setMaxSerial
public void setMaxSerial(java.math.BigInteger serial) throws EBaseExceptionSet the maximum serial number.- Specified by:
setMaxSerialin interfaceIRepository- Parameters:
serial- maximum number- Throws:
EBaseException- failed to set maximum serial number
-
getNextMaxSerial
public java.math.BigInteger getNextMaxSerial()
Get the maximum serial number in next range.- Returns:
- maximum serial number in next range
-
setNextMaxSerial
public void setNextMaxSerial(java.math.BigInteger serial) throws EBaseExceptionSet the maximum serial number in next range- Specified by:
setNextMaxSerialin interfaceIRepository- Parameters:
serial- maximum number in next range- Throws:
EBaseException- failed to set maximum serial number in next range
-
getMinSerial
public java.math.BigInteger getMinSerial()
Get the minimum serial number.- Returns:
- minimum serial number
-
setLastSerialNo
protected void setLastSerialNo(java.math.BigInteger lastSN)
-
initCacheIfNeeded
protected void initCacheIfNeeded() throws EBaseException- Throws:
EBaseException
-
peekNextSerialNumber
public java.math.BigInteger peekNextSerialNumber() throws EBaseExceptionPeek at the next serial number in cache (does not consume the number). The returned number is not necessarily the previously emitted serial number plus one, i.e. if we are going to roll into the next range. This method does not actually switch the range. Returns null if the next number exceeds the current range and there is not a next range.- Specified by:
peekNextSerialNumberin interfaceIRepository- Returns:
- serial number
- Throws:
EBaseException- failed to retrieve next serial number
-
setTheSerialNumber
public void setTheSerialNumber(java.math.BigInteger num) throws EBaseExceptionUpdates the serial number to the specified in db and cache.- Parameters:
num- serial number- Throws:
EBaseException
-
getNextSerialNumber
public java.math.BigInteger getNextSerialNumber() throws EBaseExceptionRetrieves the next serial number, and also increase the serial number by one.- Specified by:
getNextSerialNumberin interfaceIRepository- Returns:
- serial number
- Throws:
EBaseException- failed to retrieve next serial number
-
checkRange
protected void checkRange() throws EBaseExceptionChecks if the given number is in the current range. If it does not exceed the current range, return cleanly. If it exceeds the given range, and there is a next range, switch the range. If it exceeds the given range, and there is not a next range, throw EDBException. Precondition: the serial number should already have been advanced. This method will detect that and switch to the next range, including resetting mLastSerialNo to the start of the new (now current) range. Postcondition: the caller should again read mLastSerialNo after calling checkRange(), in case checkRange switched the range and the new range is not adjacent to the current range.- Throws:
EDBException- thrown when range switch is needed but next range is not allocatedEBaseException
-
setMinSerialConfig
public void setMinSerialConfig() throws EBaseExceptionSets minimum serial number limit in config file- Throws:
EBaseException- failed to set
-
setMaxSerialConfig
public void setMaxSerialConfig() throws EBaseExceptionSets maximum serial number limit in config file- Throws:
EBaseException- failed to set
-
setNextMinSerialConfig
public void setNextMinSerialConfig() throws EBaseExceptionSets minimum serial number limit for next range in config file- Throws:
EBaseException- failed to set
-
setNextMaxSerialConfig
public void setNextMaxSerialConfig() throws EBaseExceptionSets maximum serial number limit for next range in config file- Throws:
EBaseException- failed to set
-
getNextRange
public java.lang.String getNextRange() throws EBaseExceptionGets start of next range from database. Increments the nextRange attribute and allocates this range to the current instance by creating a pkiRange object.- Returns:
- start of next range
- Throws:
EBaseException
-
hasRangeConflict
public boolean hasRangeConflict() throws EBaseExceptionDetermines if a range conflict has been observed in database. If so, delete the conflicting entries and remove the next range. When the next number is requested, if the number of certs is still below the low water mark, then a new range will be requested.- Returns:
- true if range conflict, false otherwise
- Throws:
EBaseException
-
checkRanges
public void checkRanges() throws EBaseExceptionChecks to see if a new range is needed, or if we have reached the end of the current range, or if a range conflict has occurred.- Specified by:
checkRangesin interfaceIRepository- Throws:
EBaseException- failed to check next range for conflicts
-
setEnableSerialMgmt
public void setEnableSerialMgmt(boolean value) throws EBaseExceptionSets whether serial number management is enabled for certs and requests.- Specified by:
setEnableSerialMgmtin interfaceIRepository- Parameters:
value- true/false- Throws:
EBaseException- failed to set
-
getLastSerialNumberInRange
public abstract java.math.BigInteger getLastSerialNumberInRange(java.math.BigInteger serial_low_bound, java.math.BigInteger serial_upper_bound) throws EBaseException- Throws:
EBaseException
-
-