Example usage for javax.persistence PersistenceException getMessage

List of usage examples for javax.persistence PersistenceException getMessage

Introduction

In this page you can find the example usage for javax.persistence PersistenceException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String getUsersID(String userid) {
    Users p = new Users();
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();// www.  j  a  v a 2 s  .  c  o  m
    String msg = ""; //LA lista de roles que vienen de la base de datos convertido en json
    try {
        //Query q= entity.createNativeQuery("Select * From product Where productid="+productid,Product.class);
        Query q = entity.createNamedQuery("Users.findByUserid").setParameter("userid",
                Integer.parseInt(userid));
        p = (Users) q.getSingleResult();
        msg = gson.toJson(p);
        m.setCode(200);
        m.setMsg(msg);
        m.setDetail("OK");
    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("error");

    } catch (PersistenceException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("error");

    }

    return gson.toJson(m);
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String getCategoryID(String Categoryid) {
    Category p = new Category();
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/* w w w  .  jav a2 s . c o m*/
    String msg = ""; //LA lista de roles que vienen de la base de datos convertido en json
    try {
        //Query q= entity.createNativeQuery("Select * From product Where productid="+productid,Product.class);
        Query q = entity.createNamedQuery("Category.findByCategoryid").setParameter("categoryid",
                Integer.parseInt(Categoryid));
        p = (Category) q.getSingleResult();
        msg = gson.toJson(p);
        m.setCode(200);
        m.setMsg(msg);
        m.setDetail("OK");
    } catch (IllegalArgumentException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("error");

    } catch (PersistenceException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("error");

    }

    return gson.toJson(m);
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String newCategory(String categoryname) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/*from   w  ww  .  j a v  a2  s .c  o m*/
    try {
        Category p = new Category();

        p.setCategoryname(categoryname);
        entity.persist(p);
        entity.flush();
        m.setCode(200);
        m.setMsg("Todo bien compa");
        m.setDetail("OK, El id es:" + p.getCategoryid().toString());
        return gson.toJson(m);
    } catch (EntityExistsException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (IllegalArgumentException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (PersistenceException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    }
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String newCompany(String CompanyName, String neighborhood, String zipcode, String city, String country,
        String state, String region, String street, String streetnumber, String phone, String rfc,
        String logo) {//  w ww.ja v a  2  s  .  c  o m
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();
    try {
        Company p = new Company();

        p.setCompanyname(CompanyName);
        p.setNeighborhood(neighborhood);
        p.setZipcode(zipcode);
        p.setCity(city);
        p.setCountry(country);
        p.setState(state);
        p.setRegion(region);
        p.setStreet(street);
        p.setStreetnumber(streetnumber);
        p.setPhone(phone);
        p.setRfc(rfc);
        p.setLogo(logo);

        entity.persist(p);
        entity.flush();

        m.setCode(200);
        m.setMsg("Todo bien compa");
        m.setDetail("OK, El id es:" + p.getCompanyid().toString());
        return gson.toJson(m);
    } catch (EntityExistsException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (IllegalArgumentException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (PersistenceException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    }
}

From source file:mx.edu.ittepic.AEEcommerce.ejbs.OperationCommerce.java

public String newUser(String username, String password, String phone, String neigborhood, String zipcode,
        String city, String country, String state, String region, String street, String email,
        String streetnumber, Part file, String cellphone, String companyid, String roleid, String gender) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();//from ww  w  .jav  a 2 s. c om
    try {
        Users p = new Users();

        p.setUsername(username);
        p.setPassword(password);
        p.setPhone(phone);
        p.setNeigborhood(neigborhood);
        p.setZipcode(zipcode);
        p.setCity(city);
        p.setCountry(country);
        p.setState(state);
        p.setRegion(region);
        p.setStreet(street);
        p.setEmail(email);
        p.setStreetnumber(streetnumber);

        p.setCellphone(cellphone);
        Company companyid_ = entity.find(Company.class, Integer.parseInt(companyid));
        Role roleid_ = entity.find(Role.class, Integer.parseInt(roleid));
        if (companyid_ == null) {
            m.setCode(404);
            m.setMsg("Error" + 404);
            m.setDetail("ERROR");
            return gson.toJson(m);
        } else {
            p.setCompanyid(companyid_);
        }
        if (roleid_ == null) {
            m.setCode(404);
            m.setMsg("Error" + 404);
            m.setDetail("ERROR");
            return gson.toJson(m);
        } else {
            p.setRoleid(roleid_);
        }

        p.setGender(gender.charAt(0));
        p.setApikey("");
        entity.persist(p);
        entity.flush();
        p.setApikey(DigestUtils.md5Hex(p.getUserid().toString()));
        entity.merge(p);

        PreExamenProduct insertImg = new PreExamenProduct();
        p.setPhoto(insertImg.copyIMG(file, p.getUserid(), "Usuario"));

        m.setCode(200);
        m.setMsg("Todo bien compa");
        m.setDetail("OK, El id es:" + p.getUserid().toString());
        return gson.toJson(m);
    } catch (EntityExistsException e) {
        m.setCode(404);
        m.setMsg(e.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (IllegalArgumentException ex) {
        m.setCode(404);
        m.setMsg(ex.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    } catch (PersistenceException exx) {
        m.setCode(404);
        m.setMsg(exx.getMessage());
        m.setDetail("ERROR");
        return gson.toJson(m);
    }
}

From source file:org.apache.archiva.metadata.repository.cassandra.CassandraMetadataRepository.java

@Override
public Collection<String> getRepositories() throws MetadataRepositoryException {
    try {/* w  w w  .  ja  va  2s .  co  m*/
        logger.debug("getRepositories");

        final QueryResult<OrderedRows<String, String, String>> cResult = //
                HFactory.createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), //
                        ss, ss, ss) //
                        .setColumnFamily(cassandraArchivaManager.getRepositoryFamilyName()) //
                        .setColumnNames(REPOSITORY_NAME.toString()) //
                        .setRange(null, null, false, Integer.MAX_VALUE) //
                        .execute();

        List<String> repoIds = new ArrayList<>(cResult.get().getCount());

        for (Row<String, String, String> row : cResult.get()) {
            repoIds.add(getStringValue(row.getColumnSlice(), REPOSITORY_NAME.toString()));
        }

        return repoIds;
    } catch (PersistenceException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }

}

From source file:org.batoo.jpa.core.impl.criteria.jpql.JpqlQuery.java

private CommonTree parse(String query) {
    try {/*from  ww w .  j  a va  2 s . c  o  m*/
        final JpqlLexer lexer = new JpqlLexer(new ANTLRStringStream(query));
        final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        final JpqlParser parser = new JpqlParser(tokenStream);

        final ql_statement_return ql_statement = parser.ql_statement();
        final CommonTree tree = (CommonTree) ql_statement.getTree();

        final List<String> errors = parser.getErrors();
        if (errors.size() > 0) {
            final String errorMsg = Joiner.on("\n\t").join(errors);

            JpqlQuery.LOG.error("Cannot parse query: {0}", //
                    JpqlQuery.LOG.boxed(query, //
                            new Object[] { "\n\t" + errorMsg, "\n\n" + tree.toStringTree() + "\n" }));

            throw new PersistenceException("Cannot parse the query:\n " + errorMsg + ".\n" + query);
        }

        return tree;
    } catch (final PersistenceException e) {
        throw e;
    } catch (final Exception e) {
        throw new PersistenceException("Cannot parse the query:\n " + e.getMessage() + ".\n" + query, e);
    }
}

From source file:org.candlepin.resource.OwnerResource.java

/**
 * Removes an Owner/*from w w w .j av a 2 s . c  om*/
 *
 * @httpcode 404
 * @httpcode 200
 */
@DELETE
@Path("/{owner_key}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(notes = "Removes an Owner", value = "Delete Owner")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public void deleteOwner(@PathParam("owner_key") String ownerKey,
        @QueryParam("revoke") @DefaultValue("true") boolean revoke) {
    Owner owner = findOwner(ownerKey);
    Event event = eventFactory.ownerDeleted(owner);

    try {
        ownerManager.cleanupAndDelete(owner, revoke);
    } catch (PersistenceException e) {
        if (e.getCause() instanceof ConstraintViolationException) {
            throw new ConflictException(e.getMessage(), e);
        } else {
            throw e;
        }
    }

    sink.queueEvent(event);
}

From source file:org.eclipse.jubula.client.core.persistence.Persistor.java

/**
 * Installs the DB scheme used by Jubula.
 * /*from w w w . j  a  v  a 2  s  . com*/
 * @param entityManagerFactory
 *            The factory to use to create the entity manager in which the
 *            installation will occur.
 * 
 * @return <code>true</code> if the installation was successful. Otherwise,
 *         <code>false</code>.
 * @throws PMDatabaseConfException
 *             if the scheme couldn't be installed
 * @throws JBException
 *             in case of configuration problems
 */
private static boolean installDbScheme(EntityManagerFactory entityManagerFactory)
        throws PMDatabaseConfException, JBException {

    EntityManager em = null;
    try {
        em = entityManagerFactory.createEntityManager();
        SchemaManager schemaManager = new SchemaManager(em.unwrap(ServerSession.class));
        schemaManager.replaceDefaultTables();

        createOrUpdateDBVersion(em);
        createOrUpdateDBGuard(em);
        return true;
    } catch (PersistenceException e) {
        Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause instanceof SQLException) {
            if (("08001").equals(((SQLException) rootCause).getSQLState())) { //$NON-NLS-1$
                log.error(Messages.TheDBAllreadyUseAnotherProcess, e);
                throw new JBException(rootCause.getMessage(), MessageIDs.E_DB_IN_USE);
            }
            log.error(Messages.NoOrWrongUsernameOrPassword, e);
            throw new JBException(e.getMessage(), MessageIDs.E_NO_DB_CONNECTION);
        }
        final String msg = Messages.ProblemInstallingDBScheme + StringConstants.DOT;
        log.error(msg);
        throw new PMDatabaseConfException(msg, MessageIDs.E_NO_DB_SCHEME);
    } finally {
        if (em != null) {
            try {
                em.close();
            } catch (Throwable e) {
                // ignore
            }
        }
    }
}

From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java

/**
 * @return list with all available projects from database the project
 *         instances are detached from their session
 * @throws JBException/*ww  w.  j  a v a  2  s  .  c o m*/
 *             ...
 */
public static synchronized List<IProjectPO> findAllProjects() throws JBException {

    ProjectNameBP.getInstance().clearCache();
    EntityManager session = null;
    try {
        session = Persistor.instance().openSession();
        return findAllProjects(session);
    } catch (PersistenceException e) {
        log.error(Messages.PersistenceLoadFailed, e);
        throw new JBException(e.getMessage(), MessageIDs.E_PERSISTENCE_LOAD_FAILED);
    } finally {
        Persistor.instance().dropSessionWithoutLockRelease(session);
    }
}