Skip to main content
summaryrefslogtreecommitdiffstats
blob: 39fe43babeb73648882bd7245034974ca1709a13 (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
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * 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.ui.admin.dbtabletab;

import java.util.logging.Level;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.ui.admin.AdminPlugin;

public class SiteGssflRpcr extends DbItem {

   public SiteGssflRpcr() {
      super("OSEE_SITE_GSSFL_RPCR");
   }

   @Override
   public boolean isWriteable(String columnName) {
      return true;
   }

   @Override
   public boolean isBems(String columnName) {
      return false;
   }

   public String returnTic(String str) {
      return "'" + str + "'";
   }

   @Override
   public int getColumnWidth(String columnName) {
      if (columnName.equals("DIRECTORY")) {
         return 400;
      }
      return 100;
   }

   public boolean exists(String program) throws OseeCoreException {
      try {
         return ConnectionHandler.runPreparedQueryFetchInt(0,
            "SELECT count(1) FROM " + getTableName() + " WHERE PROGRAM = ?", returnTic(program)) > 0;
      } catch (OseeDataStoreException ex) {
         OseeLog.log(AdminPlugin.class, Level.SEVERE, ex);
         return false;
      }
   }

   @Override
   public void save(DbDescribe describe, DbModel model) {
      try {
         String program = (String) model.getColumn(describe.indexOfColumn("PROGRAM"));
         String dir = (String) model.getColumn(describe.indexOfColumn("DIRECTORY"));
         String programId = (String) model.getColumn(describe.indexOfColumn("PROGRAM_ID"));
         String query;
         if (exists(program)) {
            query = "UPDATE " + getTableName() + " SET directory = ?, program_id = ? WHERE PROGRAM = ?";
            ConnectionHandler.runPreparedUpdate(query, dir, programId, program);
         } else {
            query = "INSERT INTO " + getTableName() + " (program,directory,program_id) VALUES (?,?,?)";
            ConnectionHandler.runPreparedUpdate(query, program, dir, programId);
         }
      } catch (OseeCoreException ex) {
         OseeLog.log(AdminPlugin.class, Level.SEVERE, ex);
      }
   }

   @Override
   public DbModel createNewRow(DbModel example) {
      DbModel dbModel = new DbModel();
      for (int x = 0; x < example.getValues().length; x++) {
         dbModel.addColumn(x, "");
      }
      dbModel.setColumn(0, "NEW");
      dbModel.setColumnChanged("PROGRAM");
      return dbModel;
   }

}

Back to the top