Skip to content

Commit

Permalink
Add DatabaseRuleConfigurationEmptyChecker to make config api clean (#…
Browse files Browse the repository at this point in the history
…33666)

* Add DatabaseRuleConfigurationEmptyChecker to make config api clean

* Add DatabaseRuleConfigurationEmptyChecker to make config api clean
  • Loading branch information
terrymanu authored Nov 14, 2024
1 parent d7c5574 commit e9a9afb
Show file tree
Hide file tree
Showing 35 changed files with 661 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@
public final class BroadcastRuleConfiguration implements DatabaseRuleConfiguration, DistributedRuleConfiguration {

private final Collection<String> tables;

@Override
public boolean isEmpty() {
return tables.isEmpty();
}
}
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.broadcast.checker;

import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;

/**
* Broadcast rule configuration empty checker.
*/
public final class BroadcastRuleConfigurationEmptyChecker implements DatabaseRuleConfigurationEmptyChecker<BroadcastRuleConfiguration> {

@Override
public boolean isEmpty(final BroadcastRuleConfiguration ruleConfig) {
return ruleConfig.getTables().isEmpty();
}

@Override
public Class<BroadcastRuleConfiguration> getType() {
return BroadcastRuleConfiguration.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.shardingsphere.broadcast.checker.BroadcastRuleConfigurationEmptyChecker
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@
* limitations under the License.
*/

package org.apache.shardingsphere.encrypt.config;
package org.apache.shardingsphere.broadcast.checker;

import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertTrue;

class EncryptRuleConfigurationTest {
class BroadcastRuleConfigurationEmptyCheckerTest {

private BroadcastRuleConfigurationEmptyChecker checker;

@BeforeEach
void setUp() {
checker = (BroadcastRuleConfigurationEmptyChecker) TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class, BroadcastRuleConfiguration.class);
}

@Test
void assertIsEmpty() {
assertTrue(new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap()).isEmpty());
assertTrue(checker.isEmpty(new BroadcastRuleConfiguration(Collections.emptyList())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@ public final class EncryptRuleConfiguration implements DatabaseRuleConfiguration
private final Collection<EncryptTableRuleConfiguration> tables;

private final Map<String, AlgorithmConfiguration> encryptors;

@Override
public boolean isEmpty() {
return tables.isEmpty();
}
}
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.encrypt.checker.config;

import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;

/**
* Encrypt rule configuration empty checker.
*/
public final class EncryptRuleConfigurationEmptyChecker implements DatabaseRuleConfigurationEmptyChecker<EncryptRuleConfiguration> {

@Override
public boolean isEmpty(final EncryptRuleConfiguration ruleConfig) {
return ruleConfig.getTables().isEmpty();
}

@Override
public Class<EncryptRuleConfiguration> getType() {
return EncryptRuleConfiguration.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.shardingsphere.encrypt.checker.config.EncryptRuleConfigurationEmptyChecker
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@
* limitations under the License.
*/

package org.apache.shardingsphere.readwritesplitting.config;
package org.apache.shardingsphere.encrypt.checker.config;

import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertTrue;

class ReadwriteSplittingRuleConfigurationTest {
class EncryptRuleConfigurationEmptyCheckerTest {

private EncryptRuleConfigurationEmptyChecker checker;

@BeforeEach
void setUp() {
checker = (EncryptRuleConfigurationEmptyChecker) TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class, EncryptRuleConfiguration.class);
}

@Test
void assertIsEmpty() {
assertTrue(new ReadwriteSplittingRuleConfiguration(Collections.emptyList(), Collections.emptyMap()).isEmpty());
assertTrue(checker.isEmpty(new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@ public final class MaskRuleConfiguration implements DatabaseRuleConfiguration, E
private final Collection<MaskTableRuleConfiguration> tables;

private final Map<String, AlgorithmConfiguration> maskAlgorithms;

@Override
public boolean isEmpty() {
return tables.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
* limitations under the License.
*/

package org.apache.shardingsphere.mask.config;
package org.apache.shardingsphere.mask.checker;

import org.junit.jupiter.api.Test;
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.mask.config.MaskRuleConfiguration;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertTrue;

class MaskRuleConfigurationTest {
/**
* Mask rule configuration empty checker.
*/
public final class MaskRuleConfigurationEmptyChecker implements DatabaseRuleConfigurationEmptyChecker<MaskRuleConfiguration> {

@Override
public boolean isEmpty(final MaskRuleConfiguration ruleConfig) {
return ruleConfig.getTables().isEmpty();
}

@Test
void assertIsEmpty() {
assertTrue(new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap()).isEmpty());
@Override
public Class<MaskRuleConfiguration> getType() {
return MaskRuleConfiguration.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.shardingsphere.mask.checker.MaskRuleConfigurationEmptyChecker
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@
* limitations under the License.
*/

package org.apache.shardingsphere.broadcast.config;
package org.apache.shardingsphere.mask.checker;

import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mask.config.MaskRuleConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertTrue;

class BroadcastRuleConfigurationTest {
class MaskRuleConfigurationEmptyCheckerTest {

private MaskRuleConfigurationEmptyChecker checker;

@BeforeEach
void setUp() {
checker = (MaskRuleConfigurationEmptyChecker) TypedSPILoader.getService(DatabaseRuleConfigurationEmptyChecker.class, MaskRuleConfiguration.class);
}

@Test
void assertIsEmpty() {
assertTrue(new BroadcastRuleConfiguration(Collections.emptyList()).isEmpty());
assertTrue(checker.isEmpty(new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@ public final class ReadwriteSplittingRuleConfiguration implements DatabaseRuleCo
private final Collection<ReadwriteSplittingDataSourceGroupRuleConfiguration> dataSourceGroups;

private final Map<String, AlgorithmConfiguration> loadBalancers;

@Override
public boolean isEmpty() {
return dataSourceGroups.isEmpty();
}
}
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.readwritesplitting.checker;

import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfigurationEmptyChecker;
import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;

/**
* Readwrite-splitting rule configuration empty checker.
*/
public final class ReadwriteSplittingRuleConfigurationEmptyChecker implements DatabaseRuleConfigurationEmptyChecker<ReadwriteSplittingRuleConfiguration> {

@Override
public boolean isEmpty(final ReadwriteSplittingRuleConfiguration ruleConfig) {
return ruleConfig.getDataSourceGroups().isEmpty();
}

@Override
public Class<ReadwriteSplittingRuleConfiguration> getType() {
return ReadwriteSplittingRuleConfiguration.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# 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.
#

org.apache.shardingsphere.readwritesplitting.checker.ReadwriteSplittingRuleConfigurationEmptyChecker
Loading

0 comments on commit e9a9afb

Please sign in to comment.