Skip to content

Commit

Permalink
Merge pull request #421 from websudos/release/1.22.0
Browse files Browse the repository at this point in the history
Release/1.22.0
  • Loading branch information
alexflav23 committed Feb 14, 2016
2 parents 35f701a + 0625546 commit 218c1a7
Show file tree
Hide file tree
Showing 30 changed files with 298 additions and 723 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
phantom [![Build Status](https://travis-ci.org/websudos/phantom.svg?branch=develop)](https://travis-ci.org/websudos/phantom) [![Coverage Status](https://coveralls.io/repos/websudos/phantom/badge.svg)](https://coveralls.io/r/websudos/phantom) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10) [![Download](https://api.bintray.com/packages/websudos/oss-releases/phantom/images/download.svg) ](https://bintray.com/websudos/oss-releases/phantom/_latestVersion) [![Join the chat at https://gitter.im/websudos/phantom](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/websudos/phantom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
phantom [![Build Status](https://travis-ci.org/websudos/phantom.svg?branch=develop)](https://travis-ci.org/websudos/phantom) [![Coverage Status](https://coveralls.io/repos/websudos/phantom/badge.svg)](https://coveralls.io/r/websudos/phantom) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10) [![Bintray](https://api.bintray.com/packages/websudos/oss-releases/phantom/images/download.svg) ](https://bintray.com/websudos/oss-releases/phantom/_latestVersion) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/websudos/phantom?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
==================================================================================================

Reactive type-safe Scala DSL for Cassandra
Expand Down Expand Up @@ -28,8 +28,8 @@ We publish phantom in 2 formats, stable releases and bleeding edge.

Check the badges at the top of this README for the latest version. The badges are automatically updated in realtime, where as this README isn't.

- Latest stable version: 1.21.0 (Maven Central)
- Bleeding edge: 1.21.4 (Websudos OSS releases on Bintray)
- Latest stable version: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.websudos/phantom_2.10) (Maven Central)
- Bleeding edge: [![Bintray](https://api.bintray.com/packages/websudos/oss-releases/phantom/images/download.svg) ](https://bintray.com/websudos/oss-releases/phantom/_latestVersion) (Websudos OSS releases on Bintray)

<a id="learning-phantom">Tutorials on phantom and Cassandra</a>
======================================================================
Expand Down Expand Up @@ -101,21 +101,21 @@ Scala/Cassandra users in the world rely on phantom.
* Bartosz Jankiewicz ([@bjankie1](https://github.com/bjankie1))
* Benjamin Edwards ([@benjumanji](https://github.com/benjumanji))
* Eugene Zhulenev ([@ezhulenev](https://github.com/ezhulenev))
* Michal Matloka ([@mmatloka](https://github.com/mmatloka))
* Juan José Vázquez ([@juanjovazquez](https://github.com/juanjovazquez))
* Viktor Taranenko ([@viktortnk](https://github.com/viktortnk))
* Jens Halm ([@jenshalm](https://github.com/jenshalm))
* Stephen Samuel ([@sksamuel](https://github.com/sksamuel))
* Tomasz Perek ([@tperek](https://github.com/tperek))
* Evan Chan ([@evanfchan](https://github.com/evanfchan))

* Jens Halm ([@jenshalm](https://github.com/jenshalm))

<a id="copyright">Copyright</a>
===============================
<a href="#table-of-contents">back to top</a>

Special thanks to Viktor Taranenko from WhiskLabs, who gave us the original idea.

Copyright &copy; 2013 - 2015 websudos.
Copyright &copy; 2013 - 2016 websudos.


Contributing to phantom
Expand Down
16 changes: 15 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Changelog
<li><a href="#version-1.21.2">1.21.2 - 20.01.2016</a></li>
<li><a href="#version-1.21.3">1.21.3 - 28.01.2016</a></li>
<li><a href="#version-1.21.4">1.21.4 - 06.02.2016</a></li>
<li><a href="#version-1.21.5">1.21.5 - 11.02.2016</a></li>
<li><a href="#version-1.22.0">1.22.0 - 14.02.2016</a></li>
</ul>


Expand Down Expand Up @@ -340,4 +342,16 @@ removed `session.newSimpleStatement`.

- #414 Added ablity to use prepared statements inside of batch statemets.
- #417 Corrected cql type for LocalDate and Date accessor method.
- #412 Bumped Datastax Java Driver version to 3.0.0
- #412 Bumped Datastax Java Driver version to 3.0.0

<a id="version-1.21.5">1.21.5</a>
================================
- Added SmallInt and TinyInt support.
- Added a new contributor to the list.

<a id="version-1.22.0">1.22.0</a>
================================

- PHANTOM-194: Fixed serialization of ```Table.select.distinct``` queries.
- Added support for `LocalDate` columns.
- Added `driver-extras` dependency from the Datastax set.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.websudos.phantom.connectors

import com.datastax.driver.core.PoolingOptions

/**
* A builder for KeySpace instances.
*
Expand All @@ -32,6 +34,18 @@ class KeySpaceBuilder(clusterBuilder: ClusterBuilder) {
def withClusterBuilder(builder: ClusterBuilder): KeySpaceBuilder =
new KeySpaceBuilder(clusterBuilder andThen builder)

/**
* Disables the heartbeat for the current builder.
* This is designed for local instantiations of connectors or test environments.
* @return A new cluster builder, with the heartbeat interval set to 0(disabled).
*/
def noHeartbeat(): KeySpaceBuilder = {
new KeySpaceBuilder(clusterBuilder andThen(_.withPoolingOptions(
new PoolingOptions().setHeartbeatIntervalSeconds(0))
)
)
}

/**
* Create a new keySpace with the specified name.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
package com.websudos.phantom.server

import java.util.Date
import org.joda.time.{DateTime, LocalDate}

import com.websudos.phantom.builder.query.InsertQuery
import com.websudos.phantom.testkit.PhantomCassandraConnector

import com.datastax.driver.core.Row
import com.websudos.phantom.builder.query.InsertQuery
import com.websudos.phantom.db.DatabaseImpl
import com.websudos.phantom.dsl._
import org.joda.time.{DateTime, LocalDate}

sealed trait Price {
def instrumentId: String
Expand Down Expand Up @@ -95,11 +94,11 @@ sealed class OptionPrices extends CassandraTable[OptionPrices, OptionPrice] {
OptionPrice(instrumentId(r), new LocalDate(tradeDate(r)), exchangeCode(r), t(r), strikePrice(r), value(r))
}

object EquityPrices extends EquityPrices with PhantomCassandraConnector {
abstract class ConcreteEquityPrices extends EquityPrices with RootConnector {
override val tableName: String = "EquityPrices"


def insertPrice(price: EquityPrice) =
def insertPrice(price: EquityPrice): InsertQuery.Default[EquityPrices, EquityPrice] =
insert.
value(_.instrumentId, price.instrumentId).
value(_.tradeDate, price.tradeDate.toDate).
Expand All @@ -109,7 +108,7 @@ object EquityPrices extends EquityPrices with PhantomCassandraConnector {

}

object OptionPrices extends OptionPrices with PhantomCassandraConnector {
abstract class ConcreteOptionPrices extends OptionPrices with RootConnector {
override val tableName: String = "OptionPrices"

def insertPrice(price: OptionPrice): InsertQuery.Default[OptionPrices, OptionPrice] = {
Expand All @@ -121,5 +120,16 @@ object OptionPrices extends OptionPrices with PhantomCassandraConnector {
.value(_.strikePrice, price.strikePrice)
.value(_.value, price.value)
}
}

class EquityDatabase(override val connector: KeySpaceDef) extends DatabaseImpl(connector) {
object equityPrices extends ConcreteEquityPrices with connector.Connector
object optionPrices extends ConcreteOptionPrices with connector.Connector
}

object EquityConnector {
val default = ContactPoint.local.noHeartbeat().keySpace("equities")
}

object EquityDatabase extends EquityDatabase(EquityConnector.default)

Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,37 @@ object ScalatraBootstrap {
)
}

class ScalatraBootstrap extends LifeCycle with PhantomCassandraConnector {
class Boot extends EquityConnector.default.Connector {

override def init(context: ServletContext) {
val db = EquityDatabase

def boot(): Unit = {

// Create cassandra keyspace in startup
// Create prices tables
Await.ready(EquityPrices.create.ifNotExists().future(), 5.seconds)
Await.ready(OptionPrices.create.ifNotExists().future(), 5.seconds)
Await.result(db.autocreate().future(), 5.seconds)

// Insert prices
val insertApplePrices = ScalatraBootstrap.ApplePrices.map(EquityPrices.insertPrice).foldLeft(Batch.unlogged) {
val insertApplePrices = ScalatraBootstrap.ApplePrices.map(db.equityPrices.insertPrice).foldLeft(Batch.unlogged) {
(batch, insertQuery) => batch.add(insertQuery)
}

val chain = for {
truncate <- EquityPrices.truncate.future()
truncate <- EquityDatabase.equityPrices.truncate.future()
batch <- insertApplePrices.future()
} yield batch

Await.ready(chain, 3.seconds)
Await.result(chain, 5.seconds)

val insertAppleOptionPrices = ScalatraBootstrap.AppleOptionPrices.map(OptionPrices.insertPrice).foldLeft(Batch.unlogged) {
val insertAppleOptionPrices = ScalatraBootstrap.AppleOptionPrices.map(db.optionPrices.insertPrice).foldLeft(Batch.unlogged) {
(batch, insertQuery) => batch.add(insertQuery)
}

val chain2 = for {
truncate <- OptionPrices.truncate.future()
truncate <- db.optionPrices.truncate.future()
batch <- insertAppleOptionPrices.future()
} yield batch

Await.ready(chain2, 3.seconds)

// Mount prices servlet
context mount (new PricesAccess, "/*")
Await.result(chain2, 5.seconds)
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ trait DefaultPrimitives {
val cassandraType = CQLSyntax.Types.Decimal

override def fromRow(column: String, row: Row): Try[BigDecimal] = nullCheck(column, row) {
r => r.getDecimal(column)
r => BigDecimal(r.getDecimal(column))
}

override def asCql(value: BigDecimal): String = value.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class AlterQuery[
new AlterQuery(table, QueryBuilder.Alter.dropTable(table.tableName, keySpace.name), options)
}

final def dropIfExists()(implicit keySpace: KeySpace): AlterQuery[Table, Record, Status, Chain] = {
new AlterQuery(table, QueryBuilder.Alter.dropTableIfExist(table.tableName, keySpace.name), options)
}

/**
* Creates an ALTER drop query to drop the column from the schema definition.
* It will produce the following type of queries, with the CQL serialization on the right hand side:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ object CreateQuery {

private[phantom] trait CreateImplicits extends TablePropertyClauses {

val Cache = CacheStrategies
val Cache = Caching

implicit def rootCreateQueryToCreateQuery[
T <: CassandraTable[T, _],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ sealed trait CompactionStrategies {
extends CompactionProperties[LeveledCompactionStrategy](qb) {

def sstable_size_in_mb(unit: StorageUnit): LeveledCompactionStrategy = {
new LeveledCompactionStrategy(QueryBuilder.Create.sstable_size_in_mb(qb, unit.inMegabytes.toString))
new LeveledCompactionStrategy(
QueryBuilder.Create.sstable_size_in_mb(qb, unit.inMegabytes.toString)
)
}

override protected[this] def instance(qb: CQLQuery): LeveledCompactionStrategy = {
Expand Down Expand Up @@ -186,13 +188,23 @@ sealed trait CompressionStrategies {
case object DeflateCompressor extends CompressionStrategy(strategy(CQLSyntax.CompressionStrategies.DeflateCompressor))
}

sealed class CacheProperty(val qb: CQLQuery)
sealed abstract class CacheProperty(override val qb: CQLQuery) extends TablePropertyClause(qb)

sealed trait CachingStrategies {
private[this] def caching(strategy: String) = {
CQLQuery(CQLSyntax.Symbols.`{`).forcePad
.appendSingleQuote(CQLSyntax.CacheStrategies.Caching)
.forcePad.append(CQLSyntax.Symbols.`:`)
.forcePad.appendSingleQuote(strategy)
}

object CacheStrategies {
case object None extends CacheProperty(CQLQuery(CQLSyntax.CacheStrategies.None))
case object KeysOnly extends CacheProperty(CQLQuery(CQLSyntax.CacheStrategies.KeysOnly))
case object RowsOnly extends CacheProperty(CQLQuery(CQLSyntax.CacheStrategies.RowsOnly))
case object All extends CacheProperty(CQLQuery(CQLSyntax.CacheStrategies.All))
}

object Caching extends CachingStrategies

/**
* A root implementation trait of a CQL table option.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ private[phantom] trait AlterQueryBuilder {
.forcePad.append(QueryBuilder.keyspace(keyspace, table))
}

def dropTableIfExist(table: String, keyspace: String): CQLQuery = {
CQLQuery(CQLSyntax.Alter.Drop)
.forcePad.append(CQLSyntax.table)
.forcePad.append(CQLSyntax.ifExists)
.forcePad.append(QueryBuilder.keyspace(keyspace, table))
}


def alter(tableName: String): CQLQuery = {
CQLQuery(CQLSyntax.alter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ private[builder] class SelectQueryBuilder {
* @return
*/
def distinct(tableName: String, keyspace: String, names: String*): CQLQuery = {
val cols = if (names.nonEmpty) CQLQuery(names) else CQLQuery(CQLSyntax.Symbols.`*`)

CQLQuery(CQLSyntax.select)
.forcePad.append(CQLSyntax.distinct)
.pad.append(names)
.forcePad.append(cols)
.forcePad.append(CQLSyntax.from)
.forcePad.append(QueryBuilder.keyspace(keyspace, tableName))
}
Expand All @@ -179,7 +181,7 @@ private[builder] class SelectQueryBuilder {
* @param clause The CQL clause to use as the select list value.
* @return
*/
def select(tableName: String, keyspace: String, clause: CQLQuery) = {
def select(tableName: String, keyspace: String, clause: CQLQuery): CQLQuery = {
CQLQuery(CQLSyntax.select)
.pad.append(clause)
.pad.append(CQLSyntax.from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ object CQLSyntax {
}

object CacheStrategies {
val Caching = "caching"
val None = "none"
val KeysOnly = "keys_only"
val RowsOnly = "rows_only"
val All = "all"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ package object dsl extends ImplicitMechanism with CreateImplicits
type BooleanColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.PrimitiveColumn[Owner, Record, Boolean]
type DateColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.DateColumn[Owner, Record]
type DateTimeColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.DateTimeColumn[Owner, Record]
type LocalDateColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.LocalDateColumn[Owner, Record]
type DoubleColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.PrimitiveColumn[Owner, Record, Double]
type FloatColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.PrimitiveColumn[Owner, Record, Float]
type IntColumn[Owner <: CassandraTable[Owner, Record], Record] = com.websudos.phantom.column.PrimitiveColumn[Owner, Record, Int]
Expand Down
Loading

0 comments on commit 218c1a7

Please sign in to comment.