-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Java] Given a table name and run number, retrieve all variations for that table and run #39
Comments
CCDB JAVA Api under the hood works in this order:
private var variationsById = HashMap<Int, Variation>()
private var variationsByName = HashMap<String, Variation>() private var directoriesByFullPath = HashMap<String,Directory>()
private var directoriesById = HashMap<Int, Directory>()
private var directories = Vector<Directory>() So one can retrieve any variation or directory by Id or by name.
class Directory(
val id:Int, /// DB id
val parentId:Int, /// DB id of parent directory. Id=0 - root directory
val name:String, /// Name of the directory
var fullPath /// Full path (including self name) of the directory
var parentDirectory:Directory?=null /// null if there is no parent directory
var subdirectories = Vector<Directory>() /// List of subdirectories class Variation(
val id:Int, /// DB ID
val parentId:Int, /// DB of parent ID
val name:String /// Variation name
var parentVariation:Variation? = null /// Parent variation object
var children = Vector<Variation>() /// Children variations list
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` = ? The first part chooses what data to get SELECT `assignments`.`id` AS `asId`,
`constantSets`.`vault` AS `blob`,
`assignments`.`modified` as `asModified`
FROM `assignments` The middle part says how tables are connected INNER JOIN `runRanges` ON `assignments`.`runRangeId`= `runRanges`.`id`
INNER JOIN `constantSets` ON `assignments`.`constantSetId` = `constantSets`.`id`
INNER JOIN `typeTables` ON `constantSets`.`constantTypeId` = `typeTables`.`id` The last part is about how data is selected WHERE `runRanges`.`runMin` <= ?
AND `runRanges`.`runMax` >= ?
AND `assignments`.`variationId`= ?
AND `constantSets`.`constantTypeId` = ? There is also
first we need to select variations Ids. We use SELECT `assignments`.`variationId` AS `varId`
FROM `assignments` leaving middle section intact lets choose what we need to select the data. Here we need to put our run WHERE `runRanges`.`runMin` <= ?
AND `runRanges`.`runMax` >= ? Example: WHERE `runRanges`.`runMin` <= 1000
AND `runRanges`.`runMax` >= 1000 We don't need this restriction: AND `assignments`.`variationId`= ? Finally here we need Id of our directory AND `constantSets`.`constantTypeId` = 4 We get constantTypeId by loading the table by name: val typeTable = JDBCProvider.getTypeTable("/name/of/the/table")
val constantTypeId = typeTable.id Now we have everything to create the query:
SELECT DISTINCT
`assignments`.`variationId` AS `varId`
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` <= 1000
AND `runRanges`.`runMax` >= 1000
AND `constantSets`.`constantTypeId` = 1 One can run it on existing CCDB instance. Here 1000 is a run number. And 1 is a type table ID. Both are from CCDB test records. Since we selecting only variation ID's we use DISTINCT to get only unique IDs
|
Okay! Thank you very much. So basically everything can be done by manipulating and calling this mighty query? Also, just out of curiosity what do the ON and AS keywords do? I have only really used simple queries before in MySQL. |
Also, how would I sign into the CCDB using workbench? |
Yes, you can tweak this query a little bit to get all variations for the table (by removing runRanges filter) or selecting all runRanges (#38) by replacing
SELECT X,Y,Z ... usually language API allows you to get this values by ID or by order number: mysql.get("X"), mysql.get("Y") mysql.get(0) mysql.get(1). Sometimes you have a name collision and sometimes you just want to have simpler name. Basically with query above kotlin part looks like this: val result = prs.executeQuery()
//loop through results
while (result.next()) {
val variationId = result.getInt("varId") That is how
We use INNER JOIN `runRanges` ON `assignments`.`runRangeId`= `runRanges`.`id` ON here means that we select such run ranges that have the same ID as in In our case we want to select |
I believe on the home page of MySQL workbench you have an option to connect to DB. You can test use HallD DB for test purpuses. It doesn't have password and it is read only.
And just press all the buttons =) |
Oops typo. Sorry. The right address is |
No description provided.
The text was updated successfully, but these errors were encountered: