是否可以仅基于分区键使用CrudRepository删除整个cassandra分区?

时间:2018-09-25 02:42:57

标签: java spring cassandra crud default-constructor

基本上我有这张桌子:

CREATE TABLE experiment(
 experimentid varchar,
 description text,
 rt float,
 intensity float,
 mz float,
 identifier text,
 chemical_formula text,
 filename text,
 PRIMARY KEY ((experimentid),description, rt, intensity, mz, identifier, chemical_formula, filename)
);

使用Experiment.java

@Table(name= "experiment")
public class Experiment implements Serializable{

@PrimaryKey
private ExperimentKey experimentKey;

public ExperimentKey getExperimentKey() {
    return experimentKey;
}
public void setExperimentKey(ExperimentKey experimentKey) {
    this.experimentKey = experimentKey;
}
}

和ExperimentKey.java

@PrimaryKeyClass
public class ExperimentKey implements Serializable {

@PrimaryKeyColumn(name = "experimentid",ordinal = 0,type = PrimaryKeyType.PARTITIONED)
@CassandraType(type=DataType.Name.VARCHAR)
private String experimentid;
@PrimaryKeyColumn(name = "description",ordinal = 1)
@CassandraType(type=DataType.Name.VARCHAR)
private String description;
@PrimaryKeyColumn(name = "rt",ordinal = 2)
@CassandraType(type=DataType.Name.FLOAT)
private Float rt;
@PrimaryKeyColumn(name = "intensity",ordinal = 3)
@CassandraType(type=DataType.Name.FLOAT)
private Float intensity;
@PrimaryKeyColumn(name = "mz",ordinal = 4)
@CassandraType(type=DataType.Name.FLOAT)
private Float mz;
@PrimaryKeyColumn(name = "identifier",ordinal = 5)
@CassandraType(type=DataType.Name.VARCHAR)
private String identifier;
@PrimaryKeyColumn(name = "chemical_formula",ordinal = 6)
@CassandraType(type=DataType.Name.VARCHAR)
private String chemical_formula;
@PrimaryKeyColumn(name = "filename",ordinal = 7)
@CassandraType(type=DataType.Name.VARCHAR)
private String filename;

//getters and setters

public ExperimentKey(){

}
}

基本上,我想通过crudrepository实现以下查询:

Delete * from experiment where experimentid='(something)';

我知道我只能基于带有findAllByExperimentKey_Experimentid(experimentid)的分区键进行SELECT,但是是否可以对Delete进行相同的选择? 我尝试了deleteAllByExperimentKey_Experimentid(experimentid),但出现错误:

  

无法使用带有参数的构造函数NO_CONSTRUCTOR实例化void

编辑1

好的,这是我的ExperimentRepo.java

public interface ExperimentRepo extends CrudRepository<Experiment,ExperimentKey>{
     public void deleteAllByByExperimentKey_Experimentid(String expid);
}

这是我的ExperimentServiceImpl.java

@Service
public class ExperimentServiceImpl implements ExperimentService{

private ExperimentRepo experimentRepo;

@Autowired
public ExperimentServiceImpl(ExperimentRepo experimentRepo){
    this.experimentRepo=experimentRepo;
}
@Override
public void deleteAllExperimentByExperimentid(String expid){
    MapId id = id("experimentid", expid);
    experimentRepo.deleteAllByByExperimentKey_Experimentid(expid);
}

不确定我应该在哪里使用MapId id = id(“ experimentid”,<可序列化的值>)。

0 个答案:

没有答案