Skip to content

Commit 88f2a06

Browse files
SweetWuXiaoMeisebersole
authored andcommitted
HHH-19682 - Add Support for GaussDB Lock Timeout (lockwait_timeout)
1 parent 91c3c25 commit 88f2a06

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/lock/internal/GaussDBLockingSupport.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,32 @@ public Timeout getLockTimeout(Connection connection, SessionFactoryImplementor f
9494
return Timeouts.WAIT_FOREVER;
9595
}
9696
if ( value.endsWith( "min" ) ) {
97-
final int min = Integer.parseInt( value.substring( 0, value.length() - 3 ) );
98-
return Timeout.milliseconds( min * 60 * 1000 );
97+
final int minute = getTimeout( value, 3 );
98+
return Timeout.milliseconds( minute * 60 * 1000);
9999
}
100100
else if ( value.endsWith( "s" ) ) {
101-
final int second = Integer.parseInt( value.substring( 0, value.length() - 1 ) );
102-
return Timeout.seconds(second);
101+
final int seconds = getTimeout( value, 1 );
102+
return Timeout.seconds(seconds);
103103
}
104-
final int milliseconds = Integer.parseInt( value.substring( 0, value.length() - 2 ) );
104+
final int milliseconds = getTimeout( value, 2 );
105105
return Timeout.milliseconds(milliseconds);
106106
},
107107
connection,
108108
factory
109109
);
110110
}
111111

112+
private static int getTimeout(String value, int unitLength) {
113+
final int number;
114+
try {
115+
number = Integer.parseInt( value.substring( 0, value.length() - unitLength ) );
116+
}
117+
catch (NumberFormatException e) {
118+
throw new RuntimeException( e );
119+
}
120+
return number;
121+
}
122+
112123
@Override
113124
public void setLockTimeout(Timeout timeout, Connection connection, SessionFactoryImplementor factory) {
114125
Helper.setLockTimeout(

0 commit comments

Comments
 (0)