Skip to content

Commit

Permalink
update AbstractMongoDAO to use current MongoClient
Browse files Browse the repository at this point in the history
* copy mongodb to mongodb-legacy
* remove jongo from mongodb
  • Loading branch information
Felix Zwirn committed Jun 12, 2024
1 parent ab08006 commit 9be795d
Show file tree
Hide file tree
Showing 88 changed files with 3,849 additions and 633 deletions.
8 changes: 4 additions & 4 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions archetypes/dvalin-archetype-parent.iml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="1550f39e-5211-42d0-9707-106a048f7047" />
</component>
</module>
5 changes: 1 addition & 4 deletions cloud/dvalin-cloud-parent.iml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="c2d793f0-e542-44fd-b34d-ce8438d9fa47" />
</component>
</module>
5 changes: 1 addition & 4 deletions cluster/dvalin-cluster-parent.iml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="a28444bb-5298-4d52-9e90-5be68fc2d236" />
</component>
</module>
9 changes: 1 addition & 8 deletions dvalin-parent.iml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" version="4">
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
<component name="RModuleSettingsStorage">
<LOAD_PATH number="0" />
<I18N_FOLDERS number="1" string0="$MODULE_DIR$/i18n" />
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="7c2c9c50-04a2-465d-baeb-9fd85282da67" />
</component>
</module>
5 changes: 1 addition & 4 deletions interconnect/dvalin-interconnect-parent.iml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="8fddd795-bb5b-4d86-8a08-26419d6f01ba" />
</component>
</module>
57 changes: 57 additions & 0 deletions mongodb-legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## mongodb

The mongodb library adds support for the MongoDB document store. By adding the dependency you get the
full support to interact with MongoDB databases including an in-memory database for tests.

### Connection properties

The following settings are possible:

* `mongodb.type` - {fake|real} connect to real MongoDB database or in-memory version using `Mongo Java Server`
* `mongodb.name` - the name of the database to use for data storage
* `mongobee.enabled` - {true|false} use mongobee for database migration
* `mongobee.basepackage` - the base package of the Mongobee changesets
* `mongodb.demodata` - {true|false} load demodata on startup from ND-JSON files

For connections to real MongoDB databases, these extra properties can be set:

* `mongodb.host` - the host of the MongoDB instance (default: localhost)
* `mongodb.port` - the port of the MongoDB instance (default: 27017)
* `mongodb.uri` - instead of host and port you can specify the complete connection string
* `mongodb.sockettimeout` - the socket timeout of the connection (default: 10 seconds)
* `mongodb.connecttimeout` - the connection timeout of the connection attempt (default: 10 seconds)

### Access to database

To get access to the database inject the `MongoDBDataAccess<T>` for your entity class into your bean.
You can then call several methods to query and write data.

### Abstract entity and DAO interface

The library provides a general purpose DAO interface (`ICrudDAO`) and an abstract implementation
(`AbstractMongoDAO`) with many helper methods to ease the development of the data layer. For this to
work your entities have to extend the `AEntity` superclass. The DAOs created have integrated support
for JodaTime classes. If you want to use polymorphic types in your entities make sure to implement
`@IMappedSupertype` on the super class. This advises the Jackson mapper to include type information
into the created JSON for deserialization.

### Changesets

For database migration purpose the mongobee library is included and is configured as denoted above
using system properties. See the mongobee documentation on how to implement changesets.
For Index creation take a look at the `ChangelogUtil` helper class.

### MongoDBInit

To prefill the database with startup data or test data for integration tests put file on your classpath
into the package `mongodb` and name them using the following pattern: `<CollectionName>.ndjson`
If you set the system property `mongodb.demodata`to `true` dvalin will populate the given collections
with the objects contained in this new-line delimited files. Just put one JSON object per line.

### DocumentLinks

Another feature of dvalin's MongoDB support are DocumentLinks. These allow for references between your
documents. To include a reference in one of your entities just add a field of the generic type
`DocumentLink` and let your referenced entity implement `AReferenceableEntity`.
Dvalin will then include a reference to the given document in your JSON which you can resolve
by injecting the `IDlinkDAO` wherever you want.
100 changes: 100 additions & 0 deletions mongodb-legacy/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.taimos</groupId>
<artifactId>dvalin-parent</artifactId>
<version>1.36-SNAPSHOT</version>
</parent>
<artifactId>dvalin-mongodb-legacy</artifactId>
<name>Legacy MongoDB support for dvalin</name>
<inceptionYear>2015</inceptionYear>
<properties>
<jongo.version>1.5.1</jongo.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-bom</artifactId>
<version>${mongock.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>de.taimos</groupId>
<artifactId>dvalin-daemon</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
</dependency>
<dependency>
<groupId>de.undercouch</groupId>
<artifactId>bson4jackson</artifactId>
<version>${bson.version}</version>
</dependency>

<!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define
this if you use Spring Bean APIs (org.springframework.beans.*) -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
<version>${mongo.version}</version>
</dependency>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>${jongo.version}</version>
<exclusions>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>bson4jackson</artifactId>
<groupId>de.undercouch</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-standalone</artifactId>
</dependency>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongodb-sync-v4-driver</artifactId>
</dependency>
<dependency>
<groupId>de.bwaldvogel</groupId>
<artifactId>mongo-java-server</artifactId>
<version>${mongo-java-server.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.taimos.dvalin.mongo;

/*-
* #%L
* MongoDB support for dvalin
* %%
* Copyright (C) 2015 - 2017 Taimos GmbH
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import org.joda.time.DateTime;

/**
* Copyright 2015 Cinovo AG<br>
* <br>
*
* @author psigloch
*
*/
public abstract class AAuditedEntity extends AEntity {

private Integer version;
private DateTime lastChange;
private String lastChangeUser;

public Integer getVersion() {
return this.version;
}

public void setVersion(Integer version) {
this.version = version;
}

public DateTime getLastChange() {
return this.lastChange;
}

public void setLastChange(DateTime lastChange) {
this.lastChange = lastChange;
}

public String getLastChangeUser() {
return this.lastChangeUser;
}

public void setLastChangeUser(String lastChangeUser) {
this.lastChangeUser = lastChangeUser;
}

}
Loading

0 comments on commit 9be795d

Please sign in to comment.