use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.
the class SchemaSyncTest method testAlter.
@Test
public void testAlter() {
SchemaSync.drop(keyspace, session, EntityWithIndexes.class);
SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
SchemaSync.sync(keyspace, session, EntityWithIndexesV2.class);
EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
assertNotNull(tableMetadata);
assertEquals("test_entity_index", tableMetadata.getName());
assertEquals(6, tableMetadata.getColumns().size());
ColumnMetadata columnMetadata = tableMetadata.getColumn("uuid");
//assertNull(columnMetadata.getIndex());
columnMetadata = tableMetadata.getColumn("email");
//assertNotNull(columnMetadata.getIndex());
//assertEquals("test_entity_email_idx", columnMetadata.getIndex().getName());
columnMetadata = tableMetadata.getColumn("timestamp");
//assertNull(columnMetadata.getIndex());
columnMetadata = tableMetadata.getColumn("counter2");
//assertEquals("test_entity_counter_idx", columnMetadata.getIndex().getName());
columnMetadata = tableMetadata.getColumn("name");
assertNull(columnMetadata);
columnMetadata = tableMetadata.getColumn("ref");
assertNotNull(columnMetadata);
columnMetadata = tableMetadata.getColumn("pets");
assertNotNull(columnMetadata);
}
use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.
the class SchemaSyncTest method testCreate.
@Test
public void testCreate() {
EntityTypeParser.getEntityMetadata(EntityWithIndexes.class).markUnSynced(keyspace);
SchemaSync.sync(keyspace, session, EntityWithIndexes.class);
EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(EntityWithIndexes.class);
TableMetadata tableMetadata = cluster.getMetadata().getKeyspace(keyspace).getTable(entityMetadata.getTableName());
assertNotNull(tableMetadata);
assertEquals("test_entity_index", tableMetadata.getName());
assertEquals(6, tableMetadata.getColumns().size());
ColumnMetadata columnMetadata = tableMetadata.getColumn("uuid");
//assertNull(columnMetadata.getIndex());
columnMetadata = tableMetadata.getColumn("email");
//assertNotNull(columnMetadata.getIndex());
//assertEquals("test_entity_index_email_idx", columnMetadata.getIndex().getName());
columnMetadata = tableMetadata.getColumn("timestamp");
//assertNotNull(columnMetadata.getIndex());
//assertEquals("test_entity_timestamp_idx", columnMetadata.getIndex().getName());
columnMetadata = tableMetadata.getColumn("counter");
//assertNull(columnMetadata.getIndex());
columnMetadata = tableMetadata.getColumn("name");
assertNotNull(columnMetadata);
}
use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.
the class SchemaSync method drop.
public static synchronized void drop(String keyspace, Session session, Class<?> clazz) {
EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
entityMetadata.markUnSynced(keyspace);
String table = entityMetadata.getTableName();
Cluster cluster = session.getCluster();
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
if (tableMetadata != null) {
session.execute("USE " + keyspace);
// drop indexes
/*for (ColumnMetadata columnMetadata: tableMetadata.getColumns()) {
if (columnMetadata.getIndex() != null) {
session.execute(new DropIndex(keyspace, columnMetadata.getIndex().getName()));
}
}*/
// drop table
session.execute(new DropTable(keyspace, entityMetadata));
}
}
use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.
the class EntityTypeParserTest method testGetEntityMetadataForCompoundKey.
@Test
public void testGetEntityMetadataForCompoundKey() {
EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithCompositeKey.class);
assertEquals("test_entity_composites", meta.getTableName());
assertEquals(0, meta.getIndexes().size());
assertEquals(8, meta.getFields().size());
PrimaryKeyMetadata pkm = meta.getPrimaryKeyMetadata();
assertNotNull(pkm);
assertTrue(pkm.isCompound());
assertTrue(pkm.hasPartitionKey());
PrimaryKeyMetadata pk = pkm.getPartitionKey();
assertTrue(pk.isCompound());
assertFalse(pk.hasPartitionKey());
}
use of com.datastax.driver.mapping.meta.EntityTypeMetadata in project cassandra-driver-mapping by valchkou.
the class EntityTypeParserTest method testGetEntityMetadataWithProperties.
@Test
public void testGetEntityMetadataWithProperties() {
EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithProperties.class);
assertEquals("test_entity_properties", meta.getTableName());
assertEquals(0, meta.getIndexes().size());
assertEquals(6, meta.getFields().size());
List<String> props = meta.getProperties();
assertNotNull(props);
assertEquals(4, props.size());
assertTrue(props.contains("comment='Important records'"));
assertTrue(props.contains("read_repair_chance = 1.0"));
assertTrue(props.contains("compression ={ 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 }"));
}
Aggregations