-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from apache/dev
local merge
- Loading branch information
Showing
613 changed files
with
6,674 additions
and
4,317 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
...e/sharding-core-api/src/main/java/org/apache/shardingsphere/spi/DatabaseTypeAwareSPI.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,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.spi; | ||
|
||
/** | ||
* Database type aware SPI. | ||
* | ||
* @author zhangliang | ||
*/ | ||
public interface DatabaseTypeAwareSPI { | ||
|
||
/** | ||
* Get database type. | ||
* | ||
* <p> | ||
* The value of database type must registered by SPI for {@code org.apache.shardingsphere.spi.database.DatabaseType}. | ||
* </p> | ||
* | ||
* @return database type | ||
*/ | ||
String getDatabaseType(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ing-core-api/src/main/java/org/apache/shardingsphere/spi/database/BranchDatabaseType.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,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.spi.database; | ||
|
||
/** | ||
* Branch database type. | ||
* | ||
* @author zhangliang | ||
*/ | ||
public interface BranchDatabaseType extends DatabaseType { | ||
|
||
/** | ||
* Get trunk database type. | ||
* | ||
* @return trunk database type | ||
*/ | ||
DatabaseType getTrunkDatabaseType(); | ||
} |
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
50 changes: 50 additions & 0 deletions
50
.../sharding-core-api/src/main/java/org/apache/shardingsphere/spi/database/DatabaseType.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,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.spi.database; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Database type. | ||
* | ||
* @author zhangliang | ||
*/ | ||
public interface DatabaseType { | ||
|
||
/** | ||
* Get database name. | ||
* | ||
* @return database name | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Get alias of JDBC URL prefixes. | ||
* | ||
* @return Alias of JDBC URL prefixes | ||
*/ | ||
Collection<String> getJdbcUrlPrefixAlias(); | ||
|
||
/** | ||
* Get data source meta data. | ||
* | ||
* @param url data source URL | ||
* @return data source meta data | ||
*/ | ||
DataSourceMetaData getDataSourceMetaData(String url); | ||
} |
26 changes: 26 additions & 0 deletions
26
...api/src/main/java/org/apache/shardingsphere/spi/database/MemorizedDataSourceMetaData.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,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.spi.database; | ||
|
||
/** | ||
* Memorized data source meta data. | ||
* | ||
* @author zhangliang | ||
*/ | ||
public interface MemorizedDataSourceMetaData extends DataSourceMetaData { | ||
} |
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
60 changes: 0 additions & 60 deletions
60
...rding-core-common/src/main/java/org/apache/shardingsphere/core/constant/DatabaseType.java
This file was deleted.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
...ding-core-common/src/main/java/org/apache/shardingsphere/core/database/DatabaseTypes.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,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.core.database; | ||
|
||
import org.apache.shardingsphere.spi.database.BranchDatabaseType; | ||
import org.apache.shardingsphere.spi.database.DatabaseType; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* Database types. | ||
* | ||
* @author zhangliang | ||
*/ | ||
public final class DatabaseTypes { | ||
|
||
private static final Map<String, DatabaseType> DATABASE_TYPES = new HashMap<>(); | ||
|
||
static { | ||
for (DatabaseType each : ServiceLoader.load(DatabaseType.class)) { | ||
DATABASE_TYPES.put(each.getName(), each); | ||
} | ||
} | ||
|
||
/** | ||
* Get database types. | ||
* | ||
* @return database types | ||
*/ | ||
public static Collection<DatabaseType> getDatabaseTypes() { | ||
return DATABASE_TYPES.values(); | ||
} | ||
|
||
/** | ||
* Get actual database type. | ||
* | ||
* @param name database name | ||
* @return actual database type | ||
*/ | ||
public static DatabaseType getActualDatabaseType(final String name) { | ||
if (!DATABASE_TYPES.containsKey(name)) { | ||
throw new UnsupportedOperationException(String.format("Unsupported database: '%s'", name)); | ||
} | ||
return DATABASE_TYPES.get(name); | ||
} | ||
|
||
/** | ||
* Get trunk database type. | ||
* | ||
* @param name database name | ||
* @return trunk database type | ||
*/ | ||
public static DatabaseType getTrunkDatabaseType(final String name) { | ||
return DATABASE_TYPES.get(name) instanceof BranchDatabaseType ? ((BranchDatabaseType) DATABASE_TYPES.get(name)).getTrunkDatabaseType() : getActualDatabaseType(name); | ||
} | ||
|
||
/** | ||
* Get database type by URL. | ||
* | ||
* @param url database URL | ||
* @return database type | ||
*/ | ||
public static DatabaseType getDatabaseTypeByURL(final String url) { | ||
for (DatabaseType each : DATABASE_TYPES.values()) { | ||
if (matchStandardURL(url, each) || matchURLAlias(url, each)) { | ||
return each; | ||
} | ||
} | ||
throw new UnsupportedOperationException(String.format("Unsupported database from url: '%s'", url)); | ||
} | ||
|
||
private static boolean matchStandardURL(final String url, final DatabaseType databaseType) { | ||
return url.startsWith(String.format("jdbc:%s:", databaseType.getName().toLowerCase())); | ||
} | ||
|
||
private static boolean matchURLAlias(final String url, final DatabaseType databaseType) { | ||
for (String each : databaseType.getJdbcUrlPrefixAlias()) { | ||
if (url.startsWith(each)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.