You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
/* © SRSoftware 2025 */ |
|
package de.srsoftware.umbrella.contact; |
|
|
|
import static de.srsoftware.tools.jdbc.Condition.equal; |
|
import static de.srsoftware.tools.jdbc.Query.select; |
|
import static de.srsoftware.umbrella.contact.Constants.TABLE_CONTACTS; |
|
import static de.srsoftware.umbrella.contact.Constants.TABLE_CONTACTS_USERS; |
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
import de.srsoftware.umbrella.core.model.Contact; |
|
import java.sql.Connection; |
|
import java.sql.SQLException; |
|
import java.util.Collection; |
|
import java.util.HashSet; |
|
|
|
public class SqliteDb implements ContactDb{ |
|
private final Connection conn; |
|
|
|
public SqliteDb(Connection connection) { |
|
conn = connection; |
|
} |
|
|
|
@Override |
|
public Collection<Contact> listContactsOf(long userId) throws UmbrellaException{ |
|
try { |
|
var rs = select("*").from(TABLE_CONTACTS).leftJoin(ID,TABLE_CONTACTS_USERS,USER_ID).where(USER_ID,equal(userId)).exec(conn); |
|
var contacts = new HashSet<Contact>(); |
|
while (rs.next()) contacts.add(Contact.of(rs)); |
|
rs.close(); |
|
return contacts; |
|
} catch (SQLException e) { |
|
throw UmbrellaException.databaseException("Failed to load contacts og user {0}",userId); |
|
} |
|
} |
|
}
|
|
|