|
|
|
|
@ -253,8 +253,13 @@ CREATE TABLE IF NOT EXISTS {0} (
@@ -253,8 +253,13 @@ CREATE TABLE IF NOT EXISTS {0} (
|
|
|
|
|
public Set<String> list(long userId, String module, long entityId) { |
|
|
|
|
try { |
|
|
|
|
var tags = new HashSet<String>(); |
|
|
|
|
|
|
|
|
|
// load tags assigned to user
|
|
|
|
|
var rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ENTITY_ID,equal(entityId)).where(USER_ID,equal(userId)).exec(db); |
|
|
|
|
while (rs.next()) tags.add(rs.getString(1)); |
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
|
|
// load tags assigned to no user
|
|
|
|
|
rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ENTITY_ID,equal(entityId)).where(USER_ID,isNull()).exec(db); |
|
|
|
|
while (rs.next()) tags.add(rs.getString(1)); |
|
|
|
|
rs.close(); |
|
|
|
|
@ -264,6 +269,26 @@ CREATE TABLE IF NOT EXISTS {0} (
@@ -264,6 +269,26 @@ CREATE TABLE IF NOT EXISTS {0} (
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map<Long, ? extends Collection<String>> list(long userId, String module, Collection<Long> entityIds) { |
|
|
|
|
try { |
|
|
|
|
var tags = new HashMap<Long,HashSet<String>>(); |
|
|
|
|
|
|
|
|
|
// load tags assigned to user
|
|
|
|
|
var rs = select(ENTITY_ID,TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ENTITY_ID,in(entityIds.toArray())).where(USER_ID,equal(userId)).exec(db); |
|
|
|
|
while (rs.next()) tags.computeIfAbsent(rs.getLong(ENTITY_ID), k -> new HashSet<>()).add(rs.getString(TAG)); |
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
|
|
// load tags assigned to no user
|
|
|
|
|
rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ENTITY_ID,in(entityIds.toArray())).where(USER_ID,isNull()).exec(db); |
|
|
|
|
while (rs.next()) tags.computeIfAbsent(rs.getLong(ENTITY_ID), k -> new HashSet<>()).add(rs.getString(TAG)); |
|
|
|
|
rs.close(); |
|
|
|
|
return tags; |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
throw new UmbrellaException("Failed to load tags"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags) { |
|
|
|
|
try { |
|
|
|
|
|