Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016-2018 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
*
* 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 org.springframework.data.cassandra.core;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
import org.springframework.data.cassandra.core.cql.QueryOptions;
import org.springframework.data.cassandra.core.cql.QueryOptionsUtil;
import org.springframework.data.cassandra.core.cql.RowMapper;
import org.springframework.data.cassandra.core.cql.WriteOptions;
import org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity;
import org.springframework.data.cassandra.core.query.CassandraPageRequest;
import org.springframework.data.convert.EntityWriter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.datastax.driver.core.PagingState;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Statement;
import com.datastax.driver.core.querybuilder.Delete;
import com.datastax.driver.core.querybuilder.Delete.Where;
import com.datastax.driver.core.querybuilder.Insert;
import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.datastax.driver.core.querybuilder.Update;
import com.google.common.collect.Iterators;
/**
* Simple utility class for working with the QueryBuilder API using mapped entities.
*
* Only intended for internal use.
*
* @author Mark Paluch
* @since 2.0
*/
class QueryUtils {
private static final Pattern FROM_REGEX = Pattern.compile(" FROM ([\"]?[\\w]*[\\\\.]?[\\w]*[\"]?)[\\s]?",
Pattern.CASE_INSENSITIVE);
/**
* Creates a Query Object for an insert.
*
* @param tableName the table name, must not be empty and not {@literal null}.
* @param objectToInsert the object to save, must not be {@literal null}.
* @param options optional {@link WriteOptions} to apply to the {@link Insert} statement, may be {@literal null}.
* @param entityWriter the {@link EntityWriter} to write insert values.
* @param entity must not be {@literal null}.
* @return The Query object to run with session.execute();
*/
static Insert createInsertQuery(String tableName, Object objectToInsert, WriteOptions options,
CassandraConverter entityWriter, CassandraPersistentEntity entity) {
Assert.hasText(tableName, "TableName must not be empty");
Assert.notNull(objectToInsert, "Object to insert must not be null");
Assert.notNull(entityWriter, "CassandraConverter must not be null");
Assert.notNull(entity, "CassandraPersistentEntity must not be null");
Insert insert = addWriteOptions(QueryBuilder.insertInto(tableName), options);
boolean insertNulls = false;
if (options instanceof InsertOptions) {
InsertOptions insertOptions = (InsertOptions) options;
insertNulls = insertOptions.isInsertNulls();
}
if (insertNulls) {
Map toInsert = new LinkedHashMap<>();
entityWriter.write(objectToInsert, toInsert, entity);
for (Entry entry : toInsert.entrySet()) {
insert.value(entry.getKey(), entry.getValue());
}
} else {
entityWriter.write(objectToInsert, insert);
}
return insert;
}
/**
* Creates a Query Object for an Update. The {@link Update} uses the identity and values from the given
* {@code objectsToUpdate}.
*
* @param tableName the table name, must not be empty and not {@literal null}.
* @param objectToUpdate the object to update, must not be {@literal null}.
* @param options optional {@link WriteOptions} to apply to the {@link Update} statement.
* @param entityWriter the {@link EntityWriter} to write update assignments and where clauses.
* @return The Query object to run with session.execute();
*/
static Update createUpdateQuery(String tableName, Object objectToUpdate, WriteOptions options,
EntityWriter