本文整理匯總了Java中com.datastax.driver.core.DataType.isCollection方法的典型用法代碼示例。如果您正苦於以下問題:Java DataType.isCollection方法的具體用法?Java DataType.isCollection怎麽用?Java DataType.isCollection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.datastax.driver.core.DataType
的用法示例。
在下文中一共展示了DataType.isCollection方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isBuildInType
import com.datastax.driver.core.DataType; //導入方法依賴的package包/類
static boolean isBuildInType(DataType dataType) {
if (dataType.isCollection()) {
for (DataType type : dataType.getTypeArguments()) {
if (!isBuildInType(type)) {
return false;
}
}
return true;
} else {
return DataType.allPrimitiveTypes().contains(dataType) || (TupleType.class.isAssignableFrom(dataType.getClass()));
}
}
示例2: CellValidator
import com.datastax.driver.core.DataType; //導入方法依賴的package包/類
/**
* private constructor.
*
* @param type a {@link com.datastax.driver.core.DataType} coming from the underlying Java driver.
*/
private CellValidator(DataType type) {
if (type == null) {
throw new DeepInstantiationException("input DataType cannot be null");
}
cqlTypeName = type.getName();
if (!type.isCollection()) {
validatorClassName = MAP_JAVA_TYPE_TO_ABSTRACT_TYPE.get(type.asJavaClass()).getClass()
.getName();
} else {
validatorTypes = new ArrayList<>();
for (DataType dataType : type.getTypeArguments()) {
validatorTypes.add(dataType.toString());
}
switch (type.getName()) {
case SET:
validatorKind = Kind.SET;
validatorClassName = SetType.class.getName();
break;
case LIST:
validatorKind = Kind.LIST;
validatorClassName = ListType.class.getName();
break;
case MAP:
validatorKind = Kind.MAP;
validatorClassName = MapType.class.getName();
break;
default:
throw new DeepGenericException("Cannot determine collection type for " + type.getName());
}
validatorTypes = unmodifiableCollection(validatorTypes);
}
}
示例3: buildNonPKColumnsExpression
import com.datastax.driver.core.DataType; //導入方法依賴的package包/類
private void buildNonPKColumnsExpression(final StringBuilder queryExpression,
UpsertExecutionContext.ListPlacementStyle listPlacementStyle,
UpsertExecutionContext.CollectionMutationStyle collectionMutationStyle)
{
int count = 0;
for (String colNameEntry : columnDefinitions.keySet()) {
if (pkColumnNames.contains(colNameEntry)) {
continue;
}
if (count > 0) {
queryExpression.append(",");
}
count += 1;
if (counterColumns.contains(colNameEntry)) {
queryExpression.append(" " + colNameEntry + " = " + colNameEntry + " + :" + colNameEntry);
continue;
}
DataType dataType = columnDefinitions.get(colNameEntry);
if ((!dataType.isCollection()) && (!counterColumns.contains(colNameEntry))) {
queryExpression.append(" " + colNameEntry + " = :" + colNameEntry);
continue;
}
if ((dataType.isCollection()) && (!dataType.isFrozen())) {
if (collectionMutationStyle == UpsertExecutionContext.CollectionMutationStyle.REMOVE_FROM_EXISTING_COLLECTION) {
queryExpression.append(" " + colNameEntry + " = " + colNameEntry + " - :" + colNameEntry);
}
if (collectionMutationStyle == UpsertExecutionContext.CollectionMutationStyle.ADD_TO_EXISTING_COLLECTION) {
if ((setColumns.contains(colNameEntry)) || (mapColumns.contains(colNameEntry))) {
queryExpression.append(" " + colNameEntry + " = " + colNameEntry + " + :" + colNameEntry);
}
if ((listColumns.contains(colNameEntry)) &&
(listPlacementStyle == UpsertExecutionContext.ListPlacementStyle.APPEND_TO_EXISTING_LIST)) {
queryExpression.append(" " + colNameEntry + " = " + colNameEntry + " + :" + colNameEntry);
}
if ((listColumns.contains(colNameEntry)) &&
(listPlacementStyle == UpsertExecutionContext.ListPlacementStyle.PREPEND_TO_EXISTING_LIST)) {
queryExpression.append(" " + colNameEntry + " = :" + colNameEntry + " + " + colNameEntry);
}
}
} else {
if ((dataType.isCollection()) && (dataType.isFrozen())) {
queryExpression.append(" " + colNameEntry + " = :" + colNameEntry);
}
}
}
}
示例4: fromUdtValue
import com.datastax.driver.core.DataType; //導入方法依賴的package包/類
/**
* @param datatype the db datatype
* @param udtValue the udt value
* @param fieldtype1 the field 1 type
* @param fieldtype2 the field 2 type
* @param fieldname the fieldname
* @return the mapped value or <code>null</code>
*/
public <T> Object fromUdtValue(DataType datatype,
UDTValue udtValue,
Class<?> fieldtype1,
Class<?> fieldtype2,
String fieldname) {
final CodecRegistry codecRegistry = getCodecRegistry();
// build-in type
if (isBuildInType(datatype)) {
final TypeCodec<T> typeCodec = codecRegistry.codecFor(datatype);
try {
if (udtValue.isNull(fieldname)) return null;
return typeCodec.deserialize(udtValue.getBytesUnsafe(fieldname), protocolVersion);
} catch(IllegalArgumentException ex) {
return null;
}
// udt collection
} else if (datatype.isCollection()) {
// set
if (DataType.Name.SET == datatype.getName()) {
return fromUdtValues(datatype.getTypeArguments().get(0),
ImmutableSet.copyOf(udtValue.getSet(fieldname, UDTValue.class)),
fieldtype2);
// list
} else if (DataType.Name.LIST == datatype.getName()) {
return fromUdtValues(datatype.getTypeArguments().get(0),
ImmutableList.copyOf(udtValue.getList(fieldname, UDTValue.class)),
fieldtype2);
// map
} else {
if (isBuildInType(datatype.getTypeArguments().get(0))) {
return fromUdtValues(datatype.getTypeArguments().get(0),
datatype.getTypeArguments().get(1),
ImmutableMap.<Object, Object>copyOf(udtValue.getMap(fieldname, fieldtype1, UDTValue.class)),
fieldtype1,
fieldtype2);
} else if (isBuildInType(datatype.getTypeArguments().get(1))) {
return fromUdtValues(datatype.getTypeArguments().get(0),
datatype.getTypeArguments().get(1),
ImmutableMap.<Object, Object>copyOf(udtValue.getMap(fieldname, UDTValue.class, fieldtype2)),
fieldtype1,
fieldtype2);
} else {
return fromUdtValues(datatype.getTypeArguments().get(0),
datatype.getTypeArguments().get(1),
ImmutableMap.<Object, Object>copyOf(udtValue.getMap(fieldname, UDTValue.class, UDTValue.class)),
fieldtype1,
fieldtype2);
}
}
// udt
} else {
return fromUdtValue(datatype, udtValue, fieldtype1);
}
}