java.sql.Wrapper类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(425)

本文整理了Java中java.sql.Wrapper类的一些代码示例,展示了Wrapper类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Wrapper类的具体详情如下:
包路径:java.sql.Wrapper
类名称:Wrapper

Wrapper介绍

[英]This class is an actual usage of the wrapper pattern for JDBC classes. Developers can get the delegate instance when the instance may be a proxy class.
[中]这个类是JDBC类的包装器模式的实际用法。当代理实例可能是代理类时,开发人员可以获取代理实例。

代码示例

代码示例来源:origin: org.springframework.boot/spring-boot

private static <S> S safeUnwrap(Wrapper wrapper, Class<S> target) {
  try {
    return wrapper.unwrap(target);
  }
  catch (Exception ex) {
    return null;
  }
}

代码示例来源:origin: alibaba/druid

@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
  if (null == wrapper) {
    //Best to log error.
    return false;
  }
  if (iface == null) {
    return false;
  }
  if (iface == wrapper.getClass()) {
    return true;
  }
  if (iface == this.getClass()) {
    return true;
  }
  
  if (!(wrapper instanceof WrapperProxy)) {
    if (iface.isInstance(wrapper)) {
      return true;
    }
  }
  return wrapper.isWrapperFor(iface);
}

代码示例来源:origin: geotools/geotools

if (w.isWrapperFor(OracleConnection.class)) {
  return w.unwrap(OracleConnection.class);

代码示例来源:origin: stackoverflow.com

public class AdaptedWrapper {
  private Wrapper wrapper = new Wrapper();
  private List<ChannelName> channelNames;

代码示例来源:origin: stackoverflow.com

try (Connection hikariCon = dbConnect.getConnection()) {
 if (hikariCon.isWrapperFor(OracleConnection.class)) {
  OracleConnection connection = hikariCon.unwrap(OracleConnection.class);
  :
  :
 }

代码示例来源:origin: stackoverflow.com

//populate Wrapper
Wrapper wrap = new Wrapper();
//set attributes and Rows
...
String writeValueAsString = om.writeValueAsString(wrap);

代码示例来源:origin: org.javasimon/javasimon-jdbc41

public <T> T unwrap(Class<T> iface) throws SQLException {
    if (delegateType.equals(iface)) {
      return delegate.isWrapperFor(iface) ? delegate.unwrap(iface) : iface.cast(delegate);
    } else {
      return delegate.unwrap(iface);
    }
  }
}

代码示例来源:origin: alibaba/druid

@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
  if (null == wrapper) {
    //Best to log error.
    return null;
  }
  if (iface == null) {
    return null;
  }
  if (iface == wrapper.getClass()) {
    return (T) wrapper;
  }
  if (iface == this.getClass()) {
    return (T) this;
  }
  
  if (!(wrapper instanceof WrapperProxy)) {
    if (iface.isInstance(wrapper)) {
      return (T) wrapper;
    }
  }
  return wrapper.unwrap(iface);
}

代码示例来源:origin: alibaba/druid

@Override
public boolean isWrapperFor(Wrapper wrapper, Class<?> iface) throws SQLException {
  if (this.pos < filterSize) {
    return nextFilter()
        .isWrapperFor(this, wrapper, iface);
  }
  // // if driver is for jdbc 3.0
  if (iface.isInstance(wrapper)) {
    return true;
  }
  return wrapper.isWrapperFor(iface);
}

代码示例来源:origin: stackoverflow.com

public class HelloWorld{

   public static void main(String []args){
    Wrapper an = new Wrapper();
    an.getAnimalGroup(Yetti.class);
    //new AnimalGroup<String>(String.class).doSomeProcessing();

   }
}

代码示例来源:origin: stackoverflow.com

Connection unwrapConnection = databaseSession.getServerPlatform()
       .unwrapConnection(accessor.getConnection());
   oracle.jdbc.OracleConnection connection = null;
   try {
     if (unwrapConnection.isWrapperFor(OracleConnection.class)) {
       connection = unwrapConnection.unwrap(OracleConnection.class);
     } else {
       // recover, not an oracle connection
       connection = (oracle.jdbc.OracleConnection) databaseSession.getServerPlatform()
           .unwrapConnection(accessor.getConnection());
     }
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }

代码示例来源:origin: alibaba/druid

@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Wrapper wrapper, Class<T> iface) throws SQLException {
  if (this.pos < filterSize) {
    return nextFilter()
      .unwrap(this, wrapper, iface);
  }
  if (iface == null) {
    return null;
  }
  // if driver is for jdbc 3.0
  if (iface.isAssignableFrom(wrapper.getClass())) {
    return (T) wrapper;
  }
  return wrapper.unwrap(iface);
}

