private void assertStatementFactoryExists() { if (statementFactory == null) { throw new UnknownStatementTypeException("Unknown statement type- statementFactory must be specified!"); } }
String code = ((CypherException) ex).getCode(); final Class<? extends DataAccessException> dae = Neo4jErrorStatusCodes.translate(code);
@Override public RuntimeException translateExceptionIfPossible(Throwable e) { if (e instanceof ServiceUnavailableException) { return new ConnectionException(e.getMessage(), e); } if (e instanceof RuntimeException) { return (RuntimeException) e; } return new RuntimeException(e); } }
private String cypherRequest(Statements statements) { try { return OBJECT_MAPPER.writeValueAsString(statements); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
/** * Extends the current transaction. * * @param otherType type of the other transaction */ public void extend(Type otherType) { if (this.type == otherType) { long extensions = extendsCount.incrementAndGet(); logger.debug("Thread {}: Transaction extended: {}", Thread.currentThread().getId(), extensions); } else { throw new TransactionException("Incompatible transaction type specified: must be '" + this.type + "'"); } }
private void throwExceptionOnErrorEntry(JsonParser pointingToErrors) throws IOException { if (pointingToErrors == null) { return; } JsonNode errorsNode = mapper.readTree(pointingToErrors); Optional<JsonNode> optionalErrorNode = StreamSupport.stream(errorsNode.spliterator(), false) .findFirst(); if (optionalErrorNode.isPresent()) { JsonNode errorNode = optionalErrorNode.get(); throw new CypherException(errorNode.findValue("code").asText(), errorNode.findValue("message").asText()); } }
@Test public void shouldNotBeAbleToExtendAReadTransactionWithAReadWriteInnerTransaction() { try ( Transaction tx1 = session.beginTransaction(Transaction.Type.READ_ONLY); Transaction tx2 = session.beginTransaction(Transaction.Type.READ_WRITE)) { fail("Should not have allowed transaction extension of different type"); } catch (TransactionException tme) { assertThat(tme.getLocalizedMessage()) .isEqualTo("Incompatible transaction type specified: must be 'READ_ONLY'"); } }
@Override public NodeBuilder addProperty(String key, Object value) { List<Property<String, Object>> propertyList = node.getPropertyList(); for (Property<String, Object> property : propertyList) { if (property.getKey().equals(key)) { throw new MappingException("Node model already contains property: " + key); } } propertyList.add(new PropertyModel<>(key, value)); return this; }
private String cypherRequest(Statements statements) { try { return mapper.writeValueAsString(statements); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
private Session newSession(Transaction.Type type, Iterable<String> bookmarks) { Session boltSession; try { AccessMode accessMode = type.equals(Transaction.Type.READ_ONLY) ? AccessMode.READ : AccessMode.WRITE; boltSession = boltDriver.session(accessMode, bookmarks); } catch (ClientException ce) { throw new ConnectionException( "Error connecting to graph database using Bolt: " + ce.code() + ", " + ce.getMessage(), ce); } catch (Exception e) { throw new ConnectionException("Error connecting to graph database using Bolt", e); } return boltSession; }
@Override public T next() { try { return fetchNext(); } catch (ClientException ce) { LOGGER.debug("Error executing Cypher: {}, {}", ce.code(), ce.getMessage()); throw new CypherException(ce.code(), ce.getMessage(), ce); } }
@Test public void shouldNotBeAbleToExtendAReadWriteTransactionWithAReadOnlyInnerTransaction() { try ( Transaction tx1 = session.beginTransaction(Transaction.Type.READ_WRITE); Transaction tx2 = session.beginTransaction(Transaction.Type.READ_ONLY)) { fail("Should not have allowed transaction extension of different type"); } catch (TransactionException tme) { assertThat(tme.getLocalizedMessage()) .isEqualTo("Incompatible transaction type specified: must be 'READ_WRITE'"); } }
T nextDataRecord(String key) { try { if (results.hasNext()) { JsonNode dataNode = results.next(); T t = dataNode.has(key) ? mapper.treeToValue(dataNode.get(key), resultClass) : null; return t; } } catch (IOException e) { throw new ResultProcessingException("Error processing results", e); } return null; }
private Session newSession(Transaction.Type type, Iterable<String> bookmarks) { Session boltSession; try { AccessMode accessMode = type.equals(Transaction.Type.READ_ONLY) ? AccessMode.READ : AccessMode.WRITE; boltSession = boltDriver.session(accessMode, bookmarks); } catch (ClientException ce) { throw new ConnectionException( "Error connecting to graph database using Bolt: " + ce.code() + ", " + ce.getMessage(), ce); } catch (Exception e) { throw new ConnectionException("Error connecting to graph database using Bolt", e); } return boltSession; }
@Override public T next() { try { return fetchNext(); } catch (ClientException ce) { LOGGER.debug("Error executing Cypher: {}, {}", ce.code(), ce.getMessage()); throw new CypherException(ce.code(), ce.getMessage(), ce); } }
private void initialise() { try { responseNode = mapper.readTree(buffer.asParser()); JsonNode errors = responseNode.findValue("errors"); if (errors.elements().hasNext()) { throw new ResultProcessingException(errors.elements().next().asText(), null); } } catch (IOException e) { e.printStackTrace(); } }
private String cypherRequest(Statement statement) { List<Statement> statementList = new ArrayList<>(); statementList.add(statement); try { return OBJECT_MAPPER.writeValueAsString(new Statements(statementList)); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
private String cypherRequest(Statement statement) { List<Statement> statementList = new ArrayList<>(); statementList.add(statement); try { return mapper.writeValueAsString(new Statements(statementList)); } catch (JsonProcessingException jpe) { throw new ResultProcessingException("Could not create JSON due to " + jpe.getLocalizedMessage(), jpe); } }
@Override public Response<GraphModel> execute(GraphModelRequest request) { if (request.getStatement().length() == 0) { return new EmptyResponse(); } else { String cypher = cypherRequest(request); try { return new GraphModelResponse(executeRequest(cypher)); } catch (Exception e) { throw new ResultProcessingException("Could not parse response", e); } } }
@Override public Response<RowModel> execute(DefaultRequest query) { Statements statements = new Statements(query.getStatements()); String cypher = cypherRequest(statements); try { return new RowModelResponse(executeRequest(cypher)); } catch (Exception e) { throw new ResultProcessingException("Could not parse response", e); } }