com.datastax.driver.mapping.EntityMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-driver-mapping Show documentation
Show all versions of cassandra-driver-mapping Show documentation
Object mapper for the DataStax CQL Java Driver.
/*
* Copyright (C) 2012-2015 DataStax Inc.
*
* 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
*
* http://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 com.datastax.driver.mapping;
import java.lang.reflect.Field;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import com.datastax.driver.core.ConsistencyLevel;
import static com.datastax.driver.core.querybuilder.QueryBuilder.quote;
abstract class EntityMapper {
public final Class entityClass;
private final String keyspace;
private final String table;
public final ConsistencyLevel writeConsistency;
public final ConsistencyLevel readConsistency;
public final List> partitionKeys = new ArrayList>();
public final List> clusteringColumns = new ArrayList>();
public final List> regularColumns = new ArrayList>();
private final List> allColumns = new ArrayList>();
protected EntityMapper(Class entityClass, String keyspace, String table, ConsistencyLevel writeConsistency, ConsistencyLevel readConsistency) {
this.entityClass = entityClass;
this.keyspace = keyspace;
this.table = table;
this.writeConsistency = writeConsistency;
this.readConsistency = readConsistency;
}
public String getKeyspace() {
return quote(keyspace);
}
public String getTable() {
return quote(table);
}
public int primaryKeySize() {
return partitionKeys.size() + clusteringColumns.size();
}
public ColumnMapper getPrimaryKeyColumn(int i) {
return i < partitionKeys.size() ? partitionKeys.get(i) : clusteringColumns.get(i - partitionKeys.size());
}
public void addColumns(List> pks, List> ccs, List> rgs) {
partitionKeys.addAll(pks);
allColumns.addAll(pks);
clusteringColumns.addAll(ccs);
allColumns.addAll(ccs);
addColumns(rgs);
}
public void addColumns(List> rgs) {
regularColumns.addAll(rgs);
allColumns.addAll(rgs);
}
public abstract T newEntity();
public List> allColumns() {
return allColumns;
}
interface Factory {
public EntityMapper create(Class entityClass, String keyspace, String table, ConsistencyLevel writeConsistency, ConsistencyLevel readConsistency);
public ColumnMapper createColumnMapper(Class componentClass, Field field, int position, MappingManager mappingManager, AtomicInteger columnCounter);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy