use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.
the class DynamicChangeInfo method startOrContinueChange.
/**
* Write lock MUST be held!
*
* @return
*/
public XmlDynamicChange startOrContinueChange(BaseHK2JAXBBean participant) {
changeDepth++;
if (participant != null) {
participants.add(participant);
}
if (dynamicChange != null)
return dynamicChange;
globalSuccess = true;
DynamicConfiguration change = null;
DynamicConfiguration systemChange = null;
if (dynamicService != null) {
systemChange = dynamicService.createDynamicConfiguration();
if (advertiseInLocator) {
change = systemChange;
}
}
WriteableBeanDatabase wbd = null;
if (hub != null && advertiseInHub) {
wbd = hub.getWriteableDatabaseCopy();
wbd.setCommitMessage(new XmlHubCommitMessage() {
});
if (systemChange != null) {
systemChange.registerTwoPhaseResources(wbd.getTwoPhaseResource());
// Now the hub transaction is tied to the registry transaction
}
}
dynamicChange = new XmlDynamicChange(wbd, change, systemChange);
return dynamicChange;
}
use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.
the class DynamicChangeInfo method endOrDeferChange.
/**
* Write lock MUST be held!
*
* @return
*/
public void endOrDeferChange(boolean success) throws MultiException {
changeDepth--;
if (changeDepth < 0)
changeDepth = 0;
if (!success)
globalSuccess = false;
if (changeDepth > 0)
return;
List<BaseHK2JAXBBean> localParticipants = new ArrayList<BaseHK2JAXBBean>(participants);
participants.clear();
XmlDynamicChange localDynamicChange = dynamicChange;
dynamicChange = null;
if (localDynamicChange == null)
return;
ConstraintViolationException validationException = null;
if (globalSuccess && (validator != null) && (root != null) && (root.getRoot() != null)) {
// Validate root if validation is on
Set<ConstraintViolation<Object>> violations = validator.<Object>validate(root.getRoot());
if (violations != null && !violations.isEmpty()) {
validationException = new ConstraintViolationException(violations);
}
}
if (!globalSuccess || (validationException != null)) {
for (BaseHK2JAXBBean participant : localParticipants) {
participant.__rollbackChange();
}
if (validationException != null) {
throw new MultiException(validationException);
}
return;
}
for (BaseHK2JAXBBean participant : localParticipants) {
participant.__activateChange();
}
DynamicConfiguration systemChange = localDynamicChange.getSystemDynamicConfiguration();
WriteableBeanDatabase wbd = localDynamicChange.getBeanDatabase();
if (systemChange == null && wbd != null) {
// Weird case, can it happen?
wbd.commit(new XmlHubCommitMessage() {
});
return;
}
if (systemChange == null)
return;
// Can definitely throw, for example if a listener fails
systemChange.commit();
}
use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.
the class NegativeHubTest method testRemoveInstanceWithNullKey.
/**
* Null as name for addInstance
*/
@Test(expected = IllegalArgumentException.class)
public void testRemoveInstanceWithNullKey() {
WriteableBeanDatabase wbd = hub.getWriteableDatabaseCopy();
WriteableType wt = wbd.addType(ERROR_TYPE);
wt.removeInstance(null);
}
use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.
the class NegativeHubTest method testAddInstanceWithNullBoth.
/**
* Null as key and bean for addInstance
*/
@Test(expected = IllegalArgumentException.class)
public void testAddInstanceWithNullBoth() {
WriteableBeanDatabase wbd = hub.getWriteableDatabaseCopy();
WriteableType wt = wbd.addType(ERROR_TYPE);
wt.addInstance(null, null);
}
use of org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase in project glassfish-hk2 by eclipse-ee4j.
the class NegativeHubTest method testModifyInstanceWithNullValue.
/**
* Null as bean for modifyInstance
*/
@Test(expected = IllegalArgumentException.class)
public void testModifyInstanceWithNullValue() {
WriteableBeanDatabase wbd = hub.getWriteableDatabaseCopy();
WriteableType wt = wbd.addType(ERROR_TYPE);
wt.modifyInstance(ERROR_NAME, null);
}
Aggregations