scray.loader.configuration.scrayJDBCStores.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scray-loader Show documentation
Show all versions of scray-loader Show documentation
Loads and starts a scray query service
// See the LICENCE.txt file distributed with this work for additional
// information regarding copyright ownership.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package scray.loader.configuration
import com.twitter.util.Try
import scala.util.{Try => STry}
import scray.common.properties.predefined.PredefinedProperties
import scray.common.properties.ScrayProperties
import com.datastax.driver.core.policies.Policies
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy
import com.datastax.driver.core.policies.TokenAwarePolicy
import scray.common.tools.ScrayCredentials
import scray.loader.configparser.ReadableConfig
import scala.collection.convert.decorateAsScala.asScalaSetConverter
import scray.loader.configparser.ScrayConfiguration
import scray.querying.sync.DbSession
/**
* JDBC properties, needed to setup a JDBC connection
*/
case class JDBCProperties(url: String,
credentials: ScrayCredentials = new ScrayCredentials(),
name: Option[String] = None) extends DBMSConfigProperties {
override def getName: String = name.getOrElse("jdbc")
override def setName(newName: Option[String]): DBMSConfigProperties = this.copy(name = newName)
}
trait JDBCProperty
case class JDBCURLProperty(url: String) extends JDBCProperty
case class JDBCCredentialsProperty(credentials: ScrayCredentials) extends JDBCProperty
/**
* sets up and manages a Cassandra Cluster
*/
class JDBCConfiguration(override protected val startconfig: JDBCProperties)
extends DBMSConfiguration[JDBCProperties](startconfig) {
var currentURL: Option[String] = None
override def performUpdateTasks(): Unit = {
// TODO: examine what tasks need to be done for JDBC...
}
override def getSession: DbSession[_, _, _] = {
// TODO: next line is bullshit
new DbSession[Int, String, String]("") {
override def execute(statement: Int): STry[String] = STry("")
override def execute(statement: String): STry[String] = STry("")
override def insert(statement: String): STry[String] = STry("")
}
}
override def readConfig(config: ScrayConfiguration, old: JDBCProperties): Option[JDBCProperties] =
JDBCConfiguration.readConfig(config, old)
}
object JDBCConfiguration extends ReadableConfig[JDBCProperties] {
override def readConfig(config: ScrayConfiguration, old: JDBCProperties): Option[JDBCProperties] =
config.stores.find { storecf => storecf.getName == old.getName }.flatMap {
case jdbc: JDBCProperties => Some(jdbc)
case _ => None
}
}