Skip to content

Commit

Permalink
KAA-1268: Fix removeAll() method in the AbstractCassandraDao
Browse files Browse the repository at this point in the history
Fix PRIMARY KEY mistakes in the cassandra
  • Loading branch information
sashadidukh committed Sep 6, 2016
1 parent 04b43b0 commit 9e43c6e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Expand Up @@ -158,9 +158,8 @@ public T findById(K key) {
}

public void removeAll() {
Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).setConsistencyLevel(getWriteConsistencyLevel());
LOG.debug("Remove all request: {}", delete.toString());
session.execute(delete);
Statement truncate = QueryBuilder.truncate(getColumnFamilyName()).setConsistencyLevel(getWriteConsistencyLevel());
session.execute(truncate);
}

public void removeById(K key) {
Expand Down
Expand Up @@ -16,6 +16,7 @@

package org.kaaproject.kaa.server.common.nosql.cassandra.dao.model;

import com.datastax.driver.mapping.annotations.ClusteringColumn;
import com.datastax.driver.mapping.annotations.Column;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
Expand Down Expand Up @@ -43,9 +44,10 @@ public class CassandraCredentials implements Credentials, Serializable {
@Transient
private static final long serialVersionUID = 5814711856025319827L;

@PartitionKey
@Column(name = CREDENTIALS_APPLICATION_ID_PROPERTY)
private String applicationId;
@PartitionKey
@ClusteringColumn
@Column(name = CREDENTIALS_ID_PROPERTY)
private String id;
@Column(name = CREDENTIALS_BODY_PROPERTY)
Expand Down
Expand Up @@ -31,6 +31,7 @@
import java.io.Serializable;
import java.util.List;

import com.datastax.driver.mapping.annotations.ClusteringColumn;
import org.kaaproject.kaa.common.dto.EndpointUserDto;
import org.kaaproject.kaa.server.common.dao.model.EndpointUser;

Expand All @@ -45,10 +46,10 @@ public final class CassandraEndpointUser implements EndpointUser, Serializable {
@Transient
private static final long serialVersionUID = 3766947955702551264L;

@PartitionKey(value = 0)
@PartitionKey
@Column(name = EP_USER_EXTERNAL_ID_PROPERTY)
private String externalId;
@PartitionKey(value = 1)
@ClusteringColumn
@Column(name = EP_USER_TENANT_ID_PROPERTY)
private String tenantId;

Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
import java.util.Optional;

import static org.kaaproject.kaa.common.dto.credentials.CredentialsStatus.AVAILABLE;
Expand Down Expand Up @@ -75,4 +76,20 @@ public void testRemoveCredentials() {
Optional<CassandraCredentials> removed = this.credentialsDao.find(CREDENTIALS_APPLICATION_ID, CREDENTIALS_ID);
Assert.assertFalse(removed.isPresent());
}

@Test
public void testRemoveAllCredentials() {
CredentialsDto firstCredentials = this.generateCredentials(CREDENTIALS_APPLICATION_ID, CREDENTIALS_ID,
CREDENTIALS_BODY, AVAILABLE);
CredentialsDto secondCredentials = this.generateCredentials(CREDENTIALS_APPLICATION_ID.concat("1"), CREDENTIALS_ID,
CREDENTIALS_BODY, AVAILABLE);

List<CassandraCredentials> credentials = credentialsDao.find();
Assert.assertEquals(credentials.size(), 2);

credentialsDao.removeAll();
List<CassandraCredentials> removed = credentialsDao.find();
Assert.assertTrue(removed.isEmpty());
}

}

0 comments on commit 9e43c6e

Please sign in to comment.