All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.data.cassandra.core.convert.DefaultCassandraColumnType Maven / Gradle / Ivy

There is a newer version: 4.3.2
Show newest version
/*
 * Copyright 2020-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.cassandra.core.convert;

import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.springframework.data.util.Lazy;
import org.springframework.data.util.TypeInformation;

import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.UserDefinedType;

/**
 * Default {@link CassandraColumnType} implementation.
 *
 * @author Mark Paluch
 * @since 3.0
 */
class DefaultCassandraColumnType extends DefaultColumnType implements CassandraColumnType {

	private final Lazy dataType;

	DefaultCassandraColumnType(Class type, DataType dataType, ColumnType... parameters) {
		this(TypeInformation.of(type), dataType, parameters);
	}

	DefaultCassandraColumnType(TypeInformation typeInformation, Supplier dataType,
			ColumnType... parameters) {
		super(typeInformation, parameters);

		this.dataType = Lazy.of(dataType);
	}

	DefaultCassandraColumnType(TypeInformation typeInformation, DataType dataType, ColumnType... parameters) {
		super(typeInformation, parameters);

		this.dataType = Lazy.of(dataType);
	}

	public DataType getDataType() {
		return dataType.get();
	}

	@Override
	public String toString() {

		StringBuilder builder = new StringBuilder();

		if (isTupleType()) {
			builder.append("Tuple: ");
		}

		if (isUserDefinedType()) {
			builder.append("UDT: ").append(((UserDefinedType) getDataType()).getName());
		}

		builder.append(getType().getName()).append(" [").append(getDataType()).append("]");

		if (getParameters().isEmpty()) {
			return builder.toString();
		}

		builder.append("<").append(getParameters().stream().map(Object::toString).collect(Collectors.toList())).append(">");

		return builder.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy