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.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.infinispan.protostream.ImmutableSerializationContext;
import org.infinispan.protostream.RawProtoStreamReader;
import org.infinispan.protostream.RawProtoStreamWriter;
import org.infinispan.protostream.RawProtobufMarshaller;
import org.infinispan.protostream.impl.ByteArrayOutputStreamEx;
import org.infinispan.protostream.impl.RawProtoStreamWriterImpl;
import org.teiid.translator.document.Document;
public class TeiidTableMarshaller implements RawProtobufMarshaller, Serializable {
private static final long serialVersionUID = 6540991524742624955L;
private String documentName;
private TreeMap wireMap = new TreeMap<>();
public TeiidTableMarshaller(String docName, TreeMap wireMap) {
this.documentName= docName;
this.wireMap = wireMap;
}
@Override
public String getTypeName() {
return this.documentName;
}
// Read from ISPN Types >> Teiid Types
@Override
public InfinispanDocument readFrom(ImmutableSerializationContext ctx, RawProtoStreamReader in) throws IOException {
InfinispanDocument row = new InfinispanDocument(this.documentName, this.wireMap, null);
readDocument(in, row, this.wireMap);
return row;
}
// Write from Teiid Types >> ISPN Types
@Override
public void writeTo(ImmutableSerializationContext ctx, RawProtoStreamWriter out, InfinispanDocument document)
throws IOException {
TreeMap wireMap = document.getWireMap();
for (Entry entry : wireMap.entrySet()) {
TableWireFormat twf = entry.getValue();
if (twf == null) {
throw new IOException("Error in wireformat");
}
int tag = twf.getWriteTag();
if (twf.isNested()) {
List extends Document> children = document.getChildDocuments(twf.getAttributeName());
if (children != null) {
for (Document d : children) {
ByteArrayOutputStreamEx baos = new ByteArrayOutputStreamEx();
RawProtoStreamWriter rpsw = RawProtoStreamWriterImpl.newInstance(baos);
writeTo(ctx, rpsw, (InfinispanDocument)d);
rpsw.flush();
baos.flush();
// here readtag because this is inner object, even other one uses write tag but calculated
// based on the write operation used.
out.writeBytes(tag, baos.getByteBuffer());
}
}
continue;
}
Object value = document.getProperties().get(twf.getAttributeName());
if (value == null) {
continue;
}
ArrayList