diff options
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java')
-rw-r--r-- | openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java index 64c595caa5..71cce34fe4 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportSingleTable.java @@ -7,9 +7,9 @@ * Licensed 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.core.tools.importinfo; import static org.openecomp.core.tools.exportinfo.ExportDataCommand.NULL_REPRESENTATION; @@ -26,11 +25,21 @@ import com.datastax.driver.core.BoundStatement; import com.datastax.driver.core.DataType.Name; import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.Session; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Sets; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.Path; +import java.util.Base64; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; -import com.fasterxml.jackson.databind.ObjectMapper; import org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory; import org.openecomp.core.tools.exportinfo.ExportDataCommand; import org.openecomp.core.tools.model.ColumnDefinition; @@ -39,21 +48,22 @@ import org.openecomp.core.tools.util.Utils; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.file.Path; -import java.util.*; -import java.util.stream.Collectors; - public class ImportSingleTable { + public static final ImmutableMap<String, Name> dataTypesMap; private static final Logger logger = LoggerFactory.getLogger(ImportSingleTable.class); - private static final String INSERT_INTO = "INSERT INTO "; private static final String VALUES = " VALUES "; private static final Map<String, PreparedStatement> statementsCache = new HashMap<>(); - - public static final ImmutableMap<String, Name> dataTypesMap; + + static { + Builder<String, Name> builder = ImmutableMap.builder(); + Name[] values = Name.values(); + for (Name name : values) { + builder.put(name.name().toLowerCase(), name); + } + dataTypesMap = builder.build(); + } public void importFile(Path file) { try { @@ -65,7 +75,6 @@ public class ImportSingleTable { } catch (IOException e) { Utils.logError(logger, e); } - } private PreparedStatement getPrepareStatement(TableData tableData, Session session) { @@ -101,7 +110,7 @@ public class ImportSingleTable { bind.setBytes(i, ByteBuffer.wrap(Base64.getDecoder().decode(rowData.getBytes()))); break; case TIMESTAMP: - if (StringUtils.isEmpty(rowData)){ + if (StringUtils.isEmpty(rowData)) { bind.setTimestamp(i, null); } else { bind.setTimestamp(i, new Date(Long.parseLong(rowData))); @@ -148,7 +157,6 @@ public class ImportSingleTable { break; default: throw new UnsupportedOperationException("Name is not supported :" + name); - } } @@ -156,21 +164,9 @@ public class ImportSingleTable { ColumnDefinition def = tableData.getDefinitions().iterator().next(); StringBuilder sb = new StringBuilder(1024); sb.append(INSERT_INTO).append(def.getKeyspace()).append(".").append(def.getTable()); - sb.append(tableData.getDefinitions().stream().map(ColumnDefinition::getName) - .collect(Collectors.joining(" , ", " ( ", " ) "))); - sb.append(VALUES).append(tableData.getDefinitions().stream().map(definition -> "?") - .collect(Collectors.joining(" , ", " ( ", " ) "))).append(";"); + sb.append(tableData.getDefinitions().stream().map(ColumnDefinition::getName).collect(Collectors.joining(" , ", " ( ", " ) "))); + sb.append(VALUES).append(tableData.getDefinitions().stream().map(definition -> "?").collect(Collectors.joining(" , ", " ( ", " ) "))) + .append(";"); return sb.toString(); } - - - static { - Builder<String, Name> builder = ImmutableMap.builder(); - Name[] values = Name.values(); - for (Name name : values) { - builder.put(name.name().toLowerCase(), name); - } - dataTypesMap = builder.build(); - } - } |