类java.sql.Wrapper源码实例Demo

下面列出了怎么用java.sql.Wrapper的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: tx-lcn   文件: AbstractWrapper.java
@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);
}
 
源代码2 项目: lams   文件: ServerPreparedStatement.java
@Override
protected ClientPreparedStatement prepareBatchedInsertSQL(JdbcConnection localConn, int numBatches) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        try {
            ClientPreparedStatement pstmt = ((Wrapper) localConn.prepareStatement(((PreparedQuery<?>) this.query).getParseInfo().getSqlForBatch(numBatches),
                    this.resultSetConcurrency, this.query.getResultType().getIntValue())).unwrap(ClientPreparedStatement.class);
            pstmt.setRetrieveGeneratedKeys(this.retrieveGeneratedKeys);

            return pstmt;
        } catch (UnsupportedEncodingException e) {
            SQLException sqlEx = SQLError.createSQLException(Messages.getString("ServerPreparedStatement.27"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
            sqlEx.initCause(e);

            throw sqlEx;
        }
    }
}
 
源代码3 项目: FoxTelem   文件: ServerPreparedStatement.java
@Override
protected ClientPreparedStatement prepareBatchedInsertSQL(JdbcConnection localConn, int numBatches) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        try {
            ClientPreparedStatement pstmt = ((Wrapper) localConn.prepareStatement(((PreparedQuery<?>) this.query).getParseInfo().getSqlForBatch(numBatches),
                    this.resultSetConcurrency, this.query.getResultType().getIntValue())).unwrap(ClientPreparedStatement.class);
            pstmt.setRetrieveGeneratedKeys(this.retrieveGeneratedKeys);

            return pstmt;
        } catch (UnsupportedEncodingException e) {
            SQLException sqlEx = SQLError.createSQLException(Messages.getString("ServerPreparedStatement.27"), MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR,
                    this.exceptionInterceptor);
            sqlEx.initCause(e);

            throw sqlEx;
        }
    }
}
 
源代码4 项目: quarkus   文件: MySQLJDBCReflections.java
@BuildStep
void registerDriverForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {

    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, Driver.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, FailoverDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, FailoverConnectionUrl.class.getName()));
    reflectiveClass
            .produce(new ReflectiveClassBuildItem(false, false, SingleConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, LoadBalanceConnectionUrl.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            LoadBalanceDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            ReplicationDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, ReplicationConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, XDevApiConnectionUrl.class.getName()));
    reflectiveClass.produce(
            new ReflectiveClassBuildItem(false, false, XDevApiDnsSrvConnectionUrl.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
            com.mysql.cj.jdbc.ha.LoadBalancedAutoCommitInterceptor.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, StandardLogger.class.getName()));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, Wrapper.class.getName()));
}
 
源代码5 项目: tx-lcn   文件: AbstractWrapper.java
@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;
}
 
源代码6 项目: lams   文件: ConnectionWrapper.java
public boolean isWrapperFor(Class<?> iface) throws SQLException {
    boolean isInstance = iface.isInstance(this);

    if (isInstance) {
        return true;
    }

    return (iface.getName().equals(JdbcConnection.class.getName()) || iface.getName().equals(MysqlConnection.class.getName())
            || iface.getName().equals(java.sql.Connection.class.getName()) || iface.getName().equals(Wrapper.class.getName())
            || iface.getName().equals(AutoCloseable.class.getName()));
}
 
源代码7 项目: FoxTelem   文件: ConnectionWrapper.java
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
    boolean isInstance = iface.isInstance(this);

    if (isInstance) {
        return true;
    }

    return (iface.getName().equals(JdbcConnection.class.getName()) || iface.getName().equals(MysqlConnection.class.getName())
            || iface.getName().equals(java.sql.Connection.class.getName()) || iface.getName().equals(Wrapper.class.getName())
            || iface.getName().equals(AutoCloseable.class.getName()));
}
 
