Created
June 25, 2012 09:38
-
-
Save jdubois/2987647 to your computer and use it in GitHub Desktop.
Gist correspondant au blog Ippon traitant de https://github.com/ippontech/primefaces-groovy-cassandra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.ippon.blog.primegroovy.domain | |
class User implements Serializable { | |
String login | |
String username | |
String domain | |
String firstName | |
String lastName | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.ippon.blog.primegroovy.web | |
import fr.ippon.blog.primegroovy.domain.User | |
import fr.ippon.blog.primegroovy.repository.UserRepository | |
import javax.enterprise.context.RequestScoped | |
import javax.inject.Inject | |
import javax.inject.Named | |
@Named("userController") | |
@RequestScoped | |
class UserController implements Serializable { | |
@Inject | |
UserRepository userRepository | |
Collection<User> getUsers() { | |
return userRepository.users | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.ippon.blog.primegroovy.repository | |
import fr.ippon.blog.primegroovy.domain.User | |
import me.prettyprint.cassandra.model.CqlQuery | |
import me.prettyprint.cassandra.serializers.StringSerializer | |
import me.prettyprint.cassandra.service.CassandraHostConfigurator | |
import me.prettyprint.cassandra.service.ThriftCluster | |
import me.prettyprint.hector.api.beans.Row | |
import me.prettyprint.hector.api.factory.HFactory | |
import javax.enterprise.context.ApplicationScoped | |
/** | |
* Access to the Cassandra User CF. | |
*/ | |
@ApplicationScoped | |
class UserRepository implements Serializable { | |
def keyspace = HFactory.createKeyspace("tatami", | |
new ThriftCluster("Tatami cluster", | |
new CassandraHostConfigurator("localhost"))) | |
Collection<User> getUsers() { | |
def cqlQuery = | |
new CqlQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get()) | |
def rows = cqlQuery.setQuery("SELECT * FROM User").execute().get() | |
return rows.collect { Row row -> | |
new User( | |
login: row.key, | |
username: row.columnSlice.getColumnByName("username").value, | |
domain: row.columnSlice.getColumnByName("domain").value, | |
firstName: row.columnSlice.getColumnByName("firstName").value, | |
lastName: row.columnSlice.getColumnByName("lastName").value | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment