Java Code Examples for javax.ejb.LockType#WRITE

The following examples show how to use javax.ejb.LockType#WRITE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrderStore.java    From jaxrs-hypermedia with Apache License 2.0 6 votes vote down vote up
@Lock(LockType.WRITE)
public Order checkout() {
    final Order order = new Order();
    order.getSelections().addAll(shoppingCart.getSelections());
    order.setPrice(priceCalculator.calculateTotal(order.getSelections()));

    final long id = orders.size() + 1;
    order.setId(id);
    order.setDate(LocalDateTime.now());
    order.setStatus(OrderStatus.CONFIRMED);

    shoppingCart.clear();

    orders.put(id, order);
    return order;
}
 
Example 2
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void addBookSelection(BookSelection selection) {
    final Optional<BookSelection> existentSelection = selections.stream().filter(s -> s.getBook().equals(selection.getBook())).findFirst();

    if (existentSelection.isPresent()) {
        final BookSelection bookSelection = existentSelection.get();
        bookSelection.setQuantity(bookSelection.getQuantity() + selection.getQuantity());
        updatePrice(bookSelection);
    } else {
        updatePrice(selection);
        selections.add(selection);
        selection.setId(nextSelectionId++);
    }
}
 
Example 3
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void updateBookSelection(long selectionId, int quantity) {
    final BookSelection selection = selections.stream()
            .filter(s -> s.getId() == selectionId).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("No selection found"));

    selection.setQuantity(quantity);
    updatePrice(selection);

    if (quantity == 0)
        selections.remove(selection);
}
 
