Skip to content

Commit

Permalink
Fix #1758: Use long for Feature.timeOut (#1759)
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias <t.warneke@gmx.net>
  • Loading branch information
zaza and wumpz authored Apr 27, 2023
1 parent 1bbb144 commit 3314edf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public P withUnsupportedStatements(boolean allowUnsupportedStatements) {
return withFeature(Feature.allowUnsupportedStatements, allowUnsupportedStatements);
}

public P withTimeOut(int timeOutMillSeconds) {
public P withTimeOut(long timeOutMillSeconds) {
return withFeature(Feature.timeOut, timeOutMillSeconds);
}

Expand All @@ -46,7 +46,7 @@ public P withFeature(Feature f, boolean enabled) {
return me();
}

public P withFeature(Feature f, int value) {
public P withFeature(Feature f, long value) {
getConfiguration().setValue(f, value);
return me();
}
Expand All @@ -59,8 +59,8 @@ public boolean getAsBoolean(Feature f) {
return getConfiguration().getAsBoolean(f);
}

public Integer getAsInteger(Feature f) {
return getConfiguration().getAsInteger(f);
public Long getAsLong(Feature f) {
return getConfiguration().getAsLong(f);
}

public void setErrorRecovery(boolean errorRecovery) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public Statement call() throws Exception {
});
executorService.shutdown();

statement = future.get(parser.getConfiguration().getAsInteger(Feature.timeOut),
TimeUnit.MILLISECONDS);
statement = future.get( parser.getConfiguration().getAsLong(Feature.timeOut), TimeUnit.MILLISECONDS);

} catch (TimeoutException ex) {
parser.interrupted = true;
throw new JSQLParserException("Time out occurred.", ex);
Expand Down Expand Up @@ -335,8 +335,8 @@ public Statements call() throws Exception {
});
executorService.shutdown();

statements = future.get(parser.getConfiguration().getAsInteger(Feature.timeOut),
TimeUnit.MILLISECONDS);
statements = future.get( parser.getConfiguration().getAsLong(Feature.timeOut) , TimeUnit.MILLISECONDS);

} catch (TimeoutException ex) {
parser.interrupted = true;
throw new JSQLParserException("Time out occurred.", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public boolean getAsBoolean(Feature f) {
return Boolean.parseBoolean(String.valueOf(getValue(f)));
}

public Integer getAsInteger(Feature f) {
return Integer.valueOf(String.valueOf(getValue(f)));
public Long getAsLong(Feature f) {
return Long.valueOf(String.valueOf(getValue(f)));
}

public String getAsString(Feature f) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/net/sf/jsqlparser/parser/CCJSqlParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.sf.jsqlparser.parser;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import net.sf.jsqlparser.parser.feature.Feature;

public class CCJSqlParserTest {
@Test
public void parserWithTimeout() throws Exception {
CCJSqlParser parser = CCJSqlParserUtil.newParser("foo").withTimeOut(123L);

Long timeOut = parser.getAsLong(Feature.timeOut);

assertThat(timeOut).isEqualTo(123L);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.sf.jsqlparser.parser.feature;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class FeatureConfigurationTest {
@Test
public void getAsLong() {
FeatureConfiguration featureConfiguration = new FeatureConfiguration();
featureConfiguration.setValue(Feature.timeOut, 123L);

Long timeOut = featureConfiguration.getAsLong(Feature.timeOut);

assertThat(timeOut).isEqualTo(123L);
}
}

0 comments on commit 3314edf

Please sign in to comment.