Skip to content
Browse files

jpa

  • Loading branch information...
1 parent e25e8cb commit c9fd084cfa68f3dbb00f661bae82f59b08c33ccc @mchapala committed May 11, 2013
View
36 app/src/main/scala/com/ats/api/model/AtsContract.scala
@@ -1,23 +1,25 @@
package com.ats.api.model
-import javax.persistence.{Id, GeneratedValue, GenerationType}
+import javax.persistence._
// Analogous to Contract object of tws
+@Entity
+@Table(name = "Contract")
case class AtsContract(
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- m_conId: Option[Int] = None,
- m_symbol: String,
- m_secType: String,
- m_expiry: Option[String] = None,
- m_strike: Option[Double] = None,
- m_right: Option[String] = None,
- m_multiplier: Option[String] = None,
- m_exchange: Option[String],
- m_currency: String,
- m_localSymbol: Option[String] = None,
- m_primaryExch: Option[String] = None,
- m_includeExpired: Option[Boolean] = None,
- m_comboLegsDescrip: Option[String] = None,
- m_comboLegs: Option[String] = None) extends AbstractEntity
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ m_conId: Option[Int] = None,
+ m_symbol: String,
+ m_secType: String,
+ m_expiry: Option[String] = None,
+ m_strike: Option[Double] = None,
+ m_right: Option[String] = None,
+ m_multiplier: Option[String] = None,
+ m_exchange: Option[String],
+ m_currency: String,
+ m_localSymbol: Option[String] = None,
+ m_primaryExch: Option[String] = None,
+ m_includeExpired: Option[Boolean] = None,
+ m_comboLegsDescrip: Option[String] = None,
+ m_comboLegs: Option[String] = None) extends AbstractEntity
View
14 app/src/main/scala/com/ats/api/model/RequestMarketData.scala
@@ -1,9 +1,19 @@
package com.ats.api.model
-import javax.persistence.Entity
+import javax.persistence._
@Entity
-case class RequestMarketData(contract:AtsContract, tickTypeList:String, snapshot:Boolean) extends AbstractEntity
+//@Table(name="REQUEST_MARKET_DATA")
+case class RequestMarketData(
+ @OneToMany
+ contract: AtsContract,
+
+ @Column(name = "tickTypeList")
+ tickTypeList: String,
+
+ @Column(name = "snapshot")
+ snapshot: Boolean)
+ extends AbstractEntity
View
9 app/src/main/scala/com/ats/persistence/impl/AtsContractRepository.scala
@@ -0,0 +1,9 @@
+package com.ats.persistence.impl
+
+import com.ats.api.model.AtsContract
+import org.springframework.data.jpa.repository.JpaRepository
+
+trait AtsContractRepository extends JpaRepository[AtsContract, java.lang.Long] {
+
+
+}
View
27 app/src/main/scala/com/ats/persistence/impl/ContractService.scala
@@ -1,27 +0,0 @@
-package com.ats.persistence.impl
-
-import scala.language.reflectiveCalls
-
-import com.ib.client.Contract
-import com.ats.api.model.AtsContract
-
-
-
-
-
-class ContractService {
-
- def createTable() {
-
- }
-
-
-
-
-def insert(record: AtsContract) =
-{
-
-}
-
-}
-
View
24 app/src/test/scala/AtsContractsRepositoryTest.scala
@@ -2,7 +2,7 @@
import com.ats.api.model.{RequestMarketData, AtsContract}
import com.ats.app.config.spring.AtsSpringDataConfig
-import com.ats.persistence.impl.{RequestMarketDataRepository, ContractService}
+import com.ats.persistence.impl.{AtsContractRepository, RequestMarketDataRepository}
import org.scalatest.testng.TestNGSuite
import org.springframework.beans.factory.annotation.Autowired
@@ -13,21 +13,29 @@ import org.testng.annotations.Test
import scala.beans.BeanProperty
-@ContextConfiguration(loader=classOf[AnnotationConfigContextLoader],classes=Array(classOf[AtsSpringDataConfig]))
-class AtsContractsRepositoryTest extends AbstractTestNGSpringContextTests with TestNGSuite {
-
+@ContextConfiguration(loader = classOf[AnnotationConfigContextLoader], classes = Array(classOf[AtsSpringDataConfig]))
+class AtsContractsRepositoryTest extends AbstractTestNGSpringContextTests with TestNGSuite {
@Autowired
@BeanProperty
- var repository:RequestMarketDataRepository=_;
+ var repository: RequestMarketDataRepository = _;
+ @Autowired
+ @BeanProperty
+ var contractRepository: AtsContractRepository = _;
@Test
- def testAdd(){
- val contract = new AtsContract(None,"BAC","STK",None,None,None,None,Some("SMART"),"USD",None,None,Some(false),None,None)
- val data:RequestMarketData = new RequestMarketData(contract,"100",false);
+ def testAdd() {
+ val contract = new AtsContract(None, "BAC", "STK", None, None, None, None, Some("SMART"), "USD", None, None, Some(false), None, None)
+ contractRepository.save(contract);
+ val data: RequestMarketData = new RequestMarketData(contract, "100", false);
repository.save(data)
}
+ @Test
+ def testAddContract() {
+ val contract = new AtsContract(None, "BAC", "STK", None, None, None, None, Some("SMART"), "USD", None, None, Some(false), None, None)
+ contractRepository.save(contract);
+ }
}
View
0 scripts/database.sql
No changes.

0 comments on commit c9fd084

Please sign in to comment.
Something went wrong with that request. Please try again.