Search in sources :

Example 21 with EntityTypeMetadata

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

the class SchemaSyncTest method testCreateWithCompositeKey.

@Test
public void testCreateWithCompositeKey() {
    EntityTypeParser.getEntityMetadata(EntityWithCompositeKey.class).markUnSynced(keyspace);
    SchemaSync.sync(keyspace, session, EntityWithCompositeKey.class);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithCompositeKey.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    assertNotNull(tableMetadata);
    assertEquals("test_entity_composites", tableMetadata.getName());
    assertEquals(8, tableMetadata.getColumns().size());
    ColumnMetadata columnMetadata = tableMetadata.getColumn("timestamp");
    assertNotNull(columnMetadata);
    columnMetadata = tableMetadata.getColumn("asof");
    assertNotNull(columnMetadata);
    columnMetadata = tableMetadata.getColumn("created");
    assertNotNull(columnMetadata);
    columnMetadata = tableMetadata.getColumn("email");
    assertNotNull(columnMetadata);
    columnMetadata = tableMetadata.getColumn("name");
    assertNotNull(columnMetadata);
    columnMetadata = tableMetadata.getColumn("rank");
    assertNotNull(columnMetadata);
    columnMetadata = tableMetadata.getColumn("key");
    assertNull(columnMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) EntityWithCompositeKey(com.datastax.driver.mapping.entity.EntityWithCompositeKey) Test(org.junit.Test)

Example 22 with EntityTypeMetadata

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

the class SchemaSyncTest method testCreateWithTimeUUID.

@Test
public void testCreateWithTimeUUID() {
    EntityTypeParser.remove(EntityWithTimeUUID.class);
    System.out.println(SchemaSync.getScript(keyspace, session, EntityWithTimeUUID.class));
    SchemaSync.sync(keyspace, session, EntityWithTimeUUID.class);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithTimeUUID.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    assertNotNull(tableMetadata);
    assertEquals("test_entity_timeuuid", tableMetadata.getName());
    assertEquals(3, tableMetadata.getColumns().size());
    ColumnMetadata columnMetadata = tableMetadata.getColumn("name");
    assertNotNull(columnMetadata);
    assertEquals(DataType.text(), columnMetadata.getType());
    columnMetadata = tableMetadata.getColumn("convId");
    assertNotNull(columnMetadata);
    assertEquals(DataType.timeuuid(), columnMetadata.getType());
    columnMetadata = tableMetadata.getColumn("msgId");
    assertNotNull(columnMetadata);
    assertEquals(DataType.timeuuid(), columnMetadata.getType());
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) EntityWithTimeUUID(com.datastax.driver.mapping.entity.EntityWithTimeUUID) Test(org.junit.Test)

Example 23 with EntityTypeMetadata

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

the class SchemaSyncTest method testDoNotAddColumn.

@Test
public void testDoNotAddColumn() {
    SyncOptions opt = SyncOptions.withOptions().add(SyncOptionTypes.DoNotAddColumns);
    SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexesV2.class, opt);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    // column counter2 should not be added
    ColumnMetadata columnMetadata = tableMetadata.getColumn("counter2");
    assertNull(columnMetadata);
    // column counter should have been dropped
    columnMetadata = tableMetadata.getColumn("counter");
    assertNull(columnMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 24 with EntityTypeMetadata

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

the class SchemaSyncTest method testDrop.

@Test
public void testDrop() {
    SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
    SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    assertNull(tableMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Test(org.junit.Test)

Example 25 with EntityTypeMetadata

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

the class SchemaSyncTest method testDoNotDropColumn.

@Test
public void testDoNotDropColumn() {
    SyncOptions opt = SyncOptions.withOptions().add(SyncOptionTypes.DoNotDropColumns);
    SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
    SchemaSync.sync(keyspace, session, EntityWithIndexesV2.class, opt);
    EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
    TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
    // column counter2 should not be added
    ColumnMetadata columnMetadata = tableMetadata.getColumn("counter2");
    assertNull(columnMetadata);
    // column counter should have been dropped
    columnMetadata = tableMetadata.getColumn("counter");
    assertNotNull(columnMetadata);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) 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