Search in sources :

Example 21 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class Dbinfo method getDescription.

@Override
public String getDescription() {
    final Kernel kernel;
    try {
        kernel = getKernel();
    } catch (ShellException e) {
        return e.getMessage();
    }
    MBeanServer mbeans = getPlatformMBeanServer();
    StringBuilder result = new StringBuilder("Get runtime information about the Graph Database.\n" + "This uses the Neo4j management beans to get" + " information about the Graph Database.\n\n");
    availableBeans(mbeans, kernel, result);
    result.append("\n");
    getUsage(result);
    return result.toString();
}
Also used : Kernel(org.neo4j.jmx.Kernel) ShellException(org.neo4j.shell.ShellException) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 22 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class Rollback method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
    if (parser.getLineWithoutApp().trim().length() > 0) {
        out.println("Error: ROLLBACK should  be run without trailing arguments");
        return Continuation.INPUT_COMPLETE;
    }
    KernelTransaction tx = Begin.currentTransaction(getServer());
    if (tx == null) {
        throw Commit.fail(session, "Not in a transaction");
    }
    session.remove(Variables.TX_COUNT);
    tx.failure();
    try {
        tx.close();
    } catch (TransactionFailureException e) {
        throw new ShellException(e.getMessage());
    }
    out.println("Transaction rolled back");
    return Continuation.INPUT_COMPLETE;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ShellException(org.neo4j.shell.ShellException)

Example 23 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class Schema method sampleIndexes.

private void sampleIndexes(Label[] labels, String property, boolean sampleAll, boolean forceSample) throws ShellException {
    IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency(IndexingService.class);
    if (indexingService == null) {
        throw new ShellException("Internal error: failed to resolve IndexingService");
    }
    IndexSamplingMode samplingMode = getSamplingMode(forceSample);
    // Trigger sampling for all indices
    if (sampleAll) {
        indexingService.triggerIndexSampling(samplingMode);
        return;
    }
    validateLabelsAndProperty(labels, property);
    Statement statement = getServer().getStatement();
    int labelKey = statement.readOperations().labelGetForName(labels[0].name());
    int propertyKey = statement.readOperations().propertyKeyGetForName(property);
    if (labelKey == -1) {
        throw new ShellException("No label associated with '" + labels[0].name() + "' was found");
    }
    if (propertyKey == -1) {
        throw new ShellException("No property associated with '" + property + "' was found");
    }
    try {
        indexingService.triggerIndexSampling(SchemaDescriptorFactory.forLabel(labelKey, propertyKey), samplingMode);
    } catch (IndexNotFoundKernelException e) {
        throw new ShellException(e.getMessage());
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Statement(org.neo4j.kernel.api.Statement) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ShellException(org.neo4j.shell.ShellException)

Example 24 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class Set method getValueType.

private static ValueType getValueType(AppCommandParser parser) throws ShellException {
    String type = parser.options().containsKey("t") ? parser.options().get("t") : String.class.getSimpleName();
    ValueType valueType = NAME_TO_VALUE_TYPE.get(type);
    if (valueType == null) {
        throw new ShellException("Invalid value type '" + type + "'");
    }
    return valueType;
}
Also used : OptionValueType(org.neo4j.shell.OptionValueType) ShellException(org.neo4j.shell.ShellException)

Example 25 with ShellException

use of org.neo4j.shell.ShellException in project neo4j by neo4j.

the class Set method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException {
    boolean forProperty = parser.options().containsKey("p");
    boolean forLabel = parser.options().containsKey("l");
    if (forProperty || !forLabel) {
        // Property
        if (parser.arguments().size() < 2) {
            throw new ShellException("Must supply key and value, " + "like: set title \"This is a my title\"");
        }
        String key = parser.arguments().get(0);
        ValueType valueType = getValueType(parser);
        Object value = parseValue(parser.arguments().get(1), valueType);
        NodeOrRelationship thing = getCurrent(session);
        thing.setProperty(key, value);
    } else {
        // Label
        Node node = getCurrent(session).asNode();
        for (Label label : parseLabels(parser)) {
            node.addLabel(label);
        }
    }
    return Continuation.INPUT_COMPLETE;
}
Also used : OptionValueType(org.neo4j.shell.OptionValueType) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) ShellException(org.neo4j.shell.ShellException)

Aggregations

ShellException (org.neo4j.shell.ShellException)33 RemoteException (java.rmi.RemoteException)12 Node (org.neo4j.graphdb.Node)6 Test (org.junit.Test)5 Relationship (org.neo4j.graphdb.Relationship)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)4 Serializable (java.io.Serializable)3 Kernel (org.neo4j.jmx.Kernel)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 Response (org.neo4j.shell.Response)3 Session (org.neo4j.shell.Session)3 ShellServer (org.neo4j.shell.ShellServer)3 JSONException (org.neo4j.shell.util.json.JSONException)3 ManagementFactory.getPlatformMBeanServer (java.lang.management.ManagementFactory.getPlatformMBeanServer)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MBeanServer (javax.management.MBeanServer)2 Label (org.neo4j.graphdb.Label)2 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)2