com.tvd12.ezyfox.boot.mongodb.EzyMongoConfiguration Maven / Gradle / Ivy
The newest version!
package com.tvd12.ezyfox.boot.mongodb;
import com.mongodb.MongoClient;
import com.tvd12.ezydata.database.EzyDatabaseContext;
import com.tvd12.ezydata.mongodb.EzyMongoDatabaseContextBuilder;
import com.tvd12.ezydata.mongodb.loader.EzySimpleMongoClientLoader;
import com.tvd12.ezyfox.annotation.EzyProperty;
import com.tvd12.ezyfox.bean.EzyBeanAutoConfig;
import com.tvd12.ezyfox.bean.EzyPackagesToScanAware;
import com.tvd12.ezyfox.bean.EzySingletonFactory;
import com.tvd12.ezyfox.bean.EzySingletonFactoryAware;
import com.tvd12.ezyfox.bean.annotation.EzyConfigurationBefore;
import com.tvd12.ezyfox.util.EzyPropertiesAware;
import lombok.Setter;
import java.util.Properties;
import java.util.Set;
import static com.tvd12.ezyfox.boot.util.EzyDatabaseContexts.addRepositoriesFromDatabaseContextToSingletonFactory;
@Setter
@EzyConfigurationBefore
public class EzyMongoConfiguration implements
EzyBeanAutoConfig,
EzyPropertiesAware,
EzySingletonFactoryAware,
EzyPackagesToScanAware {
@EzyProperty("database.mongo.database")
private String databaseName;
private Properties properties;
private Set packagesToScan;
private EzySingletonFactory singletonFactory;
@Override
public void autoConfig() {
addRepositoriesFromDatabaseContextToSingletonFactory(
newMongodbDatabaseContext(),
singletonFactory
);
}
private EzyDatabaseContext newMongodbDatabaseContext() {
EzyMongoDatabaseContextBuilder builder = new EzyMongoDatabaseContextBuilder()
.properties(properties)
.mongoClient(newMongoClient())
.databaseName(databaseName);
for (String p : packagesToScan) {
builder.scan(p);
}
return builder.build();
}
protected MongoClient newMongoClient() {
return EzySimpleMongoClientLoader.load(properties);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy