com.arangodb.ArangoDB Java Examples

The following examples show how to use com.arangodb.ArangoDB. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomTypeHintTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    ArangoDB arangoDB = new ArangoDB.Builder()
            .serializer(new VelocyJack())
            .build();

    String TEST_DB = "custom-serde-test";
    db = arangoDB.db(TEST_DB);
    if (!db.exists()) {
        db.create();
    }

    collection = db.collection(COLLECTION_NAME);
    if (!collection.exists()) {
        collection.create();
    }
}
 
Example #2
Source File: CustomSerdeTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() {
    VelocyJack velocyJack = new VelocyJack();
    velocyJack.configure((mapper) -> {
        mapper.configure(WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true);
        mapper.configure(USE_BIG_INTEGER_FOR_INTS, true);
    });
    ArangoDB arangoDB = new ArangoDB.Builder().serializer(velocyJack).build();

    String TEST_DB = "custom-serde-test";
    db = arangoDB.db(TEST_DB);
    if (!db.exists()) {
        db.create();
    }

    collection = db.collection(COLLECTION_NAME);
    if (!collection.exists()) {
        collection.create();
    }
}
 
Example #3
Source File: BaseGraphTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() {
    if (arangoDB == null) {
        arangoDB = new ArangoDB.Builder().build();
    }
    if (arangoDB.db(TEST_DB).exists())
        arangoDB.db(TEST_DB).drop();
    arangoDB.createDatabase(TEST_DB);
    BaseGraphTest.db = arangoDB.db(TEST_DB);

    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<>();
    final EdgeDefinition edgeDefinition = new EdgeDefinition().collection(EDGE_COLLECTION_NAME)
            .from(VERTEXT_COLLECTION_NAME).to(VERTEXT_COLLECTION_NAME);
    edgeDefinitions.add(edgeDefinition);
    if (!db.graph(GRAPH_NAME).exists())
        db.createGraph(GRAPH_NAME, edgeDefinitions, null);
    addExampleElements();
}
 
Example #4
Source File: CommunicationTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void multiThread() throws Exception {
    final ArangoDB arangoDB = new ArangoDB.Builder().build();
    arangoDB.getVersion();// authentication

    final Collection<String> result = new ConcurrentLinkedQueue<>();
    final Thread fast = new Thread(() -> {
        arangoDB.db().query("return sleep(0.1)", null, null, null);
        result.add(FAST);
    });
    final Thread slow = new Thread(() -> {
        arangoDB.db().query("return sleep(0.5)", null, null, null);
        result.add(SLOW);
    });
    slow.start();
    fast.start();

    slow.join();
    fast.join();

    assertThat(result.size(), is(2));
    final Iterator<String> iterator = result.iterator();
    assertThat(iterator.next(), is(FAST));
    assertThat(iterator.next(), is(SLOW));
}
 
Example #5
Source File: CommunicationTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void multiThreadSameDatabases() throws Exception {
    final ArangoDB arangoDB = new ArangoDB.Builder().build();
    arangoDB.getVersion();// authentication

    final ArangoDatabase db = arangoDB.db();

    final Collection<String> result = new ConcurrentLinkedQueue<>();
    final Thread t1 = new Thread(() -> {
        db.query("return sleep(0.1)", null, null, null);
        result.add("1");
    });
    final Thread t2 = new Thread(() -> {
        db.query("return sleep(0.1)", null, null, null);
        result.add("1");
    });
    t2.start();
    t1.start();
    t2.join();
    t1.join();
    assertThat(result.size(), is(2));
}
 
Example #6
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 5 votes vote down vote up
public ArangoTemplate(final ArangoDB arango, final String database, final ArangoConverter converter,
	final PersistenceExceptionTranslator exceptionTranslator) {
	super();
	this.arango = arango._setCursorInitializer(new ArangoCursorInitializer(converter));
	this.databaseName = database;
	this.databaseExpression = PARSER.parseExpression(databaseName, ParserContext.TEMPLATE_EXPRESSION);
	this.converter = converter;
	this.exceptionTranslator = exceptionTranslator;
	this.context = new StandardEvaluationContext();
	// set concurrency level to 1 as writes are very rare compared to reads
	collectionCache = new ConcurrentHashMap<>(8, 0.9f, 1);
	databaseCache = new ConcurrentHashMap<>(8, 0.9f, 1);
	version = null;
}
 
Example #7
Source File: InternalArangoDBBuilder.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
public InternalArangoDBBuilder() {
    super();
    vpackBuilder = new VPack.Builder();
    vpackParserBuilder = new VPackParser.Builder();
    vpackBuilder.registerModule(new VPackDriverModule());
    vpackParserBuilder.registerModule(new VPackDriverModule());
    host = new HostDescription(ArangoDefaults.DEFAULT_HOST, ArangoDefaults.DEFAULT_PORT);
    hosts = new ArrayList<>();
    user = ArangoDefaults.DEFAULT_USER;
    loadProperties(ArangoDB.class.getResourceAsStream(DEFAULT_PROPERTY_FILE));
}
 
