org.hibernate.transform.PassThroughResultTransformer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
JPMS Module-Info's for a few of the Jakarta Libraries just until they add them in themselves
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.transform;
import java.util.Arrays;
import java.util.List;
/**
* ???
*
* @author max
*/
public class PassThroughResultTransformer extends BasicTransformerAdapter implements TupleSubsetResultTransformer {
public static final PassThroughResultTransformer INSTANCE = new PassThroughResultTransformer();
/**
* Disallow instantiation of PassThroughResultTransformer.
*/
private PassThroughResultTransformer() {
}
@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
return tuple.length==1 ? tuple[0] : tuple;
}
@Override
public boolean isTransformedValueATupleElement(String[] aliases, int tupleLength) {
return tupleLength == 1;
}
@Override
public boolean[] includeInTransform(String[] aliases, int tupleLength) {
boolean[] includeInTransformedResult = new boolean[tupleLength];
Arrays.fill( includeInTransformedResult, true );
return includeInTransformedResult;
}
/* package-protected */
List untransformToTuples(List results, boolean isSingleResult) {
// un-transform only if necessary; if transformed, do it in place;
if ( isSingleResult ) {
for ( int i = 0 ; i < results.size() ; i++ ) {
Object[] tuple = untransformToTuple( results.get( i ), isSingleResult);
results.set( i, tuple );
}
}
return results;
}
/* package-protected */
Object[] untransformToTuple(Object transformed, boolean isSingleResult ) {
return isSingleResult ? new Object[] { transformed } : ( Object[] ) transformed;
}
/**
* Serialization hook for ensuring singleton uniqueing.
*
* @return The singleton instance : {@link #INSTANCE}
*/
private Object readResolve() {
return INSTANCE;
}
}