Remove unused variables, redundant code, and commented out code.
Create a function if the same code is used in more than one place, thus avoiding duplicate code.
Working with IntelliJ is highly recommended, as it provides features like code completion, code refactoring, and code debugging. For example, points 1 & 2 mentioned above will appear as warnings, allowing you to fix them and improve your code quality.
Close all your resources: If your code implements auto closable, you can wrap it with try(). If this does not work, you should make sure you close it in the ‘finally’ block. Examples:
ResultSetWrapper --> close all result sets in the 'finally' block.
ludb().fetch --> Either wrap this command with the resource try (), or use ludb().fetch().each .
ludb().fetch("select val from root", null).firstValue() --> No need to close this, as it’s closed internally.
Db.Row rs = ludb().fetch("select * from root", null).firstRow() --> No need to close this, as it’s closed internally.
NOTE: It is recommended to change all DBQuery instances to ludb().fetch or db().fetch
Validate null values before executing a function on the given parameter. Example:
if (x != null)
x.substring(1);
Compare the constant to the parameter to avoid a NullPointerException. Example:
"CUSTOMER".equals (i_TableName)
String concatenation:
Avoid applying redundant casting. Examples:
Casting an object to long type and then using “+” to concatenate it to the SQL query is redundant.
Fabric alters all database sessions to use a uniform date format, and the default date field format is: yyyy-MM-dd HH:mm:ss (this default can be changed in the config.ini file). If it is not needed, do not use casting when extracting a date field from the source.
If date casting is mandatory, make sure the dates being compared use the same format.
Prepare & Binding:
Use Non-Bind variables in an SQL statement only when the values are constant values.
In any other case, use Prepare and send the values as parameters to the SQL statement.
NOTE: In Fabric 6.0 and above, there is no need to create a new Object[] to pass parameters to start binding.
Use binding for a get command as well.
Parameter definition:
Avoid setting unused parameters.
Always define the parameters outside of a loop.
When selecting one value:
Use ludb.fetch () with a loop.
In Fabric 5.4 and below, use DBSelectValue instead of DBSelectQuery and a loop.
Add catch to a try statement - Your process will not fail unless you throw the exception inside the catch block.
log.info should only be used for debugging. Remove these functions from your code before an actual production deployment.
It is recommended to combine two lists when possible. To do so, use the Java function: myListObject.addAll Do not use it for a loop.
Always perform Unit Testing for your code!
Remove unused variables, redundant code, and commented out code.
Create a function if the same code is used in more than one place, thus avoiding duplicate code.
Working with IntelliJ is highly recommended, as it provides features like code completion, code refactoring, and code debugging. For example, points 1 & 2 mentioned above will appear as warnings, allowing you to fix them and improve your code quality.
Close all your resources: If your code implements auto closable, you can wrap it with try(). If this does not work, you should make sure you close it in the ‘finally’ block. Examples:
ResultSetWrapper --> close all result sets in the 'finally' block.
ludb().fetch --> Either wrap this command with the resource try (), or use ludb().fetch().each .
ludb().fetch("select val from root", null).firstValue() --> No need to close this, as it’s closed internally.
Db.Row rs = ludb().fetch("select * from root", null).firstRow() --> No need to close this, as it’s closed internally.
NOTE: It is recommended to change all DBQuery instances to ludb().fetch or db().fetch
Validate null values before executing a function on the given parameter. Example:
if (x != null)
x.substring(1);
Compare the constant to the parameter to avoid a NullPointerException. Example:
"CUSTOMER".equals (i_TableName)
String concatenation:
Avoid applying redundant casting. Examples:
Casting an object to long type and then using “+” to concatenate it to the SQL query is redundant.
Fabric alters all database sessions to use a uniform date format, and the default date field format is: yyyy-MM-dd HH:mm:ss (this default can be changed in the config.ini file). If it is not needed, do not use casting when extracting a date field from the source.
If date casting is mandatory, make sure the dates being compared use the same format.
Prepare & Binding:
Use Non-Bind variables in an SQL statement only when the values are constant values.
In any other case, use Prepare and send the values as parameters to the SQL statement.
NOTE: In Fabric 6.0 and above, there is no need to create a new Object[] to pass parameters to start binding.
Use binding for a get command as well.
Parameter definition:
Avoid setting unused parameters.
Always define the parameters outside of a loop.
When selecting one value:
Use ludb.fetch () with a loop.
In Fabric 5.4 and below, use DBSelectValue instead of DBSelectQuery and a loop.
Add catch to a try statement - Your process will not fail unless you throw the exception inside the catch block.
log.info should only be used for debugging. Remove these functions from your code before an actual production deployment.
It is recommended to combine two lists when possible. To do so, use the Java function: myListObject.addAll Do not use it for a loop.
Always perform Unit Testing for your code!