Return a class that implements the requested interface, if possible.

@param interfaceClass the interface to unwrap.

@throws SQLException if this wrapper does not wrap any instances of the requested
interface.
513051
@SuppressWarnings("unchecked")
    public <T> T unwrap(final Class<T> interfaceClass) throws SQLException 
    {
        TraceComponent tc = getTracer();
        if (tc.isEntryEnabled())
            Tr.entry(this, tc, "unwrap", interfaceClass);

        activate(); 

        Object result;

        // Return the current wrapper if it already implements the interface.

        if (interfaceClass.isInstance(this))
            result = this;

        // Return an existing dynamic wrapper if one already exists for the interface.

        else if (ifcToDynamicWrapper.containsKey(interfaceClass))
            result = ifcToDynamicWrapper.get(interfaceClass);

        // Otherwise, see if any of the wrapped objects implement (or themselves wrap)
        // the interface.

        else
            try 
            {
                if (tc.isDebugEnabled())
                    Tr.debug(this, tc,
                             "No existing wrappers found. Need to create a new wrapper.");

                Object implObject = getJDBCImplObject(interfaceClass);

                if (implObject == null // Not found
                    || !interfaceClass.isInterface()) // or not an interface. 
                {
                    throw new SQLException( 
                    AdapterUtil.getNLSMessage("NO_WRAPPED_OBJECT", this, interfaceClass.getName())); 
                }

                if (tc.isDebugEnabled())
                    Tr.debug(this, tc,
                             "Creating a wrapper for:", AdapterUtil.toString(implObject));

                // An implementation object is found. Create a new wrapper for it.
                // And then add it to the map of dynamic wrappers.
                result = AccessController.doPrivileged(new PrivilegedAction<Object>() {
                    public Object run() {
                        return Proxy.newProxyInstance(interfaceClass.getClassLoader(),
                                                      new Class[] { interfaceClass },
                                                      WSJdbcWrapper.this);
                    }
                });

                ifcToDynamicWrapper.put(interfaceClass, result);
                dynamicWrapperToImpl.put(result, implObject);
            }
            catch (SQLException sqlX) {
                FFDCFilter.processException(
                                            sqlX, getClass().getName() + ".unwrap", "441", this);
                if (tc.isEntryEnabled())
                    Tr.exit(this, tc, "unwrap", sqlX);
                throw WSJdbcUtil.mapException(this, sqlX);
            } catch (NullPointerException nullX) {
                // No FFDC code needed; we might be closed.
                throw runtimeXIfNotClosed(nullX);
            } catch (RuntimeException runX) {
                FFDCFilter.processException(
                                            runX, getClass().getName() + ".unwrap", "451", this);
                if (tc.isEntryEnabled())
                    Tr.exit(this, tc, "unwrap", runX);
                throw runX;
            } catch (Error err) {
                FFDCFilter.processException(
                                            err, getClass().getName() + ".unwrap", "458", this);
                if (tc.isEntryEnabled())
                    Tr.exit(this, tc, "unwrap", err);
                throw err;
            }

        if (tc.isEntryEnabled())
            Tr.exit(this, tc, "unwrap", result);
        return (T) result;
    }
30596
protected static Class getWrapperClass(Class c) {
        if (c == Integer.TYPE) {
            c = Integer.class;
        } else if (c == Byte.TYPE) {
            c = Byte.class;
        } else if (c == Long.TYPE) {
            c = Long.class;
        } else if (c == Double.TYPE) {
            c = Double.class;
        } else if (c == Float.TYPE) {
            c = Float.class;
        } else if (c == Boolean.TYPE) {
            c = Boolean.class;
        } else if (c == Character.TYPE) {
            c = Character.class;
        } else if (c == Short.TYPE) {
            c = Short.class;
        }
        return c;
    }
1241347
private String getInstanceClass(
		final Tuple resultset,
		final int i,
		final Loadable persister,
		final Serializable id,
		final SharedSessionContractImplementor session)
	throws HibernateException {
		String discriminatorColumnName = persister.getDiscriminatorColumnName();
		if ( discriminatorColumnName == null ) {
			return persister.getEntityName();
		}
		else {
			Object value = resultset.get( discriminatorColumnName );
			return persister.getSubclassForDiscriminatorValue( value );
		}
	}
319270
public static Optional<Class> resolveInterfaceTypeArgument(Class type, Class interfaceType) {
        Type[] genericInterfaces = type.getGenericInterfaces();
        for (Type genericInterface : genericInterfaces) {
            if (genericInterface instanceof ParameterizedType) {
                ParameterizedType pt = (ParameterizedType) genericInterface;
                if (pt.getRawType() == interfaceType) {
                    return resolveSingleTypeArgument(genericInterface);
                }
            }
        }
        Class superClass = type.getSuperclass();
        if (superClass != null && superClass != Object.class) {
            return resolveInterfaceTypeArgument(superClass, interfaceType);
        }
        return Optional.empty();
    }
242373
public FacesBackingBean getFacesBackingBeanInstance( Class beanClass )
        throws InstantiationException, IllegalAccessException
    {
        assert FacesBackingBean.class.isAssignableFrom( beanClass )
                : "Class " + beanClass.getName() + " does not extend " + FacesBackingBean.class.getName();
        return ( FacesBackingBean ) beanClass.newInstance();
    }
