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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
* 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:
* Ibrahim Sallam - initial API and implementation
*/
package org.eclipse.emf.cdo.server.internal.objectivity.db;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyCommitInfo;
import org.eclipse.emf.cdo.server.internal.objectivity.utils.ObjyDb;
import com.objy.db.app.Session;
import com.objy.db.app.ooId;
import com.objy.db.app.ooObj;
import com.objy.db.util.ooTreeSetX;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ObjyCommitInfoHandler
{
protected ooId commitInfoSetId;
public ObjyCommitInfoHandler(String repositoryName)
{
commitInfoSetId = ObjyDb.getOrCreateCommitInfoList(repositoryName);
}
/***
* Factory method to create the CommitInfoList, which is a TreeListX
*/
public static ooId create(ooId scopeContOid)
{
ooTreeSetX treeSet = new ooTreeSetX(20, true);
ooObj clusterObject = ooObj.create_ooObj(scopeContOid);
clusterObject.cluster(treeSet);
return treeSet.getOid();
}
/***
* This function assume we are in an Objy trnasaction.
*/
public void writeCommitInfo(int id, long timeStamp, long previousTimeStamp, String userID, String comment)
{
ObjyCommitInfo commitInfo = new ObjyCommitInfo(id, timeStamp, previousTimeStamp, userID, comment);
getTreeSet().add(commitInfo);
}
/***
* Find all objects in the ooTreeListX that's between startTime and endTime inclusive, and have branch.getID() if
* branch is not null We don't have any optimization for time, but we could make the treeset use custom comparator.
*/
public List<ObjyCommitInfo> getCommitInfo(CDOBranch branch, long startTime, long endTime)
{
ooTreeSetX treeSet = getTreeSet();
ObjyCommitInfo ooCommitInfo = null;
List<ObjyCommitInfo> results = new ArrayList<ObjyCommitInfo>();
boolean getIt = false;
@SuppressWarnings("unchecked")
Iterator<ObjyCommitInfo> itr = treeSet.iterator();
while (itr.hasNext())
{
ooCommitInfo = itr.next();
getIt = true; // assume it's what we need, then we filter below.
long timeStamp = ooCommitInfo.getTimeStamp();
long branchId = ooCommitInfo.getBranchId();
if (branch != null && branch.getID() != branchId)
{
getIt = false;
}
if (getIt && startTime != CDOBranchPoint.UNSPECIFIED_DATE && timeStamp < startTime)
{
getIt = false;
}
if (getIt && endTime != CDOBranchPoint.UNSPECIFIED_DATE && timeStamp > endTime)
{
getIt = false;
}
if (getIt)
{
results.add(ooCommitInfo);
}
}
return results;
}
/***
* This function assume we are in an Objy trnasaction.
*/
protected ooTreeSetX getTreeSet()
{
ooTreeSetX treeSet = null;
treeSet = (ooTreeSetX)Session.getCurrent().getFD().objectFrom(commitInfoSetId.getString());
return treeSet;
}
}
|