Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: database try-with #662

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.ArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.util.database.NeqSimDataBase;

/**
* <p>
Expand Down Expand Up @@ -44,11 +45,9 @@ public static ChemicalReaction getChemicalReaction(String name) {
double rateFactor = 0;
double activationEnergy = 0;


try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase();
java.sql.ResultSet dataSet =
database.getResultSet("SELECT * FROM reactionkspdata where name='" + name + "'")) {

dataSet.next();
String reacname = dataSet.getString("name");
K[0] = Double.parseDouble(dataSet.getString("K1"));
Expand All @@ -59,16 +58,18 @@ public static ChemicalReaction getChemicalReaction(String name) {
rateFactor = Double.parseDouble(dataSet.getString("r"));

activationEnergy = Double.parseDouble(dataSet.getString("ACTENERGY"));
neqsim.util.database.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...");
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);
}
} catch (Exception ex) {
logger.error("Could not add reaction", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ public static void main(String[] args) {
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database
.getResultSet("SELECT * FROM purecomponentconductivitydata WHERE ComponentName='TEG'");
// ResultSet dataSet = database.getResultSet("NeqSimDataBase", "SELECT * FROM
// activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");

try {
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM purecomponentconductivitydata WHERE ComponentName='TEG'");) {
logger.info("adding....");
while (dataSet.next()) {
ConductivityFunction function = new ConductivityFunction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static void main(String[] args) {
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();
// ResultSet dataSet = database.getResultSet("NeqSimDataBase", "SELECT * FROM
// activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");

try (ResultSet dataSet =
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet =
database.getResultSet("SELECT * FROM purecomponentdensity WHERE ComponentName='MEG'")) {
logger.info("adding....");
while (dataSet.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static void main(String[] args) {
LevenbergMarquardt optim = new LevenbergMarquardt();
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

NeqSimDataBase database = new NeqSimDataBase();
// ComponentName<>'nC10'
// AND
// ComponentName<>'nC11'
Expand All @@ -53,7 +52,8 @@ public static void main(String[] args) {
// double guess[] = {-5.2897559010400935E-17, 7.103588505598196E-17}; //,
// 1.1161368619, 0.8363538313}; // PR param

try (ResultSet dataSet = database.getResultSet(
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM purecomponentsurfacetension2 WHERE ComponentName IN ('n-pentane','ethane','methane', 'propane','CO2', 'c-hexane','M-cy-C5', 'n-pentane','n-hexane', 'n-nonane','nC10')") // AND
) {
while (dataSet.next() && includePureCompData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static void main(String[] args) {
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();

try (ResultSet dataSet = database.getResultSet("SELECT * FROM purecomponentviscosity") // WHERE
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM purecomponentviscosity") // WHERE
// ComponentName='MDEA*'");
) {
while (dataSet.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public static void main(String[] args) {
double dP;
double Pold;
double Pnew;
NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM PatrickCO2");

try {
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM PatrickCO2");
) {
while (dataSet.next()) {
i += 1;
logger.info("Adding.... " + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public static void main(String[] args) {
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM CO2CH4MDEA");

double ID;

Expand All @@ -55,7 +53,8 @@ public static void main(String[] args) {
// double guess[] = {0.0004929757}; //Case II
double[] guess = {0.0004929757, 1e-10}; // Case II and CO2-CH4 parameter also regressed

try {
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM CO2CH4MDEA");) {
int i = 0;
logger.info("adding....");
while (dataSet.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public static void main(String[] args) {
logger.error("database error", ex);
}


try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM CO2WaterMDEA WHERE ID>230")) {
int i = 0;
Expand Down Expand Up @@ -207,7 +206,6 @@ public static void main(String[] args) {
logger.error("database error", ex);
}


try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet("SELECT * FROM CO2WaterMDEAtest")) {
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ public static void main(String[] args) {
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM luciadata8 WHERE Component='methane' AND Temperature>410.15 AND Pressure<100000000 AND L2<>NULL AND L2>0.00000001 ORDER BY Temperature,Pressure"); // AND
// Reference='Houghton1957'
// AND
// Reference<>'Nighswander1989'
// AND
// Temperature>278.15
// AND
// Temperature<383.15
// AND
// Pressure<60.01325");

// ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE
// Component='nitrogen' AND Temperature<390 AND L2<>NULL AND L2>0.0000000001
// ORDER BY Temperature,Pressure");
Expand All @@ -62,7 +51,12 @@ public static void main(String[] args) {
// binarySolubilityData WHERE ComponentSolute='methane' AND
// ComponentSolvent='water'");

try {
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM luciadata8 WHERE Component='methane' AND Temperature>410.15 AND Pressure<100000000 AND L2<>NULL AND L2>0.00000001 ORDER BY Temperature,Pressure");
// AND // Reference='Houghton1957' AND Reference<>'Nighswander1989' AND //
// Temperature>278.15 // AND // Temperature<383.15 // AND // Pressure<60.01325");
) {
int p = 0;
logger.info("adding....");
while (!dataSet.next() && p < 50) {
Expand Down Expand Up @@ -114,8 +108,6 @@ public static void main(String[] args) {
// AND Y<>NULL AND Y>0.00000001 ORDER BY Temperature,Pressure"); // AND
// Reference='Houghton1957' AND Reference<>'Nighswander1989' AND
// Temperature>278.15 AND Temperature<383.15 AND Pressure<60.01325");
dataSet = database.getResultSet(
"SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature>273.15 AND Pressure<153000000 AND Y<>NULL AND Y>0.000000001 ORDER BY Temperature,Pressure");
// dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE
// Component='nitrogen' AND Temperature<390 AND Y<>NULL AND Y>0.000000001 ORDER
// BY Temperature,Pressure");
Expand All @@ -131,7 +123,10 @@ public static void main(String[] args) {
// ResultSet dataSet = database.getResultSet( "SELECT * FROM
// binarySolubilityData WHERE ComponentSolute='methane' AND
// ComponentSolvent='water'");
try {
try (NeqSimDataBase database = new NeqSimDataBase();) {
ResultSet dataSet = database.getResultSet(
"SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature>273.15 AND Pressure<153000000 AND Y<>NULL AND Y>0.000000001 ORDER BY Temperature,Pressure");

int p = 0;
logger.info("adding....");
while (dataSet.next() && p < 150) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static void main(String[] args) {
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();
// ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE
// Component='CO2' AND Temperature>250 AND Temperature<420 AND
// Pressure<700000000 AND L2 IS NOT NULL AND L2>0.000000001 ORDER BY
Expand All @@ -56,7 +55,8 @@ public static void main(String[] args) {
// ResultSet dataSet = database.getResultSet( "SELECT * FROM LuciaData8 WHERE
// Component='H2S' AND Temperature>250 AND Temperature<420 AND Pressure<10000000
// AND L2<>NULL AND L2>0.000000001 ORDER BY Temperature,Pressure");
try (ResultSet dataSet = database.getResultSet(
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM LuciaData8 WHERE Component='methane' AND Temperature<520 AND L2<>NULL AND L2>0.0000000001 ORDER BY Temperature,Pressure") // AND
// Reference='Houghton1957'
// AND
Expand Down Expand Up @@ -164,7 +164,8 @@ public static void main(String[] args) {
// activityCoefficientTable WHERE Component1='MDEA' AND Component2='water'");
// testSystem.addComponent(dataSet.getString("ComponentSolute"), 1.0);
// testSystem.addComponent(dataSet.getString("ComponentSolvent"), 1.0);
try (ResultSet dataSet = database.getResultSet(
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM LuciaData8 WHERE Component='methane' AND ID<3000 AND Temperature<520 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure")) {
int p = 0;
logger.info("adding....");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public static void main(String[] args) {
LevenbergMarquardt optim = new LevenbergMarquardt();
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();

// inserting samples from database
NeqSimDataBase database = new NeqSimDataBase();

try (NeqSimDataBase database = new NeqSimDataBase();) {
// inserting samples from database
// ResultSet dataSet = database.getResultSet( "SELECT * FROM CO2watersolubility
// WHERE pressureMPA<6 AND reference IN ('[18]', '[35]', '[36]', '[37]', '[38]',
// '[39]', '[40]', '[41]','[42]')");

ResultSet dataSet = database.getResultSet(
"SELECT * FROM CO2watersolubility WHERE pressureMPA<5 AND reference IN ('[18]', '[35]', '[36]', '[37]', '[38]', '[39]', '[40]', '[41]','[42]', '[32]', '[33]', '[34]')");

try {
int p = 0;
while (dataSet.next() && p < 550) {
p++;
Expand Down Expand Up @@ -86,10 +86,11 @@ public static void main(String[] args) {
logger.error("database error", ex);
}

dataSet = database.getResultSet(
"SELECT * FROM LuciaData8 WHERE Component='CO2' AND ID<3000 AND Temperature>250 AND Pressure<700000000 AND Temperature<420 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure");

try {
try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM LuciaData8 WHERE Component='CO2' AND ID<3000 AND Temperature>250 AND Pressure<700000000 AND Temperature<420 AND Y<>NULL AND Y>0.0000000001 ORDER BY Temperature,Pressure");
) {
int p = 0;
while (!dataSet.next() && p < 100) {
p++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public static void main(String[] args) {
LevenbergMarquardt optim = new LevenbergMarquardt();
ArrayList<SampleValue> sampleList = new ArrayList<SampleValue>();


double parameterGuess[] = {188.385052774267, -0.84022345}; // , 2630.871733876947};

try (NeqSimDataBase database = new NeqSimDataBase();
Expand Down Expand Up @@ -180,7 +179,6 @@ public static void main(String[] args) {
logger.error("database error", ex);
}


try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='n-pentane'");) {
Expand Down Expand Up @@ -216,7 +214,6 @@ public static void main(String[] args) {
logger.error("database error", ex);
}


try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='butane'");) {
Expand Down Expand Up @@ -253,7 +250,6 @@ public static void main(String[] args) {
logger.error("database error", ex);
}


try (NeqSimDataBase database = new NeqSimDataBase();
ResultSet dataSet = database.getResultSet(
"SELECT * FROM binarySolubilityData WHERE ComponentSolute='Hg' AND ComponentSolvent='propane'");) {
Expand Down
Loading