Example usage for javax.persistence PersistenceException printStackTrace

List of usage examples for javax.persistence PersistenceException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:se.vgregion.urlservice.repository.jpa.JpaBookmarkRepositoryTest.java

@Test(expected = PersistenceException.class)
@Transactional// w  w w .j a  v a 2  s . c o  m
@Rollback
public void duplicateHashNotAllowed() {
    try {
        dao.persist(new Bookmark(bookmark1.getHash(), longUrl, Collections.EMPTY_LIST, owner));
        dao.flush();
    } catch (PersistenceException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:controllers.InstrumentController.java

public Result addInstrument() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Instrument not saved, expecting Json data");
        return badRequest("Instrument not saved, expecting Json data");
    }/*from   w  ww. ja  va2  s. c om*/
    String name = json.findPath("name").asText();
    String description = json.findPath("description").asText();
    long launchDateNumber = json.findPath("launchDate").asLong();
    Date launchDate = new Date(launchDateNumber);
    try {
        Instrument instrument = new Instrument(name, description, launchDate);
        Instrument savedinstrument = instrumentRepository.save(instrument);
        System.out.println("Instrument saved: " + savedinstrument.getId());
        return created(new Gson().toJson(instrument.getId()));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Instrument not created");
        return badRequest("Instrument Configuration not created");
    }

}

From source file:controllers.InstrumentController.java

public Result updateInstrumentById(long id) {
    if (id < 0) {
        System.out.println("id is negative!");
        return badRequest("id is negative!");
    }/*from   ww  w  .ja va2 s. c om*/
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Instrument not saved, expecting Json data");
        return badRequest("Instrument Configuration not saved, expecting Json data");
    }
    long instrumentId = json.findPath("id").asLong();
    String name = json.findPath("name").asText();
    String description = json.findPath("description").asText();
    long launchDateNumber = json.findPath("launchDate").asLong();
    Date launchDate = new Date(launchDateNumber);
    try {
        Instrument instrument = instrumentRepository.findOne(instrumentId);
        instrument.setDescription(description);
        instrument.setLaunchDate(launchDate);
        instrument.setName(name);
        Instrument savedInstrument = instrumentRepository.save(instrument);

        System.out.println("Instrument updated: " + savedInstrument.getId());
        return created("Instrument updated: " + savedInstrument.getId());
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Instrument not saved: " + id);
        return badRequest("Instrument not saved: " + id);
    }
}

From source file:controllers.DatasetLogController.java

public Result addDatasetLog() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("DatasetLog not saved, expecting Json data");
        return badRequest("DatasetLog not saved, expecting Json data");
    }/*w  w w .  j  ava2  s . c  o m*/

    String plotUrl = json.findPath("plotUrl").asText();
    String dataUrl = json.findPath("dataUrl").asText();
    long originalDatasetId = json.findPath("originalDatasetId").asLong();
    long outputDatasetId = json.findPath("outputDatasetId").asLong();
    long serviceExecutionLogId = json.findPath("serviceExecutionLogId").asLong();
    long datasetId = json.findPath("datasetId").asLong();

    try {
        Dataset originalDataset = datasetRepository.findOne(originalDatasetId);
        Dataset outputDataset = datasetRepository.findOne(outputDatasetId);
        Dataset dataset = datasetRepository.findOne(datasetId);
        DatasetLog datasetLog = new DatasetLog(dataset, plotUrl, dataUrl, originalDataset, outputDataset);
        DatasetLog saveddatasetLog = datasetLogRepository.save(datasetLog);
        System.out.println("DatasetLog saved: " + saveddatasetLog.getId());
        return created(new Gson().toJson(datasetLog.getId()));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("DatasetLog not created");
        return badRequest("DatasetLog Configuration not created");
    }

}

From source file:controllers.DatasetLogController.java