源代码8 项目: kumuluzee   文件: NonJtaXADataSourceWrapper.java
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {

    if (xaDataSource == null) {
        throw new SQLException("The underlying XADataSource is invalid or cannot be found");
    } else if (iface.isInstance(xaDataSource)) {
        return iface.cast(xaDataSource);
    } else if (xaDataSource instanceof Wrapper) {
        return ((java.sql.Wrapper) xaDataSource).unwrap(iface);
    } else {
        throw new SQLException("The requested interface cannot be unwrapped");
    }
}
 
源代码9 项目: kumuluzee   文件: NonJtaXADataSourceWrapper.java
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {

    if (xaDataSource == null) {
        throw new SQLException("The underlying XADataSource is invalid or cannot be found");
    } else if (iface.isInstance(xaDataSource)) {
        return true;
    } else if (xaDataSource instanceof Wrapper) {
        return ((java.sql.Wrapper) xaDataSource).isWrapperFor(iface);
    }

    return false;
}
 
源代码10 项目: metrics-sql   文件: JdbcProxyHandler.java
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;
}
 
源代码11 项目: lams   文件: CallableStatement.java
private void setInOutParamsOnServer() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.paramInfo.numParameters > 0) {
            for (Iterator<CallableStatementParam> paramIter = this.paramInfo.iterator(); paramIter.hasNext();) {

                CallableStatementParam inParamInfo = paramIter.next();

                if (inParamInfo.isOut && inParamInfo.isIn) {
                    if (inParamInfo.paramName == null) {
                        inParamInfo.paramName = "nullnp" + inParamInfo.index;
                    }

                    String inOutParameterName = mangleParameterName(inParamInfo.paramName);
                    StringBuilder queryBuf = new StringBuilder(4 + inOutParameterName.length() + 1 + 1);
                    queryBuf.append("SET ");
                    queryBuf.append(inOutParameterName);
                    queryBuf.append("=?");

                    ClientPreparedStatement setPstmt = null;

                    try {
                        setPstmt = ((Wrapper) this.connection.clientPrepareStatement(queryBuf.toString())).unwrap(ClientPreparedStatement.class);

                        if (((PreparedQuery<?>) this.query).getQueryBindings().getBindValues()[inParamInfo.index].isNull()) {
                            setPstmt.setBytesNoEscapeNoQuotes(1, "NULL".getBytes());

                        } else {
                            byte[] parameterAsBytes = getBytesRepresentation(inParamInfo.index);

                            if (parameterAsBytes != null) {
                                if (parameterAsBytes.length > 8 && parameterAsBytes[0] == '_' && parameterAsBytes[1] == 'b' && parameterAsBytes[2] == 'i'
                                        && parameterAsBytes[3] == 'n' && parameterAsBytes[4] == 'a' && parameterAsBytes[5] == 'r'
                                        && parameterAsBytes[6] == 'y' && parameterAsBytes[7] == '\'') {
                                    setPstmt.setBytesNoEscapeNoQuotes(1, parameterAsBytes);
                                } else {
                                    switch (inParamInfo.desiredMysqlType) {
                                        case BIT:
                                        case BINARY:
                                        case GEOMETRY:
                                        case TINYBLOB:
                                        case BLOB:
                                        case MEDIUMBLOB:
                                        case LONGBLOB:
                                        case VARBINARY:
                                            setPstmt.setBytes(1, parameterAsBytes);
                                            break;
                                        default:
                                            // the inherited PreparedStatement methods have already escaped and quoted these parameters
                                            setPstmt.setBytesNoEscape(1, parameterAsBytes);
                                    }
                                }
                            } else {
                                setPstmt.setNull(1, MysqlType.NULL);
                            }
                        }

                        setPstmt.executeUpdate();
                    } finally {
                        if (setPstmt != null) {
                            setPstmt.close();
                        }
                    }
                }
            }
        }
    }
}
 
