Example usage for org.apache.commons.lang3.mutable MutableBoolean setValue

List of usage examples for org.apache.commons.lang3.mutable MutableBoolean setValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableBoolean setValue.

Prototype

@Override
public void setValue(final Boolean value) 

Source Link

Document

Sets the value from any Boolean instance.

Usage

From source file:asterix.parser.classad.Value.java

public boolean isBooleanValue(MutableBoolean b) {
    if (valueType == ValueType.BOOLEAN_VALUE) {
        b.setValue(boolVal);
        return true;
    }/*from w  w w  .  ja  v a2  s  . c o  m*/
    return false;
}

From source file:com.datatorrent.lib.appdata.query.SimpleDoneQueryQueueManagerTest.java

@Test
public void expiredTestBlocking() throws Exception {
    SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();

    sdqqm.setup(null);//from ww  w.  j ava  2  s.  c om
    sdqqm.beginWindow(0);

    Query query = new MockQuery("1");
    MutableBoolean queueContext = new MutableBoolean(false);
    sdqqm.enqueue(query, null, queueContext);

    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    sdqqm.endWindow();

    sdqqm.beginWindow(1);

    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    queueContext.setValue(true);
    testBlocking(sdqqm);

    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    sdqqm.endWindow();
    sdqqm.teardown();
}

From source file:com.datatorrent.lib.appdata.query.SimpleDoneQueryQueueManagerTest.java

@Test
public void expiredTestBlockingValidFirstExpiredLast() throws Exception {
    SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();

    sdqqm.setup(null);/*from www.  ja  v a2s.  c  o  m*/
    sdqqm.beginWindow(0);

    Query query = new MockQuery("1");
    MutableBoolean queueContext = new MutableBoolean(false);
    sdqqm.enqueue(query, null, queueContext);

    Query query1 = new MockQuery("2");
    MutableBoolean queueContext1 = new MutableBoolean(false);
    sdqqm.enqueue(query1, null, queueContext1);

    Assert.assertEquals(2, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    sdqqm.endWindow();

    sdqqm.beginWindow(1);

    Assert.assertEquals(2, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    queueContext1.setValue(true);
    qb = sdqqm.dequeueBlock();

    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    testBlocking(sdqqm);

    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    sdqqm.endWindow();

    sdqqm.beginWindow(2);

    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    qb = sdqqm.dequeueBlock();

    testBlocking(sdqqm);

    sdqqm.endWindow();

    sdqqm.teardown();
}

From source file:enumj.Enumerator.java

/**
 * Returns an infinite enumerator obtained by applying repeatedly the
 * provided unary operator.// w  w w.j a va 2  s . co m
 * <p>
 * The resulted enumerator returns <code>seed</code>,
 * <code>f(seed)</code>, <code>f(f(seed))</code> ...
 * </p>
 *
 * @param <E> the type of enumerated elements
 * @param seed the initial element
 * @param f state-less {@link Function} instance to apply on the previous
 * element to obtain the next element
 * @return the iterated enumerator
 * @exception IllegalArgumentException <code>f</code> is null.
 */
public static <E> Enumerator<E> iterate(E seed, UnaryOperator<E> f) {
    Checks.ensureNotNull(f, Messages.NULL_ENUMERATOR_GENERATOR);
    final Mutable<E> result = new MutableObject(seed);
    final MutableBoolean first = new MutableBoolean(true);
    return of(() -> {
        if (first.booleanValue()) {
            first.setValue(false);
        } else {
            result.setValue(f.apply(result.getValue()));
        }
        return Optional.of(result.getValue());
    });
}

From source file:com.mirth.connect.plugins.datapruner.DataPrunerPanel.java

public void doStart() {
    final MutableBoolean saveChanges = new MutableBoolean(false);

    if (isSaveEnabled()) {
        if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this,
                "Settings changes must be saved first, would you like to save the settings and prune now?",
                "Select an Option", JOptionPane.OK_CANCEL_OPTION)) {
            if (!validateFields()) {
                return;
            }// w w w .java 2s.c  o  m

            saveChanges.setValue(true);
        } else {
            return;
        }
    }

    setStartTaskVisible(false);
    final String workingId = parent.startWorking("Starting the data pruner...");

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() {
            if (saveChanges.getValue()) {
                try {
                    plugin.setPropertiesToServer(getProperties());
                } catch (Exception e) {
                    getFrame().alertThrowable(getFrame(), e);
                    return null;
                }
            }

            try {
                parent.mirthClient.getServlet(DataPrunerServletInterface.class).start();
            } catch (Exception e) {
                parent.alertThrowable(parent, e,
                        "An error occurred while attempting to start the data pruner.");
                return null;
            }

            return null;
        }

        @Override
        public void done() {
            if (saveChanges.getValue()) {
                setSaveEnabled(false);
            }

            parent.stopWorking(workingId);
            updateStatus();
        }
    };

    worker.execute();
}

