コード例 #1
0
  /** Return the method for the WebSphere JDBC connection wrapper vendorConnection. */
  protected Method getVendorConnectionMethod() {
    if ((this.vendorConnectionMethod == null) && (!getWebsphereUtilClass().equals(void.class))) {
      try {
        Class args[] = new Class[1];
        args[0] = getWebsphereConnectionClass();
        this.vendorConnectionMethod =
            PrivilegedAccessHelper.getDeclaredMethod(
                getWebsphereUtilClass(), "getNativeConnection", args);
      } catch (NoSuchMethodException exception) {
        getDatabaseSession()
            .getSessionLog()
            .logThrowable(SessionLog.WARNING, SessionLog.SERVER, exception);
      }
    }

    return this.vendorConnectionMethod;
  }
コード例 #2
0
  /**
   * Return the java.lang.reflect.Member for the represented attribute. In the case of property
   * access the get method will be returned
   *
   * @return corresponding java.lang.reflect.Member
   */
  @Override
  public Member getJavaMember() {
    AttributeAccessor accessor = getMapping().getAttributeAccessor();
    if (accessor.isMethodAttributeAccessor()) {
      // Method level access here
      Method aMethod = ((MethodAttributeAccessor) accessor).getGetMethod();
      if (null == aMethod) {
        // 316991: If the getMethod is not set - use a reflective call via the getMethodName
        String getMethodName = null;
        try {
          getMethodName =
              ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName();
          if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
            aMethod =
                AccessController.doPrivileged(
                    new PrivilegedGetDeclaredMethod(
                        this.getManagedTypeImpl().getJavaType(), getMethodName, null));
          } else {
            aMethod =
                PrivilegedAccessHelper.getDeclaredMethod(
                    this.getManagedTypeImpl().getJavaType(), getMethodName, null);
          }
          // Exceptions are to be ignored for reflective calls - if the methodName is also null - it
          // will catch here
        } catch (PrivilegedActionException pae) {
          // pae.printStackTrace();
        } catch (NoSuchMethodException nsfe) {
          // nsfe.printStackTrace();
        }
      }
      return aMethod;
    }

    // Field level access here
    Member aMember = ((InstanceVariableAttributeAccessor) accessor).getAttributeField();
    // For primitive and basic types - we should not return null - the attributeAccessor on the
    // MappedSuperclass is not initialized - see
    // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_95:_20091017:_Attribute.getJavaMember.28.29_returns_null_for_a_BasicType_on_a_MappedSuperclass_because_of_an_uninitialized_accessor
    // MappedSuperclasses need special handling to get their type from an inheriting subclass
    // Note: This code does not handle attribute overrides on any entity subclass tree - use
    // descriptor initialization instead
    if (null == aMember) {
      if (this.getManagedTypeImpl().isMappedSuperclass()) {
        // get inheriting subtype member (without handling @override annotations)
        AttributeImpl inheritingTypeMember =
            ((MappedSuperclassTypeImpl) this.getManagedTypeImpl())
                .getMemberFromInheritingType(mapping.getAttributeName());
        // 322166: If attribute is defined on this current ManagedType (and not on a superclass) -
        // do not attempt a reflective call on a superclass
        if (null != inheritingTypeMember) {
          // Verify we have an attributeAccessor
          aMember =
              ((InstanceVariableAttributeAccessor)
                      inheritingTypeMember.getMapping().getAttributeAccessor())
                  .getAttributeField();
        }
      }

      if (null == aMember) {
        // 316991: Handle Embeddable types
        // If field level access - perform a getDeclaredField call
        // Field level access
        // Check declaredFields in the case where we have no getMethod or getMethodName
        try {
          if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
            aMember =
                AccessController.doPrivileged(
                    new PrivilegedGetDeclaredField(
                        this.getManagedTypeImpl().getJavaType(),
                        mapping.getAttributeName(),
                        false));
          } else {
            aMember =
                PrivilegedAccessHelper.getDeclaredField(
                    this.getManagedTypeImpl().getJavaType(), mapping.getAttributeName(), false);
          }
          // Exceptions are to be ignored for reflective calls - if the methodName is also null - it
          // will catch here
        } catch (PrivilegedActionException pae) {
          // pae.printStackTrace();
        } catch (NoSuchFieldException nsfe) {
          // nsfe.printStackTrace();
        }
      }
    }

    // 303063: secondary check for attribute override case - this will show on code coverage
    if (null == aMember) {
      AbstractSessionLog.getLog()
          .log(
              SessionLog.FINEST,
              AbstractSessionLog.METAMODEL,
              "metamodel_attribute_getmember_is_null",
              this,
              this.getManagedTypeImpl(),
              this.getDescriptor());
    }

    return aMember;
  }