aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/PushQueries.java
blob: bf7505cad7faa20692e8aa0349c3d10eef24b149 (plain) (blame)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.juick.server;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ugnich
 */
public class PushQueries {

    public static String getAndroidRegID(Connection sql, int uid) {
        return SQLHelpers.getString(sql, "SELECT regid FROM android WHERE user_id=?", uid);
    }

    public static ArrayList<String> getAndroidSubscribers(Connection sql, int uid) {
        ArrayList<String> regids = new ArrayList<String>();

        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            stmt = sql.prepareStatement("SELECT regid FROM android INNER JOIN subscr_users ON (subscr_users.user_id=? AND android.user_id=subscr_users.suser_id)");
            stmt.setInt(1, uid);
            rs = stmt.executeQuery();
            rs.beforeFirst();
            while (rs.next()) {
                regids.add(rs.getString(1));
            }
        } catch (SQLException e) {
            System.err.println(e);
        } finally {
            Utils.finishSQL(rs, stmt);
        }
        return regids;
    }

    public static String getWinPhoneURL(Connection sql, int uid) {
        return SQLHelpers.getString(sql, "SELECT url FROM winphone WHERE user_id=?", uid);
    }

    public static ArrayList<String> getWinPhoneSubscribers(Connection sql, int uid) {
        ArrayList<String> urls = new ArrayList<String>();

        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            stmt = sql.prepareStatement("SELECT url FROM winphone INNER JOIN subscr_users ON (subscr_users.user_id=? AND winphone.user_id=subscr_users.suser_id)");
            stmt.setInt(1, uid);
            rs = stmt.executeQuery();
            rs.beforeFirst();
            while (rs.next()) {
                urls.add(rs.getString(1));
            }
        } catch (SQLException e) {
            System.err.println(e);
        } finally {
            Utils.finishSQL(rs, stmt);
        }
        return urls;
    }

    public static String getAPNSToken(Connection sql, int uid) {
        return SQLHelpers.getString(sql, "SELECT token from ios WHERE user_id=?", uid);
    }

    public static List<String> getAPNSSubscribers(Connection sql, int uid) {
        List<String> urls = new ArrayList<String>();

        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            stmt = sql.prepareStatement("SELECT token FROM ios INNER JOIN subscr_users ON (subscr_users.user_id=? AND ios.user_id=subscr_users.suser_id)");
            stmt.setInt(1, uid);
            rs = stmt.executeQuery();
            rs.beforeFirst();
            while (rs.next()) {
                urls.add(rs.getString(1));
            }
        } catch (SQLException e) {
            System.err.println(e);
        } finally {
            Utils.finishSQL(rs, stmt);
        }
        return urls;
    }
}