Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags and
* the COPYRIGHT.txt file distributed with this work.
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teiid.infinispan.api;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import org.infinispan.commons.api.BasicCache;
import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.language.SQLConstants.Tokens;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.BaseColumn.NullType;
import org.teiid.metadata.Column;
import org.teiid.metadata.Column.SearchType;
import org.teiid.metadata.ExtensionMetadataProperty;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.Table;
import org.teiid.translator.MetadataProcessor;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.TranslatorProperty.PropertyType;
import com.squareup.protoparser.DataType;
import com.squareup.protoparser.EnumConstantElement;
import com.squareup.protoparser.EnumElement;
import com.squareup.protoparser.FieldElement;
import com.squareup.protoparser.FieldElement.Label;
import com.squareup.protoparser.MessageElement;
import com.squareup.protoparser.ProtoFile;
import com.squareup.protoparser.ProtoParser;
import com.squareup.protoparser.TypeElement;
public class ProtobufMetadataProcessor implements MetadataProcessor {
//private static final String WRAPPING_DEFINITIONS_RES = "/org/infinispan/protostream/message-wrapping.proto";
@ExtensionMetadataProperty(applicable=Table.class,
datatype=String.class,
display="Merge Into Table",
description="Declare the name of parent table that this table needs to be merged into.")
public static final String MERGE = MetadataFactory.INFINISPAN_PREFIX+"MERGE"; //$NON-NLS-1$
@ExtensionMetadataProperty(applicable=Table.class,
datatype=String.class,
display="Cache Name",
description="Cache name to store the contents into")
public static final String CACHE = MetadataFactory.INFINISPAN_PREFIX+"CACHE"; //$NON-NLS-1$
@ExtensionMetadataProperty(applicable= {Table.class,Column.class},
datatype=String.class,
display="Message Name",
description="Message name this table or column represents")
public static final String MESSAGE_NAME = MetadataFactory.INFINISPAN_PREFIX+"MESSAGE_NAME"; //$NON-NLS-1$
@ExtensionMetadataProperty(applicable= Column.class,
datatype=String.class,
display="Protobuf Tag Number",
description="Protobuf field tag number")
public static final String TAG = MetadataFactory.INFINISPAN_PREFIX+"TAG"; //$NON-NLS-1$
@ExtensionMetadataProperty(applicable = {Table.class, Column.class},
datatype=String.class,
display="Protobuf Parent Tag Number",
description="Protobuf field parent tag number in the case of complex document")
public static final String PARENT_TAG = MetadataFactory.INFINISPAN_PREFIX+"PARENT_TAG"; //$NON-NLS-1$
@ExtensionMetadataProperty(applicable= {Table.class, Column.class},
datatype=String.class,
display="column's parent column name",
description="Protobuf field parent column name in the case of complex document")
public static final String PARENT_COLUMN_NAME = MetadataFactory.INFINISPAN_PREFIX+"PARENT_COLUMN_NAME"; //$NON-NLS-1$
@ExtensionMetadataProperty(applicable=Column.class,
datatype=String.class,
display="Pseudo Column",
description="Pseudo column for join purposes")
public static final String PSEUDO = MetadataFactory.INFINISPAN_PREFIX+"PSEUDO"; //$NON-NLS-1$
private String protoFilePath;
private ProtobufResource protoResource;
private String protobufName;
@TranslatorProperty(display="Protobuf file path", category=PropertyType.IMPORT,
description="Protobuf file path to load as the schema of this model")
public String getProtoFilePath() {
return protoFilePath;
}
public void setProtoFilePath(String path) {
this.protoFilePath = path;
}
@TranslatorProperty(display="Protobuf Name", category=PropertyType.IMPORT,
description="When loading the Protobuf contents from Infinispan, limit the import to this given protobuf name")
public String getProtobufName() {
return protobufName;
}
public void setProtobufName(String name) {
this.protobufName = name;
}
@Override
public void process(MetadataFactory metadataFactory, InfinispanConnection connection)
throws TranslatorException {
String protobufFile = getProtoFilePath();
String cacheName = null;
if (connection != null) {
cacheName = connection.getCache().getName();
}
String protoContents = null;
if( protobufFile != null && !protobufFile.isEmpty()) {
File f = new File(protobufFile);
if(f.exists() && f.isFile()) {
try {
protoContents = ObjectConverterUtil.convertFileToString(f);
} catch (IOException e) {
throw new TranslatorException(e);
}
} else {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(protobufFile);
if (in != null) {
try {
protoContents = ObjectConverterUtil.convertToString(in);
} catch (IOException e) {
throw new TranslatorException(e);
}
} else {
throw new TranslatorException(InfinispanPlugin.Event.TEIID25000,
InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25000, protobufFile));
}
}
this.protoResource = new ProtobufResource(this.protobufName != null ? this.protobufName : protobufFile,
protoContents);
toTeiidSchema(protobufFile, protoContents, metadataFactory, cacheName);
} else if( this.protobufName != null) {
// Read from cache
boolean added = false;
BasicCache