Search in sources :

Example 16 with EntityTypeMetadata

use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.

the class EntityTypeParserTest method testGetEntityMetadataOverrideDataType.

@Test
public void testGetEntityMetadataOverrideDataType() {
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityOverrideDataType.class);
    assertEquals(2, meta.getFields().size());
    EntityFieldMetaData fd = meta.getFieldMetadata("uid");
    assertEquals(DataType.Name.TIMEUUID, fd.getDataType());
    fd = meta.getFieldMetadata("name");
    assertEquals(DataType.Name.VARCHAR, fd.getDataType());
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 17 with EntityTypeMetadata

use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.

the class EntityTypeParserTest method testGetEntityMetadataForSimplePojo.

@Test
public void testGetEntityMetadataForSimplePojo() {
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(Simple.class);
    assertEquals("Simple", meta.getTableName());
    assertEquals(0, meta.getIndexes().size());
    assertEquals(6, meta.getFields().size());
    PrimaryKeyMetadata pkm = meta.getPrimaryKeyMetadata();
    assertNotNull(pkm);
    assertFalse(pkm.isCompound());
    assertFalse(pkm.hasPartitionKey());
    assertEquals("id", pkm.getOwnField().getColumnName());
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) PrimaryKeyMetadata(com.datastax.driver.mapping.meta.PrimaryKeyMetadata) Test(org.junit.Test)

Example 18 with EntityTypeMetadata

use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.

the class EntityTypeParserTest method testGetKeyDataSimpleKey.

@Test
public void testGetKeyDataSimpleKey() {
    SimpleKey sk = new SimpleKey();
    sk.setName("name");
    sk.setRank(10);
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithKey.class);
    List<String> cols = meta.getPkColumns();
    assertEquals(4, cols.size());
    assertEquals("name", cols.get(0));
    assertEquals("rank", cols.get(1));
    assertEquals("t1", cols.get(2));
    assertEquals("t2", cols.get(3));
    List<Object> vals = meta.getIdValues(sk);
    assertEquals(4, vals.size());
    assertEquals("name", vals.get(0));
    assertEquals(10, vals.get(1));
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) SimpleKey(com.datastax.driver.mapping.entity.SimpleKey) Test(org.junit.Test)

Example 19 with EntityTypeMetadata

use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.

the class EntityTypeParserTest method testGetEntityMetadataWithEnum.

@Test
public void testGetEntityMetadataWithEnum() {
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithEnum.class);
    assertEquals("entity_with_enum", meta.getTableName());
    assertEquals(2, meta.getFields().size());
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 20 with EntityTypeMetadata

use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.

the class MappingSessionTest method getByQueryTest.

@Test
public void getByQueryTest() throws Exception {
    for (int i = 0; i < 3; i++) {
        EntityWithIndexes obj = new EntityWithIndexes();
        obj.setCount(100);
        obj.setEmail("email@test");
        obj.setName("test" + i);
        obj.setTimeStamp(new Date());
        obj.setUuid(UUID.randomUUID());
        target.save(obj);
    }
    EntityTypeMetadata emeta = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    EntityFieldMetaData fdata = emeta.getFieldMetadata("email");
    Statement query = QueryBuilder.select().all().from(keyspace, emeta.getTableName()).where(eq(fdata.getColumnName(), "email@test"));
    List<EntityWithIndexes> items = target.getByQuery(EntityWithIndexes.class, query);
    assertEquals(3, items.size());
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata)

Aggregations

EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)40 Test (org.junit.Test)18 EntityFieldMetaData (com.datastax.driver.mapping.meta.EntityFieldMetaData)13 TableMetadata (com.datastax.driver.core.TableMetadata)8 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)6 PrimaryKeyMetadata (com.datastax.driver.mapping.meta.PrimaryKeyMetadata)4 RegularStatement (com.datastax.driver.core.RegularStatement)3 EntityWithCompositeKey (com.datastax.driver.mapping.entity.EntityWithCompositeKey)2 SimpleKey (com.datastax.driver.mapping.entity.SimpleKey)2 ExecutionException (java.util.concurrent.ExecutionException)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 Cluster (com.datastax.driver.core.Cluster)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Statement (com.datastax.driver.core.Statement)1 BuiltStatement (com.datastax.driver.core.querybuilder.BuiltStatement)1 TableProperties (com.datastax.driver.mapping.annotation.TableProperties)1 TableProperty (com.datastax.driver.mapping.annotation.TableProperty)1