Created
June 18, 2012 15:35
-
-
Save jdubois/2948937 to your computer and use it in GitHub Desktop.
Gist correspondant au blog Ippon traitant de https://github.com/ippontech/primefaces-scala-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.primescala.domain | |
import reflect.BeanProperty | |
case class User(@BeanProperty var login: String, | |
@BeanProperty var username: String, | |
@BeanProperty var domain: String, | |
@BeanProperty var firstName: String, | |
@BeanProperty var lastName: String) { | |
} |
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.primescala.web | |
import javax.faces.bean.ManagedBean | |
import reflect.BeanProperty | |
import fr.ippon.blog.primescala.domain.User | |
import fr.ippon.blog.primescala.repository.UserRepository | |
@ManagedBean | |
class UserController extends Serializable { | |
@BeanProperty | |
var users: java.util.ArrayList[User] = UserRepository.getUsers | |
} |
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.primescala.repository | |
import collection.JavaConversions._ | |
import me.prettyprint.cassandra.service.{ThriftCluster, CassandraHostConfigurator} | |
import me.prettyprint.hector.api.factory.HFactory | |
import me.prettyprint.cassandra.model.CqlQuery | |
import me.prettyprint.cassandra.serializers.StringSerializer | |
import fr.ippon.blog.primescala.domain.User | |
/** | |
* Access to the Cassandra User CF. | |
*/ | |
object UserRepository { | |
val keyspace = HFactory.createKeyspace("tatami", | |
new ThriftCluster("Tatami cluster", | |
new CassandraHostConfigurator("localhost"))) | |
def getUsers: java.util.ArrayList[User] = { | |
val cqlQuery = | |
new CqlQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get()) | |
cqlQuery.setQuery("SELECT * FROM User") | |
val rows = cqlQuery.execute().get().getList | |
val users = new java.util.ArrayList[User]() | |
rows.foreach(row => { | |
users.add(User(row.getKey, | |
row.getColumnSlice.getColumnByName("username").getValue, | |
row.getColumnSlice.getColumnByName("domain").getValue, | |
row.getColumnSlice.getColumnByName("firstName").getValue, | |
row.getColumnSlice.getColumnByName("lastName").getValue)) | |
}) | |
users | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment