Package com.datastax.driver.core

Examples of com.datastax.driver.core.ColumnMetadata


     */
    public static List<AlterTable> alter(TableMetadata existing, CreateTable desired) {
        List<AlterTable> results = new ArrayList<>();

        for (BuiltTableStatement.Column column : desired.getColumns()) {
            ColumnMetadata columnMetadata = existing.getColumn(column.getName());
            if (columnMetadata == null) {
                results.add(alter(desired.getKeyspace(), desired.getTable()).addColumn(column.getName(), column.getType()));
            } else if (!columnMetadata.getType().toString().equalsIgnoreCase(column.getType())) {
                if (columnMetadata.isStatic()) {
                    throw new IllegalArgumentException("A static column cannot have its type modified");
                }
                results.add(alter(desired.getKeyspace(), desired.getTable()).alterColumn(column.getName(), column.getType()));
            }
        }
View Full Code Here


     */
    public static List<AlterTable> alter(TableMetadata existing, CreateTable desired) {
        List<AlterTable> results = new ArrayList<>();

        for (BuiltTableStatement.Column column : desired.getColumns()) {
            ColumnMetadata columnMetadata = existing.getColumn(column.getName());
            if (columnMetadata == null) {
                results.add(alter(desired.getKeyspace(), desired.getTable()).addColumn(column.getName(), column.getType()));
            } else if (!columnMetadata.getType().toString().equalsIgnoreCase(column.getType())) {
                if (columnMetadata.isStatic()) {
                    throw new IllegalArgumentException("A static column cannot have its type modified");
                }
                results.add(alter(desired.getKeyspace(), desired.getTable()).alterColumn(column.getName(), column.getType()));
            }
        }
View Full Code Here

            for (CqlColumn column : allColumns) {
                if (!column.isPhysical()) {
                    continue;
                }
                ColumnMetadata colMeta = metadata.getColumn(column.getName());
                DataType fieldType = colMeta != null ? CDT.copy(persistenceManagerImpl.protocolVersion, colMeta.getType()) : null;
                fieldExists(updateStatus, column, fieldType, true);
                if (!column.isExists() && !column.isAllowNotExists()) {
                    schemaObjectInvalid(updateStatus, "table column %s.%s for %s does not exist - exists:%s compatible:%s (%s vs %s)", cqlTable,
                        column.getEscapedName(), type, column.isExists(), column.compatible(fieldType), column.getDataType(), fieldType);
                }
View Full Code Here

        for (CqlColumn column : columns) {
            if (!colIter.hasNext()) {
                schemaObjectInvalid(updateStatus, "too few %s key columns in table %s - expected %s", type, cqlTable, Arrays.toString(columns));
                break;
            }
            ColumnMetadata colMeta = colIter.next();
            if (!column.getName().equals(colMeta.getName())) {
                schemaObjectInvalid(updateStatus, "%s key column %s not defined in table %s - expected %s", type, column.getName(), cqlTable,
                    Arrays.toString(columns));
            }
            DataType fieldType = CDT.copy(protocolVersion, colMeta.getType());
            if (!column.compatible(fieldType)) {
                schemaObjectInvalid(updateStatus, "incompatible types for %s key column %s in table %s - expected %s but got %s", type,
                    column.getName(),
                    cqlTable, column.getDataType(), colMeta.getType());
            }
        }
        if (colIter.hasNext()) {
            schemaObjectInvalid(updateStatus, "too few %s key columns in table %s - expected %s", type, cqlTable, Arrays.toString(columns));
        }
View Full Code Here

  }

  public static void assertColumns(List<ColumnSpecification> expected, List<ColumnMetadata> actual) {
    for (int i = 0; i < expected.size(); i++) {
      ColumnSpecification expectedColumn = expected.get(i);
      ColumnMetadata actualColumn = actual.get(i);

      assertColumn(expectedColumn, actualColumn);
    }
  }
View Full Code Here

      @Override
      public void doWithPersistentProperty(CassandraPersistentProperty prop) {

        String columnName = prop.getColumnName().toCql();
        DataType columnDataType = prop.getDataType();
        ColumnMetadata columnMetadata = table.getColumn(columnName.toLowerCase());

        if (columnMetadata != null && columnDataType.equals(columnMetadata.getType())) {
          return;
        }

        final StringBuilder str = new StringBuilder();
        str.append("ALTER TABLE ");
View Full Code Here

        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

        if (log.isDebugEnabled()) {
            log.debug("Validate existing column {} from table {} against type {}", cql3ColumnName, tableName, columnJavaType);
        }

        final ColumnMetadata columnMetadata = tableMetaData.getColumn(cql3ColumnName);


        if (schemaUpdateEnabled && columnMetadata == null) {
            // will be created in updater
            return;
        } else {
            Validator.validateTableTrue(columnMetadata != null, "Cannot find column '%s' in the table '%s'", cql3ColumnName, tableName);
        }

        validateColumnType(tableName, cql3ColumnName, columnMetadata, columnJavaType);
        validateStatic(cql3ColumnName, tableName, columnMetadata);


        if (!configContext.isRelaxIndexValidation()) {
            boolean columnIsIndexed = columnMetadata.getIndex() != null;
            Validator.validateTableFalse((columnIsIndexed ^ meta.structure().isIndexed()),"Column '%s' in the table '%s' is indexed (or not) whereas metadata indicates it is (or not)",cql3ColumnName, tableName);
        }
    }
View Full Code Here

        final String cql3ColumnName = meta.getCQL3ColumnName();
        final String tableName = tableMetadata.getName();


        final boolean schemaUpdateEnabled = entityMeta.config().isSchemaUpdateEnabled();
        final ColumnMetadata columnMetadata = tableMetadata.getColumn(cql3ColumnName);

        if (schemaUpdateEnabled && columnMetadata == null) {
            // will be created in updater
            return;
        } else {
            Validator.validateTableTrue(columnMetadata != null, "Cannot find column '%s' in the table '%s'", cql3ColumnName, tableName);
        }
        final Name realType = columnMetadata.getType().getName();

        if (log.isDebugEnabled()) {
            log.debug("Validate existing collection/map column {} from table {} against type {}", cql3ColumnName, tableName, realType);
        }

        final Name expectedValueType = toCQLType(meta.config().getCQL3ValueType());

        switch (meta.type()) {
            case LIST:
                Validator.validateTableTrue(realType == Name.LIST,
                        "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", cql3ColumnName, tableName,
                        realType, Name.LIST);
                Name realListValueType = columnMetadata.getType().getTypeArguments().get(0).getName();
                Validator.validateTableTrue(realListValueType == expectedValueType,
                        "Column '%s' of table '%s' of type 'List<%s>' should be of type 'List<%s>' indeed", cql3ColumnName,
                        tableName, realListValueType, expectedValueType);

                break;
            case SET:
                Validator.validateTableTrue(realType == Name.SET,
                        "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", cql3ColumnName, tableName,
                        realType, Name.SET);
                Name realSetValueType = columnMetadata.getType().getTypeArguments().get(0).getName();

                Validator.validateTableTrue(realSetValueType == expectedValueType,
                        "Column '%s' of table '%s' of type 'Set<%s>' should be of type 'Set<%s>' indeed", cql3ColumnName,
                        tableName, realSetValueType, expectedValueType);
                break;
            case MAP:
                Validator.validateTableTrue(realType == Name.MAP,
                        "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", cql3ColumnName, tableName,
                        realType, Name.MAP);

                Name expectedMapKeyType = toCQLType(meta.config().getCQL3KeyType());
                Name realMapKeyType = columnMetadata.getType().getTypeArguments().get(0).getName();
                Name realMapValueType = columnMetadata.getType().getTypeArguments().get(1).getName();
                Validator.validateTableTrue(realMapKeyType == expectedMapKeyType,
                        "Column %s' of table '%s' of type 'Map<%s,?>' should be of type 'Map<%s,?>' indeed", cql3ColumnName,
                        tableName, realMapKeyType, expectedMapKeyType);

                Validator.validateTableTrue(realMapValueType == expectedValueType,
View Full Code Here

        }

        final boolean schemaUpdateEnabled = entityMeta.config().isSchemaUpdateEnabled();

        final String tableName = tableMetaData.getName();
        final ColumnMetadata columnMetadata = tableMetaData.getColumn(cql3ColumnName);

        if (schemaUpdateEnabled && columnMetadata == null) {
            // will be created in updater
            return;
        } else {
            Validator.validateTableTrue(columnMetadata != null, "Cannot find column '%s' in the table '%s'", cql3ColumnName, tableName);
        }

        final Name realType = columnMetadata.getType().getName();

        Validator.validateTableTrue(realType == Name.COUNTER, "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed", cql3ColumnName, tableName, realType, Name.COUNTER);
    }
View Full Code Here

TOP

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

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.