List of usage examples for javax.ejb LockType WRITE
LockType WRITE
To view the source code for javax.ejb LockType WRITE.
Click Source Link
From source file:io.hops.hopsworks.common.security.OpensslOperations.java
@Lock(LockType.WRITE) public String getSubjectFromCSR(String csr) throws IOException { File csrFile = File.createTempFile(System.getProperty("java.io.tmpdir"), ".csr"); FileUtils.writeStringToFile(csrFile, csr); List<String> cmds = new ArrayList<>(); //openssl req -in certs-dir/hops-site-certs/csr.pem -noout -subject cmds.add(OPENSSL);/*from w w w. ja va2 s. c o m*/ cmds.add("req"); cmds.add("-in"); cmds.add(csrFile.getAbsolutePath()); cmds.add("-noout"); cmds.add("-subject"); return executeCommand(cmds, true); }
From source file:org.javabeanstack.data.DBManager.java
/** * Crea un entitymanager dentro de un Map utiliza la unidad de persistencia * y el threadid o sessionid del usuario como clave * /*from ww w . j av a 2 s . co m*/ * @param key id thread o sessionid del usuario * @return el entity manager creado. */ @Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) @Lock(LockType.WRITE) public EntityManager createEntityManager(String key) { EntityManager em; try { String persistentUnit = key.substring(0, key.indexOf(':')).toLowerCase(); em = (EntityManager) context.lookup("java:comp/env/persistence/" + persistentUnit); Data data = new Data(); data.em = em; entityManagers.put(key, data); LOGGER.debug("--------- Se ha creado un nuevo EntityManager --------- " + key); return em; } catch (Exception ex) { ErrorManager.showError(ex, LOGGER); } return null; }
From source file:org.javabeanstack.data.DBManager.java
/** * Ejecuta rollback de una transaccin */ @Override @Lock(LockType.WRITE) public void rollBack() { context.setRollbackOnly(); }
From source file:org.niord.core.mail.ScheduledMailService.java
/** * Called every minute to process scheduled mails *//* w w w. j a va2s . co m*/ @Schedule(persistent = false, second = "24", minute = "*", hour = "*") @Lock(LockType.WRITE) public void sendPendingMails() { // Send at most "maxMailsPerMinute" mails at a time List<Integer> scheduledMailIds = getPendingMails().stream().limit(maxMailsPerMinute).map(BaseEntity::getId) .collect(Collectors.toList()); if (!scheduledMailIds.isEmpty()) { log.info("Processing " + scheduledMailIds.size() + " pending scheduled mails"); List<MailSenderTask> tasks = scheduledMailIds.stream().map(id -> new MailSenderTask(mailService, id)) .collect(Collectors.toList()); try { managedExecutorService.invokeAll(tasks); } catch (InterruptedException e) { log.error("Error sending scheduled emails: " + scheduledMailIds, e); } } }
From source file:org.niord.core.mail.ScheduledMailService.java
/** * Called every day to delete old scheduled mails. * * Note to self: It would have been faster to execute a "delete from ScheduledMail where..." statement. * However, this will fail because of a missing mail - recipient "delete on cascade" FK constraint. * Using JPAs CascadeType.ALL for the relation does NOT work in this case. *//* w w w . j av a2s .c o m*/ @Schedule(persistent = false, second = "48", minute = "28", hour = "05") @Lock(LockType.WRITE) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) private void deleteExpiredMails() { // If expiryDate is 0 (actually, non-positive), never delete mails if (mailDeleteAfterDays <= 0) { return; } Date expiryDate = TimeUtils.add(new Date(), Calendar.DATE, -mailDeleteAfterDays); List<Integer> ids = em.createNamedQuery("ScheduledMail.findExpiredMails", Integer.class) .setParameter("expiryDate", expiryDate).getResultList(); if (!ids.isEmpty()) { long t0 = System.currentTimeMillis(); try { for (int x = 0; x < ids.size(); x++) { ScheduledMail mail = getScheduledMail(ids.get(x)); if (mail != null) { em.remove(mail); if ((x % 50) == 0) { em.flush(); } } } log.info("Deleted " + ids.size() + " scheduled mails older than " + expiryDate + " in " + (System.currentTimeMillis() - t0) + " ms"); } catch (Exception e) { log.error("Failed deleting scheduled mails older than " + expiryDate); } } }
From source file:org.niord.core.settings.SettingsService.java
/** * Updates the database value of the given setting * @param template the setting to update * @return the updated setting//from w w w .ja v a 2 s.c o m */ @Lock(LockType.WRITE) public Setting set(Setting template) { Setting setting = em.find(Setting.class, template.getKey()); if (setting == null) { throw new IllegalArgumentException("Non-existing setting " + template.getKey()); } // Update the DB setting.setValue(template.getValue()); setting = em.merge(setting); // Invalidate the cache evictFromCache(setting.getKey()); return setting; }
From source file:org.rhq.enterprise.server.auth.prefs.SubjectPreferencesCacheBean.java
@Override @Lock(LockType.WRITE) public void setUserProperty(int subjectId, String propertyName, String value) { load(subjectId);/*w w w. j a v a 2s.c o m*/ Configuration config = subjectPreferences.get(subjectId); if (config == null) { return; } PropertySimple prop = config.getSimple(propertyName); if (prop == null) { prop = new PropertySimple(propertyName, value); config.put(prop); // add new to collection mergeProperty(prop); } else if (prop.getStringValue() == null || !prop.getStringValue().equals(value)) { prop.setStringValue(value); mergeProperty(prop); } }
From source file:org.rhq.enterprise.server.auth.prefs.SubjectPreferencesCacheBean.java
@Override @Lock(LockType.WRITE) public void unsetUserProperty(int subjectId, String propertyName) { load(subjectId);/* w w w . j a v a 2s. c o m*/ Configuration config = subjectPreferences.get(subjectId); if (config == null) { return; } Property property = config.remove(propertyName); // it's possible property was already removed, and thus this operation becomes a no-op to the backing store if (property != null && property.getId() != 0) { try { configurationManager.deleteProperties(new int[] { property.getId() }); } catch (Throwable t) { log.error("Could not remove " + property, t); } } }
From source file:org.rhq.enterprise.server.auth.prefs.SubjectPreferencesCacheBean.java
@Override @Lock(LockType.WRITE) public void clearConfiguration(int subjectId) { if (log.isTraceEnabled()) { log.trace("Removing PreferencesCache For " + subjectId); }// w w w. j a v a 2s . com subjectPreferences.remove(subjectId); }