Created
April 21, 2011 06:40
-
-
Save remeniuk/933872 to your computer and use it in GitHub Desktop.
Cake pattern for Spring-flavored DAOs
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
import java.net.URI | |
trait Order | |
trait Product | |
trait Datasource | |
trait DAO[T] { | |
def create(t:T) | |
} | |
trait JdbcSupport { | |
val dataSource:Datasource | |
def init(uri:URI, user:String, password:String) = Unit | |
} | |
trait OrderDAO {self: JdbcSupport => | |
val orderDao: DAO[Order] | |
class OrderDAOImpl extends DAO[Order]{ | |
//... | |
def create(t:Order) = { | |
dataSource//... | |
} | |
} | |
} | |
trait ProductDAO {self: JdbcSupport => | |
val productDao: DAO[Product] | |
class ProductDAOImpl extends DAO[Product]{ | |
//... | |
def create(t:Product) = { | |
dataSource//... | |
} | |
} | |
} | |
object DAOLayer extends OrderDAO with ProductDAO with JdbcSupport { | |
val dataSource = new Datasource{} | |
//init(uri, user, password) | |
val productDao = new ProductDAOImpl | |
val orderDao = new OrderDAOImpl | |
} | |
class ProductService { | |
import DAOLayer._ | |
def createProduct(product: Product) = productDao.create(product) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment