Created
January 31, 2016 08:12
-
-
Save erangaeb/55c05474571e5a55d8e6 to your computer and use it in GitHub Desktop.
Cassandra based EmployeeDb component
This file contains hidden or 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
| trait CassandraEmployeeDbComp extends EmployeeDbComp { | |
| this: CakezCassandraCluster => | |
| val employeeDb = new CassandraEmployeeDb | |
| class CassandraEmployeeDb extends EmployeeDb { | |
| def logger = LoggerFactory.getLogger(this.getClass) | |
| override def createEmployee(employee: Employee) = { | |
| logger.debug(s"Create employee with id: ${employee.empId} name: ${employee.name}") | |
| // cassandra based insert query | |
| val statement = QueryBuilder.insertInto("employee") | |
| .value("emp_id", employee.empId) | |
| .value("name", employee.name) | |
| .value("department", employee.department) | |
| session.execute(statement) | |
| } | |
| override def getEmployee(empId: Int): Employee = { | |
| logger.debug(s"get employee with ID: ${empId}") | |
| // cassandra based slect query | |
| val selectStmt = select().all() | |
| .from("employee") | |
| .where(QueryBuilder.eq("emp_id", empId)) | |
| .limit(1) | |
| val resultSet = session.execute(selectStmt) | |
| val row = resultSet.one() | |
| Employee(row.getInt("emp_id"), row.getString("name"), row.getString("department")) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment