Package com.datastax.driver.core

Examples of com.datastax.driver.core.DataType


    public static DataType rawTypeToDataType(AbstractType<?> rawType) {
        if (rawType instanceof ReversedType)
            rawType = ((ReversedType) rawType).baseType;

        DataType type = rawNativeMap.get(rawType);
        if (type != null)
            return type;

        if (rawType instanceof CollectionType) {
            switch (((CollectionType)rawType).kind) {
View Full Code Here


    if (log.isTraceEnabled()) {
      log.trace("Extract data from CQL column [keyspace:{},table:{},column:{}]", column.getKeyspace(),
          column.getTable(), column.getName());
    }

    DataType type = column.getType();
    Class<?> javaClass = type.asJavaClass();
    String name = column.getName();
    Object value;
    if (type.isCollection()) {
      List<DataType> typeArguments = type.getTypeArguments();
      if (List.class.isAssignableFrom(javaClass)) {
        value = row.getList(name, typeArguments.get(0).asJavaClass());
      } else if (Set.class.isAssignableFrom(javaClass)) {
        value = row.getSet(name, typeArguments.get(0).asJavaClass());
      } else {
View Full Code Here

    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);

        isEqual = isPartiallyEqual && isSameClass && bothHaveTypeParameters;
        if(isEqual && sourceTypeParams != null) {
            isEqual = (sourceTypeParams.size() == targetTypeParams.size());
            if(isEqual) {
                for(int i=0; i<sourceTypeParams.size(); i++) {
                    final DataType sourceParamType = sourceTypeParams.get(i);
                    final DataType targetParamType = targetTypeParams.get(i);

                    final boolean sameParamType = ComparisonChain.start()
                            .compare(sourceParamType.getName(),targetParamType.getName())
                            .result() == 0;
                    if(!sameParamType) {
                        return false;
                    }
                }
View Full Code Here

        }
        return name;
    }

    public static DataType toCQLDataType(Class<?> javaType) {
        DataType dataType = java2CQLDataType.get(javaType);

        // Custom object will be JSON serialized
        if (dataType == null) {
            dataType = DataType.text();
        }
View Full Code Here

            final Row casResult = resultSet.one();
            if (casResult != null && !casResult.getBool(CAS_RESULT_COLUMN)) {
                TreeMap<String, Object> currentValues = new TreeMap<>();
                for (Definition columnDef : casResult.getColumnDefinitions()) {
                    final String columnDefName = columnDef.getName();
                    final DataType dataType = columnDef.getType();
                    final DataType.Name name = dataType.getName();

                    Object columnValue;
                    switch (name) {
                        case LIST:
                            columnValue = casResult.getList(columnDefName, dataType.getTypeArguments().get(0).asJavaClass());
                            break;
                        case SET:
                            columnValue = casResult.getSet(columnDefName, dataType.getTypeArguments().get(0).asJavaClass());
                            break;
                        case MAP:
                            final List<DataType> typeArguments = dataType.getTypeArguments();
                            columnValue = casResult.getMap(columnDefName, typeArguments.get(0).asJavaClass(), typeArguments.get(1).asJavaClass());
                            break;
                        default:
                            columnValue = invoker.invokeOnRowForType(casResult, name.asJavaClass(), columnDefName);
                    }
View Full Code Here

        Iterator<Row> rowIter = rSet.iterator();
        while (rowIter.hasNext())
        {
            Row row = rowIter.next();
            DataType dataType = row.getColumnDefinitions().getType(columnName);
            Object columnValue = DSClientUtilities.assign(row, null, null, dataType.getName(), null, columnName, null);
            results.add(columnValue);
        }
        return results;
    }
View Full Code Here

        while (columnDefIter.hasNext())
        {
            Definition columnDef = columnDefIter.next();
            final String columnName = columnDef.getName(); // column name

            DataType dataType = columnDef.getType(); // data type

            if (metadata.getRelationNames() != null && metadata.getRelationNames().contains(columnName)
                    && !columnName.equals(((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName()))
            {
                Object relationalValue = DSClientUtilities.assign(row, null, metadata, dataType.getName(), entityType,
                        columnName, null);
                relationalValues.put(columnName, relationalValue);
            }
            else
            {
                String fieldName = columnName
                        .equals(((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName()) ? metadata
                        .getIdAttribute().getName() : metadata.getFieldName(columnName);
                Attribute attribute = fieldName != null ? entityType.getAttribute(fieldName) : null;

                if (attribute != null)
                {
                    if (!attribute.isAssociation())
                    {
                        entity = DSClientUtilities.assign(row, entity, metadata, dataType.getName(), entityType,
                                columnName, null);
                    }
                }
                else if (metamodel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType()))
                {
                    entity = populateCompositeId(metadata, entity, columnName, row, metamodel,
                            metadata.getIdAttribute(), metadata.getEntityClazz(), dataType);
                }
                else
                {
                    entity = DSClientUtilities.assign(row, entity, metadata, dataType.getName(), entityType,
                            columnName, null);
                }
            }
        }
        return entity;
View Full Code Here

        return createStatement.toString();
    }

    private void buildColumnType(Entry<String, DataType> entry, StringBuilder column) {
        final DataType dataType = entry.getValue();
        final String type = dataType.getName().toString();
        column.append(entry.getKey()).append(SPACE).append(type);

        if (dataType.isCollection()) {
            final List<DataType> typeArguments = dataType.getTypeArguments();
            if (typeArguments.size() == 1) {
                column.append(OPEN_TYPE).append(typeArguments.get(0)).append(CLOSE_TYPE);
            } else if (typeArguments.size() == 2) {
                column.append(OPEN_TYPE).append(typeArguments.get(0)).append(COMMA).append(typeArguments.get(1)).append(CLOSE_TYPE);
            }
View Full Code Here

    public static DataType rawTypeToDataType(AbstractType<?> rawType) {
        if (rawType instanceof ReversedType<?>)
            rawType = ((ReversedType<?>) rawType).baseType;

        DataType type = rawNativeMap.get(rawType);
        if (type != null)
            return type;

        if (rawType instanceof CollectionType<?>) {
            switch (((CollectionType<?>)rawType).kind) {
View Full Code Here

    if (cType != null) {
      return cType;
    }
   
    // Lazy init
    DataType type = row.getColumnDefinitions().getType(index);
    if (type.isCollection()) {
      throw new RuntimeException("This operation does not work for collection objects");
    }
    String typeString = (type.getName().name()).toUpperCase();
    cType = CqlTypeMapping.getComparatorFromCqlType(typeString);
   
    return cType;
  }
View Full Code Here

TOP

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

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.