Merge branch 'develop' into 2.1.x-SNAPSHOT
This commit is contained in:
commit
635e2256b0
4 changed files with 40 additions and 9 deletions
|
@ -1,3 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 The Helenus 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 com.datastax.driver.core.querybuilder;
|
package com.datastax.driver.core.querybuilder;
|
||||||
|
|
||||||
import com.datastax.driver.core.CodecRegistry;
|
import com.datastax.driver.core.CodecRegistry;
|
||||||
|
|
|
@ -8,13 +8,15 @@ public class CreateMaterializedView extends Create {
|
||||||
private String viewName;
|
private String viewName;
|
||||||
private Select.Where selection;
|
private Select.Where selection;
|
||||||
private String primaryKey;
|
private String primaryKey;
|
||||||
|
private String clustering;
|
||||||
|
|
||||||
public CreateMaterializedView(
|
public CreateMaterializedView(
|
||||||
String keyspaceName, String viewName, Select.Where selection, String primaryKey) {
|
String keyspaceName, String viewName, Select.Where selection, String primaryKey, String clustering) {
|
||||||
super(keyspaceName, viewName);
|
super(keyspaceName, viewName);
|
||||||
this.viewName = viewName;
|
this.viewName = viewName;
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
this.primaryKey = primaryKey;
|
this.primaryKey = primaryKey;
|
||||||
|
this.clustering = clustering;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQueryString(CodecRegistry codecRegistry) {
|
public String getQueryString(CodecRegistry codecRegistry) {
|
||||||
|
@ -37,6 +39,9 @@ public class CreateMaterializedView extends Create {
|
||||||
createStatement.setLength(createStatement.length() - 1);
|
createStatement.setLength(createStatement.length() - 1);
|
||||||
createStatement.append(" ");
|
createStatement.append(" ");
|
||||||
createStatement.append(primaryKey);
|
createStatement.append(primaryKey);
|
||||||
|
if (clustering != null) {
|
||||||
|
createStatement.append(" ").append(clustering);
|
||||||
|
}
|
||||||
createStatement.append(";");
|
createStatement.append(";");
|
||||||
|
|
||||||
return createStatement.toString();
|
return createStatement.toString();
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.stream.Collectors;
|
||||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||||
import net.helenus.mapping.*;
|
import net.helenus.mapping.*;
|
||||||
import net.helenus.mapping.ColumnType;
|
import net.helenus.mapping.ColumnType;
|
||||||
|
import net.helenus.mapping.annotation.ClusteringColumn;
|
||||||
import net.helenus.mapping.type.OptionalColumnMetadata;
|
import net.helenus.mapping.type.OptionalColumnMetadata;
|
||||||
import net.helenus.support.CqlUtil;
|
import net.helenus.support.CqlUtil;
|
||||||
import net.helenus.support.HelenusMappingException;
|
import net.helenus.support.HelenusMappingException;
|
||||||
|
@ -171,11 +172,12 @@ public final class SchemaUtil {
|
||||||
String columnName = prop.getColumnName();
|
String columnName = prop.getColumnName();
|
||||||
selection = selection.column(columnName);
|
selection = selection.column(columnName);
|
||||||
}
|
}
|
||||||
String tableName =
|
Class<?> iface = entity.getMappingInterface();
|
||||||
Helenus.entity(entity.getMappingInterface().getInterfaces()[0]).getName().toCql();
|
String tableName = Helenus.entity(iface.getInterfaces()[0]).getName().toCql();
|
||||||
Select.Where where = selection.from(tableName).where();
|
Select.Where where = selection.from(tableName).where();
|
||||||
List<String> p = new ArrayList<String>(props.size());
|
List<String> p = new ArrayList<String>(props.size());
|
||||||
List<String> c = new ArrayList<String>(props.size());
|
List<String> c = new ArrayList<String>(props.size());
|
||||||
|
List<String> o = new ArrayList<String>(props.size());
|
||||||
|
|
||||||
for (HelenusPropertyNode prop : props) {
|
for (HelenusPropertyNode prop : props) {
|
||||||
String columnName = prop.getColumnName();
|
String columnName = prop.getColumnName();
|
||||||
|
@ -184,9 +186,15 @@ public final class SchemaUtil {
|
||||||
p.add(columnName);
|
p.add(columnName);
|
||||||
where = where.and(new IsNotNullClause(columnName));
|
where = where.and(new IsNotNullClause(columnName));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLUSTERING_COLUMN:
|
case CLUSTERING_COLUMN:
|
||||||
c.add(columnName);
|
c.add(columnName);
|
||||||
where = where.and(new IsNotNullClause(columnName));
|
where = where.and(new IsNotNullClause(columnName));
|
||||||
|
|
||||||
|
ClusteringColumn clusteringColumn = prop.getProperty().getGetterMethod().getAnnotation(ClusteringColumn.class);
|
||||||
|
if (clusteringColumn != null && clusteringColumn.ordering() != null) {
|
||||||
|
o.add(columnName + " " + clusteringColumn.ordering().cql());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -201,7 +209,11 @@ public final class SchemaUtil {
|
||||||
: "")
|
: "")
|
||||||
+ ")";
|
+ ")";
|
||||||
|
|
||||||
return new CreateMaterializedView(keyspace, viewName, where, primaryKey);
|
String clustering = "";
|
||||||
|
if (o.size() > 0) {
|
||||||
|
clustering = "WITH CLUSTERING ORDER BY (" + String.join(", ", o) + ")";
|
||||||
|
}
|
||||||
|
return new CreateMaterializedView(keyspace, viewName, where, primaryKey, clustering);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchemaStatement dropMaterializedView(
|
public static SchemaStatement dropMaterializedView(
|
||||||
|
|
|
@ -2,17 +2,16 @@ package net.helenus.test.integration.core.views;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.helenus.mapping.annotation.ClusteringColumn;
|
|
||||||
import net.helenus.mapping.annotation.Index;
|
import net.helenus.mapping.OrderingDirection;
|
||||||
import net.helenus.mapping.annotation.MaterializedView;
|
import net.helenus.mapping.annotation.*;
|
||||||
import net.helenus.mapping.annotation.PartitionKey;
|
|
||||||
|
|
||||||
@MaterializedView
|
@MaterializedView
|
||||||
public interface CyclistsByAge extends Cyclist {
|
public interface CyclistsByAge extends Cyclist {
|
||||||
@PartitionKey
|
@PartitionKey
|
||||||
UUID cid();
|
UUID cid();
|
||||||
|
|
||||||
@ClusteringColumn
|
@ClusteringColumn(ordering = OrderingDirection.ASC)
|
||||||
int age();
|
int age();
|
||||||
|
|
||||||
Date birthday();
|
Date birthday();
|
||||||
|
|
Loading…
Reference in a new issue