Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 82aa8acfb6a7d74f9faf43f22e2544cc4313a1eb (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Copyright (c) 2009-2013 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:
 *    Simon McDuff - initial API and implementation
 *    Eike Stepper - maintenance
 */
package org.eclipse.emf.cdo.internal.common;

import org.eclipse.emf.cdo.common.commit.CDOChangeSetData;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
import org.eclipse.emf.cdo.common.util.CDOClassNotFoundException;
import org.eclipse.emf.cdo.common.util.CDOPackageNotFoundException;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @author Simon McDuff
 */
public class CDOQueryInfoImpl implements CDOQueryInfo
{
  protected String queryLanguage;

  protected String queryString;

  protected Object context;

  protected Map<String, Object> parameters = new HashMap<String, Object>();

  protected int maxResults = UNLIMITED_RESULTS;

  protected CDOChangeSetData changeSetData;

  public CDOQueryInfoImpl(String queryLanguage, String queryString, Object context)
  {
    this.queryLanguage = queryLanguage;
    this.queryString = queryString;
    this.context = context;
  }

  public CDOQueryInfoImpl(CDODataInput in) throws IOException
  {
    queryLanguage = in.readString();
    queryString = in.readString();

    try
    {
      context = in.readCDORevisionOrPrimitiveOrClassifier();
    }
    catch (CDOPackageNotFoundException e)
    {
      //$FALL-THROUGH$
    }
    catch (CDOClassNotFoundException e)
    {
      //$FALL-THROUGH$
    }
    
    maxResults = in.readInt();

    if (in.readBoolean())
    {
      changeSetData = in.readCDOChangeSetData();
    }

    int size = in.readInt();
    for (int i = 0; i < size; i++)
    {
      String key = in.readString();
      try
      {
        Object object = in.readCDORevisionOrPrimitiveOrClassifier();
        parameters.put(key, object);
      }
      catch (CDOPackageNotFoundException e)
      {
        //$FALL-THROUGH$
      }
      catch (CDOClassNotFoundException e)
      {
        //$FALL-THROUGH$
      }
    }
  }

  public void write(CDODataOutput out) throws IOException
  {
    out.writeString(queryLanguage);
    out.writeString(queryString);
    out.writeCDORevisionOrPrimitiveOrClassifier(context);
    out.writeInt(maxResults);

    if (changeSetData != null)
    {
      out.writeBoolean(true);
      out.writeCDOChangeSetData(changeSetData);
    }
    else
    {
      out.writeBoolean(false);
    }

    out.writeInt(parameters.size());
    for (Entry<String, Object> entry : parameters.entrySet())
    {
      out.writeString(entry.getKey());
      out.writeCDORevisionOrPrimitiveOrClassifier(entry.getValue());
    }
  }

  public String getQueryString()
  {
    return queryString;
  }

  public String getQueryLanguage()
  {
    return queryLanguage;
  }

  public Map<String, Object> getParameters()
  {
    return Collections.unmodifiableMap(parameters);
  }

  public Object getContext()
  {
    return context;
  }

  public CDOQueryInfoImpl setContext(Object context)
  {
    this.context = context;
    return this;
  }

  public void addParameter(String key, Object value)
  {
    parameters.put(key, value);
  }

  public int getMaxResults()
  {
    return maxResults;
  }

  public CDOQueryInfoImpl setMaxResults(int maxResults)
  {
    this.maxResults = maxResults;
    return this;
  }

  @Deprecated
  public boolean isLegacyModeEnabled()
  {
    return true;
  }

  public CDOChangeSetData getChangeSetData()
  {
    return changeSetData;
  }

  public void setChangeSetData(CDOChangeSetData changeSetData)
  {
    this.changeSetData = changeSetData;
  }
}

Back to the top