Skip to content

Commit 3314edf

Browse files
zazawumpz
andauthored
Fix #1758: Use long for Feature.timeOut (#1759)
Co-authored-by: Tobias <t.warneke@gmx.net>
1 parent 1bbb144 commit 3314edf

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

src/main/java/net/sf/jsqlparser/parser/AbstractJSqlParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public P withUnsupportedStatements(boolean allowUnsupportedStatements) {
3333
return withFeature(Feature.allowUnsupportedStatements, allowUnsupportedStatements);
3434
}
3535

36-
public P withTimeOut(int timeOutMillSeconds) {
36+
public P withTimeOut(long timeOutMillSeconds) {
3737
return withFeature(Feature.timeOut, timeOutMillSeconds);
3838
}
3939

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

49-
public P withFeature(Feature f, int value) {
49+
public P withFeature(Feature f, long value) {
5050
getConfiguration().setValue(f, value);
5151
return me();
5252
}
@@ -59,8 +59,8 @@ public boolean getAsBoolean(Feature f) {
5959
return getConfiguration().getAsBoolean(f);
6060
}
6161

62-
public Integer getAsInteger(Feature f) {
63-
return getConfiguration().getAsInteger(f);
62+
public Long getAsLong(Feature f) {
63+
return getConfiguration().getAsLong(f);
6464
}
6565

6666
public void setErrorRecovery(boolean errorRecovery) {

src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ public Statement call() throws Exception {
268268
});
269269
executorService.shutdown();
270270

271-
statement = future.get(parser.getConfiguration().getAsInteger(Feature.timeOut),
272-
TimeUnit.MILLISECONDS);
271+
statement = future.get( parser.getConfiguration().getAsLong(Feature.timeOut), TimeUnit.MILLISECONDS);
272+
273273
} catch (TimeoutException ex) {
274274
parser.interrupted = true;
275275
throw new JSQLParserException("Time out occurred.", ex);
@@ -335,8 +335,8 @@ public Statements call() throws Exception {
335335
});
336336
executorService.shutdown();
337337

338-
statements = future.get(parser.getConfiguration().getAsInteger(Feature.timeOut),
339-
TimeUnit.MILLISECONDS);
338+
statements = future.get( parser.getConfiguration().getAsLong(Feature.timeOut) , TimeUnit.MILLISECONDS);
339+
340340
} catch (TimeoutException ex) {
341341
parser.interrupted = true;
342342
throw new JSQLParserException("Time out occurred.", ex);

src/main/java/net/sf/jsqlparser/parser/feature/FeatureConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public boolean getAsBoolean(Feature f) {
6161
return Boolean.parseBoolean(String.valueOf(getValue(f)));
6262
}
6363

64-
public Integer getAsInteger(Feature f) {
65-
return Integer.valueOf(String.valueOf(getValue(f)));
64+
public Long getAsLong(Feature f) {
65+
return Long.valueOf(String.valueOf(getValue(f)));
6666
}
6767

6868
public String getAsString(Feature f) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.sf.jsqlparser.parser;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import net.sf.jsqlparser.parser.feature.Feature;
8+
9+
public class CCJSqlParserTest {
10+
@Test
11+
public void parserWithTimeout() throws Exception {
12+
CCJSqlParser parser = CCJSqlParserUtil.newParser("foo").withTimeOut(123L);
13+
14+
Long timeOut = parser.getAsLong(Feature.timeOut);
15+
16+
assertThat(timeOut).isEqualTo(123L);
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.sf.jsqlparser.parser.feature;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class FeatureConfigurationTest {
8+
@Test
9+
public void getAsLong() {
10+
FeatureConfiguration featureConfiguration = new FeatureConfiguration();
11+
featureConfiguration.setValue(Feature.timeOut, 123L);
12+
13+
Long timeOut = featureConfiguration.getAsLong(Feature.timeOut);
14+
15+
assertThat(timeOut).isEqualTo(123L);
16+
}
17+
}

0 commit comments

Comments
 (0)