Skip to main content
summaryrefslogtreecommitdiffstats
blob: be11c1a782c04273e8f01d2aae3ea1e696b51279 (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
89
90
91
92
93
94
95
96
/*******************************************************************************
 * 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.access.internal.data;

import org.eclipse.osee.framework.access.AccessObject;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.jdk.core.type.DoubleKeyHashMap;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

/**
 * @author Jeff C. Phillips
 */
public class ArtifactAccessObject extends AccessObject {

   private final Integer artId;
   private final Integer branchId;
   private static final DoubleKeyHashMap<Integer, Integer, ArtifactAccessObject> cache =
      new DoubleKeyHashMap<Integer, Integer, ArtifactAccessObject>();

   public ArtifactAccessObject(Integer artId, Integer branchId) {
      super();
      this.artId = artId;
      this.branchId = branchId;
   }

   @Override
   public int hashCode() {
      int result = 17;
      result = 31 * result + artId;
      result = 31 * result + branchId;
      return result;
   }

   public Integer getArtId() {
      return artId;
   }

   @Override
   public int getId() {
      return branchId;
   }

   @Override
   public void removeFromCache() {
      cache.remove(artId, branchId);
   }

   @Override
   public void removeFromDatabase(int subjectId) throws OseeCoreException {
      final String DELETE_ARTIFACT_ACL =
         "DELETE FROM OSEE_ARTIFACT_ACL WHERE privilege_entity_id = ? AND art_id =? AND branch_id =?";
      ConnectionHandler.runPreparedUpdate(DELETE_ARTIFACT_ACL, subjectId, artId, branchId);
   }

   public static ArtifactAccessObject getArtifactAccessObject(Artifact artifact) {
      Integer artId = artifact.getArtId();
      Integer branchId = artifact.getBranch().getId();
      return getArtifactAccessObject(artId, branchId);
   }

   public static ArtifactAccessObject getArtifactAccessObject(Integer artId, Integer branchId) {
      ArtifactAccessObject accessObject = cache.get(artId, branchId);

      if (accessObject == null) {
         accessObject = new ArtifactAccessObject(artId, branchId);
         cache.put(artId, branchId, accessObject);
      }
      return accessObject;
   }

   public static AccessObject getArtifactAccessObjectFromCache(Artifact art) {
      return getArtifactAccessObjectFromCache(art.getArtId(), art.getBranch().getId());
   }

   public static AccessObject getArtifactAccessObjectFromCache(Integer artId2, Integer branchId2) {
      return cache.get(artId2, branchId2);
   }

   @Override
   public boolean equals(Object obj) {
      if (!(obj instanceof ArtifactAccessObject)) {
         return false;
      }
      ArtifactAccessObject ao = (ArtifactAccessObject) obj;
      return ao.artId.equals(this.artId) && ao.branchId.equals(this.branchId);
   }
}

Back to the top