Skip to content

Commit 9832019

Browse files
authored
Feature/version user agent (#15)
Added LICENSE.txt and THIRD_PARTY_LICENSES.txt to runtime jar file and LICENSE.txt to sources and javadoc jars. Add NoSQL-SpringSDK/version as extension user agent. Add new method on NosqlDbFactory getLibraryVersion() to return the version of the library.
1 parent 92fdec2 commit 9832019

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/).
55

6+
## [Unreleased]
7+
### Added
8+
- Add a way to return the library version using NosqlDbFactory.getLibraryVersion().
9+
- Add NoSQL-SpringSDK/version as extension to http user agent.
10+
- Added LICENSE.txt and THIRD_PARTY_LICENSES.txt to runtime jar file and LICENSE.txt to sources and javadoc jars.
11+
612
## [1.4.0]
713
### Added
814
- On-premise only, added support for setting durability option on writes.

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@
287287
</execution>
288288
</executions>
289289
</plugin>
290+
290291
<plugin>
291292
<groupId>org.apache.maven.plugins</groupId>
292293
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -329,6 +330,23 @@
329330
</executions>
330331
</plugin>
331332

333+
<!-- include info in MANIFEST.MF file -->
334+
<plugin>
335+
<artifactId>maven-jar-plugin</artifactId>
336+
<version>3.2.0</version>
337+
<configuration>
338+
<archive>
339+
<manifest>
340+
<addDefaultEntries>false</addDefaultEntries>
341+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
342+
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
343+
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
344+
<addClasspath>true</addClasspath>
345+
</manifest>
346+
</archive>
347+
</configuration>
348+
</plugin>
349+
332350
<!-- create the tar.gz and .zip archives in package phase -->
333351
<plugin>
334352
<artifactId>maven-assembly-plugin</artifactId>

src/main/java/com/oracle/nosql/spring/data/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public class Constants {
2828
public static final int NOTSET_TABLE_STORAGE_GB = -1;
2929
public static final int NOTSET_TABLE_TIMEOUT_MS = 0;
3030

31+
public static final String USER_AGENT = "NoSQL-SpringSDK";
32+
3133
private Constants() {}
3234
}

src/main/java/com/oracle/nosql/spring/data/NosqlDbFactory.java

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import oracle.nosql.driver.AuthorizationProvider;
1212
import oracle.nosql.driver.NoSQLHandle;
13+
import oracle.nosql.driver.NoSQLHandleConfig;
1314
import oracle.nosql.driver.NoSQLHandleFactory;
1415
import oracle.nosql.driver.ops.Request;
1516

@@ -18,10 +19,17 @@
1819

1920
import org.springframework.util.Assert;
2021

