use of alma.ArchiveIdentifierError.wrappers.AcsJUidAlreadyExistsEx in project ACS by ACS-Community.
the class UIDLibraryTest method testAllocateDefaultID.
public void testAllocateDefaultID() throws Exception {
UIDLibrary lib = new UIDLibrary(logger);
EntityT e = new EntityT();
// assign and check a UID
lib.assignUniqueEntityId(e, ident);
String uid = e.getEntityId();
logger.info("Got a new UID for an entity object: " + uid);
assertEquals("uid://X01/Xaabb/X1", uid);
// try to reassign a UID
try {
lib.assignUniqueEntityId(e, ident);
fail("expected AcsJUidAlreadyExistsEx");
} catch (AcsJUidAlreadyExistsEx ex) {
// fine
}
// verify that the exception did not change the old ID
assertEquals(uid, e.getEntityId());
// try a null identifier archive
try {
lib.assignUniqueEntityId(e, (IdentifierJ) null);
fail("Expected AcsJIdentifierUnavailableEx when using a null Identifier archive.");
} catch (AcsJIdentifierUnavailableEx ex) {
// fine
}
}
use of alma.ArchiveIdentifierError.wrappers.AcsJUidAlreadyExistsEx in project ACS by ACS-Community.
the class Range method setUniqueEntityId.
private void setUniqueEntityId(EntityT entity, boolean allowReplacing) throws AcsJUidAlreadyExistsEx, AcsJRangeLockedEx, AcsJRangeExhaustedEx {
if (entity == null) {
throw new NullPointerException("argument 'entity' must not be null.");
}
if (!isLocked) {
if (entity.getEntityId() != null && entity.getEntityId().length() > 0 && !allowReplacing) {
AcsJUidAlreadyExistsEx ex = new AcsJUidAlreadyExistsEx();
ex.setObjectDesc("Entity " + entity.getEntityTypeName());
ex.setUid(entity.getEntityId());
throw ex;
}
String uid = getNextID();
entity.setEntityId(uid);
entity.setEntityIdEncrypted("-- id encryption not yet implemented --");
} else {
AcsJRangeLockedEx ex = new AcsJRangeLockedEx();
ex.setRange(rangeIdString());
throw ex;
}
}
use of alma.ArchiveIdentifierError.wrappers.AcsJUidAlreadyExistsEx in project ACS by ACS-Community.
the class UIDLibrary method assignUniqueEntityId.
/**
* Assigns a UID from the default range to the <code>EntityT</code> castor class
* of an XML-based entity such as a SchedBlock.
* <p>
* Implementation note: the default range of UIDs is retrieved from the archive at the first call and is then shared among instances
* in order to be frugal on UIDs and to minimize archive access.
* This means that often the passed in <code>identifier</code> will not be used at all but still must be provided,
* because the calling component can not know whether another component or the container has
* called this method before.
* This method is synchronized to avoid the very unlikely situation that <code>defaultRange.hasNextId</code> succeeds for one thread but then later
* assigning the UID still fails because of another thread having stolen the last free UID in the meantime.
*
* @param identifier the identifier archive from which a new <code>Range</code> can be obtained if necessary. Use <br>
* <code>ContainerServices#getTransparentXmlComponent(IdentifierJ.class, identRaw, IdentifierOperations.class);</code> <br>
* to create the required XML binding class aware interface from the plain-Corba <code>Identifier</code> object
* (<code>identRaw</code>) that is obtained, for example, by <br>
* <code>IdentifierHelper.narrow(getDefaultComponent("IDL:alma/xmlstore/Identifier:1.0"))</code>.
* @see ContainerServices#assignUniqueEntityId(EntityT)
*/
public synchronized void assignUniqueEntityId(EntityT entity, IdentifierJ identifier) throws AcsJUidAlreadyExistsEx, AcsJIdentifierUnavailableEx, AcsJRangeUnavailableEx, AcsJIdentifierUnexpectedEx {
try {
checkDefaultRange(identifier);
defaultRange.assignUniqueEntityId(entity);
if (logger.isLoggable(Level.FINEST)) {
logger.finest("Assigned UID '" + entity.getEntityId() + "' to entity of type " + entity.getEntityTypeName());
}
} catch (AcsJUidAlreadyExistsEx e) {
throw e;
} catch (AcsJRangeUnavailableEx e) {
throw e;
} catch (AcsJIdentifierUnavailableEx e) {
throw e;
} catch (Throwable e) {
// AcsJRangeLockedEx and AcsJRangeExhaustedEx should not occur for default range, thanks to method checkDefaultRange
throw new AcsJIdentifierUnexpectedEx(e);
}
}
Aggregations