From source file:com.datatorrent.lib.appdata.query.SimpleDoneQueryQueueManagerTest.java

@Test
public void expiredTestBlockingExpiredFirstValidLast() throws Exception {
    SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();

    sdqqm.setup(null);/*from   w w  w  .ja  va2s . c  om*/
    sdqqm.beginWindow(0);

    Query query = new MockQuery("1");
    MutableBoolean queueContext = new MutableBoolean(false);
    sdqqm.enqueue(query, null, queueContext);

    Query query1 = new MockQuery("2");
    MutableBoolean queueContext1 = new MutableBoolean(false);
    sdqqm.enqueue(query1, null, queueContext1);

    Assert.assertEquals(2, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
    QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    sdqqm.endWindow();

    sdqqm.beginWindow(1);

    Assert.assertEquals(2, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    queueContext.setValue(true);
    qb = sdqqm.dequeueBlock();

    Assert.assertEquals(0, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    testBlocking(sdqqm);

    sdqqm.endWindow();

    sdqqm.beginWindow(2);

    Assert.assertEquals(1, sdqqm.getNumLeft());
    Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());

    qb = sdqqm.dequeueBlock();

    testBlocking(sdqqm);

    sdqqm.endWindow();

    sdqqm.teardown();
}

From source file:com.ibm.jaggr.core.impl.modulebuilder.javascript.RequireExpansionCompilerPassTest.java

@Test
public void testRequireExpansion() throws Exception {
    List<ModuleDeps> expanded = new ArrayList<ModuleDeps>();
    MutableBoolean hasExpandableRequires = new MutableBoolean(false);
    RequireExpansionCompilerPass pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null,
            expanded, hasExpandableRequires, true, null, false, null);

    String code, output;/* w  w  w . j  a v  a  2 s . c o  m*/

    // Ensure require list is modified
    code = "require([\"foo\"],function(foo){});";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"" + placeHolder0 + "\"]"));
    Assert.assertEquals(1, expanded.size());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })),
            expanded.get(0).getModuleIds());
    Assert.assertTrue(hasExpandableRequires.getValue());

    // Ensure require list is modified
    hasExpandableRequires.setValue(false);
    code = "require([\"foo\"]);";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"" + placeHolder0 + "\"]"));
    Assert.assertEquals(1, expanded.size());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })),
            expanded.get(0).getModuleIds());
    Assert.assertTrue(hasExpandableRequires.getValue());

    // Ensure require list is NOT modified
    hasExpandableRequires.setValue(false);
    pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null, expanded,
            hasExpandableRequires, false, null, false, null);
    code = "require([\"foo\"]);";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertEquals(code, output);
    Assert.assertEquals(0, expanded.size());
    Assert.assertTrue(hasExpandableRequires.getValue());

    // Ensure hasExpandableRequires is false
    hasExpandableRequires.setValue(false);
    pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null, expanded,
            hasExpandableRequires, false, null, false, null);
    code = "define([\"foo\"], function(foo) {});";
    Assert.assertFalse(hasExpandableRequires.getValue());

    // Ensure only array literals are expanded
    pass = new RequireExpansionCompilerPass(mockAggregator, new Features(), null, expanded,
            new MutableBoolean(false), true, null, false, null);
    code = "require(\"foo\");";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertEquals(code, output);

    // Ensure variables are not modified
    code = "require([\"foo\", jsvar])";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",jsvar,\"" + placeHolder0 + "\"]"));
    Assert.assertEquals(1, expanded.size());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })),
            expanded.get(0).getModuleIds());

    // test with compound strings
    code = "require([\"foo\" + jsvar])";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\"+jsvar]"));

    code = "require([\"foo\" + \"bar\"])";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\"+\"bar\"]"));

    code = "require([\"foo\", \"a\"+\"b\", \"x/y\"])";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"a\"+\"b\",\"x/y\",\"" + placeHolder0 + "\"]"));
    Assert.assertEquals(1, expanded.size());
    System.out.println(expanded.get(0).keySet());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b", "x/y/z" })),
            expanded.get(0).getModuleIds());

    // Ensure relative paths are resolved based on module name
    moduleName = "a/a";
    code = "require([\"foo\",\"./c\"]);";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"./c\",\"" + placeHolder0 + "\"]"));
    Assert.assertEquals(1, expanded.size());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b", "c/d" })),
            expanded.get(0).getModuleIds());
    moduleName = "test";

    // Ensure enclosing dependencies not expanded
    code = "define([\"bar\"],function(bar){require([\"foo\",\"a/b\"])});";
    moduleName = "dependsOnBar";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertEquals(code, output);

    // No encloding dependencies
    moduleName = "dependsOnModule";
    code = "define([\"module\"],function(bar){require([\"foo\"]);});";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"" + placeHolder0 + "\"]"));
    Assert.assertEquals(1, expanded.size());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })),
            expanded.get(0).getModuleIds());

    // multiple require calls
    code = "define([\"module\"],function(bar){require([\"foo\"]); var abc = 123; require([\"x/y\"]);});";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"" + placeHolder0 + "\"]"));
    Assert.assertTrue(output.contains("[\"x/y\",\"" + placeHolder1 + "\"]"));
    Assert.assertEquals(2, expanded.size());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "bar", "a/b" })),
            expanded.get(0).getModuleIds());
    Assert.assertEquals(new LinkedHashSet<String>(Arrays.asList(new String[] { "foo", "bar", "a/b", "x/y/z" })),
            expanded.get(1).getModuleIds());

    // Enable development mode and make sure a RuntimeDependencyVerificationException
    // is thrown if the dependency list specified in the code does not match
    // the dependency list returned by IDependencies.getDeclaredDependencies()
    // for the module.

    // First, enable development mode
    mockAggregator.getOptions().setOption(IOptions.DEVELOPMENT_MODE, true);
    mockAggregator.getOptions().setOption(IOptions.VERIFY_DEPS, true);

    // this test should not throw because the code matches the dependencies
    code = "define([\"module\"],function(bar){require([\"foo\"]);});";
    output = runPass(pass, code);
    System.out.println(output);
    Assert.assertTrue(output.contains("[\"foo\",\"" + placeHolder0 + "\"]"));

    // This test should throw because the code doesn't match the dependencies
    boolean exceptionThrown = false;
    code = "define([\"module\",\"another\"],function(bar){require([\"foo\"]);});";
    try {
        output = runPass(pass, code);
        System.out.println(output);
    } catch (RuntimeDependencyVerificationException e) {
        exceptionThrown = true;
    }
    Assert.assertTrue("RuntimeDependencyVerificationException not thrown", exceptionThrown);

    // This test verifies that relative dependency paths are resolved correctly
    // Will throw RuntimeDependencyVerificationException if relative modules
    // specified in define are not normalized and resolved to the absolute paths
    // specified in the dependency map for module x/y.
    moduleName = "x/y";
    code = "define([\"./y/z\",\"../foo\"],function(bar){require([\"foo\"]);});";
    output = runPass(pass, code);
    System.out.println(output);

    moduleName = "dependsOnModule";
    code = "define([\"module\",\"another\"],function(bar){require([\"foo\"]);});";

    // Assert that both development mode and verify deps need to be enabled
    // for an exception to be thrown
    mockAggregator.getOptions().setOption(IOptions.DEVELOPMENT_MODE, true);
    mockAggregator.getOptions().setOption(IOptions.VERIFY_DEPS, false);
    output = runPass(pass, code);
    mockAggregator.getOptions().setOption(IOptions.DEVELOPMENT_MODE, false);
    mockAggregator.getOptions().setOption(IOptions.VERIFY_DEPS, true);
    output = runPass(pass, code);
    mockAggregator.getOptions().setOption(IOptions.DEVELOPMENT_MODE, false);
    mockAggregator.getOptions().setOption(IOptions.VERIFY_DEPS, false);
    output = runPass(pass, code);

}