源代码12 项目: FoxTelem   文件: CallableStatement.java
private void setInOutParamsOnServer() throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.paramInfo.numParameters > 0) {
            for (Iterator<CallableStatementParam> paramIter = this.paramInfo.iterator(); paramIter.hasNext();) {

                CallableStatementParam inParamInfo = paramIter.next();

                if (inParamInfo.isOut && inParamInfo.isIn) {
                    if (inParamInfo.paramName == null) {
                        inParamInfo.paramName = "nullnp" + inParamInfo.index;
                    }

                    String inOutParameterName = mangleParameterName(inParamInfo.paramName);
                    StringBuilder queryBuf = new StringBuilder(4 + inOutParameterName.length() + 1 + 1);
                    queryBuf.append("SET ");
                    queryBuf.append(inOutParameterName);
                    queryBuf.append("=?");

                    ClientPreparedStatement setPstmt = null;

                    try {
                        setPstmt = ((Wrapper) this.connection.clientPrepareStatement(queryBuf.toString())).unwrap(ClientPreparedStatement.class);

                        if (((PreparedQuery<?>) this.query).getQueryBindings().getBindValues()[inParamInfo.index].isNull()) {
                            setPstmt.setBytesNoEscapeNoQuotes(1, "NULL".getBytes());

                        } else {
                            byte[] parameterAsBytes = getBytesRepresentation(inParamInfo.index);

                            if (parameterAsBytes != null) {
                                if (parameterAsBytes.length > 8 && parameterAsBytes[0] == '_' && parameterAsBytes[1] == 'b' && parameterAsBytes[2] == 'i'
                                        && parameterAsBytes[3] == 'n' && parameterAsBytes[4] == 'a' && parameterAsBytes[5] == 'r'
                                        && parameterAsBytes[6] == 'y' && parameterAsBytes[7] == '\'') {
                                    setPstmt.setBytesNoEscapeNoQuotes(1, parameterAsBytes);
                                } else {
                                    switch (inParamInfo.desiredMysqlType) {
                                        case BIT:
                                        case BINARY:
                                        case GEOMETRY:
                                        case TINYBLOB:
                                        case BLOB:
                                        case MEDIUMBLOB:
                                        case LONGBLOB:
                                        case VARBINARY:
                                            setPstmt.setBytes(1, parameterAsBytes);
                                            break;
                                        default:
                                            // the inherited PreparedStatement methods have already escaped and quoted these parameters
                                            setPstmt.setBytesNoEscape(1, parameterAsBytes);
                                    }
                                }
                            } else {
                                setPstmt.setNull(1, MysqlType.NULL);
                            }
                        }

                        setPstmt.executeUpdate();
                    } finally {
                        if (setPstmt != null) {
                            setPstmt.close();
                        }
                    }
                }
            }
        }
    }
}
 
源代码13 项目: paradoxdriver   文件: Utils.java
/**
 * Returns an object that implements the given interface to allow access to
 * non-standard methods, or standard methods not exposed by the proxy.
 *
 * @param <T>     the type of the class modeled by this Class object.
 * @param wrapper the wrapper class.
 * @param iFace   A Class defining an interface that the result must implement.
 * @return an object that implements the interface. May be a proxy for the
 * actual implementing object.
 * @throws java.sql.SQLException If no object found that implements the interface.
 * @since 1.2
 */
@SuppressWarnings("unchecked")
public static <T> T unwrap(final Wrapper wrapper, final Class<T> iFace) throws SQLException {
    if (wrapper.isWrapperFor(iFace)) {
        return (T) wrapper;
    }
    throw new SQLException("Type not found.", SQLStates.TYPE_NOT_FOUND.getValue());
}
 
源代码14 项目: paradoxdriver   文件: Utils.java
/**
 * Returns true if this either implements the interface argument or is
 * directly or indirectly a wrapper for an object that does. Returns false
 * otherwise..
 *
 * @param wrapper wrapper to test for.
 * @param iFace   a Class defining an interface.
 * @return true if this implements the interface or directly or indirectly
 * wraps an object that does.
 * @since 1.2
 */
public static boolean isWrapperFor(final Wrapper wrapper, final Class<?> iFace) {
    return wrapper.getClass().isAssignableFrom(iFace);
}