Skip to content

Commit

Permalink
removing deprecated code, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 7, 2018
1 parent a57e9fd commit bd2ac9f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
Expand Up @@ -21,7 +21,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

Expand Down Expand Up @@ -81,7 +81,7 @@ public static <T extends ObjectType> void validateOwners(Class<T> type, SqlRepos
}

private static final void validate(String sql, String message, Session session) {
Query query = session.createSQLQuery(sql);
Query query = session.createNativeQuery(sql);
List nullAssignments = query.list();
if (!nullAssignments.isEmpty()) {
throw new SystemException(message + Arrays.deepToString(nullAssignments.toArray()));
Expand Down
Expand Up @@ -22,7 +22,7 @@
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
Expand All @@ -31,7 +31,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
* @author lazyman
Expand Down Expand Up @@ -78,11 +77,11 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
Query query;
if (useProcedure(factory.getSqlConfiguration())) {
LOGGER.info("Using truncate procedure.");
query = session.createSQLQuery("{ call " + TRUNCATE_PROCEDURE + "() }");
query = session.createNativeQuery("{ call " + TRUNCATE_PROCEDURE + "() }");
query.executeUpdate();
} else {
LOGGER.info("Using truncate function.");
query = session.createSQLQuery("select " + TRUNCATE_FUNCTION + "();");
query = session.createNativeQuery("select " + TRUNCATE_FUNCTION + "();");
query.uniqueResult();
}

Expand Down
Expand Up @@ -192,7 +192,7 @@ private void addGetCompare(File file) throws Exception {
if (id.isReplace()) {
LOGGER.debug("{}", id.getValuesToReplace().iterator().next());
}
LOGGER.error("{}", prismContext.serializeObjectToString(newObject, PrismContext.LANG_XML));
LOGGER.error("{}", prismContext.serializerFor(PrismContext.LANG_XML).serialize(newObject));
}
} catch (Throwable ex) {
LOGGER.error("Exception occurred for {}", object, ex);
Expand Down
Expand Up @@ -31,7 +31,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
Expand Down
Expand Up @@ -24,7 +24,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.test.annotation.DirtiesContext;
Expand Down
Expand Up @@ -123,12 +123,18 @@ public void test210ModifyRowProperties() throws Exception {
.item(F_ROW, 2, F_VALUE).replace()
.item(F_ROW, 3, F_LABEL).replace(new PolyString("label 3"))
.item(F_ROW, 3, F_LAST_CHANGE_TIMESTAMP)
.replace(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 10, 10)))
.replace(XmlTypeConverter.createXMLGregorianCalendar(createDate(99, 10, 10)))
.asItemDeltas();

executeAndCheckModification(modifications, result, 0, Arrays.asList("key 1", "2 key"));
}

private Date createDate(int year, int month, int day) {
Calendar c = Calendar.getInstance();
c.set(year, month, day);
return c.getTime();
}

@Test
public void test220AddRemoveValues() throws Exception {
OperationResult result = new OperationResult("test220AddRemoveValues");
Expand Down Expand Up @@ -201,7 +207,7 @@ public void test240AddRows() throws Exception {
LookupTableRowType rowNoId = new LookupTableRowType(prismContext);
rowNoId.setKey("key new");
rowNoId.setValue("value new");
rowNoId.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 3, 4)));
rowNoId.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(createDate(99, 3, 4)));

LookupTableRowType rowNoId2 = new LookupTableRowType(prismContext);
rowNoId2.setKey("key new 2");
Expand Down Expand Up @@ -286,7 +292,7 @@ public void test255AddDeleteRows() throws Exception {
LookupTableRowType rowNoId = new LookupTableRowType(prismContext);
rowNoId.setKey("key new new");
rowNoId.setValue("value new new");
rowNoId.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 3, 4)));
rowNoId.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(createDate(99, 3, 4)));

LookupTableRowType row5 = new LookupTableRowType(prismContext);
row5.setKey("key 5");
Expand All @@ -310,7 +316,7 @@ public void test260ReplaceRowsExistingId() throws Exception {
row5.setId(5L); // dangerous
row5.setKey("key 5 plus");
row5.setValue("value 5 plus");
row5.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(new Date(99, 3, 10)));
row5.setLastChangeTimestamp(XmlTypeConverter.createXMLGregorianCalendar(createDate(99, 3, 10)));