22+
/**
23+
* Factory class for connecting to an Oracle NoSQL Database on premise
24+
* database or cloud service.
25+
*/
2126
public class NosqlDbFactory {
2227

28+
private static final String libraryVersion = findVersion();
29+
private static final String userAgent = findUserAgent();
30+
2331
private final NosqlDbConfig config;
24-
private NoSQLHandle handle;
32+
private volatile NoSQLHandle handle;
2533

2634
public NosqlDbFactory(NosqlDbConfig config) {
2735
Assert.notNull(config, "NosqlDbConfig should not be null.");
@@ -34,8 +42,20 @@ public NoSQLHandle getNosqlClient() {
3442
if ( handle == null ) {
3543
synchronized (this) {
3644
if (handle == null) {
37-
handle = NoSQLHandleFactory
38-
.createNoSQLHandle(config.getNosqlHandleConfig());
45+
NoSQLHandleConfig nosqlConfig =
46+
config.getNosqlHandleConfig();
47+
String prevUserAgent =
48+
nosqlConfig.getExtensionUserAgent();
49+
String newUserAgent = null;
50+
if (prevUserAgent == null) {
51+
newUserAgent = userAgent;
52+
} else if (!prevUserAgent.contains(Constants.USER_AGENT)) {
53+
newUserAgent = userAgent + " " + prevUserAgent;
54+
} else {
55+
newUserAgent = prevUserAgent;
56+
}
57+
nosqlConfig.setExtensionUserAgent(newUserAgent);
58+
handle = NoSQLHandleFactory.createNoSQLHandle(nosqlConfig);
3959
}
4060
}
4161
}
@@ -100,7 +120,7 @@ public static NosqlDbFactory createProxyFactory(String endpoint,
100120
}
101121

102122
/**
103-
* Returns the capacity of the prepared query cache. By default this is set
123+
* Returns the capacity of the prepared query cache. By default, this is set
104124
* to {@link Constants#DEFAULT_QUERY_CACHE_CAPACITY}.
105125
*/
106126
public int getQueryCacheCapacity() {
@@ -109,22 +129,22 @@ public int getQueryCacheCapacity() {
109129

110130
/**
111131
* Returns the lifetime of the prepared query cache in milliseconds. By
112-
* default this is set to
113-
* {@link Constants#DEFAULT_QUERY_CACHE_LIFETIME_MS}.
132+
* default, this is set to {@link Constants#DEFAULT_QUERY_CACHE_LIFETIME_MS}.
114133
*/
115134
public int getQueryCacheLifetime() {
116135
return config.getQueryCacheLifetime();
117136
}
118137

119138
/**
120-
* Returns the table request timeout in milliseconds. By default this is
139+
* Returns the table request timeout in milliseconds. By default, this is
121140
* set to {@link Constants#DEFAULT_TABLE_REQ_TIMEOUT_MS}
122141
*/
123142
public int getTableReqTimeout() {
124143
return config.getTableReqTimeout();
125144
}
126145

127-
/** Returns the table request poll interval in milliseconds. By default this
146+
/**
147+
* Returns the table request poll interval in milliseconds. By default, this
128148
* is set to {@link Constants#DEFAULT_TABLE_REQ_POLL_INTEVEL_MS}
129149
*/
130150
public int getTableReqPollInterval() {
@@ -133,15 +153,16 @@ public int getTableReqPollInterval() {
133153

134154
/**
135155
* Returns the precision of the Timestamp NoSQL DB type when creating a
136-
* new table. By default this is set to
137-
* {@link Constants#DEFAULT_TIMESTAMP_PRECISION}.
138-
* <br>
156+
* new table. By default, this is set to
157+
* {@link Constants#DEFAULT_TIMESTAMP_PRECISION}.<p>
158+
*
139159
* In the context of a CREATE TABLE statement, a precision must be
140160
* explicitly specified. This restriction is to prevent users from
141161
* inadvertently creating TIMESTAMP values with precision 9 (which takes
142-
* more space) when in reality they don't need that high precision.
143-
* <br>
144-
* See <a href="https://docs.oracle.com/en/database/other-databases/nosql-database/20.2/sqlreferencefornosql/data-type-definitions.html">Timestamp documentation</a> for more details.
162+
* more space) when in reality they don't need that high precision.<p>
163+
*
164+
* See <a href="https://docs.oracle.com/en/database/other-databases/nosql-database/20.2/sqlreferencefornosql/data-type-definitions.html">
165+
* Timestamp documentation</a> for more details.
145166
*/
146167
public int getTimestampPrecision() {
147168
return config.getTimestampPrecision();
@@ -175,6 +196,28 @@ public int getDefaultWriteUnits() {
175196
return config.getDefaultWriteUnits();
176197
}
177198

199+
/**
200+
* Pulls the version string from the manifest. The version is added
201+
* by maven.
202+
*/
203+
private static String findVersion() {
204+
return NosqlDbFactory.class.getPackage().getImplementationVersion();
205+
}
206+
207+
/**
208+
* Returns the current version of the NoSQL DB Sprint Data SDK, as a
209+
* string in an x.y.z format.
210+
*/
211+
public static String getLibraryVersion() {
212+
return libraryVersion;
213+
}
214+
215+
private static String findUserAgent() {
216+
String libVersion = findVersion();
217+
return Constants.USER_AGENT +
218+
(libVersion == null ? "" : "/" + libVersion);
219+
}
220+
178221
/**
179222
* A simple provider that uses a manufactured id for use by the
180223
* Cloud Simulator. It is used as a namespace for tables and not
@@ -183,7 +226,7 @@ public int getDefaultWriteUnits() {
183226
public static class CloudSimProvider implements AuthorizationProvider {
184227

185228
private static final String id = "Bearer exampleId";
186-
private static AuthorizationProvider provider =
229+
private static final AuthorizationProvider provider =
187230
new CloudSimProvider();
188231

189232
public static AuthorizationProvider getProvider() {

src/main/java/com/oracle/nosql/spring/data/core/mapping/NosqlCapacityMode.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @see oracle.nosql.driver.ops.TableLimits.CapacityMode
1313
*/
1414
public enum NosqlCapacityMode {
15-
1615
PROVISIONED,
1716
ON_DEMAND
1817
}

0 commit comments

Comments
 (0)