-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1393] Use TupleTransformer for SUBSELECT and MULTISET fetching to a…
…llow streaming
- Loading branch information
Showing
18 changed files
with
555 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 24 additions & 24 deletions
48
.../java/com/blazebit/persistence/view/impl/objectbuilder/ViewTypeObjectBuilderTemplate.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 0 additions & 183 deletions
183
...lazebit/persistence/view/impl/objectbuilder/transformer/MultisetTupleListTransformer.java
This file was deleted.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
...om/blazebit/persistence/view/impl/objectbuilder/transformer/MultisetTupleTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2014 - 2021 Blazebit. | ||
* | ||
* 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 com.blazebit.persistence.view.impl.objectbuilder.transformer; | ||
|
||
import com.blazebit.persistence.view.impl.objectbuilder.ContainerAccumulator; | ||
import com.blazebit.persistence.view.impl.objectbuilder.transformator.TupleTransformator; | ||
import com.blazebit.persistence.view.impl.objectbuilder.transformator.UpdatableViewMap; | ||
import com.blazebit.persistence.view.spi.type.BasicUserTypeStringSupport; | ||
import com.blazebit.persistence.view.spi.type.TypeConverter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author Christian Beikov | ||
* @since 1.5.0 | ||
*/ | ||
public class MultisetTupleTransformer implements TupleTransformer { | ||
|
||
private final int startIndex; | ||
private final boolean hasSelectOrSubselectFetchedAttributes; | ||
private final TupleTransformator tupleTransformator; | ||
private final TupleTransformer subviewTupleTransformer; | ||
private final TupleTransformer indexSubviewTupleTransformer; | ||
private final int indexStartIndex; | ||
private final BasicUserTypeStringSupport<Object>[] fieldConverters; | ||
private final TypeConverter<Object, Object> elementConverter; | ||
private final ContainerAccumulator<Object> containerAccumulator; | ||
private final boolean dirtyTracking; | ||
|
||
public MultisetTupleTransformer(int startIndex, boolean hasSelectOrSubselectFetchedAttributes, TupleTransformator tupleTransformator, TupleTransformer subviewTupleTransformer, TupleTransformer indexSubviewTupleTransformer, int indexStartIndex, | ||
BasicUserTypeStringSupport<Object>[] fieldConverters, TypeConverter<Object, Object> elementConverter, ContainerAccumulator<Object> containerAccumulator, boolean dirtyTracking) { | ||
this.startIndex = startIndex; | ||
this.hasSelectOrSubselectFetchedAttributes = hasSelectOrSubselectFetchedAttributes; | ||
this.tupleTransformator = tupleTransformator; | ||
this.subviewTupleTransformer = subviewTupleTransformer; | ||
this.indexSubviewTupleTransformer = indexSubviewTupleTransformer; | ||
this.indexStartIndex = indexStartIndex; | ||
this.elementConverter = elementConverter; | ||
this.fieldConverters = fieldConverters; | ||
this.containerAccumulator = containerAccumulator; | ||
this.dirtyTracking = dirtyTracking; | ||
} | ||
|
||
@Override | ||
public int getConsumeStartIndex() { | ||
return startIndex; | ||
} | ||
|
||
@Override | ||
public int getConsumeEndIndex() { | ||
return startIndex + 1; | ||
} | ||
|
||
@Override | ||
public Object[] transform(Object[] tuple, UpdatableViewMap updatableViewMap) { | ||
Object collection = containerAccumulator.createContainer(dirtyTracking, 0); | ||
if (tuple[startIndex] != null) { | ||
List<Object[]> objects = (List<Object[]>) tuple[startIndex]; | ||
for (int i = 0; i < objects.size(); i++) { | ||
Object[] elementTuple = objects.get(i); | ||
for (int j = 0; j < fieldConverters.length; j++) { | ||
if (elementTuple[j] instanceof CharSequence) { | ||
elementTuple[j] = fieldConverters[j].fromString((CharSequence) elementTuple[j]); | ||
} | ||
} | ||
} | ||
if (tupleTransformator != null) { | ||
// Before building the subviews, apply the tuple transformator on the nested set in isolation | ||
tupleTransformator.transformAll(objects); | ||
} | ||
for (int i = 0; i < objects.size(); i++) { | ||
Object indexObject = null; | ||
if (indexSubviewTupleTransformer != null) { | ||
indexObject = indexSubviewTupleTransformer.transform(objects.get(i), updatableViewMap)[indexSubviewTupleTransformer.getConsumeStartIndex() - 1]; | ||
} else if (indexStartIndex != -1) { | ||
indexObject = objects.get(i)[indexStartIndex]; | ||
} | ||
if (subviewTupleTransformer == null) { | ||
add(collection, indexObject, objects.get(i)[startIndex]); | ||
} else { | ||
Object[] transformedTuple = subviewTupleTransformer.transform(objects.get(i), updatableViewMap); | ||
add(collection, indexObject, transformedTuple[0]); | ||
} | ||
} | ||
} | ||
tuple[startIndex] = collection; | ||
return tuple; | ||
} | ||
|
||
protected void add(Object collection, Object index, Object value) { | ||
if (elementConverter != null) { | ||
value = elementConverter.convertToViewType(value); | ||
} | ||
containerAccumulator.add(collection, index, value, dirtyTracking); | ||
} | ||
} |
Oops, something went wrong.