Skip to main content
summaryrefslogtreecommitdiffstats
blob: b7f9b61ddd0ef135d5599895e529e5c186c9669e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.database.core;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.database.IOseeDatabaseService;

/**
 * @author Roberto E. Escobar
 */
public abstract class AbstractDbTxOperation extends AbstractOperation {

   private final IOseeDatabaseService databaseService;

   public AbstractDbTxOperation(IOseeDatabaseService databaseService, String operationName, String pluginId) {
      super(operationName, pluginId);
      this.databaseService = databaseService;
   }

   protected IOseeDatabaseService getDatabaseService() throws OseeDataStoreException {
      return databaseService;
   }

   @Override
   protected final void doWork(IProgressMonitor monitor) throws Exception {
      Transaction transaction = new Transaction(monitor);
      transaction.execute();
   }

   protected abstract void doTxWork(IProgressMonitor monitor, OseeConnection connection) throws OseeCoreException;

   protected void handleTxException(IProgressMonitor monitor, Exception ex) {
   }

   protected void handleTxFinally(IProgressMonitor monitor) throws OseeCoreException {
   }

   private final class Transaction extends DbTransaction {
      private final IProgressMonitor monitor;

      private Transaction(IProgressMonitor monitor) throws OseeCoreException {
         super();
         this.monitor = monitor;
      }

      @Override
      protected String getTxName() {
         return AbstractDbTxOperation.this.getName();
      }

      @Override
      protected void handleTxWork(OseeConnection connection) throws OseeCoreException {
         AbstractDbTxOperation.this.doTxWork(monitor, connection);
      }

      @Override
      protected void handleTxException(Exception ex) {
         AbstractDbTxOperation.this.handleTxException(monitor, ex);
      }

      @Override
      protected void handleTxFinally() throws OseeCoreException {
         AbstractDbTxOperation.this.handleTxFinally(monitor);
      }
   }
}

Back to the top