net.wicp.tams.cas.components.ComboBoxBusiAbs Maven / Gradle / Ivy
package net.wicp.tams.cas.components;
import java.sql.Connection;
import javax.sql.DataSource;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.BeforeRenderTemplate;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.http.Link;
import org.apache.tapestry5.http.services.Request;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.services.BindingSource;
import net.wicp.tams.cas.SymbolConstantsCas;
import net.wicp.tams.common.Conf;
import net.wicp.tams.common.apiext.StringUtil;
import net.wicp.tams.common.exception.ExceptAll;
import net.wicp.tams.common.exception.ProjectExceptionRuntime;
import net.wicp.tams.common.jdbc.DruidAssit;
import net.wicp.tams.component.services.IReq;
public abstract class ComboBoxBusiAbs {
@Parameter(value = "prop:componentResources.id", defaultPrefix = BindingConstants.LITERAL)
@Property
protected String id;
/**
* jdbc数据源
*/
@Parameter(required = false, value = "default", defaultPrefix = BindingConstants.LITERAL)
private String datasource;// 数据源,默认是“default”
/***
* 查询哪个数据库
*/
@Parameter(required = false, defaultPrefix = BindingConstants.LITERAL)
private String db;
@Inject
protected Request request;
@Inject
protected ComponentResources resources;
@Inject
protected BindingSource bindingSource;
@Inject
protected IReq req;
@Property
private String url;
protected abstract String getBusiName();
protected abstract void initParams();
protected final String getDb() {
return Conf.get("common.jdbc.datasource." + datasource + ".defaultdb");
}
protected final Connection getConn() {
Connection connection = DruidAssit.getConnection(datasource);
return connection;
}
// @SetupRender
// void initializeValues() {
@BeforeRenderTemplate
void init() {
String dbTrue = "";
if (resources.isBound("db")) {
dbTrue = db;
}
if (StringUtil.isNull(dbTrue)) {
dbTrue = Conf.get("common.jdbc.datasource." + datasource + ".defaultdb");
}
if (StringUtil.isNull(dbTrue)) {
throw new ProjectExceptionRuntime(ExceptAll.param_error, "需要配置db参数或全局变量");
}
DataSource ds = DruidAssit.getDataSource(datasource);
if (ds == null) {
throw new ProjectExceptionRuntime(ExceptAll.jdbc_conn_fail, "没有数据源");
}
Link link = resources.createEventLink(getBusiName());
this.url = link.getBasePath();// 示例/zh/cas/usermanager.comboboxuser:queryuser
// url = "/cas/UserManager:query?needpage=true";
initParams();
}
}