From source file:com.mgmtp.perfload.agent.Transformer.java

@Override
public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined,
        final ProtectionDomain protectionDomain, final byte[] classfileBuffer)
        throws IllegalClassFormatException {

    final String classNameWithDots = className.replace('/', '.');
    EntryPoints entryPoints = config.getEntryPoints();

    final Map<String, MethodInstrumentations> methodsConfig = config.getInstrumentations()
            .get(classNameWithDots);//from w  w  w.j a  v  a  2 s.c o m
    final boolean isFilter = entryPoints.hasFilter(classNameWithDots);
    final boolean isServlet = entryPoints.hasServlet(classNameWithDots);

    if (methodsConfig == null && !isFilter && !isServlet) {
        // no instrumentation configured for this class
        // return null, so no transformation is done
        return null;
    }

    logger.writeln("Transforming class: " + classNameWithDots);

    // flag for storing if at least one hook is weaved in
    final MutableBoolean weaveFlag = new MutableBoolean();

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
    ClassVisitor cv = new ClassVisitor(Opcodes.ASM4, cw) {
        @Override
        public MethodVisitor visitMethod(final int access, final String name, final String desc,
                final String signature, final String[] exceptions) {
            MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
            if (mv != null) {
                if (isFilter && "doFilter".equals(name)
                        || isServlet && "service".equals(name) && SERVLET_SERVICE_DESC.equals(desc)) {
                    mv = createServletApiHookVisitor(access, name, desc, mv);
                }
                if (methodsConfig != null) {
                    MethodInstrumentations methodInstrumentations = methodsConfig.get(name);
                    if (methodInstrumentations != null) {
                        mv = createMeasuringHookVisitor(access, name, desc, mv, methodInstrumentations);
                    }
                }
            }
            return mv;
        }

        private MethodVisitor createMeasuringHookVisitor(final int access, final String methodName,
                final String desc, final MethodVisitor mv,
                final MethodInstrumentations methodInstrumentations) {
            boolean weave = false;
            if (methodInstrumentations.isEmpty()) {
                // no params configured, so we just weave the hook into any method with this name
                weave = true;
            } else {
                // weave if params match
                for (List<String> paramClassNames : methodInstrumentations) {
                    Type[] argumentTypes = Type.getArgumentTypes(desc);
                    List<String> classNames = newArrayListWithCapacity(argumentTypes.length);
                    for (Type argumentType : argumentTypes) {
                        classNames.add(argumentType.getClassName());
                    }
                    if (classNames.equals(paramClassNames)) {
                        weave = true;
                        break;
                    }
                }
            }
            if (weave) {
                logger.writeln("Instrumenting method: " + classNameWithDots + "." + methodName);
                weaveFlag.setValue(true);
                return new MeasuringHookMethodVisitor(access, classNameWithDots, methodName, desc, mv);
            }
            return mv;
        }

        private MethodVisitor createServletApiHookVisitor(final int access, final String methodName,
                final String desc, final MethodVisitor mv) {
            logger.writeln("Adding servlet api hook: " + classNameWithDots + "." + methodName);
            weaveFlag.setValue(true);
            return new ServletApiHookMethodVisitor(access, methodName, desc, mv);
        }
    };

    // accept the visitor in order to perform weaving
    cr.accept(cv, ClassReader.EXPAND_FRAMES);

    if (weaveFlag.isTrue()) {
        byte[] transformedclassBytes = cw.toByteArray();
        dumpTransformedClassFile(className, transformedclassBytes);
        return transformedclassBytes;
    }

    // no transformation
    return null;
}

