-
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.
* add sharding sphere data. * add sharding sphere data. * add sharding sphere data.
- Loading branch information
1 parent
7d39fa5
commit b2d38cc
Showing
58 changed files
with
588 additions
and
84 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
32 changes: 32 additions & 0 deletions
32
...ommon/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereData.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,32 @@ | ||
/* | ||
* 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.infra.metadata.data; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* ShardingSphere data. | ||
*/ | ||
@Getter | ||
public final class ShardingSphereData { | ||
|
||
private final Map<String, ShardingSphereDatabaseData> databaseData = new LinkedHashMap<>(); | ||
} |
32 changes: 32 additions & 0 deletions
32
...c/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereDatabaseData.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,32 @@ | ||
/* | ||
* 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.infra.metadata.data; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* ShardingSphere database data. | ||
*/ | ||
@Getter | ||
public final class ShardingSphereDatabaseData { | ||
|
||
private final Map<String, ShardingSphereSchemaData> schemaData = new LinkedHashMap<>(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...on/src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereRowData.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.infra.metadata.data; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* ShardingSphere row data. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class ShardingSphereRowData { | ||
|
||
private final List<Object> rows; | ||
} |
32 changes: 32 additions & 0 deletions
32
...src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereSchemaData.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,32 @@ | ||
/* | ||
* 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.infra.metadata.data; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* ShardingSphere schema data. | ||
*/ | ||
@Getter | ||
public final class ShardingSphereSchemaData { | ||
|
||
private final Map<String, ShardingSphereTableData> tableData = new LinkedHashMap<>(); | ||
} |
36 changes: 36 additions & 0 deletions
36
.../src/main/java/org/apache/shardingsphere/infra/metadata/data/ShardingSphereTableData.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,36 @@ | ||
/* | ||
* 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.infra.metadata.data; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* ShardingSphere table data. | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class ShardingSphereTableData { | ||
|
||
private final String name; | ||
|
||
private final List<ShardingSphereRowData> rows = new LinkedList<>(); | ||
} |
38 changes: 38 additions & 0 deletions
38
...java/org/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilder.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,38 @@ | ||
/* | ||
* 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.infra.metadata.data.builder; | ||
|
||
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; | ||
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; | ||
import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI; | ||
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI; | ||
|
||
/** | ||
* ShardingSphere data Builder. | ||
*/ | ||
@SingletonSPI | ||
public interface ShardingSphereDataBuilder extends TypedSPI { | ||
|
||
/** | ||
* Build ShardingSphere data. | ||
* | ||
* @param metaData meta data | ||
* @return ShardingSphere data | ||
*/ | ||
ShardingSphereData build(ShardingSphereMetaData metaData); | ||
} |
49 changes: 49 additions & 0 deletions
49
...g/apache/shardingsphere/infra/metadata/data/builder/ShardingSphereDataBuilderFactory.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,49 @@ | ||
/* | ||
* 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.infra.metadata.data.builder; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.shardingsphere.infra.database.type.DatabaseType; | ||
import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType; | ||
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader; | ||
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* ShardingSphere data builder factory. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class ShardingSphereDataBuilderFactory { | ||
|
||
static { | ||
ShardingSphereServiceLoader.register(ShardingSphereDataBuilder.class); | ||
} | ||
|
||
/** | ||
* Find instance of dialect ShardingSphere data builder. | ||
* | ||
* @param databaseType database type | ||
* @return found instance | ||
*/ | ||
public static Optional<ShardingSphereDataBuilder> getInstance(final DatabaseType databaseType) { | ||
String type = databaseType instanceof OpenGaussDatabaseType ? "PostgreSQL" : databaseType.getType(); | ||
return TypedSPIRegistry.findRegisteredService(ShardingSphereDataBuilder.class, type); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...he/shardingsphere/infra/metadata/data/builder/dialect/MySQLShardingSphereDataBuilder.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,61 @@ | ||
/* | ||
* 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.infra.metadata.data.builder.dialect; | ||
|
||
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; | ||
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereData; | ||
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereDatabaseData; | ||
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereSchemaData; | ||
import org.apache.shardingsphere.infra.metadata.data.ShardingSphereTableData; | ||
import org.apache.shardingsphere.infra.metadata.data.builder.ShardingSphereDataBuilder; | ||
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema; | ||
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* MySQL ShardingSphere data Builder. | ||
*/ | ||
|
||
public final class MySQLShardingSphereDataBuilder implements ShardingSphereDataBuilder { | ||
|
||
private static final String SHARDING_SPHERE = "shardingsphere"; | ||
|
||
@Override | ||
public ShardingSphereData build(final ShardingSphereMetaData metaData) { | ||
ShardingSphereData result = new ShardingSphereData(); | ||
Optional<ShardingSphereSchema> shardingSphereSchema = Optional.ofNullable(metaData.getDatabase(SHARDING_SPHERE)).map(database -> database.getSchema(SHARDING_SPHERE)); | ||
if (!shardingSphereSchema.isPresent()) { | ||
return result; | ||
} | ||
ShardingSphereSchemaData schemaData = new ShardingSphereSchemaData(); | ||
for (Map.Entry<String, ShardingSphereTable> entry : shardingSphereSchema.get().getTables().entrySet()) { | ||
schemaData.getTableData().put(entry.getKey(), new ShardingSphereTableData(entry.getValue().getName())); | ||
} | ||
ShardingSphereDatabaseData databaseData = new ShardingSphereDatabaseData(); | ||
databaseData.getSchemaData().put(SHARDING_SPHERE, schemaData); | ||
result.getDatabaseData().put(SHARDING_SPHERE, databaseData); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "MySQL"; | ||
} | ||
} |
Oops, something went wrong.