예제 #1
0
  /**
   * PUBLIC: Return a session broker that behaves as a client session broker. An acquire session
   * broker is done under the covers on each session inside the session broker, and a new broker is
   * returned.
   *
   * <p>NOTE: when finished with the client broker, it should be releases. See
   * releaseClientSessionBroker.
   */
  public SessionBroker acquireClientSessionBroker() {
    log(SessionLog.FINER, SessionLog.CONNECTION, "acquire_client_session_broker");
    SessionBroker clientBroker = copySessionBroker();
    clientBroker.parent = this;
    clientBroker
        .getIdentityMapAccessorInstance()
        .setIdentityMapManager(getIdentityMapAccessorInstance().getIdentityMapManager());
    clientBroker.commitManager = getCommitManager();
    clientBroker.commandManager = getCommandManager();
    clientBroker.externalTransactionController = getExternalTransactionController();
    clientBroker.setServerPlatform(getServerPlatform());
    String sessionName;
    AbstractSession serverSession;
    Iterator names = this.getSessionsByName().keySet().iterator();
    while (names.hasNext()) {
      sessionName = (String) names.next();
      serverSession = getSessionForName(sessionName);
      if (serverSession instanceof org.eclipse.persistence.sessions.server.ServerSession) {
        if (serverSession.getProject().hasIsolatedClasses()) {
          throw ValidationException.isolatedDataNotSupportedInSessionBroker(sessionName);
        }
        clientBroker.internalRegisterSession(
            sessionName,
            ((org.eclipse.persistence.sessions.server.ServerSession) serverSession)
                .acquireClientSession());
      } else {
        throw ValidationException.cannotAcquireClientSessionFromSession();
      }
    }

    clientBroker.initializeSequencing();
    return clientBroker;
  }
    @Override
    public void bootstrapBeanValidation(
        Map puProperties, AbstractSession session, ClassLoader appClassLoader) {

      ValidatorFactory validatorFactory = getValidatorFactory(puProperties);

      // Check user/environment has specified the validator factory
      if (validatorFactory != null) {
        // We could obtain a validator factory => Bean Validation API is available at runtime. It is
        // ok to cast now
        ValidatorFactory beanValidatorFactory = validatorFactory;

        Class[] groupPrePersit =
            translateValidationGroups(
                (String) puProperties.get(PersistenceUnitProperties.VALIDATION_GROUP_PRE_PERSIST),
                appClassLoader);
        Class[] groupPreUpdate =
            translateValidationGroups(
                (String) puProperties.get(PersistenceUnitProperties.VALIDATION_GROUP_PRE_UPDATE),
                appClassLoader);
        Class[] groupPreRemove =
            translateValidationGroups(
                (String) puProperties.get(PersistenceUnitProperties.VALIDATION_GROUP_PRE_REMOVE),
                appClassLoader);

        BeanValidationListener validationListener =
            new BeanValidationListener(
                beanValidatorFactory, groupPrePersit, groupPreUpdate, groupPreRemove);
        // Install BeanValidationListener on the desc
        for (ClassDescriptor descriptor : session.getProject().getOrderedDescriptors()) {
          if (descriptor.isDescriptorTypeNormal()) {
            // add only to entities
            descriptor.getEventManager().addInternalListener(validationListener);
          }
        }
      }
    }