|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectatg.nucleus.logging.VariableArgumentApplicationLoggingImpl
atg.nucleus.GenericService
atg.service.idgen.AbstractSequentialIdGenerator
atg.service.idgen.PersistentIdGenerator
atg.service.idgen.SQLIdGenerator
atg.service.idgen.ObfuscatedSQLIdGenerator
public class ObfuscatedSQLIdGenerator
Persistent, obfuscated id generator that keeps track of ids given out using an SQL DB table.
This implementation obfuscates the generated ids in two ways. First, for a given batch of reservered ids this implementation only gives out a few ids. Second, ids can be optionally hex encoded when being used as String ids. Both the String and long ids generated use a pseudorandom number generator to get a long id from the current batch of ids. In addition to not giving out the same id twice, this implementation will not given out adjacent long ids (or String ids that come from adjacent long ids).
This implementation is suitable for use in a distributed system. Transactionality integrity is provided by the underlying data store, which is an SQL database.
The IdSpace properties batchSize and idsPerBatch
are used in conjunction. batchSize works as in the
SQLIdGenerator. idsPerBatch is the maximum never of ids that
will be given out in any given batch.
It is strongly recommended that idsPerBatch be less than 1%
of the batchSize. This is both for security and
performance. For security a sparse (i.e., less dense) id space makes it
harder to guess ids. Since this implementation does not give out adjacent
ids, it could be forced to do more work to find suitable ids if the id
space is too dense. This implementation will not allow an id space to be
added that is denser than 10%. That is, idsPerBatch /
batchSize must be less than .1. Always set these
two properties together to maintain the 1% density goal.
The recommended values for batchSize and
idsPerBatch are 100,000 and 997, respectively. These numbers
are not magic. 100,000 is the default batch size. 997 is a prime number
that is slightly less than 1% of the batch size.
PersistentIdGenerator,
SQLIdGenerator| Field Summary | |
|---|---|
static java.lang.String |
CLASS_VERSION
Class version string |
protected static java.lang.String |
ERR_TOO_DENSE
|
static float |
MAX_DENSITY
maximum density for obfuscated id generators |
| Fields inherited from class atg.service.idgen.SQLIdGenerator |
|---|
ERR_HWM_BAD_STATE, ERR_HWM_FAIL, ERR_NULL_DS, ERR_QUERY_TABLE, ERR_RESERVE_BAD_STATE |
| Fields inherited from class atg.service.idgen.PersistentIdGenerator |
|---|
ERR_ADD_BAD_STATE, ERR_ADD_NULL_SPACE, ERR_READING_BOOTSTRAP_SPACES, STATE_ERROR, STATE_INITIALIZING, STATE_NEW, STATE_RUNNING, WARN_PICKING_DEFAULT |
| Fields inherited from class atg.service.idgen.AbstractSequentialIdGenerator |
|---|
ERR_BAD_SPACE, ERR_ROLLBACK, ERR_UNSUPPORTED, mSpaces, RESOURCE_BUNDLE_NAME, sResourceBundle |
| Fields inherited from class atg.nucleus.GenericService |
|---|
SERVICE_INFO_KEY |
| Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging |
|---|
DEFAULT_LOG_TRACE_STATUS |
| Fields inherited from interface atg.nucleus.logging.ApplicationLogging |
|---|
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS |
| Constructor Summary | |
|---|---|
ObfuscatedSQLIdGenerator()
Construct a generator |
|
| Method Summary | |
|---|---|
boolean |
addIdSpace(IdSpace pSpace)
Add an id space to the id generator. |
protected boolean |
addPersistentIdSpace(IdSpace pSpace)
Add an id space to the data store. |
protected void |
createNewDefaultIdSpace()
Make sure the default id space exists, creating it if necessary. |
boolean |
getHexEncode()
Get property hexEncode |
java.lang.String |
getIdsPerBatchColumn()
Get property idsPerBatchColumn |
java.lang.String |
getInsertSQL()
Get property InsertSQL. |
java.lang.String |
getSelectSQL()
Get property SelectSQL. |
java.lang.String |
getUpdateSQL()
Get property UpdateSQL. |
boolean |
isHexEncode()
Test property hexEncode |
protected void |
reserveSeeds(IdSpace pSpace)
Reserve a batch of seeds for the specified id space. |
void |
setHexEncode(boolean pHexEncode)
Set property hexEncode |
void |
setIdsPerBatchColumn(java.lang.String pIdsPerBatchColumn)
Set property idsPerBatchColumn |
| Methods inherited from class atg.service.idgen.SQLIdGenerator |
|---|
getBatchSizeColumn, getDataSource, getNameColumn, getPrefixColumn, getSeedColumn, getSuffixColumn, getTableName, getUseRequiredTransactionMode, initializeIdSpaces, main, removePersistentIdSpaces, setBatchSizeColumn, setDataSource, setHighWaterMark, setNameColumn, setPrefixColumn, setSeedColumn, setSuffixColumn, setTableName, setUseRequiredTransactionMode |
| Methods inherited from class atg.service.idgen.PersistentIdGenerator |
|---|
getInitialIdSpaces, getLoadInitialIdSpacesAtStartup, getTransactionManager, getXMLToolsFactory, initialize, removeAllIdSpaces, removeIdSpace, setInitialIdSpaces, setLoadInitialIdSpacesAtStartup, setTransactionManager, setXMLToolsFactory |
| Methods inherited from class atg.service.idgen.AbstractSequentialIdGenerator |
|---|
doStartService, format, format, format, format, generateLongId, generateLongId, generateStringId, generateStringId, getAutoCreate, getBundle, getDefaultIdSpace, getDefaultIdSpaceName, getIdSpace, getIdSpaces, getResourceBundleName, isAutoCreate, postGenerateLongId, postGenerateStringId, setAutoCreate, setDefaultIdSpace, setDefaultIdSpaceName, toString |
| Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl |
|---|
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface atg.service.idgen.IdGenerator |
|---|
generateLongId, generateLongId, generateStringId, generateStringId, getAutoCreate, getDefaultIdSpace, getIdSpace, getIdSpaces, isAutoCreate, setAutoCreate |
| Field Detail |
|---|
public static java.lang.String CLASS_VERSION
public static float MAX_DENSITY
protected static java.lang.String ERR_TOO_DENSE
| Constructor Detail |
|---|
public ObfuscatedSQLIdGenerator()
| Method Detail |
|---|
public void setIdsPerBatchColumn(java.lang.String pIdsPerBatchColumn)
idsPerBatchColumn
pIdsPerBatchColumn - new value to setpublic java.lang.String getIdsPerBatchColumn()
idsPerBatchColumn
idsPerBatchColumnpublic void setHexEncode(boolean pHexEncode)
hexEncode
pHexEncode - new value to setpublic boolean getHexEncode()
hexEncode
hexEncodepublic boolean isHexEncode()
hexEncode
hexEncodepublic java.lang.String getSelectSQL()
SelectSQL. The SQL is lazily generated.
getSelectSQL in class SQLIdGeneratorpublic java.lang.String getInsertSQL()
InsertSQL. The SQL is lazily generated.
getInsertSQL in class SQLIdGeneratorpublic java.lang.String getUpdateSQL()
UpdateSQL. The SQL is lazily generated.
getUpdateSQL in class SQLIdGenerator
public boolean addIdSpace(IdSpace pSpace)
throws IdGeneratorException
idsPerBatch property of
the id space. Somewhat reasonable means a prime number not large than
roughly 1% of the batch size:
batchSize |
idsPerBatch |
| >=100,000 | 997 |
| >=10,000 | 89 |
| >=else | 7 |
addIdSpace in interface IdGeneratoraddIdSpace in class PersistentIdGeneratorpSpace - space to add, cannot be null
IdGeneratorException - if there is trouble adding the space
protected boolean addPersistentIdSpace(IdSpace pSpace)
throws IdGeneratorException
addPersistentIdSpace in class SQLIdGeneratorpSpace - space to add, cannot be null
IdGeneratorException - if there is trouble adding id spaceprotected void createNewDefaultIdSpace()
protected void reserveSeeds(IdSpace pSpace)
throws IdGeneratorException
DataSource for use and closes that
connection when done. This method also runs in its own new transaction.
reserveSeeds in class SQLIdGeneratorpSpace - id space to reserve seeds in, cannot be null
IdGeneratorException - if there is DB trouble
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||