Search in sources :

Example 1 with DATETIME

use of com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME in project grakn by graknlabs.

the class BasicTest method write_attributes_successfully.

@Test
public void write_attributes_successfully() throws IOException {
    LocalDateTime date_1991_1_1_0_0 = LocalDateTime.of(1991, 1, 1, 0, 0);
    reset_directory_and_create_attribute_types();
    try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
        try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.DATA)) {
            try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.WRITE)) {
                isAlive(txn).put(true);
                age(txn).put(18);
                score(txn).put(90.5);
                name(txn).put("alice");
                dob(txn).put(date_1991_1_1_0_0);
                assertEquals(1, isAlive(txn).getInstances().count());
                assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(true)));
                assertEquals(1, age(txn).getInstances().count());
                assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 18));
                assertEquals(1, score(txn).getInstances().count());
                assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 90.5));
                assertEquals(1, name(txn).getInstances().count());
                assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("alice")));
                assertEquals(1, dob(txn).getInstances().count());
                assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1991_1_1_0_0)));
                txn.commit();
            }
            try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.READ)) {
                LocalDateTime dateTime = LocalDateTime.of(1991, 1, 1, 0, 0);
                Attribute.Boolean isAlive = isAlive(txn).get(true);
                Attribute.Long age = age(txn).get(18);
                Attribute.Double score = score(txn).get(90.5);
                Attribute.String name = name(txn).get("alice");
                Attribute.DateTime dob = dob(txn).get(dateTime);
                assertNotNulls(isAlive, age, score, name, dob);
                assertEquals(true, isAlive.getValue());
                assertEquals(18, age.getValue().longValue());
                assertEquals(90.5, score.getValue(), 0.001);
                assertEquals("alice", name.getValue());
                assertEquals(dateTime, dob.getValue());
                assertEquals(1, isAlive(txn).getInstances().count());
                assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(true)));
                assertEquals(1, age(txn).getInstances().count());
                assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 18));
                assertEquals(1, score(txn).getInstances().count());
                assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 90.5));
                assertEquals(1, name(txn).getInstances().count());
                assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("alice")));
                assertEquals(1, dob(txn).getInstances().count());
                assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1991_1_1_0_0)));
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) LocalDateTime(java.time.LocalDateTime) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) Util.assertNotNulls(com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls) RelationType(com.vaticle.typedb.core.concept.type.RelationType) LONG(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.LONG) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) LogicManager(com.vaticle.typedb.core.logic.LogicManager) Rule(com.vaticle.typedb.core.logic.Rule) STRING(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.STRING) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) TypeQL(com.vaticle.typeql.lang.TypeQL) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Options(com.vaticle.typedb.core.common.parameters.Options) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Pattern(com.vaticle.typeql.lang.pattern.Pattern) RoleType(com.vaticle.typedb.core.concept.type.RoleType) Consumer(java.util.function.Consumer) TypeDB(com.vaticle.typedb.core.TypeDB) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) DATETIME(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME) Paths(java.nio.file.Paths) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) DOUBLE(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DOUBLE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) EntityType(com.vaticle.typedb.core.concept.type.EntityType) BOOLEAN(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.BOOLEAN) Assert.assertEquals(org.junit.Assert.assertEquals) Util(com.vaticle.typedb.core.test.integration.util.Util) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) TypeDB(com.vaticle.typedb.core.TypeDB) Test(org.junit.Test)

Aggregations

TypeDB (com.vaticle.typedb.core.TypeDB)1 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)1 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)1 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)1 Options (com.vaticle.typedb.core.common.parameters.Options)1 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)1 Attribute (com.vaticle.typedb.core.concept.thing.Attribute)1 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)1 BOOLEAN (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.BOOLEAN)1 DATETIME (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME)1 DOUBLE (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DOUBLE)1 LONG (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.LONG)1 STRING (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.STRING)1 EntityType (com.vaticle.typedb.core.concept.type.EntityType)1 RelationType (com.vaticle.typedb.core.concept.type.RelationType)1 RoleType (com.vaticle.typedb.core.concept.type.RoleType)1 ThingType (com.vaticle.typedb.core.concept.type.ThingType)1 CoreDatabaseManager (com.vaticle.typedb.core.database.CoreDatabaseManager)1 LogicManager (com.vaticle.typedb.core.logic.LogicManager)1 Rule (com.vaticle.typedb.core.logic.Rule)1