/** * Creates a request handler that can send TCP and UDP messages. * * @param futureResponse The future that will be called when we get an answer * @param peerBean The peer bean * @param connectionBean The connection bean * @param configuration the client-side connection configuration */ public RequestHandler( final K futureResponse, final PeerBean peerBean, final ConnectionBean connectionBean, final ConnectionConfiguration configuration) { this.peerBean = peerBean; this.connectionBean = connectionBean; this.futureResponse = futureResponse; this.message = futureResponse.request(); this.sendMessageID = new MessageID(message); this.idleTCPMillis = configuration.idleTCPMillis(); this.idleUDPMillis = configuration.idleUDPMillis(); this.connectionTimeoutTCPMillis = configuration.connectionTimeoutTCPMillis(); this.slowResponseTimeoutSeconds = configuration.slowResponseTimeoutSeconds(); }
// Uyeler icin arama metodu public List<Uyeler> selectByUye(String kriter, String param) { List<Uyeler> uyeler = new ArrayList<Uyeler>(); Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement("SELECT * FROM uyeler WHERE " + kriter + " LIKE ?"); preparedStatement.setString(1, "%" + param + "%"); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { Uyeler uye = new Uyeler(); uye.setId(resultSet.getInt("id")); uye.setTc(resultSet.getString("tc")); uye.setAd(resultSet.getString("ad")); uye.setSoyad(resultSet.getString("soyad")); uye.setMeslek(resultSet.getString("meslek")); uye.setAdres(resultSet.getString("adres")); uye.setTelefon(resultSet.getString("telefon")); uye.setMail(resultSet.getString("mail")); uye.setKullaniciadi(resultSet.getString("kullaniciadi")); uye.setSifre(resultSet.getString("sifre")); uyeler.add(uye); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } finally { kapatici(connection, preparedStatement, resultSet); } return uyeler; }
// Kitap guncelleme public void updateKitap(Kitap kitap, int param) { Connection connection = null; PreparedStatement preparedStatement = null; String updateString = "UPDATE `kitaplar` SET `isbnno`=?, `kitapad`=?, `yazarid`=?, `tur`=?,`yayintarihi`=?,`yayinevi`=?,`sayfa`=? WHERE `isbnno`=?"; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement(updateString); preparedStatement.setInt(1, kitap.getIsbnno()); preparedStatement.setString(2, kitap.getKitapad()); preparedStatement.setInt(3, kitap.getYazarid()); preparedStatement.setString(4, kitap.getTur()); preparedStatement.setString(5, kitap.getYayintarihi()); preparedStatement.setString(6, kitap.getYayinevi()); preparedStatement.setInt(7, kitap.getSayfa()); preparedStatement.setInt(8, param); preparedStatement.executeUpdate(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } finally { kapatici(connection, preparedStatement, null); } }
// Uye güncelleme public void updateUye(Uyeler uye, String param) { Connection connection = null; PreparedStatement preparedStatement = null; String updateString = "UPDATE `uyeler` SET `tc`=?, `ad`=?, `soyad`=?, `meslek`=?,`adres`=?,`telefon`=?,`mail`=?,`kullaniciadi`=?,`sifre`=? WHERE `tc`=?"; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement(updateString); preparedStatement.setString(1, uye.getTc()); preparedStatement.setString(2, uye.getAd()); preparedStatement.setString(3, uye.getSoyad()); preparedStatement.setString(4, uye.getMeslek()); preparedStatement.setString(5, uye.getAdres()); preparedStatement.setString(6, uye.getTelefon()); preparedStatement.setString(7, uye.getMail()); preparedStatement.setString(8, uye.getKullaniciadi()); preparedStatement.setString(9, uye.getSifre()); preparedStatement.setString(10, param); preparedStatement.executeUpdate(); JOptionPane.showMessageDialog(null, "Successful UPDATE"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } finally { kapatici(connection, preparedStatement, null); } }
public void KitapAlma( int isbn, String kitapad, String adsoyadi, String mail, String alinma, String iade) { Connection connection = null; PreparedStatement preparedStatement = null; String query = "INSERT INTO hareketler (`isbnno`, `kitapad`, `adsoyad`, `mail`,`alimtarihi`,`iadetarihi`) VALUES (?,?,?,?,?,?)"; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, isbn); preparedStatement.setString(2, kitapad); preparedStatement.setString(3, adsoyadi); preparedStatement.setString(4, mail); preparedStatement.setString(5, alinma); preparedStatement.setString(6, iade); preparedStatement.executeUpdate(); JOptionPane.showMessageDialog(null, "Successful INSERT INTO"); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Kayıtta hata oluştu \n" + e.getMessage()); } finally { kapatici(connection, preparedStatement, null); } }
// Kitap Kayıt public void insertKitap(Kitap kitap) { Connection connection = null; PreparedStatement preparedStatement = null; String query = "INSERT INTO kitaplar (`isbnno`, `kitapad`, `yazarid`, `tur`,`yayintarihi`,`yayinevi`,`sayfa`) VALUES (?,?,?,?,?,?,?)"; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, kitap.getIsbnno()); preparedStatement.setString(2, kitap.getKitapad()); preparedStatement.setInt(3, kitap.getYazarid()); preparedStatement.setString(4, kitap.getTur()); preparedStatement.setString(5, kitap.getYayintarihi()); preparedStatement.setString(6, kitap.getYayinevi()); preparedStatement.setInt(7, kitap.getSayfa()); preparedStatement.executeUpdate(); JOptionPane.showMessageDialog(null, "Successful INSERT INTO"); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Kayıtta hata oluştu \n" + e.getMessage()); } finally { kapatici(connection, preparedStatement, null); } }
// Uye Kayıt public void insertUye(Uyeler uye) { Connection connection = null; PreparedStatement preparedStatement = null; String query = "INSERT INTO uyeler (`tc`, `ad`, `soyad`, `meslek`,`adres`,`telefon`,`mail`,`kullaniciadi`,`sifre`) VALUES (?,?,?,?,?,?,?,?,?)"; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, uye.getTc()); preparedStatement.setString(2, uye.getAd()); preparedStatement.setString(3, uye.getSoyad()); preparedStatement.setString(4, uye.getMeslek()); preparedStatement.setString(5, uye.getAdres()); preparedStatement.setString(6, uye.getTelefon()); preparedStatement.setString(7, uye.getMail()); preparedStatement.setString(8, uye.getKullaniciadi()); preparedStatement.setString(9, uye.getSifre()); preparedStatement.executeUpdate(); JOptionPane.showMessageDialog(null, "Successful INSERT INTO"); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Kayıtta hata oluştu \n" + e.getMessage()); } finally { kapatici(connection, preparedStatement, null); } }
// kitaplar icin arama metodu public List<Kitap> selectByKitap(String kriter, String param) { List<Kitap> kitaplar = new ArrayList<Kitap>(); Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement("SELECT * FROM kitaplar WHERE " + kriter + " LIKE ?"); preparedStatement.setString(1, "%" + param + "%"); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { Kitap kitap = new Kitap(); kitap.setId(resultSet.getInt("id")); kitap.setIsbnno(resultSet.getInt("isbnno")); kitap.setKitapad(resultSet.getString("kitapad")); kitap.setYazarid(resultSet.getInt("yazarid")); kitap.setTur(resultSet.getString("tur")); kitap.setYayintarihi(resultSet.getString("yayintarihi")); kitap.setYayinevi(resultSet.getString("yayinevi")); kitap.setSayfa(resultSet.getInt("sayfa")); kitaplar.add(kitap); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } finally { kapatici(connection, preparedStatement, resultSet); } return kitaplar; }
public void delete(String tablo, String kriter, String param) { Connection connection = null; PreparedStatement preparedStatement = null; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement("DELETE FROM " + tablo + " WHERE " + kriter + " = ?"); preparedStatement.setString(1, param); preparedStatement.executeUpdate(); JOptionPane.showMessageDialog(null, "Successful DELETE FROM"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } finally { kapatici(connection, preparedStatement, null); } }
public Boolean LoginControl(String tablo, String username, String password) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; Boolean booleanparam = false; try { connection = ConnectionConfiguration.getConnection(); preparedStatement = connection.prepareStatement( "SELECT * FROM " + tablo + " WHERE kullaniciadi = ? AND sifre = ?"); preparedStatement.setString(1, username); preparedStatement.setString(2, password); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { booleanparam = true; } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage()); } finally { kapatici(connection, preparedStatement, resultSet); } return booleanparam; }
/** * Connects to GCM Cloud Connection Server using the supplied credentials. * * @param senderId Your GCM project number * @param apiKey API Key of your project */ public void connect(long senderId, String apiKey) throws XMPPException, IOException, SmackException { ConnectionConfiguration config = new ConnectionConfiguration(GCM_SERVER, GCM_PORT); config.setSecurityMode(SecurityMode.enabled); config.setReconnectionAllowed(true); config.setRosterLoadedAtLogin(false); config.setSendPresence(false); config.setSocketFactory(SSLSocketFactory.getDefault()); config.setDebuggerEnabled(false); connection = new XMPPTCPConnection(config); connection.connect(); connection.addConnectionListener(new LoggingConnectionListener()); // Handle incoming packets connection.addPacketListener( new PacketListener() { @Override public void processPacket(Packet packet) { log.info("Received: " + packet.toXML()); Message incomingMessage = (Message) packet; GcmPacketExtension gcmPacket = (GcmPacketExtension) incomingMessage.getExtension(GCM_NAMESPACE); String json = gcmPacket.getJson(); try { @SuppressWarnings("unchecked") Map<String, Object> jsonObject = new ObjectMapper().readValue(json, Map.class); // Map<String, Object> jsonObject = (Map<String, Object>) // JSONValue.parseWithException(json); // present for "ack"/"nack", null otherwise Object messageType = jsonObject.get("message_type"); if (messageType == null) { // Normal upstream data message handleUpstreamMessage(jsonObject); // Send ACK to CCS String messageId = (String) jsonObject.get("message_id"); String from = (String) jsonObject.get("from"); String ack = createJsonAck(from, messageId); send(ack); } else if ("ack".equals(messageType.toString())) { // Process Ack handleAckReceipt(jsonObject); } else if ("nack".equals(messageType.toString())) { // Process Nack handleNackReceipt(jsonObject); } else if ("control".equals(messageType.toString())) { // Process control message handleControlMessage(jsonObject); } else { log.warn("Unrecognized message type (%s)", messageType.toString()); } // } catch (ParseException e) { // log.error("Error parsing JSON " + json, e); } catch (Exception e) { log.error("Failed to process packet", e); } } }, new PacketTypeFilter(Message.class)); // Log all outgoing packets connection.addPacketInterceptor( new PacketInterceptor() { @Override public void interceptPacket(Packet packet) { log.info("Sent: {0}", packet.toXML()); } }, new PacketTypeFilter(Message.class)); connection.login(senderId + "@gcm.googleapis.com", apiKey); }