|
1 | 1 | # ----------------------------------------------------------------------------- |
2 | | -# Copyright (c) 2020, 2023, Oracle and/or its affiliates. |
| 2 | +# Copyright (c) 2020, 2024, Oracle and/or its affiliates. |
3 | 3 | # |
4 | 4 | # This software is dual-licensed to you under the Universal Permissive License |
5 | 5 | # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License |
@@ -105,59 +105,6 @@ def _verify_open(self) -> None: |
105 | 105 | if self._impl is None: |
106 | 106 | errors._raise_err(errors.ERR_POOL_NOT_OPEN) |
107 | 107 |
|
108 | | - def acquire( |
109 | | - self, |
110 | | - user: str = None, |
111 | | - password: str = None, |
112 | | - cclass: str = None, |
113 | | - purity: int = oracledb.PURITY_DEFAULT, |
114 | | - tag: str = None, |
115 | | - matchanytag: bool = False, |
116 | | - shardingkey: list = None, |
117 | | - supershardingkey: list = None, |
118 | | - ) -> "connection_module.Connection": |
119 | | - """ |
120 | | - Acquire a connection from the pool and return it. |
121 | | -
|
122 | | - If the pool is homogeneous, the user and password parameters cannot be |
123 | | - specified. If they are, an exception will be raised. |
124 | | -
|
125 | | - The cclass parameter, if specified, should be a string corresponding to |
126 | | - the connection class for database resident connection pooling (DRCP). |
127 | | -
|
128 | | - The purity parameter is expected to be one of PURITY_DEFAULT, |
129 | | - PURITY_NEW, or PURITY_SELF. |
130 | | -
|
131 | | - The tag parameter, if specified, is expected to be a string with |
132 | | - name=value pairs like “k1=v1;k2=v2” and will limit the connections that |
133 | | - can be returned from a pool unless the matchanytag parameter is |
134 | | - set to True. In that case connections with the specified tag will be |
135 | | - preferred over others, but if no such connections are available a |
136 | | - connection with a different tag may be returned instead. In any case, |
137 | | - untagged connections will always be returned if no connections with the |
138 | | - specified tag are available. Connections are tagged when they are |
139 | | - released back to the pool. |
140 | | -
|
141 | | - The shardingkey and supershardingkey parameters, if specified, are |
142 | | - expected to be a sequence of values which will be used to identify the |
143 | | - database shard to connect to. The key values can be strings, numbers, |
144 | | - bytes or dates. |
145 | | - """ |
146 | | - self._verify_open() |
147 | | - |
148 | | - return self._connection_method( |
149 | | - conn_class=self._connection_type, |
150 | | - user=user, |
151 | | - password=password, |
152 | | - cclass=cclass, |
153 | | - purity=purity, |
154 | | - tag=tag, |
155 | | - matchanytag=matchanytag, |
156 | | - shardingkey=shardingkey, |
157 | | - supershardingkey=supershardingkey, |
158 | | - pool=self, |
159 | | - ) |
160 | | - |
161 | 108 | @property |
162 | 109 | def busy(self) -> int: |
163 | 110 | """ |
@@ -414,7 +361,59 @@ def _set_connection_type(self, conn_class): |
414 | 361 | ) or issubclass(conn_class, connection_module.AsyncConnection): |
415 | 362 | errors._raise_err(errors.ERR_INVALID_CONN_CLASS) |
416 | 363 | self._connection_type = conn_class |
417 | | - self._connection_method = oracledb.connect |
| 364 | + |
| 365 | + def acquire( |
| 366 | + self, |
| 367 | + user: str = None, |
| 368 | + password: str = None, |
| 369 | + cclass: str = None, |
| 370 | + purity: int = oracledb.PURITY_DEFAULT, |
| 371 | + tag: str = None, |
| 372 | + matchanytag: bool = False, |
| 373 | + shardingkey: list = None, |
| 374 | + supershardingkey: list = None, |
| 375 | + ) -> "connection_module.Connection": |
| 376 | + """ |
| 377 | + Acquire a connection from the pool and return it. |
| 378 | +
|
| 379 | + If the pool is homogeneous, the user and password parameters cannot be |
| 380 | + specified. If they are, an exception will be raised. |
| 381 | +
|
| 382 | + The cclass parameter, if specified, should be a string corresponding to |
| 383 | + the connection class for database resident connection pooling (DRCP). |
| 384 | +
|
| 385 | + The purity parameter is expected to be one of PURITY_DEFAULT, |
| 386 | + PURITY_NEW, or PURITY_SELF. |
| 387 | +
|
| 388 | + The tag parameter, if specified, is expected to be a string with |
| 389 | + name=value pairs like “k1=v1;k2=v2” and will limit the connections that |
| 390 | + can be returned from a pool unless the matchanytag parameter is |
| 391 | + set to True. In that case connections with the specified tag will be |
| 392 | + preferred over others, but if no such connections are available a |
| 393 | + connection with a different tag may be returned instead. In any case, |
| 394 | + untagged connections will always be returned if no connections with the |
| 395 | + specified tag are available. Connections are tagged when they are |
| 396 | + released back to the pool. |
| 397 | +
|
| 398 | + The shardingkey and supershardingkey parameters, if specified, are |
| 399 | + expected to be a sequence of values which will be used to identify the |
| 400 | + database shard to connect to. The key values can be strings, numbers, |
| 401 | + bytes or dates. |
| 402 | + """ |
| 403 | + self._verify_open() |
| 404 | + |
| 405 | + return oracledb.connect( |
| 406 | + conn_class=self._connection_type, |
| 407 | + user=user, |
| 408 | + password=password, |
| 409 | + cclass=cclass, |
| 410 | + purity=purity, |
| 411 | + tag=tag, |
| 412 | + matchanytag=matchanytag, |
| 413 | + shardingkey=shardingkey, |
| 414 | + supershardingkey=supershardingkey, |
| 415 | + pool=self, |
| 416 | + ) |
418 | 417 |
|
419 | 418 | def close(self, force: bool = False) -> None: |
420 | 419 | """ |
@@ -882,7 +881,59 @@ def _set_connection_type(self, conn_class): |
882 | 881 | elif not issubclass(conn_class, connection_module.AsyncConnection): |
883 | 882 | errors._raise_err(errors.ERR_INVALID_CONN_CLASS) |
884 | 883 | self._connection_type = conn_class |
885 | | - self._connection_method = oracledb.connect_async |
| 884 | + |
| 885 | + def acquire( |
| 886 | + self, |
| 887 | + user: str = None, |
| 888 | + password: str = None, |
| 889 | + cclass: str = None, |
| 890 | + purity: int = oracledb.PURITY_DEFAULT, |
| 891 | + tag: str = None, |
| 892 | + matchanytag: bool = False, |
| 893 | + shardingkey: list = None, |
| 894 | + supershardingkey: list = None, |
| 895 | + ) -> "connection_module.AsyncConnection": |
| 896 | + """ |
| 897 | + Acquire a connection from the pool and return it. |
| 898 | +
|
| 899 | + If the pool is homogeneous, the user and password parameters cannot be |
| 900 | + specified. If they are, an exception will be raised. |
| 901 | +
|
| 902 | + The cclass parameter, if specified, should be a string corresponding to |
| 903 | + the connection class for database resident connection pooling (DRCP). |
| 904 | +
|
| 905 | + The purity parameter is expected to be one of PURITY_DEFAULT, |
| 906 | + PURITY_NEW, or PURITY_SELF. |
| 907 | +
|
| 908 | + The tag parameter, if specified, is expected to be a string with |
| 909 | + name=value pairs like “k1=v1;k2=v2” and will limit the connections that |
| 910 | + can be returned from a pool unless the matchanytag parameter is |
| 911 | + set to True. In that case connections with the specified tag will be |
| 912 | + preferred over others, but if no such connections are available a |
| 913 | + connection with a different tag may be returned instead. In any case, |
| 914 | + untagged connections will always be returned if no connections with the |
| 915 | + specified tag are available. Connections are tagged when they are |
| 916 | + released back to the pool. |
| 917 | +
|
| 918 | + The shardingkey and supershardingkey parameters, if specified, are |
| 919 | + expected to be a sequence of values which will be used to identify the |
| 920 | + database shard to connect to. The key values can be strings, numbers, |
| 921 | + bytes or dates. |
| 922 | + """ |
| 923 | + self._verify_open() |
| 924 | + |
| 925 | + return oracledb.connect_async( |
| 926 | + conn_class=self._connection_type, |
| 927 | + user=user, |
| 928 | + password=password, |
| 929 | + cclass=cclass, |
| 930 | + purity=purity, |
| 931 | + tag=tag, |
| 932 | + matchanytag=matchanytag, |
| 933 | + shardingkey=shardingkey, |
| 934 | + supershardingkey=supershardingkey, |
| 935 | + pool=self, |
| 936 | + ) |
886 | 937 |
|
887 | 938 | async def close(self, force: bool = False) -> None: |
888 | 939 | """ |
|
0 commit comments