Skip to content

Commit

Permalink
Updated for release 4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Feb 17, 2021
1 parent 4d92155 commit 30a6efe
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 182 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swordfish",
"productName": "Swordfish",
"version": "4.1.3",
"version": "4.2.0",
"description": "Swordfish Translation Editor",
"main": "js/App.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
},
"dependencies": {},
"devDependencies": {
"electron": "^11.2.1",
"typescript": "^4.1.3"
"electron": "^11.2.3",
"typescript": "^4.1.5"
}
}
4 changes: 2 additions & 2 deletions src/com/maxprograms/swordfish/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ private Constants() {
}

public static final String APPNAME = "Swordfish";
public static final String VERSION = "4.1.3";
public static final String BUILD = "20210203_0654";
public static final String VERSION = "4.2.0";
public static final String BUILD = "20210217_1214";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
8 changes: 4 additions & 4 deletions src/com/maxprograms/swordfish/ProjectsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ private JSONObject getTerms(String request) {
if (projectStores.containsKey(project)) {
result.put("terms", projectStores.get(project).getTerms(json));
}
} catch (SQLException | JSONException e) {
} catch (SQLException | IOException e) {
logger.log(Level.ERROR, e);
result.put(Constants.REASON, e.getMessage());
}
Expand Down Expand Up @@ -1641,7 +1641,7 @@ private JSONObject getNotes(String request) {
result.put("notes", projectStores.get(project).getNotes(json.getString("file"), json.getString("unit"),
json.getString("segment")));
}
} catch (SQLException e) {
} catch (SQLException | IOException e) {
logger.log(Level.ERROR, e);
result.put(Constants.REASON, e.getMessage());
}
Expand All @@ -1657,7 +1657,7 @@ private JSONObject addNote(String request) {
result.put("notes", projectStores.get(project).addNote(json.getString("file"), json.getString("unit"),
json.getString("segment"), json.getString("noteText")));
}
} catch (SQLException e) {
} catch (SQLException | IOException e) {
logger.log(Level.ERROR, e);
result.put(Constants.REASON, e.getMessage());
}
Expand All @@ -1673,7 +1673,7 @@ private JSONObject removeNote(String request) {
result.put("notes", projectStores.get(project).removeNote(json.getString("file"),
json.getString("unit"), json.getString("segment"), json.getString("noteId")));
}
} catch (SQLException e) {
} catch (SQLException | IOException e) {
logger.log(Level.ERROR, e);
result.put(Constants.REASON, e.getMessage());
}
Expand Down
51 changes: 32 additions & 19 deletions src/com/maxprograms/swordfish/tm/InternalDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Redistribution of this Software or parts of it in any form (source code or
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -95,6 +96,26 @@ public InternalDatabase(String dbname, String workFolder) throws SQLException, I
createTable();
logger.log(Level.INFO, "H2 database created");
}

boolean needsUpgrade = false;
try (Statement stmt = conn.createStatement()) {
String sql = "SELECT TYPE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TUV' AND COLUMN_NAME='SEG'";
try (ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
needsUpgrade = !rs.getString(1).equalsIgnoreCase("CLOB");
}
}
}
if (needsUpgrade) {
String s1 = "ALTER TABLE TUV ALTER COLUMN SEG SET DATA TYPE CLOB";
String s2 = "ALTER TABLE TUV ALTER COLUMN PURETEXT SET DATA TYPE CLOB";
try (Statement upgrade = conn.createStatement()) {
upgrade.execute(s1);
upgrade.execute(s2);
conn.commit();
}
}

storeTUV = conn.prepareStatement("INSERT INTO tuv (tuid, lang, seg, puretext, textlength) VALUES (?,?,?,?,?)");
searchTUV = conn.prepareStatement("SELECT textlength FROM tuv WHERE tuid=? AND lang=?");
deleteTUV = conn.prepareStatement("DELETE FROM tuv WHERE tuid=? AND lang=?");
Expand All @@ -115,7 +136,7 @@ public InternalDatabase(String dbname, String workFolder) throws SQLException, I
}

