Github user lewismc commented on a diff in the pull request: https://github.com/apache/gora/pull/134#discussion_r202526769 --- Diff: gora-ignite/src/main/java/org/apache/gora/ignite/store/IgniteMappingBuilder.java --- @@ -0,0 +1,109 @@ +/** + * 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.gora.ignite.store; + +import com.google.inject.ConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.gora.persistency.impl.PersistentBase; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Builder for Mapping definitions of Ignite. + */ +public class IgniteMappingBuilder<K, T extends PersistentBase> { + + private static final Logger LOG = LoggerFactory.getLogger(IgniteMappingBuilder.class); + /** + * Mapping instance being built + */ + private IgniteMapping igniteMapping; + + private final IgniteStore<K, T> dataStore; + + public IgniteMappingBuilder(final IgniteStore<K, T> store) { + this.igniteMapping = new IgniteMapping(); + this.dataStore = store; + } + + public IgniteMapping getIgniteMapping() { + return igniteMapping; + } + + public void setIgniteMapping(IgniteMapping igniteMapping) { + this.igniteMapping = igniteMapping; + } + + public void readMappingFile(String mappingFile) { + try { + SAXBuilder saxBuilder = new SAXBuilder(); + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mappingFile); + if (inputStream == null) { + LOG.error("Mapping file '{}' could not be found!", mappingFile); + throw new IOException("Mapping file '" + mappingFile + "' could not be found!"); + } + Document document = saxBuilder.build(inputStream); + if (document == null) { + LOG.error("Mapping file '{}' could not be found!", mappingFile); + throw new IOException("Mapping file '" + mappingFile + "' could not be found!"); + } + List<Element> classes = document.getRootElement().getChildren("class"); + for (Element classElement : classes) { + if (classElement.getAttributeValue("keyClass").equals( + dataStore.getKeyClass().getCanonicalName()) + && classElement.getAttributeValue("name").equals( + dataStore.getPersistentClass().getCanonicalName())) { + final String tableNameFromMapping = classElement.getAttributeValue("table"); + String tableName = dataStore.getSchemaName(tableNameFromMapping, dataStore.getPersistentClass()); + igniteMapping.setTableName(tableName); + List<Element> prColumns = classElement.getChildren("primarykey"); --- End diff -- Type safety: The expression of type List needs unchecked conversion to conform to List < Element >
---