Example #8
Source File: SslExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void connect() throws Exception {
	final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
	ks.load(this.getClass().getResourceAsStream(SSL_TRUSTSTORE), SSL_TRUSTSTORE_PASSWORD.toCharArray());

	final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
	kmf.init(ks, SSL_TRUSTSTORE_PASSWORD.toCharArray());

	final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
	tmf.init(ks);

	final SSLContext sc = SSLContext.getInstance("TLS");
	sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);


	final ArangoDB arangoDB = new ArangoDB.Builder()
			.host("127.0.0.1", 8529)
			.password("test")
			.useSsl(true)
			.sslContext(sc)
			.useProtocol(Protocol.HTTP_JSON)
			.build();
	final ArangoDBVersion version = arangoDB.getVersion();
	assertThat(version, is(notNullValue()));
	System.out.println(version.getVersion());
}
 
Example #9
Source File: ExampleBase.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
    arangoDB = new ArangoDB.Builder().build();
    if (arangoDB.db(DB_NAME).exists())
        arangoDB.db(DB_NAME).drop();
    arangoDB.createDatabase(DB_NAME);
    db = arangoDB.db(DB_NAME);
    db.createCollection(COLLECTION_NAME);
    collection = db.collection(COLLECTION_NAME);
}
 
Example #10
Source File: AQLActorsAndMoviesExample.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
    arangoDB = new ArangoDB.Builder().build();
    if (arangoDB.db(TEST_DB).exists())
        arangoDB.db(TEST_DB).drop();
    arangoDB.createDatabase(TEST_DB);
    db = arangoDB.db(TEST_DB);
    createData();
}
 
Example #11
Source File: SimpleSyncPerfTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
public SimpleSyncPerfTest(final Protocol protocol) {
    System.out.println("---");
    System.out.println(protocol);
    this.arangoDB = new ArangoDB.Builder().useProtocol(protocol).build();
}
 
Example #12
Source File: ArangoDBTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
private boolean isAtLeastVersion(final int major, final int minor) {
    final ArangoDB arangoDB = new ArangoDB.Builder().build();
    return com.arangodb.util.TestUtils.isAtLeastVersion(arangoDB.getVersion().getVersion(), major,minor,0);
}
 
Example #13
Source File: ArangoDBTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
private boolean isCluster() {
    final ArangoDB arangoDB = new ArangoDB.Builder().build();
    return arangoDB.getRole() == ServerRole.COORDINATOR;
}
 
Example #14
Source File: ArangoDBTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
private boolean isEnterprise() {
    final ArangoDB arangoDB = new ArangoDB.Builder().build();
    return arangoDB.getVersion().getLicense() == License.ENTERPRISE;
}
 
Example #15
Source File: ArangoSerializationTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() {
    final ArangoDB arangoDB = new ArangoDB.Builder().build();
    util = arangoDB.util();
}
 
Example #16
Source File: CommunicationTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Test
public void defaultMaxConnection() {
    final ArangoDB arangoDB = new ArangoDB.Builder().maxConnections(null).build();
    final ArangoDBVersion version = arangoDB.getVersion();
    assertThat(version, is(notNullValue()));
}
 
Example #17
Source File: CommunicationTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Test
public void minOneConnection() {
    final ArangoDB arangoDB = new ArangoDB.Builder().maxConnections(0).build();
    final ArangoDBVersion version = arangoDB.getVersion();
    assertThat(version, is(notNullValue()));
}
 
Example #18
Source File: CommunicationTest.java    From arangodb-java-driver with Apache License 2.0 4 votes vote down vote up
@Test
public void chunkSizeSmall() {
    final ArangoDB arangoDB = new ArangoDB.Builder().chunksize(20).build();
    final ArangoDBVersion version = arangoDB.getVersion();
    assertThat(version, is(notNullValue()));
}
 
Example #19
Source File: ArangoMultiTenancyTestConfiguration.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public ArangoDB.Builder arango() {
	return new ArangoDB.Builder();
}
 
Example #20
Source File: ArangoTestConfiguration.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public ArangoDB.Builder arango() {
	return new ArangoDB.Builder();
}
 
Example #21
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
@Override
public ArangoDB driver() {
	return arango;
}
 
Example #22
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
public ArangoTemplate(final ArangoDB arango, final String database, final ArangoConverter converter) {
	this(arango, database, converter, new ArangoExceptionTranslator());
}
 
Example #23
Source File: ArangoTemplate.java    From spring-data with Apache License 2.0 4 votes vote down vote up
public ArangoTemplate(final ArangoDB arango, final String database) {
	this(arango, database, null);
}
 
Example #24
Source File: ArangoOperations.java    From spring-data with Apache License 2.0 2 votes vote down vote up
/**
 * Give direct access to the underlying driver
 *
 * @return main access object of the driver
 */
ArangoDB driver();
 
Example #25
Source File: ArangoConfiguration.java    From spring-data with Apache License 2.0 votes vote down vote up
ArangoDB.Builder arango();