private void createTable() throws SQLException {
String sql = "CREATE TABLE tuv (tuid VARCHAR(256) NOT NULL, lang VARCHAR(15) NOT NULL, seg VARCHAR(6000) NOT NULL, puretext VARCHAR(4000) NOT NULL, textlength INTEGER NOT NULL, PRIMARY KEY(tuid, lang));";
String sql = "CREATE TABLE tuv (tuid VARCHAR(256) NOT NULL, lang VARCHAR(15) NOT NULL, seg CLOB NOT NULL, puretext CLOB NOT NULL, textlength INTEGER NOT NULL, PRIMARY KEY(tuid, lang));";
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
}
Expand Down Expand Up @@ -199,7 +220,7 @@ public void exportMemory(String tmxfile, Set<String> langs, String srcLang) thro
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String lang = rs.getString(1);
String seg = rs.getString(2);
String seg = TMUtils.getString(rs.getNCharacterStream(2));
if (seg.equals("<seg></seg>")) {
continue;
}
Expand Down Expand Up @@ -319,8 +340,8 @@ public List<Match> searchTranslation(String searchStr, String srcLang, String tg
stmt.setString(2, tuid);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String pure = rs.getNString(1);
String srcSeg = rs.getNString(2);
String pure = TMUtils.getString(rs.getNCharacterStream(1));
String srcSeg = TMUtils.getString(rs.getNCharacterStream(2));
int distance;
if (caseSensitive) {
distance = MatchQuality.similarity(searchStr, pure);
Expand All @@ -335,7 +356,7 @@ public List<Match> searchTranslation(String searchStr, String srcLang, String tg
try (ResultSet rs2 = stmt2.executeQuery()) {
while (rs2.next()) {
String lang = rs2.getString(1);
String seg = rs2.getNString(2);
String seg = TMUtils.getString(rs2.getNCharacterStream(2));
target = TMUtils.buildTuv(lang, seg);
tgtFound = true;
}
Expand Down Expand Up @@ -418,7 +439,7 @@ public List<Element> concordanceSearch(String searchStr, String srcLang, int lim
try (ResultSet rs2 = stmt2.executeQuery()) {
while (rs2.next()) {
String lang = rs2.getString(1);
String seg = rs2.getNString(2);
String seg = TMUtils.getString(rs2.getNCharacterStream(2));
Element tuv = TMUtils.buildTuv(lang, seg);
tu.addContent(tuv);
}
Expand Down Expand Up @@ -507,18 +528,10 @@ public void storeTu(Element tu) throws SQLException, IOException {
if (puretext.length() < 1) {
continue;
}
String ele = seg.toString();
if (ele.length() > 6000) {
ele = puretext;
}
if (ele.length() > 6000) {
throw new IOException("Segment too large");
}
int length = puretext.length();
storeTUV.setString(2, lang);
storeTUV.setString(3, ele);
storeTUV.setString(4, puretext);
storeTUV.setInt(5, length);
storeTUV.setNCharacterStream(3, new StringReader(seg.toString()));
storeTUV.setNCharacterStream(4, new StringReader(puretext));
storeTUV.setInt(5, puretext.length());
storeTUV.execute();
tuLangs.add(lang);

Expand Down Expand Up @@ -600,7 +613,7 @@ public Element getTu(String tuid) throws SQLException, SAXException, IOException
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String lang = rs.getString(1);
String seg = rs.getString(2);
String seg = TMUtils.getString(rs.getNCharacterStream(2));
if (seg.equals("<seg></seg>")) {
continue;
}
Expand Down Expand Up @@ -685,7 +698,7 @@ public List<Element> searchAll(String searchStr, String srcLang, int similarity,
stmt.setString(2, tuid);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String pure = rs.getNString(1);
String pure = TMUtils.getString(rs.getNCharacterStream(1));
int distance;
if (caseSensitive) {
distance = MatchQuality.similarity(searchStr, pure);
Expand Down
12 changes: 12 additions & 0 deletions src/com/maxprograms/swordfish/tm/TMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Redistribution of this Software or parts of it in any form (source code or

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Reader;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -150,4 +151,15 @@ public static String extractText(Element seg) {
}
return text.toString();
}

public static String getString(Reader reader) throws IOException {
StringBuilder sb = new StringBuilder();
char[] array = new char[1024];
int read = 0;
while ((read = reader.read(array)) != -1) {
sb.append(array, 0, read);
}
reader.close();
return sb.toString();
}
}
Loading

0 comments on commit 30a6efe

Please sign in to comment.