use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaPreferenceDao method getPreferences.
@Override
@Transactional
public Map<String, String> getPreferences(String userId) throws ServerException {
requireNonNull(userId);
try {
final EntityManager manager = managerProvider.get();
final PreferenceEntity prefs = manager.find(PreferenceEntity.class, userId);
return prefs == null ? new HashMap<>() : prefs.getPreferences();
} catch (RuntimeException ex) {
throw new ServerException(ex.getLocalizedMessage(), ex);
}
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaAccountDao method doRemove.
@Transactional
protected Optional<AccountImpl> doRemove(String id) {
final EntityManager manager = managerProvider.get();
final Optional<AccountImpl> account = Optional.ofNullable(manager.find(AccountImpl.class, id));
account.ifPresent(manager::remove);
return account;
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaAccountDao method getById.
@Override
@Transactional
public AccountImpl getById(String id) throws NotFoundException, ServerException {
requireNonNull(id, "Required non-null account id");
final EntityManager manager = managerProvider.get();
try {
AccountImpl account = manager.find(AccountImpl.class, id);
if (account == null) {
throw new NotFoundException(format("Account with id '%s' was not found", id));
}
return account;
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaFactoryDao method getByAttribute.
@Override
@Transactional
public List<FactoryImpl> getByAttribute(int maxItems, int skipCount, List<Pair<String, String>> attributes) throws ServerException {
try {
LOG.info("FactoryDao#getByAttributes #maxItems: {} #skipCount: {}, #attributes: {}", maxItems, skipCount, attributes);
final Map<String, String> params = new HashMap<>();
String query = "SELECT factory FROM Factory factory";
if (!attributes.isEmpty()) {
final StringJoiner matcher = new StringJoiner(" AND ", " WHERE ", " ");
int i = 0;
for (Pair<String, String> attribute : attributes) {
final String parameterName = "parameterName" + i++;
params.put(parameterName, attribute.second);
matcher.add("factory." + attribute.first + " = :" + parameterName);
}
query = query + matcher;
}
final TypedQuery<FactoryImpl> typedQuery = managerProvider.get().createQuery(query, FactoryImpl.class).setFirstResult(skipCount).setMaxResults(maxItems);
for (Map.Entry<String, String> entry : params.entrySet()) {
typedQuery.setParameter(entry.getKey(), entry.getValue());
}
return typedQuery.getResultList().stream().map(FactoryImpl::new).collect(Collectors.toList());
} catch (RuntimeException ex) {
throw new ServerException(ex.getLocalizedMessage(), ex);
}
}
use of com.google.inject.persist.Transactional in project che by eclipse.
the class JpaFactoryDao method doCreate.
@Transactional
protected void doCreate(FactoryImpl factory) {
final EntityManager manager = managerProvider.get();
if (factory.getWorkspace() != null) {
factory.getWorkspace().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
}
manager.persist(factory);
manager.flush();
}
Aggregations