|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.shardingsphere.data.pipeline.mysql.ingest.dumper.type.number; |
| 19 | + |
| 20 | +import lombok.NoArgsConstructor; |
| 21 | +import org.apache.shardingsphere.data.pipeline.core.metadata.model.PipelineColumnMetaData; |
| 22 | +import org.apache.shardingsphere.data.pipeline.mysql.ingest.dumper.type.number.impl.MySQLBinlogUnsignedBigintHandler; |
| 23 | +import org.apache.shardingsphere.data.pipeline.mysql.ingest.dumper.type.number.impl.MySQLBinlogUnsignedIntHandler; |
| 24 | +import org.apache.shardingsphere.data.pipeline.mysql.ingest.dumper.type.number.impl.MySQLBinlogUnsignedMediumintHandler; |
| 25 | +import org.apache.shardingsphere.data.pipeline.mysql.ingest.dumper.type.number.impl.MySQLBinlogUnsignedSmallintHandler; |
| 26 | +import org.apache.shardingsphere.data.pipeline.mysql.ingest.dumper.type.number.impl.MySQLBinlogUnsignedTinyintHandler; |
| 27 | + |
| 28 | +import java.io.Serializable; |
| 29 | +import java.util.HashMap; |
| 30 | +import java.util.Map; |
| 31 | +import java.util.Optional; |
| 32 | + |
| 33 | +/** |
| 34 | + * MySQL binlog number data type handler engine. |
| 35 | + */ |
| 36 | +@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE) |
| 37 | +public final class MySQLBinlogNumberDataTypeHandlerEngine { |
| 38 | + |
| 39 | + private static final Map<String, MySQLBinlogNumberDataTypeHandler> HANDLERS = new HashMap<>(); |
| 40 | + |
| 41 | + static { |
| 42 | + HANDLERS.put("TINYINT UNSIGNED", new MySQLBinlogUnsignedTinyintHandler()); |
| 43 | + HANDLERS.put("SMALLINT UNSIGNED", new MySQLBinlogUnsignedSmallintHandler()); |
| 44 | + HANDLERS.put("MEDIUMINT UNSIGNED", new MySQLBinlogUnsignedMediumintHandler()); |
| 45 | + HANDLERS.put("INT UNSIGNED", new MySQLBinlogUnsignedIntHandler()); |
| 46 | + HANDLERS.put("BIGINT UNSIGNED", new MySQLBinlogUnsignedBigintHandler()); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Handle column value. |
| 51 | + * |
| 52 | + * @param columnMetaData column meta data |
| 53 | + * @param value column value |
| 54 | + * @return handled column value |
| 55 | + */ |
| 56 | + public static Optional<Serializable> handle(final PipelineColumnMetaData columnMetaData, final Serializable value) { |
| 57 | + String dataTypeName = columnMetaData.getDataTypeName(); |
| 58 | + return HANDLERS.containsKey(dataTypeName) ? Optional.of(HANDLERS.get(dataTypeName).handle(value)) : Optional.empty(); |
| 59 | + } |
| 60 | +} |
0 commit comments