From source file:nl.b3p.viewer.config.services.FeatureSource.java

public SimpleFeatureType addOrUpdateFeatureType(String typeName, SimpleFeatureType newType,
        MutableBoolean updated) {
    SimpleFeatureType old = getFeatureType(typeName);
    if (old != null) {
        updated.setValue(old.update(newType));
        return old;
    }//from w  ww  . ja  v a  2  s. c o  m

    newType.setFeatureSource(this);
    getFeatureTypes().add(newType);

    return newType;
}

From source file:org.apache.asterix.app.translator.QueryTranslator.java

protected void doDropDataset(Dataset ds, String datasetName, AqlMetadataProvider metadataProvider,
        MutableObject<MetadataTransactionContext> mdTxnCtx, List<JobSpecification> jobsToExecute,
        String dataverseName, MutableBoolean bActiveTxn, MutableObject<ProgressState> progress,
        IHyracksClientConnection hcc) throws Exception {
    Map<FeedConnectionId, Pair<JobSpecification, Boolean>> disconnectJobList = new HashMap<>();
    if (ds.getDatasetType() == DatasetType.INTERNAL) {
        // prepare job spec(s) that would disconnect any active feeds involving the dataset.
        IActiveEntityEventsListener[] activeListeners = ActiveJobNotificationHandler.INSTANCE
                .getEventListeners();// w  w  w.j ava 2 s. c  o m
        for (IActiveEntityEventsListener listener : activeListeners) {
            if (listener.isEntityUsingDataset(dataverseName, datasetName)) {
                throw new AsterixException(
                        "Can't drop dataset since it is connected to active entity: " + listener.getEntityId());
            }
        }

        // #. prepare jobs to drop the datatset and the indexes in NC
        List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx.getValue(), dataverseName,
                datasetName);
        for (int j = 0; j < indexes.size(); j++) {
            if (indexes.get(j).isSecondaryIndex()) {
                CompiledIndexDropStatement cds = new CompiledIndexDropStatement(dataverseName, datasetName,
                        indexes.get(j).getIndexName());
                jobsToExecute.add(IndexOperations.buildDropSecondaryIndexJobSpec(cds, metadataProvider, ds));
            }
        }
        CompiledDatasetDropStatement cds = new CompiledDatasetDropStatement(dataverseName, datasetName);
        jobsToExecute.add(DatasetOperations.createDropDatasetJobSpec(cds, metadataProvider));

        // #. mark the existing dataset as PendingDropOp
        MetadataManager.INSTANCE.dropDataset(mdTxnCtx.getValue(), dataverseName, datasetName);
        MetadataManager.INSTANCE.addDataset(mdTxnCtx.getValue(),
                new Dataset(dataverseName, datasetName, ds.getItemTypeDataverseName(), ds.getItemTypeName(),
                        ds.getMetaItemTypeDataverseName(), ds.getMetaItemTypeName(), ds.getNodeGroupName(),
                        ds.getCompactionPolicy(), ds.getCompactionPolicyProperties(), ds.getDatasetDetails(),
                        ds.getHints(), ds.getDatasetType(), ds.getDatasetId(),
                        IMetadataEntity.PENDING_DROP_OP));

        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
        bActiveTxn.setValue(false);
        progress.setValue(ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA);

        // # disconnect the feeds
        for (Pair<JobSpecification, Boolean> p : disconnectJobList.values()) {
            JobUtils.runJob(hcc, p.first, true);
        }

        // #. run the jobs
        for (JobSpecification jobSpec : jobsToExecute) {
            JobUtils.runJob(hcc, jobSpec, true);
        }

        mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction());
        bActiveTxn.setValue(true);
        metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
    } else {
        // External dataset
        ExternalDatasetsRegistry.INSTANCE.removeDatasetInfo(ds);
        // #. prepare jobs to drop the datatset and the indexes in NC
        List<Index> indexes = MetadataManager.INSTANCE.getDatasetIndexes(mdTxnCtx.getValue(), dataverseName,
                datasetName);
        for (int j = 0; j < indexes.size(); j++) {
            if (ExternalIndexingOperations.isFileIndex(indexes.get(j))) {
                CompiledIndexDropStatement cds = new CompiledIndexDropStatement(dataverseName, datasetName,
                        indexes.get(j).getIndexName());
                jobsToExecute.add(IndexOperations.buildDropSecondaryIndexJobSpec(cds, metadataProvider, ds));
            } else {
                CompiledIndexDropStatement cds = new CompiledIndexDropStatement(dataverseName, datasetName,
                        indexes.get(j).getIndexName());
                jobsToExecute
                        .add(ExternalIndexingOperations.buildDropFilesIndexJobSpec(cds, metadataProvider, ds));
            }
        }

        // #. mark the existing dataset as PendingDropOp
        MetadataManager.INSTANCE.dropDataset(mdTxnCtx.getValue(), dataverseName, datasetName);
        MetadataManager.INSTANCE.addDataset(mdTxnCtx.getValue(),
                new Dataset(dataverseName, datasetName, ds.getItemTypeDataverseName(), ds.getItemTypeName(),
                        ds.getNodeGroupName(), ds.getCompactionPolicy(), ds.getCompactionPolicyProperties(),
                        ds.getDatasetDetails(), ds.getHints(), ds.getDatasetType(), ds.getDatasetId(),
                        IMetadataEntity.PENDING_DROP_OP));

        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue());
        bActiveTxn.setValue(false);
        progress.setValue(ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA);

        // #. run the jobs
        for (JobSpecification jobSpec : jobsToExecute) {
            JobUtils.runJob(hcc, jobSpec, true);
        }
        if (!indexes.isEmpty()) {
            ExternalDatasetsRegistry.INSTANCE.removeDatasetInfo(ds);
        }
        mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction());
        bActiveTxn.setValue(true);
        metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue());
    }

    // #. finally, delete the dataset.
    MetadataManager.INSTANCE.dropDataset(mdTxnCtx.getValue(), dataverseName, datasetName);
    // Drop the associated nodegroup
    String nodegroup = ds.getNodeGroupName();
    if (!nodegroup.equalsIgnoreCase(MetadataConstants.METADATA_DEFAULT_NODEGROUP_NAME)) {
        MetadataManager.INSTANCE.dropNodegroup(mdTxnCtx.getValue(), dataverseName + ":" + datasetName);
    }
}