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

Fix #1758: Use long for Feature.timeOut #1759

Merged
merged 2 commits into from
Apr 27, 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 @@ -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);
}
}