@Test public void testTransformTupleWithSearchExplanation() { String[] aliases = new String[] { "__HSearch_Explanation", "_hibernate_class", "foo", "bar" }; Object[] tuple = new Object[] { explanation, String.class, "Hi there!", "Hello right back at ya, buddy!" }; MyModelView myModelView = (MyModelView) sut.transformTuple(tuple, aliases); assertEquals("Hi there!", myModelView.getFoo()); assertEquals("Hello right back at ya, buddy!", myModelView.getBar()); assertEquals(explanation.toString(), myModelView.getSearchIndexExplanationString()); }
@Override public Object transformTuple(final Object[] tuple, final String[] aliases) { Map<String, Object> properties = getMapFromTuplesAndAliases(tuple, aliases); Class< ? > entityClass = (Class< ? >) properties.get(HIBERNATE_CLASS_PROPERTY_NAME); if (!modelToViewClassMap.containsKey(entityClass)) { String message = "Unhandled entity class: " + entityClass.getName() + ", cannot determine which ModelView subclass to instantiate."; log.error(message); throw new IllegalArgumentException(message); } Class< ? > modelClass = modelToViewClassMap.get(entityClass); ModelView modelView = (ModelView) reflectiveInstantiator.instantiateObject(modelClass); modelView.loadProperties(properties); if (properties.containsKey("__HSearch_Explanation")) { Explanation explanation = (Explanation) properties.get("__HSearch_Explanation"); modelView.setSearchIndexExplanationString(explanation.toString()); } return modelView; }
ProjectionToModelViewTransformer implements ResultTransformer { @Override public Object transformTuple(final Object[] tuple, final String[] aliases) { Map<String, Object> properties = getMapFromTuplesAndAliases(tuple, aliases); Class< ? > entityClass = (Class< ? >) properties.get(HIBERNATE_CLASS_PROPERTY_NAME); if (!modelToViewClassMap.containsKey(entityClass)) { String message = "Unhandled entity class: " + entityClass.getName() + ", cannot determine which ModelView subclass to instantiate."; log.error(message); throw new IllegalArgumentException(message); } Class< ? > modelClass = modelToViewClassMap.get(entityClass); ModelView modelView = (ModelView) reflectiveInstantiator.instantiateObject(modelClass); modelView.loadProperties(properties); if (properties.containsKey("__HSearch_Explanation")) { Explanation explanation = (Explanation) properties.get("__HSearch_Explanation"); modelView.setSearchIndexExplanationString(explanation.toString()); } return modelView; } }
ProjectionToModelViewTransformer implements ResultTransformer { @Override public Object transformTuple(final Object[] tuple, final String[] aliases) { Map<String, Object> properties = getMapFromTuplesAndAliases(tuple, aliases); Class< ? > entityClass = (Class< ? >) properties.get(HIBERNATE_CLASS_PROPERTY_NAME); if (!modelToViewClassMap.containsKey(entityClass)) { String message = "Unhandled entity class: " + entityClass.getName() + ", cannot determine which ModelView subclass to instantiate."; log.error(message); throw new IllegalArgumentException(message); } Class< ? > modelClass = modelToViewClassMap.get(entityClass); ModelView modelView = (ModelView) reflectiveInstantiator.instantiateObject(modelClass); modelView.loadProperties(properties); if (properties.containsKey("__HSearch_Explanation")) { Explanation explanation = (Explanation) properties.get("__HSearch_Explanation"); modelView.setSearchIndexExplanationString(explanation.toString()); } return modelView; } ProjectionToModelViewTransformer(final Map<Class< ? >, Class< ? >> theModelToViewMap,
            final ReflectiveInstantiator inReflectiveInstantiator); }
ProjectionToModelViewTransformer implements ResultTransformer { @Override public Object transformTuple(final Object[] tuple, final String[] aliases) { Map<String, Object> properties = getMapFromTuplesAndAliases(tuple, aliases); Class< ? > entityClass = (Class< ? >) properties.get(HIBERNATE_CLASS_PROPERTY_NAME); if (!modelToViewClassMap.containsKey(entityClass)) { String message = "Unhandled entity class: " + entityClass.getName() + ", cannot determine which ModelView subclass to instantiate."; log.error(message); throw new IllegalArgumentException(message); } Class< ? > modelClass = modelToViewClassMap.get(entityClass); ModelView modelView = (ModelView) reflectiveInstantiator.instantiateObject(modelClass); modelView.loadProperties(properties); if (properties.containsKey("__HSearch_Explanation")) { Explanation explanation = (Explanation) properties.get("__HSearch_Explanation"); modelView.setSearchIndexExplanationString(explanation.toString()); } return modelView; } ProjectionToModelViewTransformer(final Map<Class< ? >, Class< ? >> theModelToViewMap,
            final ReflectiveInstantiator inReflectiveInstantiator); @SuppressWarnings("unchecked") @Override List transformList(final List list); @Override Object transformTuple(final Object[] tuple, final String[] aliases); }
ProjectionToModelViewTransformer implements ResultTransformer { @Override public Object transformTuple(final Object[] tuple, final String[] aliases) { Map<String, Object> properties = getMapFromTuplesAndAliases(tuple, aliases); Class< ? > entityClass = (Class< ? >) properties.get(HIBERNATE_CLASS_PROPERTY_NAME); if (!modelToViewClassMap.containsKey(entityClass)) { String message = "Unhandled entity class: " + entityClass.getName() + ", cannot determine which ModelView subclass to instantiate."; log.error(message); throw new IllegalArgumentException(message); } Class< ? > modelClass = modelToViewClassMap.get(entityClass); ModelView modelView = (ModelView) reflectiveInstantiator.instantiateObject(modelClass); modelView.loadProperties(properties); if (properties.containsKey("__HSearch_Explanation")) { Explanation explanation = (Explanation) properties.get("__HSearch_Explanation"); modelView.setSearchIndexExplanationString(explanation.toString()); } return modelView; } ProjectionToModelViewTransformer(final Map<Class< ? >, Class< ? >> theModelToViewMap,
            final ReflectiveInstantiator inReflectiveInstantiator); @SuppressWarnings("unchecked") @Override List transformList(final List list); @Override Object transformTuple(final Object[] tuple, final String[] aliases);  }