Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,141 @@
package com.stackify.daos;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.stackify.models.User;
import com.stackify.utils.ConnectionUtil;
public class UserDAO {
private Logger logger = LogManager.getLogger(UserDAO.class);
public void createTable() {
try (Connection con = ConnectionUtil.getConnection()) {
String createQuery = "CREATE TABLE users(email varchar(50) primary key, name varchar(50))";
PreparedStatement pstmt = con.prepareStatement(createQuery);
pstmt.execute();
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
}
public void add(User user) {
try (Connection con = ConnectionUtil.getConnection()) {
String insertQuery = "INSERT INTO users(email,name) VALUES(?,?)";
PreparedStatement pstmt = con.prepareStatement(insertQuery);
pstmt.setString(1, user.getEmail());
pstmt.setString(2, user.getName());
pstmt.executeUpdate();
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
}
public void update(User user) {
try (Connection con = ConnectionUtil.getConnection()) {
String updateQuery = "UPDATE users SET name=? WHERE email=?";
PreparedStatement pstmt = con.prepareStatement(updateQuery);
pstmt.setString(1, user.getName());
pstmt.setString(2, user.getEmail());
pstmt.executeUpdate();
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
}
public void delete(User user) {
try (Connection con = ConnectionUtil.getConnection()) {
String deleteQuery = "DELETE FROM users WHERE email=?";
PreparedStatement pstmt = con.prepareStatement(deleteQuery);
pstmt.setString(1, user.getEmail());
pstmt.executeUpdate();
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
}
public void delete(String email) {
try (Connection con = ConnectionUtil.getConnection()) {
String deleteQuery = "DELETE FROM users WHERE email=?";
PreparedStatement pstmt = con.prepareStatement(deleteQuery);
pstmt.setString(1, email);
pstmt.executeUpdate();
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
}
public User findOne(String email) {
User user = null;
try (Connection con = ConnectionUtil.getConnection()) {
String query = "SELECT * FROM users WHERE email=?";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setString(1, email);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
user = new User();
user.setEmail(rs.getString("email"));
user.setName(rs.getString("name"));
}
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
return user;
}
public List<User> findAll() {
List<User> users = new ArrayList<>();
try (Connection con = ConnectionUtil.getConnection()) {
String query = "SELECT * FROM users";
PreparedStatement pstmt = con.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
User user = new User();
user.setEmail(rs.getString("email"));
user.setName(rs.getString("name"));
users.add(user);
}
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
return users;
}
public void deleteAll() {
try (Connection con = ConnectionUtil.getConnection()) {
String deleteQuery = "DELETE FROM users";
PreparedStatement pstmt = con.prepareStatement(deleteQuery);
pstmt.executeUpdate();
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
}
}
@@ -0,0 +1,63 @@
package com.stackify.models;
public class User {
private String email;
private String name;
public User() {
}
public User(String email, String name) {
super();
this.email = email;
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -0,0 +1,15 @@
package com.stackify.test.conditions;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisabledOnEnvironmentCondition.class)
public @interface DisabledOnEnvironment {
String[] value();
}
@@ -0,0 +1,38 @@
package com.stackify.test.conditions;
import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;
import java.util.Properties;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.TestExecutionCondition;
import org.junit.jupiter.api.extension.TestExtensionContext;
import org.junit.platform.commons.support.AnnotationSupport;
import com.stackify.utils.ConnectionUtil;
public class DisabledOnEnvironmentCondition implements TestExecutionCondition {
@Override
public ConditionEvaluationResult evaluate(TestExtensionContext context) {
Properties props = new Properties();
String env = "";
try {
props.load(ConnectionUtil.class.getResourceAsStream("/application.properties"));
env = props.getProperty("env");
} catch (IOException e) {
e.printStackTrace();
}
Optional<DisabledOnEnvironment> disabled = AnnotationSupport.findAnnotation(context.getElement().get(), DisabledOnEnvironment.class);
if (disabled.isPresent()) {
String[] envs = disabled.get().value();
if (Arrays.asList(envs).contains(env)) {
return ConditionEvaluationResult.disabled("Disabled on environment " + env);
}
}
return ConditionEvaluationResult.enabled("Enabled on environment "+env);
}
}
@@ -0,0 +1,38 @@
package com.stackify.utils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ConnectionUtil {
private static Logger logger = LogManager.getLogger(ConnectionUtil.class);
public static Connection getConnection() {
try {
Properties props = new Properties();
props.load(ConnectionUtil.class.getResourceAsStream("jdbc.properties"));
Class.forName(props.getProperty("jdbc.driver"));
Connection con = DriverManager.getConnection(props.getProperty("jdbc.url"), props.getProperty("jdbc.user"), props.getProperty("jdbc.password"));
return con;
}
catch (FileNotFoundException exc) {
logger.error(exc.getMessage());
} catch (IOException exc) {
logger.error(exc.getMessage());
} catch (ClassNotFoundException exc) {
logger.error(exc.getMessage());
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
return null;
}
}