use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class EJBTimerServiceUpgrade method doUpgrade.
private void doUpgrade(EjbTimerService ts) {
String value = ts.getMinimumDeliveryIntervalInMillis();
if (value == null || "7000".equals(value)) {
value = "" + EjbContainerUtil.MINIMUM_TIMER_DELIVERY_INTERVAL;
}
List<Property> properties = ts.getProperty();
if (properties != null) {
for (Property p : properties) {
if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
// Already set
return;
}
}
}
try {
final String minDelivery = value;
ConfigSupport.apply(new SingleConfigCode<EjbTimerService>() {
public Object run(EjbTimerService ts) throws PropertyVetoException, TransactionFailure {
Property prop = ts.createChild(Property.class);
ts.getProperty().add(prop);
prop.setName(EjbContainerUtil.TIMER_SERVICE_UPGRADED);
prop.setValue("false");
ts.setMinimumDeliveryIntervalInMillis(minDelivery);
return null;
}
}, ts);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class PersistentEJBTimerService method isUpgrade.
private static boolean isUpgrade(String resource, EjbTimerService _ejbt, File root) {
boolean upgrade = false;
Property prop = null;
if (_ejbt != null) {
List<Property> properties = _ejbt.getProperty();
if (properties != null) {
for (Property p : properties) {
if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
String value = p.getValue();
if (value != null && "false".equals(value)) {
upgrade = true;
prop = p;
break;
}
}
}
}
}
if (logger.isLoggable(Level.FINE)) {
logger.fine("===> Upgrade? <==");
}
if (upgrade) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("===> Upgrade! <==");
}
boolean success = false;
try {
File dir = new File(root, "lib/install/databases/upgrade");
if (!dir.exists()) {
logger.log(Level.WARNING, "Cannot upgrade EJBTimerService: " + "required directory is not available");
} else {
Java2DBProcessorHelper h = new Java2DBProcessorHelper(TIMER_SERVICE_APP_NAME);
success = h.executeDDLStatement(dir.getCanonicalPath() + "/ejbtimer_upgrade_", resource);
ConfigSupport.apply(new SingleConfigCode<Property>() {
public Object run(Property p) throws PropertyVetoException, TransactionFailure {
p.setValue("true");
return null;
}
}, prop);
}
} catch (Exception e) {
logger.log(Level.WARNING, "", e);
}
if (!success) {
logger.log(Level.SEVERE, "Failed to upgrade EJBTimerService: see log for details");
}
}
return upgrade;
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class JDBCResourceManager method create.
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
setAttributes(attributes, target);
ResourceStatus validationStatus = isValid(resources, true, target);
if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
return validationStatus;
}
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
return createResource(param, properties);
}
}, resources);
resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("create.jdbc.resource.fail", "JDBC resource {0} create failed ", jndiName) + " " + tfe.getLocalizedMessage();
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("create.jdbc.resource.success", "JDBC resource {0} created successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class JDBCConnectionPoolManager method create.
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
setAttributes(attributes);
ResourceStatus validationStatus = isValid(resources);
if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
return validationStatus;
}
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
return createResource(param, properties);
}
}, resources);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("create.jdbc.connection.pool.fail", "JDBC connection pool {0} create failed: {1}", jdbcconnectionpoolid, tfe.getMessage());
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
String msg = localStrings.getLocalString("create.jdbc.connection.pool.success", "JDBC connection pool {0} created successfully", jdbcconnectionpoolid);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class CreateJdbcResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
// Delete the created resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
// and removal runs at the same time.
for (Resource resource : param.getResources()) {
if (resource instanceof JdbcResource) {
JdbcResource jr = (JdbcResource) resource;
if (jr.getJndiName().equals("jdbc/foo") || jr.getJndiName().equals("dupRes") || jr.getJndiName().equals("jdbc/sun") || jr.getJndiName().equals("jdbc/alldefaults") || jr.getJndiName().equals("jdbc/junk")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
parameters = new ParameterMap();
}
Aggregations