aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java126
1 files changed, 126 insertions, 0 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java
new file mode 100644
index 00000000..73f98abf
--- /dev/null
+++ b/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java
@@ -0,0 +1,126 @@
+package com.juick.service;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.inject.Inject;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Created by aalexeev on 11/13/16.
+ */
+@Repository
+public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueriesService {
+
+ @Inject
+ public PushQueriesServiceImpl(JdbcTemplate jdbcTemplate) {
+ super(jdbcTemplate, null);
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getGCMRegID(final int uid) {
+ return getJdbcTemplate().queryForList(
+ "SELECT regid FROM android WHERE user_id=?",
+ String.class,
+ uid);
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getGCMTokens(final Collection<Integer> uids) {
+ if (CollectionUtils.isEmpty(uids))
+ return Collections.emptyList();
+
+ return getNamedParameterJdbcTemplate().queryForList(
+ "SELECT regid FROM android INNER JOIN users ON (users.id = android.user_id) WHERE users.id IN (:ids)",
+ new MapSqlParameterSource("ids", uids),
+ String.class);
+ }
+
+ @Transactional
+ @Override
+ public boolean addGCMToken(Integer uid, String token) {
+ return getJdbcTemplate().update("INSERT IGNORE INTO android(user_id,regid) VALUES (?, ?)",
+ uid, token) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean deleteGCMToken(String token) {
+ return getJdbcTemplate().update("DELETE FROM android WHERE regid=?", token) > 0;
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getMPNSURL(final int uid) {
+ return getJdbcTemplate().queryForList(
+ "SELECT url FROM winphone WHERE user_id=?",
+ String.class,
+ uid);
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getMPNSTokens(final Collection<Integer> uids) {
+ if (CollectionUtils.isEmpty(uids))
+ return Collections.emptyList();
+
+ return getNamedParameterJdbcTemplate().queryForList(
+ "SELECT url FROM winphone INNER JOIN users ON (users.id=winphone.user_id) WHERE users.id IN (:ids)",
+ new MapSqlParameterSource("ids", uids),
+ String.class);
+ }
+
+ @Transactional
+ @Override
+ public boolean addMPNSToken(Integer uid, String token) {
+ return getJdbcTemplate().update("INSERT IGNORE INTO winphone(user_id,url) VALUES (?, ?)",
+ uid, token) > 0;
+ }
+
+ @Transactional
+ @Override
+ public boolean deleteMPNSToken(String token) {
+ return getJdbcTemplate().update("DELETE FROM winphone WHERE url=?", token) > 0;
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getAPNSToken(final int uid) {
+ return getJdbcTemplate().queryForList(
+ "SELECT token from ios WHERE user_id=?",
+ String.class,
+ uid);
+ }
+
+ @Transactional
+ @Override
+ public boolean deleteAPNSToken(String token) {
+ return getJdbcTemplate().update("DELETE FROM ios WHERE token=?", token) > 0;
+ }
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getAPNSTokens(final Collection<Integer> uids) {
+ if (CollectionUtils.isEmpty(uids))
+ return Collections.emptyList();
+
+ return getNamedParameterJdbcTemplate().queryForList(
+ "SELECT token FROM ios INNER JOIN users ON (users.id = ios.user_id) WHERE users.id IN (:ids)",
+ new MapSqlParameterSource("ids", uids),
+ String.class);
+ }
+
+ @Transactional
+ @Override
+ public boolean addAPNSToken(Integer uid, String token) {
+ return getJdbcTemplate().update("INSERT IGNORE INTO ios(user_id,token) VALUES (?, ?)",
+ uid, token) > 0;
+ }
+}