-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use OceanBaseConnectionInfo to maintain server information (#20)
* add OceanBaseConnectionInfo * fix typo
- Loading branch information
Showing
9 changed files
with
256 additions
and
122 deletions.
There are no files selected for viewing
34 changes: 0 additions & 34 deletions
34
...nbase/src/main/java/com/oceanbase/connector/flink/connection/OceanBaseCompatibleMode.java
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
...nbase/src/main/java/com/oceanbase/connector/flink/connection/OceanBaseConnectionInfo.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,109 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase | ||
* flink-connector-oceanbase is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http:https://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
package com.oceanbase.connector.flink.connection; | ||
|
||
import com.oceanbase.connector.flink.dialect.OceanBaseDialect; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.Serializable; | ||
|
||
public class OceanBaseConnectionInfo implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public enum CompatibleMode { | ||
MYSQL, | ||
ORACLE; | ||
|
||
public static CompatibleMode fromString(String text) { | ||
if (StringUtils.isBlank(text)) { | ||
throw new IllegalArgumentException("Compatible mode should not be blank"); | ||
} | ||
switch (text.trim().toUpperCase()) { | ||
case "MYSQL": | ||
return MYSQL; | ||
case "ORACLE": | ||
return ORACLE; | ||
default: | ||
throw new UnsupportedOperationException("Unsupported compatible mode: " + text); | ||
} | ||
} | ||
|
||
public boolean isMySqlMode() { | ||
return CompatibleMode.MYSQL.equals(this); | ||
} | ||
} | ||
|
||
public enum Version { | ||
LEGACY, | ||
V4; | ||
|
||
public static Version fromString(String text) { | ||
return (StringUtils.isBlank(text) || !text.startsWith("4.")) ? LEGACY : V4; | ||
} | ||
|
||
public boolean isV4() { | ||
return Version.V4.equals(this); | ||
} | ||
} | ||
|
||
private final String clusterName; | ||
private final String tenantName; | ||
private final OceanBaseDialect dialect; | ||
private final Version version; | ||
|
||
public OceanBaseConnectionInfo(String username, OceanBaseDialect dialect, Version version) { | ||
String clusterName = "", tenantName = "sys"; | ||
try { | ||
if (username.contains("@")) { | ||
int i = username.indexOf("@"); | ||
String s = username.substring(i + 1); | ||
String[] arr = s.split("#"); | ||
if (arr.length > 0) { | ||
tenantName = arr[0]; | ||
} | ||
if (arr.length > 1) { | ||
clusterName = arr[1]; | ||
} | ||
} else { | ||
String[] arr = username.split(":"); | ||
if (arr.length == 3) { | ||
clusterName = arr[0]; | ||
tenantName = arr[1]; | ||
} | ||
} | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Failed to parse username", e); | ||
} | ||
this.clusterName = clusterName; | ||
this.tenantName = tenantName; | ||
this.dialect = dialect; | ||
this.version = version; | ||
} | ||
|
||
public String getClusterName() { | ||
return clusterName; | ||
} | ||
|
||
public String getTenantName() { | ||
return tenantName; | ||
} | ||
|
||
public OceanBaseDialect getDialect() { | ||
return dialect; | ||
} | ||
|
||
public Version getVersion() { | ||
return version; | ||
} | ||
} |
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
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.