tech.guyi.ipojo.module.h2.executor.JdbcExecutor Maven / Gradle / Ivy
The newest version!
package tech.guyi.ipojo.module.h2.executor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.h2.jdbcx.JdbcDataSource;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.Logger;
import tech.guyi.ipojo.application.ApplicationContext;
import tech.guyi.ipojo.application.annotation.Component;
import tech.guyi.ipojo.application.annotation.Resource;
import tech.guyi.ipojo.application.bean.interfaces.ApplicationStartSuccessEvent;
import tech.guyi.ipojo.application.bean.interfaces.InitializingBean;
import tech.guyi.ipojo.application.osgi.log.Log;
import tech.guyi.ipojo.module.h2.datasource.JdbcDataSourceProvider;
import tech.guyi.ipojo.module.stream.Mono;
import tech.guyi.ipojo.module.stream.producer.Producer;
import tech.guyi.ipojo.module.stream.publisher.Publisher;
import tech.guyi.ipojo.module.stream.subscriber.Subscriber;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
@Component
public class JdbcExecutor implements InitializingBean, ApplicationStartSuccessEvent {
@Resource
private JdbcDataSourceProvider provider;
@Log
private Logger logger;
public void setLogger(Logger logger) {
this.logger = logger;
}
private JdbcDataSource dataSource;
private QueryRunner runner;
private Mono readyMono;
private Publisher _publisher;
public boolean isReady(){
return this.runner != null;
}
public void await(Subscriber subscriber){
if (this.readyMono == null || this.isReady()){
subscriber.subscription(true);
}else{
this.readyMono.subscription(subscriber);
}
}
@Override
public void afterPropertiesSet() {
this.readyMono = Mono.create(new Producer() {
@Override
public void produce(Publisher publisher) {
_publisher = publisher;
}
});
this.readyMono.open();
}
private List