1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.juick.server;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Optional;
/**
*
* @author ugnich
*/
public class PushQueries {
public static Optional<String> getAndroidRegID(JdbcTemplate sql, int uid) {
try {
return Optional.of(sql.queryForObject("SELECT regid FROM android WHERE user_id=?", String.class, uid));
} catch (EmptyResultDataAccessException e) {
return Optional.empty();
}
}
public static List<String> getAndroidSubscribers(JdbcTemplate sql, int uid) {
return sql.queryForList("SELECT regid FROM android INNER JOIN subscr_users " +
"ON (subscr_users.user_id=? AND android.user_id=subscr_users.suser_id)", String.class, uid);
}
public static List<String> getAndroidTokens(JdbcTemplate sql, List<Integer> uids) {
return sql.queryForList("SELECT regid FROM android INNER JOIN users " +
"ON (users.id=android.user_id) WHERE users.id IN (" + StringUtils.collectionToCommaDelimitedString(uids) + ")", String.class);
}
public static Optional<String> getWinPhoneURL(JdbcTemplate sql, int uid) {
try {
return Optional.of(sql.queryForObject("SELECT url FROM winphone WHERE user_id=?", String.class, uid));
} catch (EmptyResultDataAccessException e) {
return Optional.empty();
}
}
public static List<String> getWinPhoneSubscribers(JdbcTemplate sql, int uid) {
return sql.queryForList("SELECT url FROM winphone INNER JOIN subscr_users " +
"ON (subscr_users.user_id=? AND winphone.user_id=subscr_users.suser_id)", String.class, uid);
}
public static List<String> getWindowsTokens(JdbcTemplate sql, List<Integer> uids) {
return sql.queryForList("SELECT url FROM winphone INNER JOIN users " +
"ON (users.id=winphone.user_id) WHERE users.id IN (" + StringUtils.collectionToCommaDelimitedString(uids) + ")", String.class);
}
public static Optional<String> getAPNSToken(JdbcTemplate sql, int uid) {
try {
return Optional.of(sql.queryForObject("SELECT token from ios WHERE user_id=?", String.class, uid));
} catch (EmptyResultDataAccessException e) {
return Optional.empty();
}
}
public static List<String> getAPNSSubscribers(JdbcTemplate sql, int uid) {
return sql.queryForList("SELECT token FROM ios INNER JOIN subscr_users " +
"ON (subscr_users.user_id=? AND ios.user_id=subscr_users.suser_id)", String.class, uid);
}
public static List<String> getAPNSTokens(JdbcTemplate sql, List<Integer> uids) {
return sql.queryForList("SELECT token FROM ios INNER JOIN users " +
"ON (users.id=ios.user_id) WHERE users.id IN (" + StringUtils.collectionToCommaDelimitedString(uids) + ")", String.class);
}
}
|