Skip to content

Commit cff0bb6

Browse files
#34: Rename wrongly named packages (#42)
* renamed package `naming_conventions` to `naming` and reorganized the files within * renamed package `statushandling` to `status` and reorganized the files within * renamed `DBSeqFunction` to `DBMultipleResultFunction` * renamed `DBUniqueFunction` to `DBSingleResultFunction` * renamed `DBOptionFunction` to `DBOptionalResultFunction` * renamed the execution methods within `DBFunction` to match the above successor names --------- Co-authored-by: miroslavpojer <[email protected]>
1 parent 42e8448 commit cff0bb6

File tree

26 files changed

+86
-67
lines changed

26 files changed

+86
-67
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ___
1212
<!-- toc -->
1313
- [What is fa-db](#what-is-fa-db)
1414
- [Usage](#usage)
15+
- [Concepts](#concepts)
1516
- [How to generate code coverage report](#how-to-generate-code-coverage-report)
1617
- [How to Release](#how-to-release)
1718
<!-- tocstop -->
@@ -98,7 +99,13 @@ Modules:
9899
</dependency>
99100
```
100101

101-
### How to generate code coverage report
102+
## Concepts
103+
104+
### Status codes
105+
106+
Text about status codes returned from the database function can be found [here](core/src/main/scala/za/co/absa/fadb/status/README.md).
107+
108+
## How to generate code coverage report
102109
```sbt
103110
sbt jacoco
104111
```

core/src/main/scala/za/co/absa/fadb/DBEngine.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ trait DBEngine {
4646
* @tparam R - return the of the query
4747
* @return - sequence of the results of database query
4848
*/
49-
def execute[R](query: QueryType[R]): Future[Seq[R]] = run(query)
49+
def fetchAll[R](query: QueryType[R]): Future[Seq[R]] = run(query)
5050

5151
/**
5252
* Public method to execute when query is expected to return exactly one row
5353
* @param query - the query to execute
5454
* @tparam R - return the of the query
5555
* @return - sequence of the results of database query
5656
*/
57-
def unique[R](query: QueryType[R]): Future[R] = {
57+
def fetchHead[R](query: QueryType[R]): Future[R] = {
5858
run(query).map(_.head)
5959
}
6060

@@ -65,7 +65,7 @@ trait DBEngine {
6565
* @return - sequence of the results of database query
6666
*/
6767

68-
def option[R](query: QueryType[R]): Future[Option[R]] = {
68+
def fetchHeadOption[R](query: QueryType[R]): Future[Option[R]] = {
6969
run(query).map(_.headOption)
7070
}
7171
}

core/src/main/scala/za/co/absa/fadb/DBFunction.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package za.co.absa.fadb
1818

19-
import za.co.absa.fadb.naming_conventions.NamingConvention
20-
19+
import za.co.absa.fadb.naming.NamingConvention
2120
import scala.concurrent.Future
2221

2322
/**
@@ -85,9 +84,9 @@ abstract class DBFunction[I, R, E <: DBEngine](functionNameOverride: Option[Stri
8584
override protected def fieldsToSelect: Seq[String] = super.fieldsToSelect //TODO should get the names from R #6
8685

8786
/*these 3 functions has to be defined here and not in the ancestors, as there the query type is not compatible - path-dependent types*/
88-
protected def execute(values: I): Future[Seq[R]] = dBEngine.execute[R](query(values))
89-
protected def unique(values: I): Future[R] = dBEngine.unique(query(values))
90-
protected def option(values: I): Future[Option[R]] = dBEngine.option(query(values))
87+
protected def multipleResults(values: I): Future[Seq[R]] = dBEngine.fetchAll(query(values))
88+
protected def singleResult(values: I): Future[R] = dBEngine.fetchHead(query(values))
89+
protected def optionalResult(values: I): Future[Option[R]] = dBEngine.fetchHeadOption(query(values))
9190

9291
}
9392

@@ -103,8 +102,8 @@ object DBFunction {
103102
* @tparam R - the type covering the returned fields from the database function
104103
* @tparam E - the type of the [[DBEngine]] engine
105104
*/
106-
abstract class DBSeqFunction[I, R, E <: DBEngine](functionNameOverride: Option[String] = None)
107-
(implicit schema: DBSchema, dBEngine: E)
105+
abstract class DBMultipleResultFunction[I, R, E <: DBEngine](functionNameOverride: Option[String] = None)
106+
(implicit schema: DBSchema, dBEngine: E)
108107
extends DBFunction[I, R, E](functionNameOverride) {
109108

110109
def this(schema: DBSchema, functionNameOverride: String)
@@ -133,7 +132,7 @@ object DBFunction {
133132
* @return - a sequence of values, each coming from a row returned from the DB function transformed to scala
134133
* type `R`
135134
*/
136-
def apply(values: I): Future[Seq[R]] = execute(values)
135+
def apply(values: I): Future[Seq[R]] = multipleResults(values)
137136
}
138137

139138
/**
@@ -147,8 +146,8 @@ object DBFunction {
147146
* @tparam R - the type covering the returned fields from the database function
148147
* @tparam E - the type of the [[DBEngine]] engine
149148
*/
150-
abstract class DBUniqueFunction[I, R, E <: DBEngine](functionNameOverride: Option[String] = None)
151-
(implicit schema: DBSchema, dBEngine: E)
149+
abstract class DBSingleResultFunction[I, R, E <: DBEngine](functionNameOverride: Option[String] = None)
150+
(implicit schema: DBSchema, dBEngine: E)
152151
extends DBFunction[I, R, E](functionNameOverride) {
153152

154153
def this(schema: DBSchema, functionNameOverride: String)
@@ -176,7 +175,7 @@ object DBFunction {
176175
* @param values - the values to pass over to the database function
177176
* @return - the value returned from the DB function transformed to scala type `R`
178177
*/
179-
def apply(values: I): Future[R] = unique(values)
178+
def apply(values: I): Future[R] = singleResult(values)
180179
}
181180

182181
/**
@@ -190,8 +189,8 @@ object DBFunction {
190189
* @tparam R - the type covering the returned fields from the database function
191190
* @tparam E - the type of the [[DBEngine]] engine
192191
*/
193-
abstract class DBOptionFunction[I, R, E <: DBEngine](functionNameOverride: Option[String] = None)
194-
(implicit schema: DBSchema, dBEngine: E)
192+
abstract class DBOptionalResultFunction[I, R, E <: DBEngine](functionNameOverride: Option[String] = None)
193+
(implicit schema: DBSchema, dBEngine: E)
195194
extends DBFunction[I, R, E](functionNameOverride) {
196195

197196
def this(schema: DBSchema, functionNameOverride: String)
@@ -219,6 +218,6 @@ object DBFunction {
219218
* @param values - the values to pass over to the database function
220219
* @return - the value returned from the DB function transformed to scala type `R` if a row is returned, otherwise `None`
221220
*/
222-
def apply(values: I): Future[Option[R]] = option(values)
221+
def apply(values: I): Future[Option[R]] = optionalResult(values)
223222
}
224223
}

core/src/main/scala/za/co/absa/fadb/DBSchema.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package za.co.absa.fadb
1818

19-
import za.co.absa.fadb.naming_conventions.NamingConvention
19+
import za.co.absa.fadb.naming.NamingConvention
2020

2121
/**
2222
* An abstract class, an ancestor to represent a database schema (each database function should be placed in a schema)
@@ -25,7 +25,7 @@ import za.co.absa.fadb.naming_conventions.NamingConvention
2525
* possibility of override
2626
* @param dBEngine - [[DBEngine]] to execute the functions with. Not directly needed for the DBSchema class, rather
2727
* to be passed on to [[DBFunction]] members of the schema
28-
* @param namingConvention - the [[za.co.absa.fadb.naming_conventions.NamingConvention NamingConvention]] prescribing how to convert a class name into a db object name
28+
* @param namingConvention - the [[za.co.absa.fadb.naming.NamingConvention NamingConvention]] prescribing how to convert a class name into a db object name
2929
*/
3030
abstract class DBSchema(schemaNameOverride: Option[String] = None)
3131
(implicit dBEngine: DBEngine, implicit val namingConvention: NamingConvention) {
@@ -57,7 +57,7 @@ abstract class DBSchema(schemaNameOverride: Option[String] = None)
5757

5858
/**
5959
* Function to convert a class to the associated DB object name, based on the class' name. For transformation from the
60-
* class name to usual db name the schema's [[za.co.absa.fadb.naming_conventions.NamingConvention NamingConvention]] is used.
60+
* class name to usual db name the schema's [[za.co.absa.fadb.naming.NamingConvention NamingConvention]] is used.
6161
* @param c - class which name to use to get the DB object name
6262
* @return - the db object name
6363
*/

core/src/main/scala/za/co/absa/fadb/naming_conventions/ExplicitNamingRequired.scala renamed to core/src/main/scala/za/co/absa/fadb/naming/ExplicitNamingRequired.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package za.co.absa.fadb.naming_conventions
17+
package za.co.absa.fadb.naming
1818

1919
import za.co.absa.fadb.exceptions.NamingException
2020

core/src/main/scala/za/co/absa/fadb/naming_conventions/letters_case/LettersCase.scala renamed to core/src/main/scala/za/co/absa/fadb/naming/LettersCase.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package za.co.absa.fadb.naming_conventions.letters_case
17+
package za.co.absa.fadb.naming
1818

1919
sealed trait LettersCase {
2020
def convert(s: String): String

core/src/main/scala/za/co/absa/fadb/naming_conventions/NamingConvention.scala renamed to core/src/main/scala/za/co/absa/fadb/naming/NamingConvention.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package za.co.absa.fadb.naming_conventions
17+
package za.co.absa.fadb.naming
1818

1919
trait NamingConvention {
2020
def fromClassNamePerConvention(c: Class[_]): String = {

core/src/main/scala/za/co/absa/fadb/naming_conventions/AsIsNaming.scala renamed to core/src/main/scala/za/co/absa/fadb/naming/implementations/AsIsNaming.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package za.co.absa.fadb.naming_conventions
17+
package za.co.absa.fadb.naming.implementations
1818

19-
import za.co.absa.fadb.naming_conventions.letters_case.LettersCase
20-
import za.co.absa.fadb.naming_conventions.letters_case.LettersCase.AsIs
19+
import za.co.absa.fadb.naming.{LettersCase, NamingConvention}
20+
import LettersCase.AsIs
2121

2222
class AsIsNaming(lettersCase: LettersCase) extends NamingConvention{
2323
override def stringPerConvention(original: String): String = {

core/src/main/scala/za/co/absa/fadb/naming_conventions/SnakeCaseNaming.scala renamed to core/src/main/scala/za/co/absa/fadb/naming/implementations/SnakeCaseNaming.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
package za.co.absa.fadb.naming_conventions
17+
package za.co.absa.fadb.naming.implementations
1818

19-
import za.co.absa.fadb.naming_conventions.letters_case.LettersCase
20-
import za.co.absa.fadb.naming_conventions.letters_case.LettersCase.LowerCase
19+
import za.co.absa.fadb.naming.{LettersCase, NamingConvention}
20+
import LettersCase.LowerCase
2121

2222
class SnakeCaseNaming(lettersCase: LettersCase) extends NamingConvention {
2323
private def camelCaseToSnakeCase(s: String): String = {

core/src/main/scala/za/co/absa/fadb/statushandling/FunctionStatus.scala renamed to core/src/main/scala/za/co/absa/fadb/status/FunctionStatus.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package za.co.absa.fadb.statushandling
17+
package za.co.absa.fadb.status
1818

1919
/**
2020
* Class represents the status of calling a fa-db function (if it supports status that is)

0 commit comments

Comments
 (0)