Example 4
Source File: ReadersWritersSingleton.java    From training with MIT License 5 votes vote down vote up
@Lock(LockType.WRITE)
public void writerMethod(int threadId) {
	System.out.println("Entering WRITER " + threadId + ". R:" + readerCount.get() + "/w:"
			+ writerCount.incrementAndGet());
	try {
		Thread.sleep(300);
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	System.out.println("Exiting WRITER " + threadId + ". R:" + readerCount.get() + "/w:"
			+ writerCount.decrementAndGet());
}
 
Example 5
Source File: ConfigurationServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
@Lock(LockType.WRITE)
public void setConfigurationSetting(String informationId, String value) {
    ConfigurationSetting configSetting = new ConfigurationSetting(
            ConfigurationKey.valueOf(informationId),
            Configuration.GLOBAL_CONTEXT, value);
    setConfigurationSetting(configSetting);
}
 
Example 6
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void addBookSelection(BookSelection selection) {
    final Optional<BookSelection> existentSelection = selections.stream().filter(s -> s.getBook().equals(selection.getBook())).findFirst();

    if (existentSelection.isPresent()) {
        final BookSelection bookSelection = existentSelection.get();
        bookSelection.setQuantity(bookSelection.getQuantity() + selection.getQuantity());
        updatePrice(bookSelection);
    } else {
        updatePrice(selection);
        selections.add(selection);
        selection.setId(nextSelectionId++);
    }
}
 
Example 7
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void updateBookSelection(long selectionId, int quantity) {
    final BookSelection selection = selections.stream()
            .filter(s -> s.getId() == selectionId).findFirst()
            .orElseThrow(() -> new IllegalArgumentException("No selection found"));

    selection.setQuantity(quantity);
    updatePrice(selection);

    if (quantity == 0)
        selections.remove(selection);
}
 
Example 8
Source File: TransactionRegistryInTimeoutTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Timeout
@Lock(LockType.WRITE)
public void timerFired() {
    try {
        final String jndi = "java:comp/TransactionSynchronizationRegistry";
        final TransactionSynchronizationRegistry txRegistry = (TransactionSynchronizationRegistry) new InitialContext().lookup(jndi);
        assertNotNull(txRegistry);
        assertNotNull(context.lookup(jndi));
        assertNotNull(registry);
        txRegistry.registerInterposedSynchronization(sync);
    } catch (final NamingException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 9
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 5 votes vote down vote up
@Lock(LockType.WRITE)
public void addBookSelection(BookSelection selection) {
    final Optional<BookSelection> existentSelection = selections.stream().filter(s -> s.getBook().equals(selection.getBook())).findFirst();

    if (existentSelection.isPresent()) {
        final BookSelection bookSelection = existentSelection.get();
        bookSelection.setQuantity(bookSelection.getQuantity() + selection.getQuantity());
        updatePrice(bookSelection);
    } else {
        updatePrice(selection);
        selections.add(selection);
        selection.setId(nextSelectionId++);
    }
}
 
Example 10
Source File: ConfigurationServiceBean.java    From development with Apache License 2.0 5 votes vote down vote up
@Schedule(minute = "*/10")
@Lock(LockType.WRITE)
public void refreshCache() {
    cache = new HashMap<>();
    for (ConfigurationSetting configurationSetting : getAllConfigurationSettings()) {
        addToCache(configurationSetting);
    }
}
 
Example 11
Source File: CountryStateContainerManagedBean.java    From tutorials with MIT License 5 votes vote down vote up
@Lock(LockType.WRITE)
@PostConstruct
public void initialize() {

    List<String> states = new ArrayList<String>();
    states.add("Texas");
    states.add("Alabama");
    states.add("Alaska");
    states.add("Arizona");
    states.add("Arkansas");

    countryStatesMap.put("UnitedStates", states);
}
 
Example 12
Source File: MarketSummarySingleton.java    From sample.daytrader7 with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void setMarketSummaryDataBean(MarketSummaryDataBean marketSummaryDataBean) {
    this.marketSummaryDataBean = marketSummaryDataBean;
}
 
Example 13
Source File: SessionRegistry.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void remove(Session session) {
    sessions.remove(session);
}
 
Example 14
Source File: ConfigurationServiceBean.java    From development with Apache License 2.0 4 votes vote down vote up
@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
@Lock(LockType.WRITE)
public void setConfigurationSetting(ConfigurationSetting configSetting) {
    ConfigurationSetting setting = getConfigurationSettingExactMatch(
            configSetting.getInformationId(), configSetting.getContextId());
    if (!isEmpty(configSetting.getValue())) {
        // check the type and trim the string if necessary
        String value = configSetting.getValue();

        if (configSetting.getInformationId()
                .getType() == ConfigurationKey.TYPE_BOOLEAN
                || configSetting.getInformationId()
                        .getType() == ConfigurationKey.TYPE_LONG
                || configSetting.getInformationId()
                        .getType() == ConfigurationKey.TYPE_URL
                || configSetting.getInformationId()
                        .getType() == ConfigurationKey.TYPE_STRING
                || configSetting.getInformationId()
                        .getType() == ConfigurationKey.TYPE_PASSWORD) {

            value = value.trim();
        }

        // if the value is not empty, update or create the setting
        if (setting != null) {
            // if entry is already present, update it
            setting.setValue(value);
        } else {
            // if not, create a new one
            try {
                configSetting.setValue(value);
                dm.persist(configSetting);
            } catch (NonUniqueBusinessKeyException e) {
                logger.logError(Log4jLogger.SYSTEM_LOG, e,
                        LogMessageIdentifier.ERROR_PERSIST_CONFIGURATION_SETTING);
            }
        }
    } else {
        // remove optional empty settings so that the default value can be
        // used again
        if (setting != null) {
            dm.remove(setting);
        }
    }
    refreshCache();
}
 
Example 15
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void clear() {
    selections.clear();
}
 
Example 16
Source File: SessionRegistry.java    From packt-java-ee-7-code-samples with GNU General Public License v2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void remove(Session session) {
    sessions.remove(session);
}
 
Example 17
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void clear() {
    selections.clear();
}
 
Example 18
Source File: CountryStateContainerManagedBean.java    From tutorials with MIT License 4 votes vote down vote up
@Lock(LockType.WRITE)
public void setStates(String country, List<String> states) {
    countryStatesMap.put(country, states);
}
 
Example 19
Source File: ShoppingCart.java    From jaxrs-hypermedia with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void clear() {
    selections.clear();
}
 
Example 20
Source File: UserMethodLevelBean.java    From javaee8-cookbook with Apache License 2.0 4 votes vote down vote up
@Lock(LockType.WRITE)
public void addUser(){
    userCount++;
}