33import com .xxdb .data .BasicInt ;
44import org .slf4j .Logger ;
55import org .slf4j .LoggerFactory ;
6+
7+ import java .io .IOException ;
68import java .util .ArrayList ;
79import java .util .Objects ;
810import java .util .concurrent .CopyOnWriteArrayList ;
@@ -95,7 +97,9 @@ protected class SimpleDBConnectionPoolImpl {
9597 try {
9698 for (int i = 0 ; i < initialPoolSize ; i ++) {
9799 PoolEntry poolEntry = new PoolEntry (useSSL , compress , usePython , String .format ("DolphinDBConnection_%d" , i + 1 ));
98- if (!poolEntry .connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , loadBalance )) {
100+ if (poolEntry .connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , loadBalance )) {
101+ poolEntry .isFirstLogin .set (false );
102+ }else {
99103 log .error (String .format ("Connection %s connect failure." , poolEntry .connectionName ));
100104 }
101105 poolEntryArrayList .add (poolEntry );
@@ -156,6 +160,8 @@ boolean isClosed() {
156160
157161 class PoolEntry extends DBConnection {
158162 AtomicBoolean inUse = new AtomicBoolean (false );
163+ AtomicBoolean isFirstConnect = new AtomicBoolean (true );
164+ AtomicBoolean isFirstLogin = new AtomicBoolean (true );
159165 String connectionName ;
160166
161167 PoolEntry (boolean useSSL , boolean compress , boolean usePython , String connectionName ) {
@@ -171,6 +177,27 @@ boolean isIdle() {
171177 return !this .inUse .get ();
172178 }
173179
180+ @ Override
181+ public void setLoadBalance (boolean loadBalance ) {
182+ throw new RuntimeException ("The loadBalance configuration of connection in connection pool can only be set in SimpleDBConnectionPoolConfig." );
183+ }
184+
185+ @ Override
186+ public boolean connect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance ) throws IOException {
187+ if (isFirstConnect .compareAndSet (true , false ))
188+ return super .connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , enableLoadBalance );
189+ else
190+ throw new RuntimeException ("The connection in connection pool can only connect by pool." );
191+ }
192+
193+ @ Override
194+ public void login (String userId , String password , boolean enableEncryption ) throws IOException {
195+ if (isFirstLogin .get ())
196+ super .login (userId , password , enableEncryption );
197+ else
198+ throw new RuntimeException ("The connection in connection pool can only login by pool." );
199+ }
200+
174201 @ Override
175202 public void close () {
176203 if (isBusy ())
0 commit comments