23
23
import java .sql .ResultSet ;
24
24
import java .sql .SQLException ;
25
25
import java .sql .Statement ;
26
- import java .util .ArrayList ;
27
26
import java .util .Calendar ;
27
+ import java .util .Collections ;
28
28
import java .util .Hashtable ;
29
29
import java .util .Iterator ;
30
30
import java .util .List ;
31
31
import java .util .Map ;
32
32
import java .util .Properties ;
33
33
import java .util .Set ;
34
34
import java .util .TreeSet ;
35
+ import java .util .Vector ;
35
36
36
37
import javax .xml .parsers .ParserConfigurationException ;
37
38
38
- import org .xml .sax .SAXException ;
39
-
40
- import com .maxprograms .tmx .TMXReader ;
41
39
import com .maxprograms .tmutils .TMUtils ;
40
+ import com .maxprograms .tmx .TMXReader ;
42
41
import com .maxprograms .xml .Attribute ;
43
42
import com .maxprograms .xml .Element ;
44
43
import com .maxprograms .xml .Indenter ;
45
44
45
+ import org .xml .sax .SAXException ;
46
+
46
47
public class SQLEngine implements ITmEngine {
47
48
48
49
private static final Logger LOGGER = System .getLogger (SQLEngine .class .getName ());
@@ -61,7 +62,7 @@ public class SQLEngine implements ITmEngine {
61
62
62
63
private long next ;
63
64
64
- private TreeSet <String > languages ;
65
+ private Set <String > languages ;
65
66
66
67
private PreparedStatement insertProperties ;
67
68
private PreparedStatement removeProperties ;
@@ -282,7 +283,7 @@ public void flag(String tuid) throws SQLException {
282
283
283
284
@ Override
284
285
public Set <String > getAllClients () throws SQLException {
285
- Set <String > result = new TreeSet <>();
286
+ Set <String > result = Collections . synchronizedSortedSet ( new TreeSet <>() );
286
287
try (Statement stmt = conn .createStatement ()) {
287
288
try (ResultSet rs = stmt
288
289
.executeQuery ("SELECT DISTINCT content FROM `" + dbName + "`.tuprop WHERE propType='customer'" )) {
@@ -297,7 +298,7 @@ public Set<String> getAllClients() throws SQLException {
297
298
@ Override
298
299
public Set <String > getAllLanguages () throws SQLException {
299
300
if (languages == null ) {
300
- languages = new TreeSet <>();
301
+ languages = Collections . synchronizedSortedSet ( new TreeSet <>() );
301
302
try (Statement stmt = conn .createStatement ()) {
302
303
try (ResultSet rs = stmt .executeQuery ("SELECT lang FROM `" + dbName + "`.langs" )) {
303
304
while (rs .next ()) {
@@ -311,7 +312,7 @@ public Set<String> getAllLanguages() throws SQLException {
311
312
312
313
@ Override
313
314
public Set <String > getAllProjects () throws SQLException {
314
- Set <String > result = new TreeSet <>();
315
+ Set <String > result = Collections . synchronizedSortedSet ( new TreeSet <>() );
315
316
try (Statement stmt = conn .createStatement ()) {
316
317
try (ResultSet rs = stmt
317
318
.executeQuery ("SELECT DISTINCT content FROM `" + dbName + "`.tuprop WHERE propType='project'" )) {
@@ -325,7 +326,7 @@ public Set<String> getAllProjects() throws SQLException {
325
326
326
327
@ Override
327
328
public Set <String > getAllSubjects () throws SQLException {
328
- Set <String > result = new TreeSet <>();
329
+ Set <String > result = Collections . synchronizedSortedSet ( new TreeSet <>() );
329
330
try (Statement stmt = conn .createStatement ()) {
330
331
try (ResultSet rs = stmt
331
332
.executeQuery ("SELECT DISTINCT content FROM `" + dbName + "`.tuprop WHERE propType='subject'" )) {
@@ -340,7 +341,7 @@ public Set<String> getAllSubjects() throws SQLException {
340
341
@ Override
341
342
public List <Match > searchTranslation (String searchStr , String srcLang , String tgtLang , int similarity ,
342
343
boolean caseSensitive ) throws IOException , SAXException , ParserConfigurationException , SQLException {
343
- List <Match > result = new ArrayList <>();
344
+ List <Match > result = new Vector <>();
344
345
345
346
int [] ngrams = NGrams .getNGrams (searchStr );
346
347
int size = ngrams .length ;
@@ -357,7 +358,7 @@ public List<Match> searchTranslation(String searchStr, String srcLang, String tg
357
358
set .append ("," + ngrams [i ]);
358
359
}
359
360
360
- Set <String > candidates = new TreeSet <>();
361
+ Set <String > candidates = Collections . synchronizedSortedSet ( new TreeSet <>() );
361
362
String lowerSearch = searchStr .toLowerCase ();
362
363
363
364
PreparedStatement stmt = selectNgram .get (srcLang );
@@ -420,7 +421,7 @@ private String getPureText(String lang, String tuid) throws SQLException {
420
421
@ Override
421
422
public List <Element > concordanceSearch (String searchStr , String srcLang , int limit , boolean isRegexp ,
422
423
boolean caseSensitive ) throws IOException , SAXException , ParserConfigurationException , SQLException {
423
- Set <String > candidates = new TreeSet <>();
424
+ Set <String > candidates = Collections . synchronizedSortedSet ( new TreeSet <>() );
424
425
if (isRegexp ) {
425
426
try (PreparedStatement stmt = conn .prepareStatement (
426
427
"SELECT tuid, pureText FROM `" + dbName + "`.tuv WHERE lang=? AND pureText REGEXP ? LIMIT ?" )) {
@@ -460,7 +461,7 @@ public List<Element> concordanceSearch(String searchStr, String srcLang, int lim
460
461
}
461
462
}
462
463
}
463
- List <Element > result = new ArrayList <>();
464
+ List <Element > result = new Vector <>();
464
465
Iterator <String > it = candidates .iterator ();
465
466
while (it .hasNext ()) {
466
467
Element tu = getTu (it .next ());
@@ -511,7 +512,7 @@ public void storeTu(Element tu) throws IOException, SQLException {
511
512
tuProperties .put ("project" , currProject );
512
513
}
513
514
List <Element > tuvs = tu .getChildren ("tuv" );
514
- Set <String > tuLangs = new TreeSet <>();
515
+ Set <String > tuLangs = Collections . synchronizedSortedSet ( new TreeSet <>() );
515
516
516
517
Iterator <Element > it = tuvs .iterator ();
517
518
while (it .hasNext ()) {
@@ -659,7 +660,7 @@ public void commit() throws SQLException {
659
660
private Element getTu (String tuid , Set <String > langs )
660
661
throws SQLException , SAXException , IOException , ParserConfigurationException {
661
662
if (tuAttributes == null ) {
662
- tuAttributes = new TreeSet <>();
663
+ tuAttributes = Collections . synchronizedSortedSet ( new TreeSet <>() );
663
664
String [] array = new String [] { "tuid" , "o-encoding" , "datatype" , "usagecount" , "lastusagedate" ,
664
665
"creationtool" , "creationtoolversion" , "creationdate" , "creationid" , "changedate" , "segtype" ,
665
666
"changeid" , "o-tmf" , "srclang" };
@@ -699,7 +700,7 @@ private Element getTu(String tuid, Set<String> langs)
699
700
700
701
@ Override
701
702
public Element getTu (String tuid ) throws IOException , SAXException , ParserConfigurationException , SQLException {
702
- return getTu (tuid , new TreeSet <>());
703
+ return getTu (tuid , Collections . synchronizedSortedSet ( new TreeSet <>() ));
703
704
}
704
705
705
706
private String getSegText (String lang , String tuid ) throws SQLException {
0 commit comments