Skip to content
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

Fl01 #9

Merged
merged 6 commits into from
Oct 23, 2019
Merged

Fl01 #9

merged 6 commits into from
Oct 23, 2019

Conversation

f-lombardo
Copy link
Contributor

Implementing methods for DB access

Copy link
Contributor

@ftomassetti ftomassetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the PR is not obvious to me, but the description in the first comment helps. I am not familiar with this part of the codebase, so I am not sure I can yet provide good insights.

Beside minor comments and hints it looks good to me.

return if (result.matches(lastKey)) {
result
} else {
resultSet?.last()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this acceptable to have a null resultSet here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment filterRecord is called just when resultSet is not null, but, as I think it could be used elsewhere, I think we can have a "relaxed" behaviour. The idea is "in case you have an open resultset, just set on EOF, if you don't have it, EOF is already on". Do you think it wolud be better to encapsulate this in a fun with a speaking name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure as I do not know the context very well, but if you would be "surprised" if resultSet is actually null then I would write resultSet!!.last() and if later you confirm it can be relaxed then I would change it back

@@ -4,12 +4,13 @@ import com.smeup.rpgparser.interpreter.DBFile
import com.smeup.rpgparser.interpreter.Field
import com.smeup.rpgparser.interpreter.Record
import com.smeup.rpgparser.interpreter.Value
import java.lang.RuntimeException
import java.sql.Connection
import java.sql.ResultSet

class DBSQLFile(private val name: String, private val connection: Connection) : DBFile {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given I am not familiar with this part of the code I looked into DBFile. Depending on the background of other contributors what DBFile does could be not obvious and we may want to add a few comments

import java.sql.Connection
import java.sql.ResultSet

class DBSQLFile(private val name: String, private val connection: Connection) : DBFile {
private var resultSet: ResultSet? = null
private var lastKey: List<Field> = emptyList()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this specific for the readEqual? Or will this be updated by multiple operations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The answer is "Since I'm learning RPG while creating the interpreter, I don't really know" :-)
Should we write the code differently depending on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, just maybe a more specific name like readEqualLastKey

@@ -19,7 +20,7 @@ class DBSQLFile(private val name: String, private val connection: Connection) :
if (resultSet == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use require here. I personally find it more obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!

return chain(toFields(key))
}

private fun toFields(keyValue: Value): List<Field> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me what this function does. Probably because I am not familiar with this portion of the codebase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A chain operation (lookup a record in a table) can be perfomed using one or more keys. So we have to transform a value (e.g. "ABC") in a Field (i.e. "PART_NUMBER"->"ABC") and then encapsulate it in a list. Do you have any suggestion in order to make the code more clear?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me is not clear what a Field is in this context. Is it a data structure field? In your example is "PART_NUMBER" the name of the field used as a key and is "ABC" the actual value of the field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the term Field makes me think to the data structure fields, while these are different fields, right? Perhaps we could have a more specific name to make this more obvious

add(it)
}
}
fun matches(keyFields: List<Field>): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a newline before matches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}
}
fun matches(keyFields: List<Field>): Boolean {
return keyFields.all { this[it.name] == it.value }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the body is an expression you could rewrite it using the shortcut with the equals:

fun matches(keyFields: List<Field>) = keyFields.all { this[it.name] == it.value }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

assertEquals(DecimalValue(bigDecimalValue), chainedRecord[1].value)
val fieldsIterator = chainedRecord.iterator()
assertEquals(StringValue("XXX"), fieldsIterator.next().value)
assertEquals(DecimalValue(bigDecimalValue), fieldsIterator.next().value)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would add a newline at the end of the file

)
assertFalse(record.matches((keyFieldsKO)))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a newline here

@f-lombardo f-lombardo merged commit 80c3888 into master Oct 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants