Review Board 1.7.22


SQOOP-942 Sqoop2: Refactore code repetition in SqoopRequests objects

Review Request #9991 - Created March 17, 2013 and submitted

Jarek Cecho
SQOOP-942
Reviewers
Sqoop
sqoop-sqoop2
I've moved the logic of applying validations from SqoopRequests to SqoopClient as it logically belongs there.
Unit and integration tests seems to be passing.
client/src/main/java/org/apache/sqoop/client/SqoopClient.java
Revision 554a8fe97a14db3f03e0adfc200871391bfb1b64 New Change
[20] 15 lines
[+20]
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18
package org.apache.sqoop.client;
18
package org.apache.sqoop.client;
19

    
   
19

   
20
import org.apache.sqoop.client.request.SqoopRequests;
20
import org.apache.sqoop.client.request.SqoopRequests;

    
   
21
import org.apache.sqoop.json.ValidationBean;

    
   
22
import org.apache.sqoop.model.FormUtils;
21
import org.apache.sqoop.model.MConnection;
23
import org.apache.sqoop.model.MConnection;
22
import org.apache.sqoop.model.MConnector;
24
import org.apache.sqoop.model.MConnector;
23
import org.apache.sqoop.model.MFramework;
25
import org.apache.sqoop.model.MFramework;
24
import org.apache.sqoop.model.MJob;
26
import org.apache.sqoop.model.MJob;
25
import org.apache.sqoop.model.MSubmission;
27
import org.apache.sqoop.model.MSubmission;
26
import org.apache.sqoop.validation.Status;
28
import org.apache.sqoop.validation.Status;

    
   
29
import org.apache.sqoop.validation.Validation;
27

    
   
30

   
28
import java.util.List;
31
import java.util.List;
29
import java.util.ResourceBundle;
32
import java.util.ResourceBundle;
30

    
   
33

   
31
/**
34
/**
[+20] [20] 104 lines
[+20] [+] public MConnection getConnection(long xid) {
136
   *
139
   *
137
   * @param connection Connection that should be created
140
   * @param connection Connection that should be created
138
   * @return
141
   * @return
139
   */
142
   */
140
  public Status createConnection(MConnection connection) {
143
  public Status createConnection(MConnection connection) {
141
    return requests.createConnectionApplyValidations(connection);
144
    return applyValidations(requests.createConnection(connection), connection);
142
  }
145
  }
143

    
   
146

   
144
  /**
147
  /**
145
   * Update connection on the server.
148
   * Update connection on the server.
146
   *
149
   *
147
   * @param connection Connection that should be updated
150
   * @param connection Connection that should be updated
148
   * @return
151
   * @return
149
   */
152
   */
150
  public Status updateConnection(MConnection connection) {
153
  public Status updateConnection(MConnection connection) {
151
    return requests.updateConnectionApplyValidations(connection);
154
    return applyValidations(requests.updateConnection(connection), connection);
152
  }
155
  }
153

    
   
156

   
154
  /**
157
  /**
155
   * Delete connection with given id.
158
   * Delete connection with given id.
156
   *
159
   *
[+20] [20] 46 lines
[+20] [+] public MJob getJob(long jid) {
203
   *
206
   *
204
   * @param job Job that should be created
207
   * @param job Job that should be created
205
   * @return
208
   * @return
206
   */
209
   */
207
  public Status createJob(MJob job) {
210
  public Status createJob(MJob job) {
208
    return requests.createJobApplyValidations(job);
211
    return applyValidations(requests.createJob(job), job);
209
  }
212
  }
210

    
   
213

   
211
  /**
214
  /**
212
   * Update job on server.
215
   * Update job on server.
213
   * @param job Job that should be updated
216
   * @param job Job that should be updated
214
   * @return
217
   * @return
215
   */
218
   */
216
  public Status updateJob(MJob job) {
219
  public Status updateJob(MJob job) {
217
    return requests.updateJobApplyValidations(job);
220
    return applyValidations(requests.updateJob(job), job);
218
  }
221
  }
219

    
   
222

   
220
  /**
223
  /**
221
   * Delete job with given id.
224
   * Delete job with given id.
222
   *
225
   *
[+20] [20] 30 lines
[+20] [+] public MSubmission stopSubmission(long jid) {
253
   * @return
256
   * @return
254
   */
257
   */
255
  public MSubmission getSubmissionStatus(long jid) {
258
  public MSubmission getSubmissionStatus(long jid) {
256
    return requests.readSubmission(jid).getSubmission();
259
    return requests.readSubmission(jid).getSubmission();
257
  }
260
  }

    
   
261

   

    
   
262
  private Status applyValidations(ValidationBean bean, MConnection connection) {

    
   
263
    Validation connector = bean.getConnectorValidation();

    
   
264
    Validation framework = bean.getFrameworkValidation();

    
   
265

   

    
   
266
    FormUtils.applyValidation(connection.getConnectorPart().getForms(), connector);

    
   
267
    FormUtils.applyValidation(connection.getFrameworkPart().getForms(), framework);

    
   
268

   

    
   
269
    Long id = bean.getId();

    
   
270
    if(id != null) {

    
   
271
      connection.setPersistenceId(id);

    
   
272
    }

    
   
273

   

    
   
274
    return Status.getWorstStatus(connector.getStatus(), framework.getStatus());

    
   
275
  }

    
   
276

   

    
   
277
  private Status applyValidations(ValidationBean bean, MJob job) {

    
   
278
    Validation connector = bean.getConnectorValidation();

    
   
279
    Validation framework = bean.getFrameworkValidation();

    
   
280

   

    
   
281
    FormUtils.applyValidation(job.getConnectorPart().getForms(), connector);

    
   
282
    FormUtils.applyValidation(job.getFrameworkPart().getForms(), framework);

    
   
283

   

    
   
284
    Long id = bean.getId();

    
   
285
    if(id != null) {

    
   
286
      job.setPersistenceId(id);

    
   
287
    }

    
   
288

   

    
   
289
    return Status.getWorstStatus(connector.getStatus(), framework.getStatus());

    
   
290
  }
258
}
291
}
client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java
Revision 5ed38b638618d13ecd0d1b3ed10b580514d828ea New Change
 
  1. client/src/main/java/org/apache/sqoop/client/SqoopClient.java: Loading...
  2. client/src/main/java/org/apache/sqoop/client/request/SqoopRequests.java: Loading...