gpt4 book ai didi

java - Spring 数据 Cassandra @Indexed 注解

转载 作者:行者123 更新时间:2023-12-03 21:29:46 24 4
gpt4 key购买 nike

我正在处理 Spring 数据 Cassandra 在创建实体时,我正在为字段提供所需的注释,但是当我提供 @Indexed 注释以在架构中创建二级索引时,我无法在不提供 Allow 的情况下查询索引属性过滤。请告诉我如何在 Cassandra 中使用 Spring 数据注释创建二级索引

This is the sample cod that I am using creating a Sprind data Cassandra Entity.@Indexed annotation not creating a secondary index in Cassandra database

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.springframework.data.cassandra.mapping.CassandraType;
import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.Indexed;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.mapping.UserDefinedType;
import com.datastax.driver.core.DataType;
import com.suntecgroup.xelerate.platform.demo.config.SpringContainer;
import com.suntecgroup.xelerate.platform.demo.store.CustomerCassandraStore;
import com.suntecgroup.xelerate.platform.demo.store.impl.CustomerCassandraStoreImpl;

@Table(value="CustomerCassandra")
public class CustomerCassandra extends CassandraEntity<Integer> {

@PrimaryKey(value="cust_id")
private Integer custId;
@Indexed(value="name")
private String name;
@Indexed(value="email")
private String email;
@Column(value="domain")
private String domain;
@Column(value="category")
private String category;
@Column(value="created_at")
private Date createdAt;
@CassandraType(type=DataType.Name.LIST,typeArguments = { DataType.Name.UDT }, userTypeName = "address_demo_type")
@Column(value="addresses")
private List<Address> addresses;
@Override
public Integer getId() {
return custId;
}
@Override
public void setId(Integer id) {
this.custId = id;
}
public static CustomerCassandraStore getStore() {
return (CustomerCassandraStore) SpringContainer.getBean(CustomerCassandraStoreImpl.class);
}
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public List<Address> getAddresses() {
return addresses;
}

public void setAddresses(Address... addresses) {
LinkedList<Address> addressList = new LinkedList<>();
for(Address addr: addresses) {
addressList.add(addr);
}
setAddresses(addressList);
}

public void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}

public String getDomain() {
return domain;
}

public void setDomain(String domain) {
this.domain = domain;
}

@UserDefinedType(value="address_demo_type")
public static class Address {

@CassandraType(type = DataType.Name.TEXT)
@Column(value="street_address")
private String streetAddress;

@CassandraType(type = DataType.Name.TEXT)
@Column(value="city")
private String city;

@CassandraType(type = DataType.Name.TEXT)
@Column(value="country")
private String country;

@CassandraType(type = DataType.Name.TEXT)
@Column(value="pincode")
private String pincode;

public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getPincode() {
return pincode;
}
public void setPincode(String pincode) {
this.pincode = pincode;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((city == null) ? 0 : city.hashCode());
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((pincode == null) ? 0 : pincode.hashCode());
result = prime * result
+ ((streetAddress == null) ? 0 : streetAddress.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Address other = (Address) obj;
if (city == null) {
if (other.city != null)
return false;
} else if (!city.equals(other.city))
return false;
if (country == null) {
if (other.country != null)
return false;
} else if (!country.equals(other.country))
return false;
if (pincode == null) {
if (other.pincode != null)
return false;
} else if (!pincode.equals(other.pincode))
return false;
if (streetAddress == null) {
if (other.streetAddress != null)
return false;
} else if (!streetAddress.equals(other.streetAddress))
return false;
return true;
}}




}

最佳答案

它看起来像是 spring-data-cassandra 库中的一些错误。我也无法通过注释创建索引。

关于java - Spring 数据 Cassandra @Indexed 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44773942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com