Skip to content

Commit a7bd458

Browse files
committed
Migrate db starters, fixes
1 parent 4c48e9b commit a7bd458

File tree

4 files changed

+116
-118
lines changed

4 files changed

+116
-118
lines changed

docs/src/main/asciidoc/aqjms.adoc renamed to docs/src/main/asciidoc/db_starters.adoc

Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright (c) 2024, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

4-
[#AQ/JMS]
5-
== AQ/JMS
4+
[[database-spring-starters]]
5+
== Database Spring Boot Starters
6+
7+
=== AQ/JMS
68

79
This starter provides support for Oracle Transactional Event Queues (TxEventQ) and Oracle Advanced Queuing (AQ) as Java Message Service (JMS) providers. It depends on the Universal Connection Pool (UCP) starter.
810

@@ -28,13 +30,13 @@ dependencies {
2830
}
2931
----
3032

31-
=== Using AQ/JMS
33+
==== Using AQ/JMS
3234

3335
To configure your application to use Oracle Transactional Event Queues or Oracle Advanced Queuing, you must annotate you application with the `@EnableJms` annotation, and create the
3436
two following beans:
3537

3638
* A `JmsListenerContainerFactory<?>` bean, which can be created as shown in the following example. Note that you can override settings if you need to. Also, note that the name of the method defines the name of the factory, which you will use when creating JMS listeners.
37-
* A `MessageConverter` bean to map objects of your class representing the payload into a text based format (like JSON) that can be used in the actual messages.
39+
* A `MessageConverter` bean to map objects of your class representing the payload into a text based format (like JSON) that can be used in the actual messages.
3840

3941
**Note**: Any queues or topics that you want to use must be pre-created in the database. See [Sample Code](https://www.oracle.com/database/advanced-queuing/#rc30sample-code) for
4042
examples.
@@ -71,19 +73,19 @@ public class JmsSampleApplication {
7173
// You could override some of Boot's defaults here if necessary
7274
return factory;
7375
}
74-
76+
7577
@Bean
7678
public MessageConverter jacksonJmsMessageConverter() {
7779
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
7880
converter.setTargetType(MessageType.TEXT);
7981
converter.setTypeIdPropertyName("_type");
8082
return converter;
8183
}
82-
84+
8385
public static void main(String[] args) {
8486
ConfigurableApplicationContext context = SpringApplication.run(JmsSampleApplication.class, args);
8587
}
86-
88+
8789
}
8890
----
8991

@@ -117,3 +119,107 @@ public class Receiver {
117119
----
118120

119121
**Note**: The starter uses the configuration for `spring.datasource` as the connection details for the Oracle Database hosting the queues and topics. If you wish to use a different configuration, you must use a named configuration, for example `spring.datasource.txeventq` and use Java configuration and annotate the configuration with the standard Spring `@Qualifier` annotation, specifying the correct name, for example `txevevntq`.
122+
123+
=== Universal Connection Pool
124+
125+
This starter provides a connection (data source) to an Oracle Database using Universal Connection Pool, which provides an efficient way to use database connections.
126+
127+
To add this starter to your project, add this Maven dependency:
128+
129+
[source,xml]
130+
----
131+
<dependency>
132+
<groupId>com.oracle.database.spring</groupId>
133+
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
134+
<version>23.4.0</version>
135+
</dependency>
136+
----
137+
138+
For Gradle projects, add this dependency:
139+
140+
[source,subs="normal"]
141+
----
142+
dependencies {
143+
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-ucp:23.4.0'
144+
}
145+
----
146+
147+
==== Using Universal Connection Pool
148+
149+
An Oracle data source is injected into your application and can be used normally. You must configure the data source as shown below, and you should also add either Spring Data JDBC or Spring Data JPA to your project.
150+
151+
To configure the data source, provide a `spring.datasource` object in your Spring `application.yaml`, or equivalent, as shown in the following example. The `oracleucp` entry is optional, and can be used to fine tune the configuration of the connection pool, if desired. For details of available settings, refer to the [JavaDoc](https://docs.oracle.com/en/database/oracle/oracle-database/21/jjuar/oracle/ucp/jdbc/UCPDataSource.html).
152+
153+
[source,yaml]
154+
----
155+
spring:
156+
jpa:
157+
hibernate:
158+
ddl-auto: validate
159+
properties:
160+
hibernate:
161+
dialect: org.hibernate.dialect.OracleDialect
162+
format_sql: true
163+
show-sql: true
164+
datasource:
165+
url: jdbc:oracle:thin:@//myhost:1521/pdb1
166+
username: username
167+
password: password
168+
driver-class-name: oracle.jdbc.OracleDriver
169+
type: oracle.ucp.jdbc.PoolDataSource
170+
oracleucp:
171+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
172+
connection-pool-name: AccountConnectionPool
173+
initial-pool-size: 15
174+
min-pool-size: 10
175+
max-pool-size: 30
176+
----
177+
178+
The `spring.datasource.url` can be in the basic format (as previously shown), or in TNS format if your application uses Transparent Network Substrate (TNS).
179+
180+
Note that the connections to the database use the `DEDICATED` server by default. If you wish to use `SHARED` or `POOLED`, you can append that to the basic URL, or add it to the TNS names entry. For example, to use database resident pooled connections, you would change the URL shown in the previous example to the following:
181+
182+
[source,yaml]
183+
----
184+
datasource:
185+
url: jdbc:oracle:thin:@//myhost:1521/pdb1:pooled
186+
----
187+
188+
If you are using TNS, add `server=pooled` to the `connect_data`. For example:
189+
190+
[source,text]
191+
----
192+
mydb_tp = (description=
193+
(retry_count=20)
194+
(retry_delay=3)
195+
(address=(protocol=tcps)(port=1521)(host=myhost))
196+
(connect_data=(service_name=pdb1)(server=pooled))
197+
(security=(ssl_server_dn_match=yes)))
198+
----
199+
200+
If you prefer to use Java configuration, the data source can be configured as shown in the following example:
201+
202+
[source,java]
203+
----
204+
import oracle.jdbc.pool.OracleDataSource;
205+
import org.springframework.context.annotation.Bean;
206+
import org.springframework.context.annotation.Configuration;
207+
208+
import javax.sql.DataSource;
209+
import java.sql.SQLException;
210+
211+
@Configuration
212+
public class DataSourceConfiguration {
213+
214+
@Bean
215+
public DataSource dataSource() throws SQLException {
216+
OracleDataSource dataSource = new OracleDataSource();
217+
dataSource.setUser("account");
218+
dataSource.setPassword("password");
219+
dataSource.setURL("jdbc:oracle:thin:@//myhost:1521/pdb1");
220+
dataSource.setDataSourceName("AccountConnectionPool");
221+
return dataSource;
222+
}
223+
}
224+
----
225+

docs/src/main/asciidoc/index.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ include::streaming.adoc[]
3434

3535
include::vault.adoc[]
3636

37-
include::ucp.adoc[]
38-
39-
include::aqjms.adoc[]
37+
include::db_starters.adoc[]
4038

4139
== Configuration properties
4240

docs/src/main/asciidoc/ucp.adoc

Lines changed: 0 additions & 106 deletions
This file was deleted.

docs/src/main/asciidoc/vault.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) 2024, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
33

4-
[#vault]
5-
== Vault
4+
[#oci-vault]
5+
== OCI Vault
66

77
https://docs.oracle.com/en-us/iaas/Content/KeyManagement/home.htm[Vault] can be used as a Spring property source for Vault secrets, and as an application bean for creating, updating, listing, and deleting secrets from a Vault.
88

0 commit comments

Comments
 (0)