Review Board 1.7.22


SQOOP-1059 Sqoop2: Remove ad hoc modle cloning methods in common module

Review Request #11768 - Created June 9, 2013 and submitted

Jarek Cecho
SQOOP-1059
Reviewers
Sqoop
sqoop-sqoop2
I've removed the adhoc code and reused the model's clone method instead.
Unit and integration tests seems to be passing.

Diff revision 2 (Latest)

1 2
1 2

  1. core/src/main/java/org/apache/sqoop/repository/Repository.java: Loading...
core/src/main/java/org/apache/sqoop/repository/Repository.java
Revision a2911c5c0c050fe39fb03e3a66b609e363ca8f71 New Change
[20] 391 lines
[+20] [+] public final void upgradeConnector(MConnector oldConnector, MConnector newConnector) {
392
      for (MConnection connection : connections) {
392
      for (MConnection connection : connections) {
393
        long connectionID = connection.getPersistenceId();
393
        long connectionID = connection.getPersistenceId();
394
        // Make a new copy of the forms from the connector,
394
        // Make a new copy of the forms from the connector,
395
        // else the values will get set in the forms in the connector for
395
        // else the values will get set in the forms in the connector for
396
        // each connection.
396
        // each connection.
397
        List<MForm> forms = cloneForms(newConnector.getConnectionForms()
397
        List<MForm> forms = newConnector.getConnectionForms().clone(false).getForms();
398
          .getForms());

   
399
        MConnectionForms newConnectionForms = new MConnectionForms(forms);
398
        MConnectionForms newConnectionForms = new MConnectionForms(forms);
400
        upgrader.upgrade(connection.getConnectorPart(), newConnectionForms);
399
        upgrader.upgrade(connection.getConnectorPart(), newConnectionForms);
401
        MConnection newConnection = new MConnection(connectorID,
400
        MConnection newConnection = new MConnection(connectorID,
402
          newConnectionForms, connection.getFrameworkPart());
401
          newConnectionForms, connection.getFrameworkPart());
403
        newConnection.setPersistenceId(connectionID);
402
        newConnection.setPersistenceId(connectionID);
404
        updateConnection(newConnection, tx);
403
        updateConnection(newConnection, tx);
405
      }
404
      }
406
      for (MJob job : jobs) {
405
      for (MJob job : jobs) {
407
        // Make a new copy of the forms from the connector,
406
        // Make a new copy of the forms from the connector,
408
        // else the values will get set in the forms in the connector for
407
        // else the values will get set in the forms in the connector for
409
        // each connection.
408
        // each connection.
410
        List<MForm> forms = cloneForms(newConnector.getJobForms(job.getType())
409
        List<MForm> forms = newConnector.getJobForms(job.getType()).clone(false).getForms();
411
          .getForms());

   
412
        MJobForms newJobForms = new MJobForms(job.getType(), forms);
410
        MJobForms newJobForms = new MJobForms(job.getType(), forms);
413
        upgrader.upgrade(job.getConnectorPart(), newJobForms);
411
        upgrader.upgrade(job.getConnectorPart(), newJobForms);
414
        MJob newJob = new MJob(connectorID, job.getConnectionId(),
412
        MJob newJob = new MJob(connectorID, job.getConnectionId(),
415
          job.getType(), newJobForms, job.getFrameworkPart());
413
          job.getType(), newJobForms, job.getFrameworkPart());
416
        newJob.setPersistenceId(job.getPersistenceId());
414
        newJob.setPersistenceId(job.getPersistenceId());
[+20] [20] 30 lines
[+20] [+] public final void upgradeFramework(MFramework framework) {
447
      for (MConnection connection : connections) {
445
      for (MConnection connection : connections) {
448
        long connectionID = connection.getPersistenceId();
446
        long connectionID = connection.getPersistenceId();
449
        // Make a new copy of the forms from the connector,
447
        // Make a new copy of the forms from the connector,
450
        // else the values will get set in the forms in the connector for
448
        // else the values will get set in the forms in the connector for
451
        // each connection.
449
        // each connection.
452
        List<MForm> forms = cloneForms(framework.getConnectionForms()
450
        List<MForm> forms = framework.getConnectionForms().clone(false).getForms();
453
          .getForms());

   
454
        MConnectionForms newConnectionForms = new MConnectionForms(forms);
451
        MConnectionForms newConnectionForms = new MConnectionForms(forms);
455
        upgrader.upgrade(connection.getFrameworkPart(), newConnectionForms);
452
        upgrader.upgrade(connection.getFrameworkPart(), newConnectionForms);
456
        MConnection newConnection = new MConnection(connection.getConnectorId(),
453
        MConnection newConnection = new MConnection(connection.getConnectorId(),
457
          connection.getConnectorPart(), newConnectionForms);
454
          connection.getConnectorPart(), newConnectionForms);
458
        newConnection.setPersistenceId(connectionID);
455
        newConnection.setPersistenceId(connectionID);
459
        updateConnection(newConnection, tx);
456
        updateConnection(newConnection, tx);
460
      }
457
      }
461
      for (MJob job : jobs) {
458
      for (MJob job : jobs) {
462
        // Make a new copy of the forms from the framework,
459
        // Make a new copy of the forms from the framework,
463
        // else the values will get set in the forms in the connector for
460
        // else the values will get set in the forms in the connector for
464
        // each connection.
461
        // each connection.
465
        List<MForm> forms = cloneForms(framework.getJobForms(job.getType())
462
        List<MForm> forms = framework.getJobForms(job.getType()).clone(false).getForms();
466
          .getForms());

   
467
        MJobForms newJobForms = new MJobForms(job.getType(), forms);
463
        MJobForms newJobForms = new MJobForms(job.getType(), forms);
468
        upgrader.upgrade(job.getFrameworkPart(), newJobForms);
464
        upgrader.upgrade(job.getFrameworkPart(), newJobForms);
469
        MJob newJob = new MJob(job.getConnectorId(), job.getConnectionId(),
465
        MJob newJob = new MJob(job.getConnectorId(), job.getConnectionId(),
470
          job.getType(), job.getConnectorPart(), newJobForms);
466
          job.getType(), job.getConnectorPart(), newJobForms);
471
        newJob.setPersistenceId(job.getPersistenceId());
467
        newJob.setPersistenceId(job.getPersistenceId());
[+20] [20] 10 lines
[+20] public final void upgradeFramework(MFramework framework) {
482
        tx.close();
478
        tx.close();
483
      }
479
      }
484
      LOG.info("Framework metadata upgrade finished");
480
      LOG.info("Framework metadata upgrade finished");
485
    }
481
    }
486
  }
482
  }
487

    
   

   
488
  /**

   
489
   * Clones the forms, but does not set the actual data,

   
490
   * validation message etc in the inputs, but only the persistence id of the

   
491
   * inputs.

   
492
   * @param mForms MForms which must be cloned

   
493
   * @return Cloned MForms

   
494
   * @throws Exception

   
495
   */

   
496
  private List<MForm> cloneForms(List<MForm> mForms) throws Exception {

   
497
    List<MForm> forms = new ArrayList<MForm>();

   
498
    for(MForm mForm : mForms) {

   
499
      List<MInput<?>> inputs = new ArrayList<MInput<?>>();

   
500
      for (MInput<?> input : mForm.getInputs()) {

   
501
        MInput newInput;

   
502
        if(input instanceof MEnumInput) {

   
503
          newInput = new MEnumInput(input.getName(), input.isSensitive(),

   
504
            ((MEnumInput) input).getValues());

   
505
        } else if (input instanceof MMapInput) {

   
506
          newInput = new MMapInput(input.getName(), input.isSensitive());

   
507
        } else if (input instanceof MBooleanInput) {

   
508
          newInput = new MBooleanInput(input.getName(), input.isSensitive());

   
509
        } else if(input instanceof MStringInput) {

   
510
          newInput = new MStringInput(input.getName(), input.isSensitive(),

   
511
            ((MStringInput) input).getMaxLength());

   
512
        } else if (input instanceof MIntegerInput) {

   
513
          newInput = new MIntegerInput(input.getName(), input.isSensitive());

   
514
        } else {

   
515
          throw new SqoopException(ModelError.MODEL_003);

   
516
        }

   
517
        newInput.setPersistenceId(input.getPersistenceId());

   
518
        inputs.add(newInput);

   
519
      }

   
520
      forms.add(new MForm(mForm.getName(), inputs));

   
521
    }

   
522
    return forms;

   
523
  }

   
524
}
483
}
  1. core/src/main/java/org/apache/sqoop/repository/Repository.java: Loading...