代码示例来源:origin: codingapi/tx-lcn

@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
 if (iface.isAssignableFrom(getClass())) {
  // if the proxy directly proxy the interface or extends it, return true
  return true;
 } else if (iface.isAssignableFrom(delegate.getClass())) {
  // if the proxied object directly implements the interface or extends it, return true
  return true;
 } else if (Wrapper.class.isAssignableFrom(delegate.getClass())) {
  // if the proxied object implements the wrapper interface, then
  // return the result of it's isWrapperFor method.
  return ((Wrapper) unwrapP6SpyProxy()).isWrapperFor(iface);
 }
 return false;
}

代码示例来源:origin: stackoverflow.com

public Wrapper(int value, String name) {
  this.value = value;
  this.name = name;
}

public String getName() {
  return name;
}

public int getValue() {
  return value;
}
}

Wrapper x = new Wrapper(3, "x");

代码示例来源:origin: stackoverflow.com

Context ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS");
Connection conn = ds.getConnection();

// Returns true if this either implements the interface argument
// or is directly or indirectly a wrapper for an object that does.
if (conn.isWrapperFor(oracle.jdbc.OracleConnection.class)) {
  // Returns an object that implements the given interface to
  // allow access to non-standard methods, or standard methods
  // not exposed by the proxy.
  oracle.jdbc.OracleConnection oraCon = conn.unwrap(oracle.jdbc.OracleConnection.class);
  // Do some Oracle-specific work here.
}

代码示例来源:origin: alibaba/canal

if (conn instanceof java.sql.Wrapper) {
  Class<?> connIface = Class.forName("com.mysql.jdbc.Connection");
  conn = ((java.sql.Wrapper) conn).unwrap(connIface);
  continue;

代码示例来源:origin: p6spy/p6spy

@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
 return ((Wrapper) realDataSource).isWrapperFor(iface);
}

代码示例来源:origin: stackoverflow.com

int iDaysAlive = 0;
final Wrapper w = new Wrapper(iDaysAlive);

代码示例来源:origin: com.github.gquintana.metrics/metrics-sql

protected Object unwrap(MethodInvocation<T> methodInvocation) throws SQLException {
  final Class iface = getClassArg(methodInvocation);
  final Wrapper delegateWrapper = (Wrapper) delegate;
  Object result;
  if (isDelegateType(iface)) {
    result = delegateWrapper.isWrapperFor(iface) ? delegateWrapper.unwrap(iface) : iface.cast(delegateWrapper);
  } else {
    result = delegateWrapper.unwrap(iface);
  }
  return result;
}

代码示例来源:origin: codingapi/tx-lcn

@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
 final Object result;
 if (iface.isAssignableFrom(getClass())) {
  // if the proxy directly implements the interface or extends it, return the proxy
  result = this;
 } else if (iface.isAssignableFrom(delegate.getClass())) {
  // if the proxied object directly implements the interface or extends it, return
  // the proxied object
  result = unwrapP6SpyProxy();
 } else if (Wrapper.class.isAssignableFrom(delegate.getClass())) {
  // if the proxied object implements the wrapper interface, then
  // return the result of it's unwrap method.
  result = ((Wrapper) unwrapP6SpyProxy()).unwrap(iface);
 } else {
  /*
    This line of code can only be reached when the underlying object does not implement the wrapper
    interface.  This would mean that either the JDBC driver or the wrapper of the underlying object
    does not implement the JDBC 4.0 API.
   */
  throw new SQLException("Can not unwrap to " + iface.getName());
 }
 return iface.cast(result);
}

相关文章

微信公众号

最新文章

更多