Skip to content

Commit

Permalink
fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Nov 26, 2024
1 parent 1bd5502 commit 17616b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@
Every database access using Exposed is started by obtaining a connection and creating a transaction.
To configure the database connection, use the <code>Database.connect()</code> function.
</p>
<p>
By default, Exposed using `ServiceLoader` to get `DatabaseConnectionAutoRegistration`.
It can be modified when calling `Database.connect` method by providing `connectionAutoRegistration` in parameter list.
</p>
<procedure id="config-db-connection-procedure">
<step>
<p>
Expand Down Expand Up @@ -254,6 +250,12 @@
but it does not immediately establish a connection with the database. The actual connection
to the database will be established later when a database operation is performed.
</note>
<note>
By default, Exposed uses a <code>ServiceLoader</code> to get an implementation of the <code>DatabaseConnectionAutoRegistration</code>
interface that represents a connection accessed by the <code>Database</code> instance.
This can be modified when calling the <code>Database.connect</code> method by providing an argument to <code>connectionAutoRegistration</code>
in the parameter list.
</note>
<p>
With this, you've added Exposed to your Kotlin project and configured a database connection.
You're now ready to define your data model and engage with the database using Exposed's DSL API.
Expand Down
18 changes: 11 additions & 7 deletions documentation-website/Writerside/topics/Working-with-Database.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Every database access using Exposed is started by obtaining a connection and cre
First of all, you have to tell Exposed how to connect to a database by using the `Database.connect` function.
It won't create a real database connection but will only provide a descriptor for future usage.

By default, Exposed using `ServiceLoader` to get `DatabaseConnectionAutoRegistration`.
It can be modified when calling `Database.connect` method by providing `connectionAutoRegistration` in parameter list.

A real connection will be instantiated later by calling the `transaction` lambda
(see [Transactions](Transactions.md) for more details).

Expand All @@ -27,13 +24,20 @@ val db = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")
<note>Executing this code more than once per database will create leaks in your application, hence it is recommended to store it for later use:
<code-block lang="kotlin">
object DbSettings {
val db by lazy {
Database.connect(/* setup connection */)
}
}
val db by lazy {
Database.connect(/* setup connection */)
}
}
</code-block>
</note>

<note>
By default, Exposed uses a <code>ServiceLoader</code> to get an implementation of the <code>DatabaseConnectionAutoRegistration</code>
interface that represents a connection accessed by the <code>Database</code> instance.
This can be modified when calling the <code>Database.connect</code> method by providing an argument to <code>connectionAutoRegistration</code>
in the parameter list.
</note>

### H2

In order to use H2, you need to add the H2 driver dependency:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class Database private constructor(
* but instead provides the details necessary to do so whenever a connection is required by a transaction.
*
* @param datasource The [DataSource] object to be used as a means of getting a connection.
* @param connectionAutoRegistration The connection provider for database. If not provided, will use ServiceLoaded [connectionInstanceImpl]
* @param connectionAutoRegistration The connection provider for database. If not provided,
* a service loader will be used to locate and load a provider for [DatabaseConnectionAutoRegistration].
* @param setupConnection Any setup that should be applied to each new connection.
* @param databaseConfig Configuration parameters for this [Database] instance.
* @param manager The [TransactionManager] responsible for new transactions that use this [Database] instance.
Expand Down Expand Up @@ -251,7 +252,8 @@ class Database private constructor(
* but instead provides the details necessary to do so whenever a connection is required by a transaction.
*
* @param getNewConnection A function that returns a new connection.
* @param connectionAutoRegistration The connection provider for database. If not provided, will use ServiceLoaded [connectionInstanceImpl]
* @param connectionAutoRegistration The connection provider for database. If not provided,
* a service loader will be used to locate and load a provider for [DatabaseConnectionAutoRegistration].
* @param databaseConfig Configuration parameters for this [Database] instance.
* @param manager The [TransactionManager] responsible for new transactions that use this [Database] instance.
*/
Expand All @@ -277,7 +279,8 @@ class Database private constructor(
* but instead provides the details necessary to do so whenever a connection is required by a transaction.
*
* @param url The URL that represents the database when getting a connection.
* @param connectionAutoRegistration The connection provider for database. If not provided, will use ServiceLoaded [connectionInstanceImpl]
* @param connectionAutoRegistration The connection provider for database. If not provided,
* a service loader will be used to locate and load a provider for [DatabaseConnectionAutoRegistration].
* @param driver The JDBC driver class. If not provided, the specified [url] will be used to find
* a match from the existing driver mappings.
* @param user The database user that owns the new connections.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ org.gradle.configuration.cache=true
org.gradle.caching=true

group=org.jetbrains.exposed
version=0.57.0
version=0.56.0

0 comments on commit 17616b2

Please sign in to comment.