-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDBHelper.groovy
46 lines (32 loc) · 1.29 KB
/
DBHelper.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import org.sqlite.*
import java.sql.*
class DBHelper {
def static setupDB(workingDir){
def dbFile = new File(workingDir, "stats.db")
boolean dbExists = dbFile.exists()
// in memory
// db = groovy.sql.Sql.newInstance("jdbc:sqlite::memory:","org.sqlite.JDBC")
// persitent
def db = groovy.sql.Sql.newInstance("jdbc:sqlite:"+dbFile.absolutePath,"org.sqlite.JDBC")
if(!dbExists){
db.execute("create table jenkins(instanceid, month, version)")
db.execute("create table plugin(instanceid, month, name, version)")
db.execute("create table job(instanceid, month, type, jobnumber)")
db.execute("create table node(instanceid, month, osname, nodenumber)")
db.execute("create table executor(instanceid, month, numberofexecutors)")
db.execute("create table importedfile(name)")
}
return db;
}
/**
* is the file with the given name already imported?
*/
static boolean doImport(db, fileName){
if(db){
def filePrefix = fileName.substring(0, fileName.indexOf("."))+"%"
def rows = db.rows("select name from importedfile where name like $filePrefix;")
return rows.size() == 0
}
true
}
}