Package org.springframework.cassandra.core.keyspace

Examples of org.springframework.cassandra.core.keyspace.CreateTableSpecification


  @Override
  public CreateTableSpecification getCreateTableSpecificationFor(CassandraPersistentEntity<?> entity) {

    Assert.notNull(entity);

    final CreateTableSpecification spec = createTable().name(entity.getTableName());

    entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {

      @Override
      public void doWithPersistentProperty(CassandraPersistentProperty prop) {

        if (prop.isCompositePrimaryKey()) {

          CassandraPersistentEntity<?> pkEntity = getPersistentEntity(prop.getRawType());

          pkEntity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {

            @Override
            public void doWithPersistentProperty(CassandraPersistentProperty pkProp) {

              if (pkProp.isPartitionKeyColumn()) {
                spec.partitionKeyColumn(pkProp.getColumnName(), pkProp.getDataType());
              } else { // it's a cluster column
                spec.clusteredKeyColumn(pkProp.getColumnName(), pkProp.getDataType(), pkProp.getPrimaryKeyOrdering());
              }
            }
          });

        } else {

          if (prop.isIdProperty() || prop.isPartitionKeyColumn()) {
            spec.partitionKeyColumn(prop.getColumnName(), prop.getDataType());
          } else if (prop.isClusterKeyColumn()) {
            spec.clusteredKeyColumn(prop.getColumnName(), prop.getDataType());
          } else {
            spec.column(prop.getColumnName(), prop.getDataType());
          }
        }
      }

    });

    if (spec.getPartitionKeyColumns().isEmpty()) {
      throw new MappingException("no partition key columns found in the entity " + entity.getType());
    }

    return spec;
  }
View Full Code Here


  @Test
  public void insertAndTruncateQueryObjectTest() {

    String tableName = "truncate_test";

    CreateTableSpecification createTableSpec = new CreateTableSpecification();

    createTableSpec.name(tableName).partitionKeyColumn("id", DataType.text()).column("foo", DataType.text());

    cqlTemplate.execute(createTableSpec);

    Insert insert = QueryBuilder.insertInto(tableName).value("id", uuid()).value("foo", "bar");
View Full Code Here

    for (CassandraPersistentProperty p : properties) {
      actualColumnNames.addAll(p.getColumnNames());
    }
    assertTrue(expectedColumnNames.equals(actualColumnNames));

    CreateTableSpecification spec = context.getCreateTableSpecificationFor(thing);

    List<ColumnSpecification> partitionKeyColumns = spec.getPartitionKeyColumns();
    assertEquals(1, partitionKeyColumns.size());
    ColumnSpecification partitionKeyColumn = partitionKeyColumns.get(0);
    assertEquals("z", partitionKeyColumn.getName().toCql());
    assertEquals(PrimaryKeyType.PARTITIONED, partitionKeyColumn.getKeyType());
    assertEquals(DataType.text(), partitionKeyColumn.getType());

    List<ColumnSpecification> clusteredKeyColumns = spec.getClusteredKeyColumns();
    assertEquals(1, clusteredKeyColumns.size());
    ColumnSpecification clusteredKeyColumn = clusteredKeyColumns.get(0);
    assertEquals("a", clusteredKeyColumn.getName().toCql());
    assertEquals(PrimaryKeyType.CLUSTERED, clusteredKeyColumn.getKeyType());
    assertEquals(DataType.text(), partitionKeyColumn.getType());
View Full Code Here

TOP

Related Classes of org.springframework.cassandra.core.keyspace.CreateTableSpecification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.