-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query compatibleMode, cluster, tenant by jdbc connection
- Loading branch information
Showing
10 changed files
with
252 additions
and
178 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...anbase-base/src/main/java/com/oceanbase/connector/flink/connection/OceanBaseUserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2024 OceanBase. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.oceanbase.connector.flink.connection; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.io.Serializable; | ||
|
||
public class OceanBaseUserInfo implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String cluster; | ||
private String tenant; | ||
private final String user; | ||
|
||
public OceanBaseUserInfo(String cluster, String tenant, String user) { | ||
this.cluster = cluster; | ||
this.tenant = tenant; | ||
this.user = user; | ||
} | ||
|
||
public String getCluster() { | ||
return cluster; | ||
} | ||
|
||
public String getTenant() { | ||
return tenant; | ||
} | ||
|
||
public String getUser() { | ||
return user; | ||
} | ||
|
||
public void setCluster(@Nonnull String cluster) { | ||
this.cluster = cluster; | ||
} | ||
|
||
public void setTenant(@Nonnull String tenant) { | ||
this.tenant = tenant; | ||
} | ||
|
||
public static OceanBaseUserInfo parse(String username) { | ||
final String sepUserAtTenant = "@"; | ||
final String sepTenantAtCluster = "#"; | ||
final String sep = ":"; | ||
final int expectedSepCount = 2; | ||
if (username.contains(sepTenantAtCluster) && username.contains(sepUserAtTenant)) { | ||
String[] parts = username.split(sepTenantAtCluster); | ||
String[] userAndTenant = parts[0].split(sepUserAtTenant); | ||
return new OceanBaseUserInfo(parts[1], userAndTenant[1], userAndTenant[0]); | ||
} else if (StringUtils.countMatches(username, sep) == expectedSepCount) { | ||
String[] parts = username.split(sep); | ||
return new OceanBaseUserInfo(parts[0], parts[1], parts[2]); | ||
} else if (username.contains(sepUserAtTenant) && !username.contains(sepTenantAtCluster)) { | ||
String[] parts = username.split(sepUserAtTenant); | ||
return new OceanBaseUserInfo(null, parts[1], parts[0]); | ||
} else { | ||
return new OceanBaseUserInfo(null, null, username); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.