Skip to content

Commit

Permalink
fixed error handling for extension/clob querying.
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jun 25, 2014
1 parent 5664c93 commit cb5d95b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 37 deletions.
Expand Up @@ -275,7 +275,6 @@ public void queryEnabled() throws Exception {
}
}


@Test
public void queryGenericLong() throws Exception {
Session session = open();
Expand Down Expand Up @@ -1513,4 +1512,55 @@ public void test400queryObjectypeByTypeComplex() throws Exception {
close(session);
}
}

@Test(expectedExceptions = QueryException.class)
public void test410QueryGenericClob() throws Exception {
Session session = open();
try {
EqualFilter eq = EqualFilter.createEqual(
new ItemPath(ObjectType.F_EXTENSION, new QName("http://example.com/p", "locations")),
GenericObjectType.class, prismContext, null);

getInterpretedQuery(session, GenericObjectType.class, ObjectQuery.createObjectQuery(eq));
} catch (QueryException ex) {
LOGGER.info("Exception", ex);
throw ex;
} finally {
close(session);
}
}

@Test
public void test420QueryGenericString() throws Exception {
Session session = open();
try {
Criteria main = session.createCriteria(RGenericObject.class, "g");

Criteria stringExt = main.createCriteria("strings", "s", JoinType.LEFT_OUTER_JOIN);

//and
Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("s.ownerType", RObjectExtensionType.EXTENSION));
c2.add(Restrictions.eq("s.name", new QName("http://example.com/p", "stringType")));
c2.add(Restrictions.eq("s.value", "asdf"));

main.add(c2);
ProjectionList projections = Projections.projectionList();
addFullObjectProjectionList("g", projections, false);
main.setProjection(projections);

String expected = HibernateToSqlTranslator.toSql(main);

EqualFilter eq = EqualFilter.createEqual(
new ItemPath(ObjectType.F_EXTENSION, new QName("http://example.com/p", "stringType")),
GenericObjectType.class, prismContext, "asdf");

String real = getInterpretedQuery(session, GenericObjectType.class, ObjectQuery.createObjectQuery(eq));

LOGGER.info("exp. query>\n{}\nreal query>\n{}", new Object[]{expected, real});
AssertJUnit.assertEquals(expected, real);
} finally {
close(session);
}
}
}
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.util.ValueSerializationUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.sql.query.QueryException;
import com.evolveum.midpoint.repo.sql.type.XMLGregorianCalendarType;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.RUtil;
Expand Down Expand Up @@ -249,14 +250,6 @@ public void convertFromRValue(RAnyValue value, PrismContainerValue any) throws D
}
}

private Element createElement(QName name) {
if (document == null) {
document = DOMUtil.getDocument();
}

return DOMUtil.createElement(document, name);
}

private void addValueToItem(RAnyValue value, Item item) throws SchemaException {
Object realValue = createRealValue(value, item.getDefinition().getTypeName());
if (!(value instanceof ROExtReference) && realValue == null) {
Expand Down Expand Up @@ -338,37 +331,12 @@ private Object createRealValue(RAnyValue rValue, QName type) throws SchemaExcept
* extension value is or can be saved.
*
* @param definition
* @param value
* @param <T>
*
* @return One of "strings", "longs", "dates", "clobs"
* @throws SchemaException
*/
public static <T extends ObjectType> String getAnySetType(ItemDefinition definition, Element value) throws
SchemaException {
QName typeName = definition == null ? DOMUtil.resolveXsiType(value) : definition.getTypeName();
Validate.notNull(typeName, "Definition was not defined for element value '"
+ DOMUtil.getQNameWithoutPrefix(value) + "' and it doesn't have xsi:type.");

ValueType valueType = getValueType(typeName);
switch (valueType) {
case DATE:
return "dates";
case LONG:
return "longs";
case STRING:
default:
boolean indexed = definition == null ? isIndexable(typeName) : isIndexable(definition);
if (indexed) {
return "strings";
} else {
return "clobs";
}
}
}


public static <T extends ObjectType> String getAnySetType(ItemDefinition definition) throws
SchemaException {
SchemaException, QueryException {
QName typeName = definition.getTypeName();

ValueType valueType = getValueType(typeName);
Expand All @@ -382,7 +350,7 @@ public static <T extends ObjectType> String getAnySetType(ItemDefinition definit
if (isIndexable(definition)) {
return "strings";
} else {
return "clobs";
throw new QueryException("Can't query CLOB (non indexed string) value, definition " + definition);
}
}
}
Expand Down

0 comments on commit cb5d95b

Please sign in to comment.