Search in sources :

Example 26 with EntityTypeMetadata

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);
}
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 27 with EntityTypeMetadata

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);
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) ColumnMetadata(com.datastax.driver.core.ColumnMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) EntityWithIndexes(com.datastax.driver.mapping.entity.EntityWithIndexes) Test(org.junit.Test)

Example 28 with EntityTypeMetadata

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));
    }
}
Also used : TableMetadata(com.datastax.driver.core.TableMetadata) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Cluster(com.datastax.driver.core.Cluster) KeyspaceMetadata(com.datastax.driver.core.KeyspaceMetadata)

Example 29 with EntityTypeMetadata

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());
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) PrimaryKeyMetadata(com.datastax.driver.mapping.meta.PrimaryKeyMetadata) Test(org.junit.Test)

Example 30 with EntityTypeMetadata

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 }"));
}
Also used : 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