Package com.datastax.driver.core

Examples of com.datastax.driver.core.TableMetadata


    assertColumns(expected.getColumns(), tmd.getColumns());
    assertOptions(expected.getOptions(), tmd.getOptions());
  }

  public static void assertNoTable(DropTableSpecification expected, String keyspace, Session session) {
    TableMetadata tmd = session.getCluster().getMetadata().getKeyspace(keyspace.toLowerCase())
        .getTable(expected.getName().toCql());

    assertNull(tmd);
  }
View Full Code Here


    CassandraPersistentEntity<?> entity = getCassandraMappingContext().getPersistentEntity(entityClass);

    Assert.notNull(entity);

    final TableMetadata tableMetadata = getTableMetadata(keyspace, tableName);
    final List<String> queryList = CqlUtils.alterTable(tableName.toCql(), entity, tableMetadata);

    execute(new SessionCallback<Object>() {

      @Override
View Full Code Here

    }

    public CassandraTable getTable(SchemaTableName tableName)
            throws TableNotFoundException
    {
        TableMetadata tableMeta = getTableMetadata(tableName);

        ImmutableList.Builder<CassandraColumnHandle> columnHandles = ImmutableList.builder();

        // add primary keys first
        Set<String> primaryKeySet = new HashSet<>();
        int index = 0;
        for (ColumnMetadata columnMeta : tableMeta.getPartitionKey()) {
            primaryKeySet.add(columnMeta.getName());
            CassandraColumnHandle columnHandle = buildColumnHandle(columnMeta, true, false, index++);
            columnHandles.add(columnHandle);
        }

        // add clustering columns
        index = 0;
        for (ColumnMetadata columnMeta : tableMeta.getClusteringColumns()) {
            primaryKeySet.add(columnMeta.getName());
            CassandraColumnHandle columnHandle = buildColumnHandle(columnMeta, false, true, index++);
            columnHandles.add(columnHandle);
        }

        // add other columns
        for (ColumnMetadata columnMeta : tableMeta.getColumns()) {
            if (!primaryKeySet.contains(columnMeta.getName())) {
                CassandraColumnHandle columnHandle = buildColumnHandle(columnMeta, false, false, 0);
                columnHandles.add(columnHandle);
            }
        }

        CassandraTableHandle tableHandle = new CassandraTableHandle(connectorId, tableMeta.getKeyspace().getName(), tableMeta.getName());
        return new CassandraTable(tableHandle, columnHandles.build());
    }
View Full Code Here

    {
        String schemaName = schemaTableName.getSchemaName();
        String tableName = schemaTableName.getTableName();

        KeyspaceMetadata keyspaceMetadata = getCheckedKeyspaceMetadata(schemaName);
        TableMetadata tableMetadata = keyspaceMetadata.getTable(tableName);
        if (tableMetadata != null) {
            return tableMetadata;
        }

        for (TableMetadata table : keyspaceMetadata.getTables()) {
View Full Code Here

   *                         of this store with these settings
   */
  protected void createTableIfNecessary(String keyspaceName, KeyspaceMetadata keyspaceMetadata)
  {
    String tableName = settings.getTableName();
    TableMetadata tableMetadata = keyspaceMetadata != null ? keyspaceMetadata.getTable(tableName) : null;
    if (tableMetadata == null)
    {
      session.execute(
        String.format(
          "CREATE TABLE %s.%s (" +
View Full Code Here

            EntityMeta entityMeta = entry.getValue();
            final EntityMetaConfig metaConfig = entityMeta.config();
            String qualifiedTableName = metaConfig.getQualifiedTableName().toLowerCase();

            if (tableMetaDatas.containsKey(qualifiedTableName)) {
                TableMetadata tableMetaData = tableMetaDatas.get(qualifiedTableName);
                schemaContext.validateForEntity(entityMeta, tableMetaData);
                schemaContext.updateForEntity(entityMeta, tableMetaData);
            } else {
                schemaContext.createTableForEntity(entry.getValue());
            }
View Full Code Here

public class ColumnMetaDataComparator {

    public boolean isEqual(ColumnMetadata source, ColumnMetadata target) {
        boolean isEqual;
        final String sourceName = source.getName();
        final TableMetadata sourceTable = source.getTable();
        final DataType sourceType = source.getType();
        final Class<?> sourceClass = sourceType.asJavaClass();
        final List<DataType> sourceTypeParams = sourceType.getTypeArguments();

        final String targetName = target.getName();
        final TableMetadata targetTable = target.getTable();
        final DataType targetType = target.getType();
        final Class<?> targetClass = targetType.asJavaClass();
        final List<DataType> targetTypeParams = targetType.getTypeArguments();

        final boolean isPartiallyEqual = ComparisonChain.start()
                                           .compare(sourceName, targetName)
                                           .compare(sourceTable.getName(), targetTable.getName())
                                           .compare(sourceType.getName(), targetType.getName())
                                           .compareFalseFirst(sourceType.isCollection(), targetType.isCollection())
                                           .result() == 0;
        final boolean isSameClass = sourceClass.equals(targetClass);
        final boolean bothHaveTypeParameters = (sourceTypeParams != null && targetTypeParams != null) || (sourceTypeParams == null && targetTypeParams == null);
View Full Code Here

    public void validateAchillesCounter(KeyspaceMetadata keyspaceMetaData, String keyspaceName) {
        log.debug("Validate existing Achilles Counter table");
        Name textTypeName = text().getName();
        Name counterTypeName = counter().getName();

        TableMetadata tableMetaData = keyspaceMetaData.getTable(ACHILLES_COUNTER_TABLE);
        Validator.validateTableTrue(tableMetaData != null, "Cannot find table '%s' from keyspace '%s'",ACHILLES_COUNTER_TABLE, keyspaceName);

        ColumnMetadata fqcnColumn = tableMetaData.getColumn(ACHILLES_COUNTER_FQCN);
        Validator.validateTableTrue(fqcnColumn != null, "Cannot find column '%s' from table '%s'", ACHILLES_COUNTER_FQCN,ACHILLES_COUNTER_TABLE);
        Validator.validateTableTrue(fqcnColumn.getType().getName() == textTypeName,
                "Column '%s' of type '%s' should be of type '%s'", ACHILLES_COUNTER_FQCN, fqcnColumn.getType().getName(),
                textTypeName);
        Validator.validateBeanMappingTrue(hasColumnMeta(tableMetaData.getPartitionKey(), fqcnColumn),
                "Column '%s' of table '%s' should be a partition key component", ACHILLES_COUNTER_FQCN, ACHILLES_COUNTER_TABLE);


        ColumnMetadata pkColumn = tableMetaData.getColumn(ACHILLES_COUNTER_PRIMARY_KEY);
        Validator.validateTableTrue(pkColumn != null, "Cannot find column '%s' from table '%s'",ACHILLES_COUNTER_PRIMARY_KEY, ACHILLES_COUNTER_TABLE);
        Validator.validateTableTrue(pkColumn.getType().getName() == textTypeName,
                "Column '%s' of type '%s' should be of type '%s'", ACHILLES_COUNTER_PRIMARY_KEY, pkColumn.getType()
                        .getName(), textTypeName);
        Validator.validateBeanMappingTrue(hasColumnMeta(tableMetaData.getPartitionKey(), pkColumn),
                "Column '%s' of table '%s' should be a partition key component", ACHILLES_COUNTER_PRIMARY_KEY,ACHILLES_COUNTER_TABLE);


        ColumnMetadata propertyNameColumn = tableMetaData.getColumn(ACHILLES_COUNTER_PROPERTY_NAME);
        Validator.validateTableTrue(propertyNameColumn != null, "Cannot find column '%s' from table '%s'",ACHILLES_COUNTER_PROPERTY_NAME, ACHILLES_COUNTER_TABLE);
        Validator.validateTableTrue(propertyNameColumn.getType().getName() == textTypeName,
                "Column '%s' of type '%s' should be of type '%s'", ACHILLES_COUNTER_PROPERTY_NAME, propertyNameColumn
                        .getType().getName(), textTypeName);
        Validator.validateBeanMappingTrue(hasColumnMeta(tableMetaData.getClusteringColumns(), propertyNameColumn),
                "Column '%s' of table '%s' should be a clustering key component", ACHILLES_COUNTER_PROPERTY_NAME,ACHILLES_COUNTER_TABLE);



        ColumnMetadata counterValueColumn = tableMetaData.getColumn(ACHILLES_COUNTER_VALUE);
        Validator.validateTableTrue(counterValueColumn != null, "Cannot find column '%s' from table '%s'",ACHILLES_COUNTER_VALUE, ACHILLES_COUNTER_TABLE);
        Validator.validateTableTrue(counterValueColumn.getType().getName() == counterTypeName,
                "Column '%s' of type '%s' should be of type '%s'", ACHILLES_COUNTER_VALUE, counterValueColumn.getType().getName(), counterTypeName);
    }
View Full Code Here

        for (KeyspaceAndTable keyspaceAndTable : keyspaceAndTables) {
            final KeyspaceMetadata keyspaceMetadata = clusterMetadata.getKeyspace(keyspaceAndTable.keyspaceName);
            Validator.validateTableTrue(keyspaceMetadata != null, "Keyspace '%s' doest not exist or cannot be found", keyspaceAndTable.keyspaceName);

            final TableMetadata tableMetadata = keyspaceMetadata.getTable(keyspaceAndTable.tableName);
            if (tableMetadata != null) {
                tableMetas.put(keyspaceAndTable.qualifiedTableName, tableMetadata);
            }
        }
        return tableMetas;
View Full Code Here

    @Test
    public void should_validate_for_entity() throws Exception {
        // Given
        EntityMeta entityMeta = mock(EntityMeta.class);
        TableMetadata tableMetaData = mock(TableMetadata.class);

        // When
        context.validateForEntity(entityMeta, tableMetaData);

        // Then
View Full Code Here

TOP

Related Classes of com.datastax.driver.core.TableMetadata

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.