Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17071 Do not create unused db table sf_loc2forum; improve localeToForum #4034

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 5 additions & 99 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/SurveyForum.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public class SurveyForum {

private static final String DB_FORA = "sf_fora"; // forum name -> id

// TODO: Remove DB_LOC2FORUM (sf_loc2forum) -- a table that's created or recreated every time on
// start-up, but is never read -- at least the name is private to SurveyForum and SurveyForm
// only writes it, never reads it. Searching for "sf_loc2forum" in IntelliJ, it is not found
// anywhere else. Also remove reloadLocales.
// Reference: https://unicode-org.atlassian.net/browse/CLDR-13962
private static final String DB_LOC2FORUM = "sf_loc2forum"; // locale -> forum.. for selects.

private static final String F_FORUM = "forum";

public static final String F_XPATH = "xpath";
Expand Down Expand Up @@ -427,72 +420,6 @@ private SurveyForum(SurveyMain ourSm) {

private Date oldOnOrBefore = null;

/**
* Re-create DB_LOC2FORUM table from scratch, called at start-up
*
* @param conn
* @throws SQLException
*/
private void reloadLocales(Connection conn) throws SQLException {
String sql;
synchronized (conn) {
Statement s = conn.createStatement();
if (!DBUtils.hasTable(DB_LOC2FORUM)) { // user attribute
sql =
"CREATE TABLE "
+ DB_LOC2FORUM
+ " ( "
+ " locale VARCHAR(255) NOT NULL, "
+ " forum VARCHAR(255) NOT NULL"
+ " )";
s.execute(sql);
sql =
"CREATE UNIQUE INDEX "
+ DB_LOC2FORUM
+ "_loc ON "
+ DB_LOC2FORUM
+ " (locale) ";
s.execute(sql);
sql = "CREATE INDEX " + DB_LOC2FORUM + "_f ON " + DB_LOC2FORUM + " (forum) ";
s.execute(sql);
} else {
s.executeUpdate("delete from " + DB_LOC2FORUM);
}
s.close();

PreparedStatement initbl =
DBUtils.prepareStatement(
conn,
"initbl",
"INSERT INTO " + DB_LOC2FORUM + " (locale,forum) VALUES (?,?)");
int errs = 0;
for (CLDRLocale l : SurveyMain.getLocalesSet()) {
initbl.setString(1, l.toString());
String forum = localeToForum(l);
initbl.setString(2, forum);
try {
initbl.executeUpdate();
} catch (SQLException se) {
if (errs == 0) {
System.err.println(
"While updating "
+ DB_LOC2FORUM
+ " - "
+ DBUtils.unchainSqlException(se)
+ " - "
+ l
+ ":"
+ forum
+ ", [This and further errors, ignored]");
}
errs++;
}
}
initbl.close();
conn.commit();
}
}

/** internal - called to setup db */
private void setupDB(Connection conn) throws SQLException {
String onOrBefore =
Expand Down Expand Up @@ -625,7 +552,6 @@ private void setupDB(Connection conn) throws SQLException {
s.close();
conn.commit();
}
reloadLocales(conn);
SurveyThreadManager.getExecutorService().submit(() -> new SurveyForumCheck(sm).run());
}

Expand Down Expand Up @@ -680,32 +606,12 @@ private static PreparedStatement prepare_pIntUsers(Connection conn) throws SQLEx
"SELECT uid from " + UserRegistry.CLDR_INTEREST + " where forum=?");
}

// TODO: remove this function, see localeToForum.
// Reference: https://unicode-org.atlassian.net/browse/CLDR-13962
private static String uLocaleToForum(ULocale locale) {
return locale.getLanguage();
}

private static String localeToForum(CLDRLocale locale) {
// TODO: for encapsulation (and efficiency?) call locale.getLanguage() instead of
// locale.toULocale().getLanguage(). That is, call
// org.unicode.cldr.util.CLDRLocale.getLanguage instead of
// com.ibm.icu.util.ULocale.getLanguage.
// As of 2023-05-23, the results are the same, for all sets
// returned by SurveyMain.getLocalesSet(), with the single exception of "root",
// for which ULocale.getLanguage returns empty string instead of "root".
// Reference: https://unicode-org.atlassian.net/browse/CLDR-13962
// if (LocaleNames.ROOT.equals(locale.getBaseName())) {
// return "";
// } else {
// String test1 = locale.getLanguage();
// String test2 = locale.toULocale().getLanguage();
// if (!test1.equals(test2)) { // this does not happen
// throw new RuntimeException("localeToForum: " + locale + " " + test1 + " " +
// test2);
// }
// }
return uLocaleToForum(locale.toULocale());
if (LocaleNames.ROOT.equals(locale.getBaseName())) {
return "";
} else {
return locale.getLanguage();
}
}

/**
Expand Down
Loading