started adding comments, restructured Database class

This commit is contained in:
2022-04-19 08:41:03 +02:00
parent 9b1cc974ad
commit aae095f2ea
5 changed files with 146 additions and 125 deletions

View File

@@ -69,7 +69,7 @@ public class MailingList {
.append(SMTP_PASS).append(" ").append(VARCHAR).append(", ")
.append(STATE).append(" ").append(INT)
.append(");");
Database.open().query(sql).run();
Database.open().query(sql).compile().run();
}
public String email() {
@@ -79,12 +79,12 @@ public class MailingList {
public void enable(boolean enable) throws SQLException {
state = enable ? state | STATE_ENABLED : state ^ (state & STATE_ENABLED);
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).run();
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
}
public void hide(boolean hide) throws SQLException {
state = hide ? state ^ (state & STATE_PUBLIC) : state | STATE_PUBLIC;
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).run();
Database.open().update(TABLE_NAME).set(STATE,state).where(EMAIL, email()).compile().run();
}
public boolean isOpenFor(User user) {
@@ -129,7 +129,7 @@ public class MailingList {
var rs = Database.open()
.select(TABLE_NAME)
.where(EMAIL,listEmail)
.exec();
.compile().exec();
if (rs.next()) lists.put(listEmail,ml = MailingList.from(rs));
} catch (SQLException e) {
LOG.debug("Failed to load MailingList: ",e);
@@ -156,7 +156,7 @@ public class MailingList {
var rs = Database.open()
.select(TABLE_NAME,EMAIL, "(" + STATE + " & " + STATE_PUBLIC + ") as test")
.where("test", STATE_PUBLIC)
.exec();
.compile().exec();
var emails = new ArrayList<String>();
while (rs.next()) emails.add(rs.getString(EMAIL));
rs.close();
@@ -182,7 +182,8 @@ public class MailingList {
private MailingList save() throws SQLException {
Database.open().insertInto(TABLE_NAME)
Database.open()
.insertInto(TABLE_NAME)
.values(Map.ofEntries(
Map.entry(EMAIL, email),
Map.entry(NAME, name),
@@ -195,6 +196,7 @@ public class MailingList {
Map.entry(SMTP_USER, smtp.username()),
Map.entry(SMTP_PASS, smtp.password()),
Map.entry(STATE, state)))
.compile()
.run();
return this;
}
@@ -222,14 +224,14 @@ public class MailingList {
try {
if (user == null) return openLists();
if (user.hashPermission(PERMISSION_ADMIN)) {
var rs = Database.open().select(TABLE_NAME).exec();
var rs = Database.open().select(TABLE_NAME).compile().exec();
var result = new HashSet<MailingList>();
while (rs.next()) result.add(MailingList.from(rs));
rs.close();
return result;
}
var listEmails = ListMember.listsOwnedBy(user);
var rs = Database.open().select(TABLE_NAME).where(EMAIL, listEmails).exec();
var rs = Database.open().select(TABLE_NAME).where(EMAIL, listEmails).compile().exec();
var result = openLists();
while (rs.next()) result.add(MailingList.from(rs));
rs.close();