public Result updateDatasetLogById(long id) {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("DatasetLog not saved, expecting Json data");
        return badRequest("DatasetLog Configuration not saved, expecting Json data");
    }//from w  ww . j  a  va2 s  .  c om

    String plotUrl = json.findPath("plotUrl").asText();
    String dataUrl = json.findPath("dataUrl").asText();
    long originalDatasetId = json.findPath("originalDatasetId").asLong();
    long outputDatasetId = json.findPath("outputDatasetId").asLong();
    long serviceExecutionLogId = json.findPath("serviceExecutionLogId").asLong();
    long datasetId = json.findPath("datasetId").asLong();

    try {
        Dataset originalDataset = datasetRepository.findOne(originalDatasetId);
        Dataset outputDataset = datasetRepository.findOne(outputDatasetId);
        Dataset dataset = datasetRepository.findOne(datasetId);
        DatasetLog datasetLog = datasetLogRepository.findOne(id);
        datasetLog.setDataSet(dataset);
        datasetLog.setDataUrl(dataUrl);
        datasetLog.setOriginalDataset(originalDataset);
        datasetLog.setOutputDataset(outputDataset);
        datasetLog.setPlotUrl(plotUrl);
        DatasetLog savedDatasetLog = datasetLogRepository.save(datasetLog);

        System.out.println("DatasetLog updated: " + savedDatasetLog.getId());
        return created("DatasetLog updated: " + savedDatasetLog.getId());
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("DatasetLog not saved: " + id);
        return badRequest("DatasetLog not saved: " + id);
    }
}

From source file:controllers.ParameterController.java

public Result addParameter() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Parameter not saved, expecting Json data");
        return badRequest("Parameter not saved, expecting Json data");
    }/* w w w  .jav  a 2  s .  c  o m*/

    //Parse JSON file
    long serviceId = json.findPath("serviceId").asLong();
    long indexInService = json.findPath("indexInService").asLong();
    String name = json.findPath("name").asText();
    String dataRange = json.findPath("dataRange").asText();
    String rule = json.findPath("rule").asText();
    String purpose = json.findPath("purpose").asText();

    try {
        ClimateService climateService = climateServiceRepository.findOne(serviceId);
        Parameter parameter = new Parameter(climateService, indexInService, name, dataRange, rule, purpose);
        Parameter savedParameter = parameterRepository.save(parameter);

        System.out.println("Parameter saved: " + savedParameter.getName());
        return created(new Gson().toJson(savedParameter.getId()));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println(serviceId);
        System.out.println(pe.getClass().toString());
        System.out.println("Parameter not saved: " + name);
        return badRequest("Parameter not saved: " + name);
    }
}

From source file:controllers.ParameterController.java

public Result updateParameterById(long id) {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Parameter not updated, expecting Json data");
        return badRequest("Parameter not updated, expecting Json data");
    }/*from w  w  w.jav a 2  s.  co  m*/

    //Parse JSON file
    long serviceId = json.findPath("serviceId").asLong();
    long indexInService = json.findPath("indexInService").asLong();
    String name = json.findPath("name").asText();
    Iterator<JsonNode> elements = json.findPath("dataType").elements();
    StringBuffer dataType = new StringBuffer();
    while (elements.hasNext()) {
        dataType.append(elements.next().asText());
        dataType.append(",");
    }
    dataType.deleteCharAt(dataType.length() - 1);
    String dataRange = json.findPath("dataRange").asText();
    String rule = json.findPath("rule").asText();
    String purpose = json.findPath("purpose").asText();

    try {
        ClimateService climateService = climateServiceRepository.findOne(serviceId);

        Parameter parameter = parameterRepository.findOne(id);
        parameter.setClimateService(climateService);
        parameter.setIndexInService(indexInService);
        parameter.setName(name);
        parameter.setDataRange(dataRange);
        parameter.setRule(rule);
        parameter.setPurpose(purpose);

        Parameter savedParameter = parameterRepository.save(parameter);

        System.out.println("Parameter updated: " + savedParameter.getName());
        return created("Parameter updated: " + savedParameter.getName());
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Parameter not updated: " + name);
        return badRequest("Parameter not updated: " + name);
    }
}

