Search in sources :

Example 11 with EntityTypeMetadata

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

the class SchemaSync method sync.

public static synchronized void sync(String keyspace, Session session, Class<?> clazz, SyncOptions syncOptions) {
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
    if (entityMetadata.isSynced(keyspace))
        return;
    List<RegularStatement> statements = buildSyncStatements(keyspace, session, entityMetadata, syncOptions);
    for (RegularStatement stmt : statements) {
        session.execute(stmt);
    }
    entityMetadata.markSynced(keyspace);
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 12 with EntityTypeMetadata

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

the class EntityTypeParserTest method testGetEntityMetadataForSimpleCompoundKey.

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

Example 13 with EntityTypeMetadata

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

the class EntityTypeParserTest method testGetEntityMetadataWithTtl.

@Test
public void testGetEntityMetadataWithTtl() {
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithTtl.class);
    assertEquals("test_entity_ttl", meta.getTableName());
    assertEquals(0, meta.getIndexes().size());
    assertEquals(3, meta.getFields().size());
    assertEquals(3, meta.getTtl());
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 14 with EntityTypeMetadata

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

the class EntityTypeParserTest method testGetEntityMetadataOverrideCollectionType.

@Test
public void testGetEntityMetadataOverrideCollectionType() {
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithCollectionsOverride.class);
    assertEquals(4, meta.getFields().size());
    EntityFieldMetaData fd = meta.getFieldMetadata("rates");
    assertEquals(TreeMap.class, fd.getCollectionType());
    fd = meta.getFieldMetadata("refs");
    assertEquals(TreeSet.class, fd.getCollectionType());
    fd = meta.getFieldMetadata("trades");
    assertEquals(LinkedList.class, fd.getCollectionType());
}
Also used : EntityFieldMetaData(com.datastax.driver.mapping.meta.EntityFieldMetaData) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 15 with EntityTypeMetadata

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

the class EntityTypeParserTest method testGetKeyDataIdKey.

@Test
public void testGetKeyDataIdKey() {
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(Simple.class);
    List<String> cols = meta.getPkColumns();
    assertEquals(1, cols.size());
    assertEquals("id", cols.get(0));
    UUID id = UUID.randomUUID();
    List<Object> vals = meta.getIdValues(id);
    assertEquals(1, vals.size());
    assertEquals(id, vals.get(0));
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) UUID(java.util.UUID) Test(org.junit.Test)

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