Skip to content
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

Change to use an injection based API along with the build tool to man… #84

Merged
merged 1 commit into from
Nov 13, 2018
Merged
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
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
package org.jboss.shamrock.agroal;

import javax.inject.Inject;
import static org.jboss.shamrock.annotations.ExecutionTime.STATIC_INIT;

import org.jboss.shamrock.agroal.runtime.DataSourceProducer;
import org.jboss.shamrock.agroal.runtime.DataSourceTemplate;
import org.jboss.shamrock.deployment.ArchiveContext;
import org.jboss.shamrock.deployment.BeanDeployment;
import org.jboss.shamrock.deployment.ProcessorContext;
import org.jboss.shamrock.deployment.ResourceProcessor;
import org.jboss.shamrock.deployment.RuntimePriority;
import org.jboss.shamrock.annotations.BuildProducer;
import org.jboss.shamrock.annotations.BuildStep;
import org.jboss.shamrock.annotations.Record;
import org.jboss.shamrock.deployment.buildconfig.BuildConfig;
import org.jboss.shamrock.deployment.codegen.BytecodeRecorder;
import org.jboss.shamrock.deployment.builditem.AdditionalBeanBuildItem;
import org.jboss.shamrock.deployment.builditem.ReflectiveClassBuildItem;
import org.jboss.shamrock.deployment.cdi.BeanContainerListenerBuildItem;
import org.jboss.shamrock.deployment.recording.BytecodeRecorder;
import org.jboss.shamrock.runtime.ConfiguredValue;

class AgroalProcessor implements ResourceProcessor {
class AgroalProcessor {

@Inject
private BeanDeployment beanDeployment;

@Override
public void process(ArchiveContext archiveContext, ProcessorContext processorContext) throws Exception {
processorContext.addReflectiveClass(false, false,
@BuildStep
AdditionalBeanBuildItem registerBean() {
return new AdditionalBeanBuildItem(DataSourceProducer.class);
}

@Record(STATIC_INIT)
@BuildStep
BeanContainerListenerBuildItem build(BuildConfig config,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass, DataSourceTemplate template, BytecodeRecorder bc) throws Exception {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
io.agroal.pool.ConnectionHandler[].class.getName(),
io.agroal.pool.ConnectionHandler.class.getName(),
java.sql.Statement[].class.getName(),
java.sql.Statement.class.getName(),
java.sql.ResultSet.class.getName(),
java.sql.ResultSet[].class.getName()
);
BuildConfig config = archiveContext.getBuildConfig();
));
BuildConfig.ConfigNode ds = config.getApplicationConfig().get("datasource");
if (ds.isNull()) {
return;
return null;
}
String driver = ds.get("driver").asString();
String url = ds.get("url").asString();
Expand All @@ -52,16 +57,9 @@ public void process(ArchiveContext archiveContext, ProcessorContext processorCon
final Integer maxSize = ds.get("maxSize").asInteger();


processorContext.addReflectiveClass(false, false, driver);
beanDeployment.addAdditionalBean(DataSourceProducer.class);
try (BytecodeRecorder bc = processorContext.addDeploymentTask(RuntimePriority.DATASOURCE_DEPLOYMENT)) {
DataSourceTemplate template = bc.getRecordingProxy(DataSourceTemplate.class);
template.addDatasource(null, configuredURL.getValue(), bc.classProxy(configuredDriver.getValue()), configuredUsername.getValue(), configuredPassword.getValue(), minSize, maxSize );
}
}
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, driver));

return new BeanContainerListenerBuildItem(template.addDatasource(configuredURL.getValue(), bc.classProxy(configuredDriver.getValue()), configuredUsername.getValue(), configuredPassword.getValue(), minSize, maxSize));

@Override
public int getPriority() {
return 1;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package org.jboss.shamrock.agroal.runtime;

import org.jboss.shamrock.runtime.BeanContainer;
import org.jboss.shamrock.runtime.ContextObject;
import org.jboss.shamrock.runtime.Template;
import org.jboss.shamrock.runtime.cdi.BeanContainer;
import org.jboss.shamrock.runtime.cdi.BeanContainerListener;

@Template
public class DataSourceTemplate {

public void addDatasource(@ContextObject("bean.container") BeanContainer beanContainer,
String url, Class driver,
String userName, String password, Integer minSize, Integer maxSize) {
DataSourceProducer producer = beanContainer.instance(DataSourceProducer.class);
producer.setDriver(driver);
producer.setUrl(url);
producer.setUserName(userName);
producer.setPassword(password);
producer.setMinSize(minSize);
producer.setMaxSize(maxSize);
public BeanContainerListener addDatasource(
String url, Class driver,
String userName, String password, Integer minSize, Integer maxSize) {
return new BeanContainerListener() {
@Override
public void created(BeanContainer beanContainer) {
DataSourceProducer producer = beanContainer.instance(DataSourceProducer.class);
producer.setDriver(driver);
producer.setUrl(url);
producer.setUserName(userName);
producer.setPassword(password);
producer.setMinSize(minSize);
producer.setMaxSize(maxSize);
}
};
}

}
4 changes: 4 additions & 0 deletions arc/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<groupId>org.jboss.protean.arc</groupId>
<artifactId>arc-processor</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shamrock</groupId>
<artifactId>shamrock-undertow-deployment</artifactId>
</dependency>
</dependencies>

</project>
Loading