Skip to content

Instantly share code, notes, and snippets.

Created May 27, 2015 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e068ad4366c7759c58dc to your computer and use it in GitHub Desktop.
Save anonymous/e068ad4366c7759c58dc to your computer and use it in GitHub Desktop.
private static String getUniqueFileId(){
String fileId=getRandomString(FILE_ID_LENGTH);
LoggerDAO loggerDao = ObjectContainer.getObject("LoggerDAO");
int count = 1;
try {
while(!loggerDao.isFileIdUnique(fileId)){
Logger.log(componentName, levelInfo, requestTransaction,
sourceId, customerId,null, "File Id:"+fileId+" exists. Retry new fileId ..!");
fileId=getRandomString(FILE_ID_LENGTH);
if(count++ > 20){
Logger.log(componentName,levelDebug, requestTransaction,
sourceId, customerId,null, "Finding unique key took 21 cycles,It's time to increase the key size..!");
}
}
} catch (DataAccessException e) {
Logger.log(componentName,levelError, requestTransaction,
sourceId, customerId,e, "Error in validating the uniqueness of fileId..");
}
return fileId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment