Skip to content

Commit

Permalink
Kotlin update for JAVA version. Not very well tested yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Aug 24, 2017
1 parent 2971013 commit 58fe3f5
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 641 deletions.
10 changes: 10 additions & 0 deletions java/.idea/dictionaries/romanov.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions java/.idea/libraries/KotlinJavaRuntime.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions java/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

892 changes: 397 additions & 495 deletions java/.idea/workspace.xml

Large diffs are not rendered by default.

Binary file removed java/lib/kotlin-runtime-sources.jar
Binary file not shown.
Binary file removed java/lib/kotlin-runtime.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion java/src/javaExamples/SimpleExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class SimpleExample {

public static void main(String [ ] args){
JDBCProvider provider = CcdbPackage.createProvider("mysql://localhost") ;
JDBCProvider provider = CcdbPackage.createProvider("mysql://ccdb_test@localhost/test_ccdb") ;
provider.connect();

//to check the table exists
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/ccdb/CCDB.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:JvmName("CcdbPackage")

package org.jlab.ccdb

import org.jlab.ccdb.JDBCProvider
Expand Down
8 changes: 5 additions & 3 deletions java/src/org/ccdb/JDBCProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ open public class JDBCProvider(public val connectionString: String) {
*
* @remark this directory is not stored in database
*/
public val rootDir: Directory = Directory(0, 0, "", Date(0), Date(0), "root directory"); {
rootDir.fullPath = "/"
}
public val rootDir: Directory = Directory(0, 0, "", Date(0), Date(0), "root directory")

/**
* Collect statistics of getData function
Expand All @@ -86,6 +84,10 @@ open public class JDBCProvider(public val connectionString: String) {
return !(connection?.isClosed() ?: true)
}

init {
this.rootDir.fullPath = "/"
}


/**
* Connects to database using connection string
Expand Down
96 changes: 44 additions & 52 deletions java/src/org/ccdb/MySqlProvider.kt
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
/**
* Created by Dmitry on 4/15/2014.
*/
package org.jlab.ccdb

import java.sql.DriverManager
import java.sql.Connection
import java.sql.DriverManager
import java.sql.Connection

import org.jlab.ccdb.JDBCProvider
import org.jlab.ccdb.JDBCProvider


public class MySqlProvider(connectionString:String): JDBCProvider(connectionString) {
public class MySqlProvider(connectionString: String) : JDBCProvider(connectionString) {

override fun connect()
{
// load the sqlite-JDBC driver using the current class loader
Class.forName("com.mysql.jdbc.Driver");
override fun connect() {
// load the sqlite-JDBC driver using the current class loader
Class.forName("com.mysql.jdbc.Driver");

//first check for uri type
val typePos = connectionString.indexOf("mysql://")
if(typePos != 0){
throw IllegalArgumentException("Connection string doesn't start with mysql:// but is given to MySqlProvider")
}
//first check for uri type
val typePos = connectionString.indexOf("mysql://")
if (typePos != 0) {
throw IllegalArgumentException("Connection string doesn't start with mysql:// but is given to MySqlProvider")
}

//ok we don't need mysql:// in the future. Moreover it will mess our separation logic
var workStr = connectionString.substring(8)
var userName = "ccdb_user"
var password = ""
//ok we don't need mysql:// in the future. Moreover it will mess our separation logic
var workStr = connectionString.substring(8)
var userName = "ccdb_user"
var password = ""

//then if there is '@' that separates login/password part of uri
val atPos = workStr.indexOf('@')
//then if there is '@' that separates login/password part of uri
val atPos = workStr.indexOf('@')

if(atPos != -1)
{
var logPassStr:String
when(atPos){
if (atPos != -1) {
var logPassStr: String
when (atPos) {
(workStr.length - 1) -> {
//it is like 'login:pwd@' string
logPassStr = workStr.substring(0,atPos)
logPassStr = workStr.substring(0, atPos)
workStr = ""
}
0 -> {
Expand All @@ -46,55 +41,52 @@ package org.jlab.ccdb
}
else -> {
//a regular case
logPassStr = workStr.substring(0,atPos);
workStr = workStr.substring(atPos+1);
logPassStr = workStr.substring(0, atPos);
workStr = workStr.substring(atPos + 1);
}
}

//is it only login or login&&password?
var colonPos = logPassStr.indexOf(':');
if(colonPos!=-1)
{
userName = logPassStr.substring(0,colonPos)
password = logPassStr.substring(colonPos+1)
}
else
{
if (colonPos != -1) {
userName = logPassStr.substring(0, colonPos)
password = logPassStr.substring(colonPos + 1)
} else {
userName = logPassStr
}
}

//ok, now we have only "address:port/database" part of the string
//if we doesn't have /<database> we have to add it
val host = "jdbc:mysql://" +
if(workStr.indexOf('/') == -1) workStr + "/ccdb" else workStr
if (workStr.indexOf('/') == -1) workStr + "/ccdb" else workStr

//Connect to through JDBC
connectJDBC(host, userName, password)
}

private fun connectJDBC(host:String, userName:String, password:String){
private fun connectJDBC(host: String, userName: String, password: String) {
connection = DriverManager.getConnection(host, userName, password)

val con:Connection = connection!!
val con: Connection = connection!!

prsDirectories = con.prepareStatement("SELECT id, parentId, name, created, modified, comment FROM directories");
prsVariationById = con.prepareStatement("SELECT id, parentId, name FROM variations WHERE id = ?")
prsVariationByName = con.prepareStatement("SELECT id, parentId, name FROM variations WHERE name = ?")
//ok now we must build our mighty query...
val dataQuery=
"SELECT `assignments`.`id` AS `asId`, "+
"`constantSets`.`vault` AS `blob`, "+
"`assignments`.`modified` as `asModified`"+
"FROM `assignments` "+
"USE INDEX (id_UNIQUE) "+
"INNER JOIN `runRanges` ON `assignments`.`runRangeId`= `runRanges`.`id` "+
"INNER JOIN `constantSets` ON `assignments`.`constantSetId` = `constantSets`.`id` "+
"INNER JOIN `typeTables` ON `constantSets`.`constantTypeId` = `typeTables`.`id` "+
"WHERE `runRanges`.`runMin` <= ? "+
"AND `runRanges`.`runMax` >= ? "+
"AND `assignments`.`variationId`= ? "+
"AND `constantSets`.`constantTypeId` = ? "
val dataQuery =
"SELECT `assignments`.`id` AS `asId`, " +
"`constantSets`.`vault` AS `blob`, " +
"`assignments`.`modified` as `asModified`" +
"FROM `assignments` " +
"USE INDEX (id_UNIQUE) " +
"INNER JOIN `runRanges` ON `assignments`.`runRangeId`= `runRanges`.`id` " +
"INNER JOIN `constantSets` ON `assignments`.`constantSetId` = `constantSets`.`id` " +
"INNER JOIN `typeTables` ON `constantSets`.`constantTypeId` = `typeTables`.`id` " +
"WHERE `runRanges`.`runMin` <= ? " +
"AND `runRanges`.`runMax` >= ? " +
"AND `assignments`.`variationId`= ? " +
"AND `constantSets`.`constantTypeId` = ? "

val timeConstrain = "AND UNIX_TIMESTAMP(`assignments`.`created`) <= ? "
val orderBy = "ORDER BY `assignments`.`id` DESC LIMIT 1 "
Expand Down
18 changes: 9 additions & 9 deletions java/src/org/ccdb/PathUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fun extractDirectory(path: String): String {
*/
fun extractObjectname(path: String): String {
val index = path.lastIndexOf("/")
if (index < 0 || index == path.size - 1) return ""
if (index < 0 || index == path.length - 1) return ""
return path.substring(index + 1)
}

Expand Down Expand Up @@ -142,7 +142,7 @@ fun parseTime(timeStr: String): Date {
var lastIsDigit = false // last symbol was digit

//scan all symbols
for (i in 0..(workStr.size - 1)) {
for (i in 0..(workStr.length - 1)) {
val symbol = workStr[i]


Expand All @@ -156,7 +156,7 @@ fun parseTime(timeStr: String): Date {
delimCount++
if (delimCount == 1) //it was a year
{
if (tmpStr.size != 4) //it is an error with length
if (tmpStr.length != 4) //it is an error with length
{
throw IllegalArgumentException("Year should be in form YYYY but given is '$tmpStr'. Overall date should be in form 'YYYY/MM/dd hh:mm:ss'")
}
Expand All @@ -166,7 +166,7 @@ fun parseTime(timeStr: String): Date {

if (delimCount == 2) //it was a month
{
if (tmpStr.size != 2) //it is an error with length
if (tmpStr.length != 2) //it is an error with length
{
throw IllegalArgumentException("Month should be in form 'MM' but given is '$tmpStr'. Overall date should be in form 'YYYY/MM/dd hh:mm:ss'")
}
Expand All @@ -192,7 +192,7 @@ fun parseTime(timeStr: String): Date {
if (delimCount == 3) //it was a day
{

if (tmpStr.size != 2) //it is an error with length
if (tmpStr.length != 2) //it is an error with length
{
throw IllegalArgumentException("Day should be in form 'dd' but given is '$tmpStr'. Overall date should be in form 'YYYY/MM/dd hh:mm:ss'")
}
Expand All @@ -201,7 +201,7 @@ fun parseTime(timeStr: String): Date {

if (delimCount == 4) //it was a hour
{
if (tmpStr.size != 2) //it is an error with length
if (tmpStr.length != 2) //it is an error with length
{
throw IllegalArgumentException("Hour should be in form 'hh' but given is '$tmpStr'." +
"Overall date should be in form 'YYYY/MM/dd hh:mm:ss'")
Expand All @@ -212,7 +212,7 @@ fun parseTime(timeStr: String): Date {

if (delimCount == 5) //it is a minutes
{
if (tmpStr.size != 2) //it is an error with length
if (tmpStr.length != 2) //it is an error with length
{
throw IllegalArgumentException("Minutes should be in form 'mm' but given is '$tmpStr'." +
"Overall date should be in form 'YYYY/MM/dd hh:mm:ss'")
Expand All @@ -223,7 +223,7 @@ fun parseTime(timeStr: String): Date {

if (delimCount == 6) //it is seconds
{
if (tmpStr.size != 2) //it is an error with length
if (tmpStr.length != 2) //it is an error with length
{
throw IllegalArgumentException("Seconds should be in form 'ss' but given is '$tmpStr'." +
"Overall date should be in form 'YYYY/MM/dd hh:mm:ss'")
Expand Down Expand Up @@ -259,7 +259,7 @@ fun parseRequest( requestStr:String ): RequestParseResult{
val result = RequestParseResult(requestStr)
var colonCount = 0
var runStr = ""
for (i in 0..(requestStr.size-1)) {
for (i in 0..(requestStr.length-1)) {
val symbol = requestStr[i]
if (symbol != ':') {
//it is not a colon so we add this symbol somewhere
Expand Down
Loading

0 comments on commit 58fe3f5

Please sign in to comment.