Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol authored and asmfstatoil committed Jun 8, 2023
1 parent 252ee1e commit 0eb1b3a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.util.database.NeqSimDataBase;

/**
* <p>
Expand All @@ -27,17 +26,15 @@ public class ChemicalReactionFactory {
* Constructor for ChemicalReactionFactory.
* </p>
*/
public ChemicalReactionFactory() {
}
public ChemicalReactionFactory() {}

/**
* <p>
* getChemicalReaction.
* </p>
*
* @param name a {@link java.lang.String} object
* @return a {@link neqsim.chemicalReactions.chemicalReaction.ChemicalReaction}
* object
* @return a {@link neqsim.chemicalReactions.chemicalReaction.ChemicalReaction} object
*/
public static ChemicalReaction getChemicalReaction(String name) {
ArrayList<String> names = new ArrayList<String>();
Expand All @@ -48,31 +45,40 @@ public static ChemicalReaction getChemicalReaction(String name) {
double activationEnergy = 0;

try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase();
java.sql.ResultSet dataSet = database.getResultSet("SELECT * FROM REACTIONDATA where name='" + name + "'")) {
dataSet.next();
String reacname = dataSet.getString("name");
K[0] = Double.parseDouble(dataSet.getString("K1"));
K[1] = Double.parseDouble(dataSet.getString("K2"));
K[2] = Double.parseDouble(dataSet.getString("K3"));
K[3] = Double.parseDouble(dataSet.getString("K4"));
refT = Double.parseDouble(dataSet.getString("Tref"));
rateFactor = Double.parseDouble(dataSet.getString("r"));
java.sql.ResultSet dataSet =
database.getResultSet("SELECT * FROM reactiondata where name='" + name + "'")) {
if (dataSet.next()) {
String reacname = dataSet.getString("name");
K[0] = Double.parseDouble(dataSet.getString("K1"));
K[1] = Double.parseDouble(dataSet.getString("K2"));
K[2] = Double.parseDouble(dataSet.getString("K3"));
K[3] = Double.parseDouble(dataSet.getString("K4"));
refT = Double.parseDouble(dataSet.getString("Tref"));
rateFactor = Double.parseDouble(dataSet.getString("r"));

activationEnergy = Double.parseDouble(dataSet.getString("ACTENERGY"));
try (NeqSimDataBase database2 = new neqsim.util.database.NeqSimDataBase();
java.sql.ResultSet dataSet2 = database2
.getResultSet("SELECT * FROM stoccoefdata where reacname='" + reacname + "'")) {
dataSet2.next();
do {
names.add(dataSet2.getString("compname").trim());
stocCoef.add((dataSet2.getString("stoccoef")).trim());
} while (dataSet2.next());
// System.out.println("reaction added ok...");
} catch (Exception ex) {
logger.error("Could not add reaction", ex);
activationEnergy = Double.parseDouble(dataSet.getString("ACTENERGY"));
try (java.sql.ResultSet dataSet2 =
database.getResultSet("SELECT * FROM stoccoefdata where reacname='" + reacname + "'")) {
while (dataSet2.next()) {
names.add(dataSet2.getString("compname").trim());
stocCoef.add((dataSet2.getString("stoccoef")).trim());
}
} finally {
if (names.size() == 0) {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(
"ChemicalReactionFactory", "getChemicalReaction", "reacname",
"- found no data in table stoccoefdata for component named " + reacname));
}
}
} else {
throw new RuntimeException(new neqsim.util.exception.InvalidInputException(
"ChemicalReactionFactory", "getChemicalReaction", "reacname",
"- found no data in table REACTIONDATA for component named " + name));
}
} catch (Exception ex) {
logger.error("Could not add reaction", ex);
// TODO: improve warning message, probably table missing?
logger.error("Failed getting data from REACTIONDATA for component named " + name + ":\n\t"
+ ex.getMessage());
}

String[] nameArray = new String[names.size()];
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/neqsim/util/database/NeqSimBlobDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Connection openConnection() throws SQLException, ClassNotFoundException {
return DriverManager.getConnection(getConnectionString(), username, password);
}
} catch (Exception ex) {
logger.error("error loading NeqSimDataBase... ", ex);
logger.error("error loading NeqSimBlobDatabase... ", ex);
throw new RuntimeException(ex);
} finally {
try {
Expand Down Expand Up @@ -151,7 +151,7 @@ public ResultSet getResultSet(String sqlString) {
ResultSet result = getStatement().executeQuery(sqlString);
return result;
} catch (Exception ex) {
logger.error("error loading NeqSimbataBase ", ex);
logger.error("error loading NeqSimBlobDatabase ", ex);
throw new RuntimeException(ex);
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/neqsim/util/database/NeqSimDataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.h2.jdbc.JdbcSQLSyntaxErrorException;

/**
* <p>
Expand Down Expand Up @@ -206,7 +207,7 @@ public void executeQuery(String sqlString) {

/**
* <p>
* Execute query using executeQueryy and return ResultSet.
* Execute query using executeQuery and return ResultSet.
* </p>
*
* @param sqlString Query to execute.
Expand All @@ -215,6 +216,12 @@ public void executeQuery(String sqlString) {
public ResultSet getResultSet(String sqlString) {
try {
return getStatement().executeQuery(sqlString);
} catch (JdbcSQLSyntaxErrorException ex) {
if (ex.getMessage().startsWith("Table ") && ex.getMessage().contains(" not found;")) {
throw new RuntimeException(new neqsim.util.exception.NotInitializedException(this,
"getResultSet", ex.getMessage()));
}
throw new RuntimeException(ex);
} catch (Exception ex) {
logger.error("error loading NeqSimbataBase ", ex);
throw new RuntimeException(ex);
Expand Down Expand Up @@ -451,6 +458,7 @@ public static void initH2DatabaseFromCSVfiles() {
updateTable("ISO6976constants2016");
updateTable("STOCCOEFDATA");
updateTable("REACTIONDATA");
// Table ReactionKSPdata is not in use anywhere
updateTable("ReactionKSPdata");
updateTable("AdsorptionParameters");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Connection openConnection() throws SQLException, ClassNotFoundException {
return DriverManager.getConnection(getConnectionString(), username, password);
}
} catch (Exception ex) {
logger.error("error loading NeqSimDataBase... ", ex);
logger.error("error loading NeqSimExperimentDatabase... ", ex);
throw new RuntimeException(ex);
} finally {
try {
Expand Down Expand Up @@ -144,7 +144,7 @@ public ResultSet getResultSet(String sqlString) {
ResultSet result = getStatement().executeQuery(sqlString);
return result;
} catch (Exception ex) {
logger.error("error loading NeqSimbataBase ", ex);
logger.error("error loading NeqSimExperimentDatabase ", ex);
throw new RuntimeException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Connection openConnection() throws SQLException, ClassNotFoundException {
return DriverManager.getConnection(getConnectionString(), username, password);
}
} catch (Exception ex) {
logger.error("error loading NeqSimDataBase... ", ex);
logger.error("error loading NeqSimTechnicalDesignDatabase... ", ex);
throw new RuntimeException(ex);
} finally {
try {
Expand Down Expand Up @@ -144,7 +144,7 @@ public ResultSet getResultSet(String sqlString) {
ResultSet result = getStatement().executeQuery(sqlString);
return result;
} catch (Exception ex) {
logger.error("error loading NeqSimbataBase ", ex);
logger.error("error loading NeqSimTechnicalDesignDatabase ", ex);
throw new RuntimeException(ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public class ChemicalReactionFactoryTest {
void testGetChemicalReaction() {
String[] reactionNames = ChemicalReactionFactory.getChemicalReactionNames();
Assertions.assertNotEquals(0, reactionNames.length);

ChemicalReactionFactory.getChemicalReaction("test");
ChemicalReactionFactory.getChemicalReaction("CO2water");
ChemicalReactionFactory.getChemicalReaction(reactionNames[0]);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
status = error
name = PropertiesConfig
status = warn
dest = out
name = NeqSimTestConfig

filters = threshold

Expand All @@ -15,6 +16,6 @@ appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


# Define the root logger with appender file - see https://www.tutorialspoint.com/log4j/log4j_logging_levels.htm
rootLogger.level = OFF
rootLogger.level = warn
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

0 comments on commit 0eb1b3a

Please sign in to comment.