下面列出了怎么用com.google.inject.persist.PersistService的API类实例代码及写法,或者点击链接到github查看源代码。
public Client(@NonNull Path filePath, @NonNull Config config, boolean cleanRun, @NonNull List<?> listeners) {
this.filePath = checkFile(filePath);
this.cleanRun = cleanRun;
this.config = config;
Injector injector = Guice.createInjector(
Stage.PRODUCTION,
new ConfigurationModule(ConfigValidator.checkValid(config.withFallback(ConfigFactory.load()))),
new JpaRepositoryModule(),
new ServiceModule()
);
persistService = injector.getInstance(PersistService.class);
persistService.start();
handlerType = injector.getInstance(MovieHandler.Type.class);
handlerChain = injector.getInstance(MovieHandler.class);
importProgressService = injector.getInstance(ImportProgressService.class);
eventBus = new EventBus();
listeners.forEach(eventBus::register);
}
@Override
protected void configurePersistence() {
poolsMultibinder = Multibinder.newSetBinder(binder(), PoolManager.class);
final OrientDBFactory info = new OrientDBFactory(
uri, user, password, autoCreateLocalDb, config, serverUser, serverPassword, remoteType);
bind(OrientDBFactory.class).toInstance(info);
bind(TxConfig.class).annotatedWith(Names.named("orient.txconfig"))
.toInstance(txConfig == null ? new TxConfig() : txConfig);
configureCustomTypes();
bind(CustomTypesInstaller.class);
// extension points
bind(TransactionManager.class);
// SchemeInitializer.class
// DataInitializer.class
bind(PersistService.class).to(DatabaseManager.class);
bind(OrientDB.class).toProvider(DatabaseManager.class);
bind(UnitOfWork.class).to(TransactionManager.class);
configurePools();
configureInterceptor();
bindRetryInterceptor();
}
@Before
public void setUp() throws Exception {
Injector injector = Guice.createInjector(new JpaPersistModule("CapabilitiesDirectory"), new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(Names.named(PROPERTY_DISCOVERY_PROVIDER_DEFAULT_EXPIRY_TIME_MS))
.toInstance(String.valueOf(DEFAULT_EXPIRY_INTERVAL_MS));
bind(CapabilitiesProvisioning.class).to(DefaultCapabilitiesProvisioning.class);
requestStaticInjection(CapabilityUtils.class, RoutingTypesUtil.class);
}
});
service = injector.getInstance(PersistService.class);
store = injector.getInstance(GlobalDiscoveryEntryPersistedStorePersisted.class);
entityManager = injector.getInstance(EntityManager.class);
}
private void init() {
//JPA module
final Map<String, Object> props = Maps.newHashMap(configuration);
props.put("hibernate.connection.datasource",
DataSourceManager.get().load(catalogShardName, configuration).get(catalogShardName));
final Module jpaModule = new JpaPersistModule("s3").properties(props);
final Module s3Module = new S3Module(catalogName, configuration, infoConverter);
final Injector injector = Guice.createInjector(jpaModule, s3Module);
persistService = injector.getInstance(PersistService.class);
persistService.start();
this.databaseService = injector.getInstance(ConnectorDatabaseService.class);
this.tableService = injector.getInstance(ConnectorTableService.class);
this.partitionService = injector.getInstance(ConnectorPartitionService.class);
}
@Override
protected void configurePersistence() {
bind(JooqPersistService.class).in(Singleton.class);
bind(PersistService.class).to(JooqPersistService.class);
bind(UnitOfWork.class).to(JooqPersistService.class);
bind(DSLContext.class).toProvider(JooqPersistService.class);
transactionInterceptor = new JdbcLocalTxnInterceptor(getProvider(JooqPersistService.class),
getProvider(UnitOfWork.class));
requestInjection(transactionInterceptor);
}
@Override
protected void configure() {
// prevent usage without main OrientModule
requireBinding(PersistService.class);
// if package not provided empty string will mean root package (search all classpath)
// not required if provided scheme initializers not used
bindConstant().annotatedWith(Names.named("orient.model.package")).to(pkgs);
// required explicit binding to inject correct injector instance (instead of always root injector)
bind(ExtensionsDescriptorFactory.class);
bindSchemeInitializer();
}
/**
* Configure module.
* Used init code from {@link AbstractSchemeModule}
*/
@Override
protected void configure() {
// prevent usage without main OrientModule
requireBinding(PersistService.class);
// init empty set of packages
Multibinder.newSetBinder(binder(), String.class, Names.named("orient.model.packages"));
// required explicit binding to inject correct injector instance (instead of always root injector)
bind(ExtensionsDescriptorFactory.class);
}
/**
* Start {@link PersistService}
* @see <a href="https://github.com/xvik/guice-persist-orient#lifecycle">Lifecycle of guice-persist-orient</a>
* @param application Wicket application
*/
@Override
public void init(Application application) {
OrienteerWebApplication app = (OrienteerWebApplication) application;
PersistService persistService = app.getServiceInstance(PersistService.class);
persistService.start();
}
/**
* Stop {@link PersistService}
* @see <a href="https://github.com/xvik/guice-persist-orient#lifecycle">Lifecycle of guice-persist-orient</a>
* @param application Wicket application
*/
@Override
public void destroy(Application application) {
OrienteerWebApplication app = (OrienteerWebApplication) application;
PersistService persistService = app.getServiceInstance(PersistService.class);
persistService.stop();
}
@Inject
public GlobalDiscoveryEntryPersistedStorePersisted(CapabilitiesProvisioning staticProvisioning,
Provider<EntityManager> entityManagerProvider,
PersistService persistService,
@Named(PROPERTY_DISCOVERY_PROVIDER_DEFAULT_EXPIRY_TIME_MS) String defaultExpiryTimeMs) {
persistService.start();
entityManager = entityManagerProvider.get();
this.defaultExpiryTimeMs = Long.parseLong(defaultExpiryTimeMs);
logger.debug("Creating CapabilitiesStore with static provisioning");
}
@Inject
public DBTermination(PersistService persistService, EntityManagerFactory emFactory) {
this.persistService = persistService;
this.emFactory = emFactory;
}
@Inject
public CapabilitiesDirectoryLauncher(PersistService persistService) {
this.persistService = persistService;
}