blob: 44786f888ceaf3f3d9cd6fe0ee18ca70b42d4749 (
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
|
/*******************************************************************************
* 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.orcs.db.internal.proxy;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.orcs.core.ds.CharacterDataProxy;
/**
* @author Roberto E. Escobar
*/
public class ClobDataProxy extends AbstractDataProxy implements CharacterDataProxy {
public static final int MAX_VARCHAR_LENGTH = 4000;
private String rawStringValue;
public ClobDataProxy() {
super();
this.rawStringValue = "";
}
@Override
public String getDisplayableString() throws OseeCoreException {
return getValueAsString();
}
@Override
public void setDisplayableString(String toDisplay) {
throw new UnsupportedOperationException();
}
@Override
public String getValueAsString() throws OseeCoreException {
String fromStorage = null;
byte[] data = null;
try {
data = getStorage().getContent();
if (data != null) {
data = Lib.decompressBytes(new ByteArrayInputStream(data));
fromStorage = new String(data, "UTF-8");
}
} catch (IOException ex) {
OseeExceptions.wrapAndThrow(ex);
}
String toReturn = fromStorage != null ? fromStorage : rawStringValue;
return toReturn != null ? toReturn : "";
}
@Override
public boolean setValue(String value) throws OseeCoreException {
boolean response = false;
if (getValueAsString() == value || getValueAsString() != null && getValueAsString().equals(value)) {
response = false;
} else {
storeValue(value);
response = true;
}
return response;
}
private void storeValue(String value) throws OseeCoreException {
if (value != null && value.length() > MAX_VARCHAR_LENGTH) {
try {
byte[] compressed =
Lib.compressStream(new ByteArrayInputStream(value.getBytes("UTF-8")),
getResolver().getInternalFileName());
getStorage().setContent(compressed, "zip", "application/zip", "ISO-8859-1");
this.rawStringValue = "";
} catch (IOException ex) {
OseeExceptions.wrapAndThrow(ex);
}
} else {
this.rawStringValue = value;
getStorage().clear();
}
}
@Override
public Object[] getData() {
return new Object[] {rawStringValue, getStorage().getLocator()};
}
@Override
public void setData(Object... objects) throws OseeCoreException {
if (objects != null && objects.length > 1) {
storeValue((String) objects[0]);
getStorage().setLocator((String) objects[1]);
}
}
@Override
public void persist(int storageId) throws OseeCoreException {
getStorage().persist(storageId);
}
@Override
public void purge() throws OseeCoreException {
getStorage().purge();
}
}
|