List<ItemDelta<?,?>> modifications = DeltaBuilder.deltaFor(LookupTableType.class, prismContext)
.item(F_ROW).replace(row5)
Expand Down
Expand Up @@ -45,7 +45,7 @@

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.test.annotation.DirtiesContext;
Expand Down Expand Up @@ -348,14 +348,14 @@ public void test002modifyOrgStructAddRef() throws Exception {

private List<ROrgClosure> getOrgClosure(String ancestorOid, String descendantOid, Session session) {
Query query = session.createQuery("from ROrgClosure where ancestorOid=:aOid and descendantOid=:dOid");
query.setString("aOid", ancestorOid);
query.setString("dOid", descendantOid);
query.setParameter("aOid", ancestorOid);
query.setParameter("dOid", descendantOid);
return query.list();
}

private List<ROrgClosure> getOrgClosureByDescendant(String descendantOid, Session session) {
Query query = session.createQuery("from ROrgClosure where descendantOid=:oid");
query.setString("oid", descendantOid);
query.setParameter("oid", descendantOid);
return query.list();
}

Expand Down
Expand Up @@ -54,7 +54,7 @@ public void test100Parsing() throws Exception {
for (int i = 0; i < COUNT; i++) {
List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects();
for (PrismObject obj : elements) {
prismContext.serializeObjectToString(obj, PrismContext.LANG_XML);
prismContext.serializerFor(PrismContext.LANG_XML).serialize(obj);
}
}
LOGGER.info("xxx>> time: {}", (System.currentTimeMillis() - time));
Expand Down Expand Up @@ -239,7 +239,7 @@ private PolyStringType createPoly(String orig) {
private void writeObject(ObjectType obj, Writer writer) throws IOException, SchemaException {
PrismObject prism = obj.asPrismObject();
prismContext.adopt(prism);
writer.write(prismContext.serializeObjectToString(prism, PrismContext.LANG_XML));
writer.write(prismContext.serializerFor(PrismContext.LANG_XML).serialize(prism));
writer.write('\n');
}

Expand Down
Expand Up @@ -27,9 +27,7 @@
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.OrgFilter;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.repo.sql.BaseSQLRepoTest;
import com.evolveum.midpoint.repo.sql.data.common.ROrgClosure;
Expand All @@ -47,7 +45,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.query.Query;
import org.hibernate.Session;
import org.hibernate.type.LongType;
import org.hibernate.type.StringType;
Expand Down Expand Up @@ -202,7 +200,7 @@ protected boolean checkClosureMatrix() throws SchemaException {

if (DUMP_TC_MATRIX_DETAILS) LOGGER.info("TC matrix expected = {}", result);

Query q = session.createSQLQuery("select descendant_oid, ancestor_oid, val from m_org_closure")
Query q = session.createNativeQuery("select descendant_oid, ancestor_oid, val from m_org_closure")
.addScalar("descendant_oid", StringType.INSTANCE)
.addScalar("ancestor_oid", StringType.INSTANCE)
.addScalar("val", LongType.INSTANCE);
Expand Down Expand Up @@ -291,13 +289,13 @@ protected Set<String> getActualChildrenOf(String ancestor) {

private List<ROrgClosure> getOrgClosureByDescendant(String descendantOid) {
Query query = getSession().createQuery("from ROrgClosure where descendantOid=:oid");
query.setString("oid", descendantOid);
query.setParameter("oid", descendantOid);
return query.list();
}

private List<ROrgClosure> getOrgClosureByAncestor(String ancestorOid) {
Query query = getSession().createQuery("from ROrgClosure where ancestorOid=:oid");
query.setString("oid", ancestorOid);
query.setParameter("oid", ancestorOid);
return query.list();
}

Expand Down Expand Up @@ -626,7 +624,7 @@ private void registerVertexIfNeeded(String oid) {

protected List<String> getChildren(String oid) {
Query childrenQuery = getSession().createQuery("select distinct ownerOid from RObjectReference where targetOid=:oid and referenceType=0");
childrenQuery.setString("oid", oid);
childrenQuery.setParameter("oid", oid);
return childrenQuery.list();
}

Expand All @@ -635,7 +633,7 @@ private List<String> getOrgChildren(String oid) {
" join parentRef.owner as owner where parentRef.targetOid=:oid and parentRef.referenceType=0" +
" and owner.objectTypeClass = :orgType");
childrenQuery.setParameter("orgType", RObjectType.ORG); // TODO eliminate use of parameter here
childrenQuery.setString("oid", oid);
childrenQuery.setParameter("oid", oid);
return childrenQuery.list();
}

Expand Down Expand Up @@ -814,7 +812,7 @@ protected void _test100LoadOrgStructure() throws Exception {
long start = System.currentTimeMillis();
loadOrgStructure(0, null, "", opResult);
System.out.println("Loaded " + allOrgCreated.size() + " orgs and " + (objectCount - allOrgCreated.size()) + " users in " + (System.currentTimeMillis() - start) + " ms");
Query q = getSession().createSQLQuery("select count(*) from m_org_closure");
Query q = getSession().createNativeQuery("select count(*) from m_org_closure");
System.out.println("OrgClosure table has " + q.list().get(0) + " rows");
closureSize = Long.parseLong(q.list().get(0).toString());
}
Expand All @@ -825,7 +823,7 @@ protected void _test110ScanOrgStructure() throws Exception {
long start = System.currentTimeMillis();
scanOrgStructure(opResult);
System.out.println("Found " + allOrgCreated.size() + " orgs and " + (objectCount - allOrgCreated.size()) + " users in " + (System.currentTimeMillis() - start) + " ms");
Query q = getSession().createSQLQuery("select count(*) from m_org_closure");
Query q = getSession().createNativeQuery("select count(*) from m_org_closure");
System.out.println("OrgClosure table has " + q.list().get(0) + " rows");
closureSize = Long.parseLong(q.list().get(0).toString());
}
Expand Down Expand Up @@ -1042,7 +1040,7 @@ protected void _test400UnloadOrgStructure() throws Exception {
removeOrgStructure(opResult);
System.out.println("Removed in " + (System.currentTimeMillis() - start) + " ms");

Query q = getSession().createSQLQuery("select count(*) from m_org_closure");
Query q = getSession().createNativeQuery("select count(*) from m_org_closure");
System.out.println("OrgClosure table has " + q.list().get(0) + " rows");

LOGGER.info("Finish.");
Expand All @@ -1054,7 +1052,7 @@ protected void _test410RandomUnloadOrgStructure() throws Exception {
randomRemoveOrgStructure(opResult);
System.out.println("Removed in " + (System.currentTimeMillis() - start) + " ms");

Query q = getSession().createSQLQuery("select count(*) from m_org_closure");
Query q = getSession().createNativeQuery("select count(*) from m_org_closure");
Object count = q.list().get(0);
System.out.println("OrgClosure table has " + count + " rows");
assertEquals("Closure is not empty", "0", count.toString());
Expand Down

0 comments on commit bd2ac9f

Please sign in to comment.