Search in sources :

Example 21 with Transactional

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);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) Transactional(com.google.inject.persist.Transactional)

Example 22 with Transactional

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;
}
Also used : EntityManager(javax.persistence.EntityManager) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Transactional(com.google.inject.persist.Transactional)

Example 23 with Transactional

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);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) AccountImpl(org.eclipse.che.account.spi.AccountImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 24 with Transactional

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);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) StringJoiner(java.util.StringJoiner) FactoryImpl(org.eclipse.che.api.factory.server.model.impl.FactoryImpl) Transactional(com.google.inject.persist.Transactional)

Example 25 with Transactional

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();
}
Also used : EntityManager(javax.persistence.EntityManager) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Transactional(com.google.inject.persist.Transactional)

Aggregations

Transactional (com.google.inject.persist.Transactional)51 EntityManager (javax.persistence.EntityManager)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)16 ServerException (org.eclipse.che.api.core.ServerException)12 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)6 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)5 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)4 NoResultException (javax.persistence.NoResultException)4 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 Timestamp (java.sql.Timestamp)3 AccountImpl (org.eclipse.che.account.spi.AccountImpl)3 FactoryImpl (org.eclipse.che.api.factory.server.model.impl.FactoryImpl)3 DateTime (org.joda.time.DateTime)3 TaskBean (com.linkedin.thirdeye.datalayer.pojo.TaskBean)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EntityTransaction (javax.persistence.EntityTransaction)2 Query (javax.persistence.Query)2