Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added count().
  • Loading branch information
boneill42 committed Jul 10, 2012
commit 7b4e905092f0361088f4acdfe7a98af680a72c24
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;

import org.apache.commons.lang.NotImplementedException;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,6 +16,10 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import com.impetus.kundera.metadata.KunderaMetadataManager;
import com.impetus.kundera.metadata.model.EntityMetadata;
import com.impetus.kundera.persistence.EntityManagerFactoryImpl;

/**
* Repository base implementation for Cassandra.
*
Expand Down Expand Up @@ -68,7 +73,14 @@ public boolean exists(ID id) {
* @see org.springframework.data.repository.CrudRepository#count()
*/
public long count() {
throw new NotImplementedException();
// TODO: Use count() syntax here, doesn't appear to be working...
// need to check on status of count() in CQL.
// Still costly across the entire cluster?
//EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(this.entityType);
String jpqQuery = "select u from " + this.entityType.getSimpleName() + " u";
Query query = entityManager.createQuery(jpqQuery);
List<Long> result = query.getResultList();
return result.size();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -53,7 +55,7 @@ public void testSave() {
public void testFindOne() {
User user = this.getUser1();
userRepository.save(user);
assert(userRepository.exists(USER1_ID));
assertTrue(userRepository.exists(USER1_ID));
User findOne = userRepository.findOne(USER1_ID);
assertNotNull(findOne);
}
Expand All @@ -62,7 +64,7 @@ public void testFindOne() {
public void testDeleteByID() throws InterruptedException {
User user = this.getUser1();
userRepository.save(user);
assert(userRepository.exists(USER1_ID));
assertTrue(userRepository.exists(USER1_ID));
userRepository.delete(USER1_ID);
assertFalse(userRepository.exists(USER1_ID));
}
Expand All @@ -71,7 +73,7 @@ public void testDeleteByID() throws InterruptedException {
public void testDelete() throws InterruptedException {
User user = this.getUser1();
userRepository.save(user);
assert(userRepository.exists(USER1_ID));
assertTrue(userRepository.exists(USER1_ID));
userRepository.delete(USER1_ID);
assertFalse(userRepository.exists(USER1_ID));
}
Expand All @@ -82,8 +84,8 @@ public void testDeleteSet() throws InterruptedException {
User user2 = this.getUser2();
userRepository.save(user1);
userRepository.save(user2);
assert(userRepository.exists(USER1_ID));
assert(userRepository.exists(USER2_ID));
assertTrue(userRepository.exists(USER1_ID));
assertTrue(userRepository.exists(USER2_ID));

List<User> users = new ArrayList<User>();
users.add(user1);
Expand All @@ -93,4 +95,23 @@ public void testDeleteSet() throws InterruptedException {
assertFalse(userRepository.exists(USER2_ID));
}

@Test
public void testCount() throws InterruptedException {
User user1 = this.getUser1();
User user2 = this.getUser2();
userRepository.save(user1);
userRepository.save(user2);
assertTrue(userRepository.exists(USER1_ID));
assertTrue(userRepository.exists(USER2_ID));

List<User> users = new ArrayList<User>();
users.add(user1);
users.add(user2);
Assert.assertEquals(2, userRepository.count());

userRepository.delete(users);
assertFalse(userRepository.exists(USER1_ID));
assertFalse(userRepository.exists(USER2_ID));
}

}