1168582
public static String deleteFromTable(Class<?> entityClass, String defaultTableName) {
        StringBuilder sql = new StringBuilder();
        sql.append("DELETE FROM ");
        sql.append(getDynamicTableName(entityClass, defaultTableName));
        sql.append(" ");
        return sql.toString();
    }
927770
public Class<?> getClass(int id) throws IOException {
      if (id < 0 || id > internalIdToClass.length) {
         throw new IOException("Unknown class id " + id);
      }
      Class<?> clazz = internalIdToClass[id];
      if (clazz == null) {
         throw new IOException("Unknown class id " + id);
      }
      return clazz;
   }
892030
@Override
    <T> Class<T> loadClass(final Class<T> superclassOrInterfaceType) {
        final Class<?> type = getType();
        if (!superclassOrInterfaceType.isAssignableFrom(type)) {
            throw new IllegalArgumentException(
                    "Primitive class " + baseType + " cannot be cast to " + superclassOrInterfaceType.getName());
        }
        @SuppressWarnings("unchecked")
        final Class<T> classT = (Class<T>) type;
        return classT;
    }
146558
protected SqlForClass getSqlForClass(ClassDescriptor cld)
    {
        SqlForClass result = (SqlForClass) sqlForClass.get(cld);
        if(result == null)
        {
            result = newInstanceSqlForClass();
            sqlForClass.put(cld, result);
        }
        return result;
    }
479654
protected final <T> T createDataSource(Class<T> dataSourceClass) throws SQLException {
		if (getRealDataSourceClassName() == null) {
			throw new SQLException("Property realDataSourceClassName is not set");
		}
		try {
			T ds = dataSourceClass.cast(Class.forName(realDataSourceClassName).newInstance());
			for (Method m : ds.getClass().getMethods()) {
				String methodName = m.getName();
				if (methodName.startsWith("set") && m.getParameterTypes().length == 1) {
					final Object propertyValue;
					if (methodName.equals("setUser")) {
						propertyValue = getUser();
					} else if (methodName.equals("setPassword")) {
						propertyValue = getPassword();
					} else if (methodName.equalsIgnoreCase("setUrl")) {
						propertyValue = getRealUrl();
					} else if (methodName.equals("setLogWriter")) {
						propertyValue = getLogWriter();
					} else if (methodName.equals("setLoginTimeout")) {
						propertyValue = getLoginTimeout();
					} else {
						String propertyName = methodName.substring(3, 4).toLowerCase();
						if (methodName.length() > 4) {
							propertyName += methodName.substring(4);
						}
						final Class<?> propertyType = m.getParameterTypes()[0];
						propertyValue = getPropertyAs(propertyName, propertyType);
					}
					if (propertyValue != null) {
						m.invoke(ds, propertyValue);
					}
				}
			}
			return ds;

		} catch (Exception e) {
			throw new SQLException(e);
		}
	}
667244
@Override
	public <T> T getObject(final int columnIndex, final Class<T> type) throws SQLException {
		String columnLabel = getWrapped().getMetaData().getColumnLabel(columnIndex);

		return getObject(columnLabel, type);
	}
1054821
public static <T> int createTableIfNotExists(ConnectionSource connectionSource, Class<T> dataClass)
			throws SQLException {
		Dao<T, ?> dao = DaoManager.createDao(connectionSource, dataClass);
		return doCreateTable(dao, true);
	}
1360606
@Override
    public Class<?> getProxyClass() {
        if (proxyClass != null) {
            return proxyClass;
        }
        if (generic) {
            return GenericService.class;
        }
        try {
            if (StringUtils.isNotBlank(interfaceId)) {
                this.proxyClass = ClassUtils.forName(interfaceId);
                if (!proxyClass.isInterface()) {
                    throw ExceptionUtils.buildRuntime("consumer.interface",
                        interfaceId, "interfaceId must set interface class, not implement class");
                }
            } else {
                throw ExceptionUtils.buildRuntime("consumer.interface",
                    "null", "interfaceId must be not null");
            }
        } catch (RuntimeException t) {
            throw new IllegalStateException(t.getMessage(), t);
        }
        return proxyClass;
    }
910124
public Object getObject(int parameterIndex, Map<String, Class<?>> map)
			throws SQLException {
		checkClosed();
		try {
			return this.internalCallableStatement.getObject(parameterIndex, map);
		} catch (SQLException e) {
			throw this.connectionHandle.markPossiblyBroken(e);
			
		}

	}
216176
public @Nonnull <U extends T> U getInstance(@Nonnull Class<U> type) throws IllegalStateException {
        for (T ext : this)
            if(ext.getClass()==type)
                return type.cast(ext);
        
        throw new IllegalStateException("The class " + type.getName() + " was not found, potentially not yet loaded");
    }
893066
@SuppressWarnings( "unchecked" )
    public static <T> Class<T> returnedClass(Class<?> type)
    {
        ParameterizedType parameterizedType = (ParameterizedType) type.getGenericSuperclass();
        return (Class<T>) parameterizedType.getActualTypeArguments()[0];
    }
498362
public static<T extends Object> T getWrapper(Class<T> clientType){
        return getWrapper(clientType,generateClientId(clientType));
    }