From source file:controllers.ParameterController.java

public Result updateParameterByName(String oldName) {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Parameter not updated, expecting Json data");
        return badRequest("Parameter not updated, expecting Json data");
    }//from   w  w w  . j a va  2s  . co m

    //Parse JSON file
    long serviceId = json.findPath("serviceId").asLong();
    long indexInService = json.findPath("indexInService").asLong();
    String name = json.findPath("name").asText();
    Iterator<JsonNode> elements = json.findPath("dataType").elements();
    StringBuffer dataType = new StringBuffer();
    while (elements.hasNext()) {
        dataType.append(elements.next().asText());
        dataType.append(",");
    }
    dataType.deleteCharAt(dataType.length() - 1);
    String dataRange = json.findPath("dataRange").asText();
    String rule = json.findPath("rule").asText();
    String purpose = json.findPath("purpose").asText();

    if (oldName == null || oldName.length() == 0) {
        System.out.println("Parameter Name is null or empty!");
        return badRequest("Parameter Name is null or empty!");
    }

    try {
        ClimateService climateService = climateServiceRepository.findOne(serviceId);

        Parameter parameter = parameterRepository.findByNameAndClimateService_Id(oldName, serviceId);
        parameter.setClimateService(climateService);
        parameter.setIndexInService(indexInService);
        parameter.setName(name);
        parameter.setDataRange(dataRange);
        parameter.setRule(rule);
        parameter.setPurpose(purpose);

        Parameter savedParameter = parameterRepository.save(parameter);

        System.out.println("Parameter updated: " + savedParameter.getName());
        return created("Parameter updated: " + savedParameter.getName());
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Parameter not updated: " + name);
        return badRequest("Parameter not updated: " + name);
    }
}

From source file:controllers.CommentController.java

public Result deleteComment(Long serviceId, Long versionId, Long commentId) {
    System.out.println("DELETE COMMENT");

    ObjectNode response = Json.newObject();

    try {/*from w  w  w  . ja v  a 2  s .  co  m*/
        deleteCommentById(serviceId, versionId, commentId);

        response.put("success", true);
        response.put("total_comment", commentRepository.countComments(serviceId, versionId));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Comment not deleted");
        return badRequest(failJson("Comment not deleted"));
    }

    return ok(response.toString());
}

From source file:controllers.ClimateServiceController.java

public Result addClimateService() {
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Climate service not saved, expecting Json data");
        return badRequest("Climate service not saved, expecting Json data");
    }//from  ww w. j a  v a2s  . c  o m

    // Parse JSON file
    long rootServiceId = json.findPath("rootServiceId").asLong();
    String creatorEmail = json.findPath("creatorEmail").asText();
    String name = json.findPath("name").asText();
    String purpose = json.findPath("purpose").asText();
    String url = json.findPath("url").asText();
    String scenario = json.findPath("scenario").asText();
    Date createTime = new Date();
    SimpleDateFormat format = new SimpleDateFormat(Common.DATE_PATTERN);
    try {
        createTime = format.parse(json.findPath("createTime").asText());
    } catch (ParseException e) {
        System.out.println("No creation date specified, set to current time");
    }
    String versionNo = json.findPath("versionNo").asText();

    try {
        User user = userRepository.findByEmail(creatorEmail);
        ClimateService climateService = new ClimateService(rootServiceId, user, name, purpose, url, scenario,
                createTime, versionNo);
        ClimateService savedClimateService = climateServiceRepository.save(climateService);
        String registerNote = "ClimateService Name: " + savedClimateService.getName() + ", VersionNo: "
                + versionNo;
        ServiceEntry serviceEntry = new ServiceEntry(createTime, versionNo, user, createTime, registerNote,
                initialcount, savedClimateService);
        serviceEntryRepository.save(serviceEntry);
        System.out.println("Climate Service saved: " + savedClimateService.getName());
        return created(new Gson().toJson(savedClimateService.getId()));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Climate Service not saved: " + name);
        return badRequest("Climate Service not saved: " + name);
    }
}