<commit_before>/**
 * @license
 * Copyright 2014 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

foam.CLASS({
  package: 'foam.dao',
  name: 'EasyDAO',
  extends: 'foam.dao.ProxyDAO',
  implements: [
    'foam.mlang.Expressions',
    'foam.nanos.boot.NSpecAware'
  ],

  documentation: function() {/*
    Facade for easily creating decorated DAOs.
    <p>
    Most DAOs are most easily created and configured with EasyDAO.
    Simply require foam.dao.EasyDAO and create() with the flags
    to indicate what behavior you're looking for. Under the hood, EasyDAO
    will create one or more DAO instances to service your requirements and then
  */},

  requires: [
    'foam.box.Context',
    'foam.box.HTTPBox',
    'foam.box.RetryBox',
    'foam.box.SessionClientBox',
    'foam.box.SocketBox',
    'foam.box.TimeoutBox',
    'foam.box.WebSocketBox',
    'foam.dao.CachingDAO',
    'foam.dao.ClientDAO',
    'foam.dao.CompoundDAODecorator',
    'foam.dao.ContextualizingDAO',
    'foam.dao.DeDupDAO',
    'foam.dao.DecoratedDAO',
    'foam.dao.GUIDDAO',
    'foam.dao.IDBDAO',
    {
      path: 'foam.dao.JDAO',
      flags: ['js'],
    },
    {
      name: 'JDAOJava',
      path: 'foam.dao.java.JDAO',
      flags: ['java'],
    },
    'foam.dao.MDAO',
    'foam.dao.OrderedDAO',
    'foam.dao.PromisedDAO',
    'foam.dao.TTLCachingDAO',
    'foam.dao.TTLSelectCachingDAO',
    'foam.dao.RequestResponseClientDAO',
    'foam.dao.SequenceNumberDAO',
    'foam.dao.SyncDAO',
    'foam.dao.TimingDAO',
    'foam.dao.JournalType',
    'foam.nanos.auth.ServiceProviderAware',
    'foam.nanos.auth.ServiceProviderAwareDAO',
    'foam.nanos.logger.Logger',
    'foam.nanos.logger.LoggingDAO'
  ],

  imports: [ 'document', 'log' ],

  javaImports: [
    'foam.nanos.logger.Logger'
  ],

  constants: [
    {
      documentation: 'Aliases for daoType',
      name: 'aliases',
      flags: [ 'js' ],
      value: {
        ARRAY:  'foam.dao.ArrayDAO',
        CLIENT: 'foam.dao.RequestResponseClientDAO',
        IDB:    'foam.dao.IDBDAO',
        LOCAL:  'foam.dao.LocalStorageDAO',
        MDAO:   'foam.dao.MDAO'
      }
    }
  ],

  properties: [
    {
      documentation: 'The developer-friendly name for this EasyDAO',
      class: 'String',
      name: 'name',
      factory: function() {
        return this.nSpec && this.nSpec.name || this.of.id;
      },
      javaFactory: `
      if ( getNSpec() != null ) {
        return getNSpec().getName();
      }
      return this.getOf().getId();
     `
    },
    {
      name: 'nSpec',
      class: 'FObjectProperty',
      type: 'foam.nanos.boot.NSpec'
    },
    {
      /** This is set automatically when you create an EasyDAO.
        @private */
      name: 'delegate',
      javaFactory: `
        Logger logger = (Logger) getX().get("logger");

        foam.dao.DAO delegate = getInnerDAO();
        foam.dao.DAO head = delegate;
        foam.dao.ProxyDAO pxy = null;
        while( head instanceof foam.dao.ProxyDAO ) {
          pxy = (foam.dao.ProxyDAO) head;
          head = ( (ProxyDAO) head).getDelegate();
        }
        if ( head instanceof foam.dao.MDAO ) {
          setMdao((foam.dao.MDAO)head);
          if ( getIndex() != null && getIndex().length > 0 )
            getMdao().addIndex(getIndex());
        }
        if ( getFixedSize() != null ) {
          if ( head instanceof foam.dao.MDAO && pxy != null ) {
            foam.dao.ProxyDAO fixedSizeDAO = (foam.dao.ProxyDAO) getFixedSize();
            fixedSizeDAO.setDelegate(head);
            pxy.setDelegate(fixedSizeDAO);
          }
          else {
            logger.error(this.getClass().getSimpleName(), "NSpec.name", (getNSpec() != null ) ? getNSpec().getName() : null, "of_", of_, "FixedSizeDAO did not find instanceof MDAO");
            System.exit(1);
          }
        }

        delegate = getOuterDAO(delegate);

        if ( getDecorator() != null ) {
          if ( ! ( getDecorator() instanceof ProxyDAO ) ) {
            logger.error(this.getClass().getSimpleName(), "delegate", "NSpec.name", (getNSpec() != null ) ? getNSpec().getName() : null, "of_", of_ , "delegateDAO", getDecorator(), "not instanceof ProxyDAO");
            System.exit(1);
          }
          // The decorator dao may be a proxy chain
          ProxyDAO proxy = (ProxyDAO) getDecorator();
          while ( proxy.getDelegate() != null &&
                  proxy.getDelegate() instanceof ProxyDAO )
            proxy = (ProxyDAO) proxy.getDelegate();
          proxy.setDelegate(delegate);
          delegate = (ProxyDAO) getDecorator();
        }

        if ( getGuid() && getSeqNo() )
          throw new RuntimeException("EasyDAO GUID and SeqNo are mutually exclusive");

        if ( getSeqNo() ) {
          delegate = new foam.dao.SequenceNumberDAO.Builder(getX()).
          setDelegate(delegate).
          setProperty(getSeqPropertyName()).
          setStartingValue(getSeqStartingValue()).
          build();
        }

        if ( getApprovableAware() ) {
          delegate = new foam.nanos.approval.ApprovableAwareDAO
          .Builder(getX())
          .setDaoKey(getName())
          .setOf(getOf())
          .setDelegate(delegate)
          .setIsEnabled(getApprovableAwareEnabled())
          .build();
        }
        
        if ( getGuid() )
          delegate = new foam.dao.GUIDDAO.Builder(getX()).setDelegate(delegate).build();

        if ( getValidated() ) {
          if ( getValidator() != null )
            delegate = new foam.dao.ValidatingDAO(getX(), delegate, getValidator());
          else
            delegate = new foam.dao.ValidatingDAO(getX(), delegate, foam.core.ValidatableValidator.instance());
        }

        if ( getServiceProviderAware() ) {
          foam.nanos.auth.ServiceProviderAwareDAO dao = new foam.nanos.auth.ServiceProviderAwareDAO.Builder(getX()).setDelegate(delegate).build();
          if ( getServiceProviderAwarePropertyInfos() != null ) {<commit_msg>Basically moved the approvableAwareDAO after GUID and SEQNO<commit_after>/**
 * @license
 * Copyright 2014 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

foam.CLASS({
  package: 'foam.dao',
  name: 'EasyDAO',
  extends: 'foam.dao.ProxyDAO',
  implements: [
    'foam.mlang.Expressions',
    'foam.nanos.boot.NSpecAware'
  ],

  documentation: function() {/*
    Facade for easily creating decorated DAOs.
    <p>
    Most DAOs are most easily created and configured with EasyDAO.
    Simply require foam.dao.EasyDAO and create() with the flags
    to indicate what behavior you're looking for. Under the hood, EasyDAO
    will create one or more DAO instances to service your requirements and then
  */},

  requires: [
    'foam.box.Context',
    'foam.box.HTTPBox',
    'foam.box.RetryBox',
    'foam.box.SessionClientBox',
    'foam.box.SocketBox',
    'foam.box.TimeoutBox',
    'foam.box.WebSocketBox',
    'foam.dao.CachingDAO',
    'foam.dao.ClientDAO',
    'foam.dao.CompoundDAODecorator',
    'foam.dao.ContextualizingDAO',
    'foam.dao.DeDupDAO',
    'foam.dao.DecoratedDAO',
    'foam.dao.GUIDDAO',
    'foam.dao.IDBDAO',
    {
      path: 'foam.dao.JDAO',
      flags: ['js'],
    },
    {
      name: 'JDAOJava',
      path: 'foam.dao.java.JDAO',
      flags: ['java'],
    },
    'foam.dao.MDAO',
    'foam.dao.OrderedDAO',
    'foam.dao.PromisedDAO',
    'foam.dao.TTLCachingDAO',
    'foam.dao.TTLSelectCachingDAO',
    'foam.dao.RequestResponseClientDAO',
    'foam.dao.SequenceNumberDAO',
    'foam.dao.SyncDAO',
    'foam.dao.TimingDAO',
    'foam.dao.JournalType',
    'foam.nanos.auth.ServiceProviderAware',
    'foam.nanos.auth.ServiceProviderAwareDAO',
    'foam.nanos.logger.Logger',
    'foam.nanos.logger.LoggingDAO'
  ],

  imports: [ 'document', 'log' ],

  javaImports: [
    'foam.nanos.logger.Logger'
  ],

  constants: [
    {
      documentation: 'Aliases for daoType',
      name: 'aliases',
      flags: [ 'js' ],
      value: {
        ARRAY:  'foam.dao.ArrayDAO',
        CLIENT: 'foam.dao.RequestResponseClientDAO',
        IDB:    'foam.dao.IDBDAO',
        LOCAL:  'foam.dao.LocalStorageDAO',
        MDAO:   'foam.dao.MDAO'
      }
    }
  ],

  properties: [
    {
      documentation: 'The developer-friendly name for this EasyDAO',
      class: 'String',
      name: 'name',
      factory: function() {
        return this.nSpec && this.nSpec.name || this.of.id;
      },
      javaFactory: `
      if ( getNSpec() != null ) {
        return getNSpec().getName();
      }
      return this.getOf().getId();
     `
    },
    {
      name: 'nSpec',
      class: 'FObjectProperty',
      type: 'foam.nanos.boot.NSpec'
    },
    {
      /** This is set automatically when you create an EasyDAO.
        @private */
      name: 'delegate',
      javaFactory: `
        Logger logger = (Logger) getX().get("logger");

        foam.dao.DAO delegate = getInnerDAO();
        foam.dao.DAO head = delegate;
        foam.dao.ProxyDAO pxy = null;
        while( head instanceof foam.dao.ProxyDAO ) {
          pxy = (foam.dao.ProxyDAO) head;
          head = ( (ProxyDAO) head).getDelegate();
        }
        if ( head instanceof foam.dao.MDAO ) {
          setMdao((foam.dao.MDAO)head);
          if ( getIndex() != null && getIndex().length > 0 )
            getMdao().addIndex(getIndex());
        }
        if ( getFixedSize() != null ) {
          if ( head instanceof foam.dao.MDAO && pxy != null ) {
            foam.dao.ProxyDAO fixedSizeDAO = (foam.dao.ProxyDAO) getFixedSize();
            fixedSizeDAO.setDelegate(head);
            pxy.setDelegate(fixedSizeDAO);
          }
          else {
            logger.error(this.getClass().getSimpleName(), "NSpec.name", (getNSpec() != null ) ? getNSpec().getName() : null, "of_", of_, "FixedSizeDAO did not find instanceof MDAO");
            System.exit(1);
          }
        }

        delegate = getOuterDAO(delegate);

        if ( getDecorator() != null ) {
          if ( ! ( getDecorator() instanceof ProxyDAO ) ) {
            logger.error(this.getClass().getSimpleName(), "delegate", "NSpec.name", (getNSpec() != null ) ? getNSpec().getName() : null, "of_", of_ , "delegateDAO", getDecorator(), "not instanceof ProxyDAO");
            System.exit(1);
          }
          // The decorator dao may be a proxy chain
          ProxyDAO proxy = (ProxyDAO) getDecorator();
          while ( proxy.getDelegate() != null &&
                  proxy.getDelegate() instanceof ProxyDAO )
            proxy = (ProxyDAO) proxy.getDelegate();
          proxy.setDelegate(delegate);
          delegate = (ProxyDAO) getDecorator();
        }

        if ( getApprovableAware() ) {
          delegate = new foam.nanos.approval.ApprovableAwareDAO
          .Builder(getX())
          .setDaoKey(getName())
          .setOf(getOf())
          .setDelegate(delegate)
          .setIsEnabled(getApprovableAwareEnabled())
          .build();
        }

        if ( getGuid() && getSeqNo() )
          throw new RuntimeException("EasyDAO GUID and SeqNo are mutually exclusive");

        if ( getSeqNo() ) {
          delegate = new foam.dao.SequenceNumberDAO.Builder(getX()).
          setDelegate(delegate).
          setProperty(getSeqPropertyName()).
          setStartingValue(getSeqStartingValue()).
          build();
        }
        
        if ( getGuid() )
          delegate = new foam.dao.GUIDDAO.Builder(getX()).setDelegate(delegate).build();

        if ( getValidated() ) {
          if ( getValidator() != null )
            delegate = new foam.dao.ValidatingDAO(getX(), delegate, getValidator());
          else
            delegate = new foam.dao.ValidatingDAO(getX(), delegate, foam.core.ValidatableValidator.instance());
        }

        if ( getServiceProviderAware() ) {
          foam.nanos.auth.ServiceProviderAwareDAO dao = new foam.nanos.auth.ServiceProviderAwareDAO.Builder(getX()).setDelegate(delegate).build();
          if ( getServiceProviderAwarePropertyInfos() != null ) {
{'fraction_non_alphanumeric': 0.1350107394906413, 'fraction_numerical': 0.0016876342436330162, 'mean_word_length': 2.3445356593124678, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7213576', 'n_tokens_mistral': 4206, 'n_tokens_neox': 4253, 'n_words': 875}