Skip to content

Without app jar standalone (#21) #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions driver-wrappers/mongodb-springdata-v2-wrapper/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>driver-wrappers</artifactId>
<groupId>io.mongock</groupId>
<version>5.0.28-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>mongodb-springdata-v2-wrapper</artifactId>

<properties>
<mongodb.driver-sync.version>4.3.3</mongodb.driver-sync.version>
<mongodb-reactivestreams.version>4.4.1</mongodb-reactivestreams.version>
<mongodb.spring-data.starter.version>2.6.3</mongodb.spring-data.starter.version>
</properties>

<dependencies>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-cli-util</artifactId>
<version>${project.version}</version>
</dependency>
<!-- MONGODB -->
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongodb-springdata-v2-driver</artifactId>
<version>${mongock.community.version}</version>
</dependency>


<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.2.13.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>3.11.2</version>
</dependency>






<!-- END MONGODB -->

</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.mongock.driver.cli.wrapper.mongodb.springdata.v2;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

@ReadingConverter
public enum DateToZonedDateTimeConverter implements Converter<Date, ZonedDateTime> {
INSTANCE;

@Override
public ZonedDateTime convert(Date source) {
return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.mongock.driver.cli.wrapper.mongodb.springdata.v2;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import io.mongock.cli.util.CliConfiguration;
import io.mongock.cli.util.ConnectionDriverProvider;
import io.mongock.driver.api.driver.ConnectionDriver;
import io.mongock.driver.mongodb.springdata.v2.SpringDataMongoV2Driver;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;

import java.util.ArrayList;
import java.util.List;

public class SpringDataMongoV2DriverProvider implements ConnectionDriverProvider {


@Override
public ConnectionDriver getDriver(CliConfiguration configuration) {


MongoTemplate mongoTemplate = getMongoTemplate(configuration.getDatabaseUrl(), configuration.getDatabaseName());

// Driver
SpringDataMongoV2Driver driver = SpringDataMongoV2Driver.withDefaultLock(mongoTemplate);
driver.enableTransaction();

return driver;
}

/**
* Main MongoTemplate for Mongock to work.
*/
private static MongoTemplate getMongoTemplate(String connectionString, String dbName) {

MongoClient mongoClient = MongoClients.create(connectionString);
MongoTemplate mongoTemplate = new MongoTemplate(mongoClient, dbName);

// Custom converters to map ZonedDateTime.
MappingMongoConverter mongoMapping = (MappingMongoConverter) mongoTemplate.getConverter();
mongoMapping.setCustomConversions(customConversions());
mongoMapping.afterPropertiesSet();

return mongoTemplate;
}


private static MongoCustomConversions customConversions() {
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(DateToZonedDateTimeConverter.INSTANCE);
converters.add(ZonedDateTimeToDateConverter.INSTANCE);
return new MongoCustomConversions(converters);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.mongock.driver.cli.wrapper.mongodb.springdata.v2;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;

import java.time.ZonedDateTime;
import java.util.Date;

@WritingConverter
public enum ZonedDateTimeToDateConverter implements Converter<ZonedDateTime, Date> {
INSTANCE;

@Override
public Date convert(ZonedDateTime source) {
return source == null ? null : Date.from(source.toInstant());
}
}
87 changes: 87 additions & 0 deletions driver-wrappers/mongodb-springdata-v3-wrapper/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>driver-wrappers</artifactId>
<groupId>io.mongock</groupId>
<version>5.0.28-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>mongodb-springdata-v3-wrapper</artifactId>

<properties>
<mongodb.driver-sync.version>4.3.3</mongodb.driver-sync.version>
<mongodb-reactivestreams.version>4.4.1</mongodb-reactivestreams.version>
<mongodb.spring-data.starter.version>2.6.3</mongodb.spring-data.starter.version>
</properties>

<dependencies>

<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-cli-util</artifactId>
<version>${project.version}</version>
</dependency>

<!-- MONGODB -->
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongodb-springdata-v3-driver</artifactId>
<version>${mongock.community.version}</version>
</dependency>



<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.3.1</version>
</dependency>

<!-- END MONGODB -->

</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.mongock.driver.cli.wrapper.mongodb.springdata.v3;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

@ReadingConverter
public enum DateToZonedDateTimeConverter implements Converter<Date, ZonedDateTime> {
INSTANCE;

@Override
public ZonedDateTime convert(Date source) {
return source == null ? null : ZonedDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.mongock.driver.cli.wrapper.mongodb.springdata.v3;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import io.mongock.cli.util.CliConfiguration;
import io.mongock.cli.util.ConnectionDriverProvider;
import io.mongock.driver.api.driver.ConnectionDriver;
import io.mongock.driver.mongodb.springdata.v3.SpringDataMongoV3Driver;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;

import java.util.ArrayList;
import java.util.List;

public class SpringDataMongoV3DriverProvider implements ConnectionDriverProvider {


@Override
public ConnectionDriver getDriver(CliConfiguration configuration) {


MongoTemplate mongoTemplate = getMongoTemplate(configuration.getDatabaseUrl(), configuration.getDatabaseName());

// Driver
SpringDataMongoV3Driver driver = SpringDataMongoV3Driver.withDefaultLock(mongoTemplate);
driver.enableTransaction();

return driver;
}

/**
* Main MongoTemplate for Mongock to work.
*/
private static MongoTemplate getMongoTemplate(String connectionString, String dbName) {

MongoClient mongoClient = MongoClients.create(connectionString);
MongoTemplate mongoTemplate = new MongoTemplate(mongoClient, dbName);

// Custom converters to map ZonedDateTime.
MappingMongoConverter mongoMapping = (MappingMongoConverter) mongoTemplate.getConverter();
mongoMapping.setCustomConversions(customConversions());
mongoMapping.afterPropertiesSet();

return mongoTemplate;
}



private static MongoCustomConversions customConversions() {
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(DateToZonedDateTimeConverter.INSTANCE);
converters.add(ZonedDateTimeToDateConverter.INSTANCE);
return new MongoCustomConversions(converters);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.mongock.driver.cli.wrapper.mongodb.springdata.v3;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;

import java.time.ZonedDateTime;
import java.util.Date;

@WritingConverter
public enum ZonedDateTimeToDateConverter implements Converter<ZonedDateTime, Date> {
INSTANCE;

@Override
public Date convert(ZonedDateTime source) {
return source == null ? null : Date.from(source.toInstant());
}
}
20 changes: 20 additions & 0 deletions driver-wrappers/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>mongock-cli-project</artifactId>
<groupId>io.mongock</groupId>
<version>5.0.28-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>driver-wrappers</artifactId>
<packaging>pom</packaging>
<modules>
<module>mongodb-springdata-v3-wrapper</module>
<module>mongodb-springdata-v2-wrapper</module>
</modules>


</project>
Loading