Skip to content

Commit

Permalink
renamed variables for RUtil.getSerializedFormFromBytes calls + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jun 15, 2020
1 parent d5fd1ce commit 90d2825
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
Expand Up @@ -13,14 +13,11 @@
import java.sql.ResultSet;
import javax.persistence.*;

import com.evolveum.midpoint.prism.SerializationOptions;

import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationAuditType;

import org.hibernate.annotations.ForeignKey;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.SerializationOptions;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.repo.sql.data.InsertQueryBuilder;
Expand All @@ -39,6 +36,7 @@
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationAuditType;
import com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType;

/**
Expand Down Expand Up @@ -231,22 +229,21 @@ private void recomputeChecksum() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) { return true; }
if (o == null || getClass() != o.getClass()) { return false; }

RObjectDeltaOperation that = (RObjectDeltaOperation) o;

if (getChecksum() != null ? !getChecksum().equals(that.getChecksum()) : that.getChecksum() != null)
return false;
if (delta != null ? !delta.equals(that.delta) : that.delta != null) return false;
if (fullResult != null ? !fullResult.equals(that.fullResult) : that.fullResult != null)
return false;
if (status != that.status) return false;
if (deltaType != null ? !deltaType.equals(that.deltaType) : that.deltaType != null) return false;
if (deltaOid != null ? !deltaOid.equals(that.deltaOid) : that.deltaOid != null) return false;
if (objectName != null ? !objectName.equals(that.objectName) : that.objectName != null) return false;
if (resourceOid != null ? !resourceOid.equals(that.resourceOid) : that.resourceOid != null) return false;
if (resourceName != null ? !resourceName.equals(that.resourceName) : that.resourceName != null) return false;
if (getChecksum() != null ? !getChecksum().equals(that.getChecksum()) : that.getChecksum() != null) { return false; }
// TODO: likely a bug - question is whether entity-style id-only-based equals wouldn't be better (+hashCode)
if (delta != null ? !delta.equals(that.delta) : that.delta != null) { return false; }
if (fullResult != null ? !fullResult.equals(that.fullResult) : that.fullResult != null) { return false; }
if (status != that.status) { return false; }
if (deltaType != null ? !deltaType.equals(that.deltaType) : that.deltaType != null) { return false; }
if (deltaOid != null ? !deltaOid.equals(that.deltaOid) : that.deltaOid != null) { return false; }
if (objectName != null ? !objectName.equals(that.objectName) : that.objectName != null) { return false; }
if (resourceOid != null ? !resourceOid.equals(that.resourceOid) : that.resourceOid != null) { return false; }
if (resourceName != null ? !resourceName.equals(that.resourceName) : that.resourceName != null) { return false; }

return true;
}
Expand Down Expand Up @@ -376,16 +373,18 @@ public static ObjectDeltaOperation fromRepo(RObjectDeltaOperation operation, Pri
try {
if (operation.getDelta() != null) {
byte[] data = operation.getDelta();
String xmlDelta = RUtil.getSerializedFormFromBytes(data, useUtf16);
String serializedDelta = RUtil.getSerializedFormFromBytes(data, useUtf16);

ObjectDeltaType delta = prismContext.parserFor(xmlDelta).parseRealValue(ObjectDeltaType.class);
ObjectDeltaType delta = prismContext.parserFor(serializedDelta)
.parseRealValue(ObjectDeltaType.class);
odo.setObjectDelta(DeltaConvertor.createObjectDelta(delta, prismContext));
}
if (operation.getFullResult() != null) {
byte[] data = operation.getFullResult();
String xmlResult = RUtil.getSerializedFormFromBytes(data, useUtf16);
String serializedResult = RUtil.getSerializedFormFromBytes(data, useUtf16);

OperationResultType resultType = prismContext.parserFor(xmlResult).parseRealValue(OperationResultType.class);
OperationResultType resultType = prismContext.parserFor(serializedResult)
.parseRealValue(OperationResultType.class);
odo.setExecutionResult(OperationResult.createOperationResult(resultType));
}
odo.setObjectName(RPolyString.fromRepo(operation.getObjectName(), prismContext));
Expand All @@ -406,24 +405,32 @@ public static ObjectDeltaOperation fromRepo(ResultSet resultSet, PrismContext pr
try {
if (resultSet.getBytes(DELTA_COLUMN_NAME) != null) {
byte[] data = resultSet.getBytes(DELTA_COLUMN_NAME);
String xmlDelta = RUtil.getSerializedFormFromBytes(data, useUtf16);
String seralizedDelta = RUtil.getSerializedFormFromBytes(data, useUtf16);

ObjectDeltaType delta = prismContext.parserFor(xmlDelta).parseRealValue(ObjectDeltaType.class);
ObjectDeltaType delta = prismContext.parserFor(seralizedDelta)
.parseRealValue(ObjectDeltaType.class);
odo.setObjectDelta(DeltaConvertor.createObjectDelta(delta, prismContext));
}
if (resultSet.getBytes(FULL_RESULT_COLUMN_NAME) != null) {
byte[] data = resultSet.getBytes(FULL_RESULT_COLUMN_NAME);
String xmlResult = RUtil.getSerializedFormFromBytes(data, useUtf16);
String serializedResult = RUtil.getSerializedFormFromBytes(data, useUtf16);

OperationResultType resultType = prismContext.parserFor(xmlResult).parseRealValue(OperationResultType.class);
OperationResultType resultType = prismContext.parserFor(serializedResult)
.parseRealValue(OperationResultType.class);
odo.setExecutionResult(OperationResult.createOperationResult(resultType));
}
if (resultSet.getString(OBJECT_NAME_ORIG_COLUMN_NAME) != null || resultSet.getString(OBJECT_NAME_NORM_COLUMN_NAME) != null) {
odo.setObjectName(new PolyString(resultSet.getString(OBJECT_NAME_ORIG_COLUMN_NAME), resultSet.getString(OBJECT_NAME_NORM_COLUMN_NAME)));
if (resultSet.getString(OBJECT_NAME_ORIG_COLUMN_NAME) != null
|| resultSet.getString(OBJECT_NAME_NORM_COLUMN_NAME) != null) {
odo.setObjectName(new PolyString(
resultSet.getString(OBJECT_NAME_ORIG_COLUMN_NAME),
resultSet.getString(OBJECT_NAME_NORM_COLUMN_NAME)));
}
odo.setResourceOid(resultSet.getString(RESOURCE_OID_COLUMN_NAME));
if (resultSet.getString(RESOURCE_NAME_ORIG_COLUMN_NAME) != null || resultSet.getString(RESOURCE_NAME_NORM_COLUMN_NAME) != null) {
odo.setResourceName(new PolyString(resultSet.getString(RESOURCE_NAME_ORIG_COLUMN_NAME), resultSet.getString(RESOURCE_NAME_NORM_COLUMN_NAME)));
if (resultSet.getString(RESOURCE_NAME_ORIG_COLUMN_NAME) != null
|| resultSet.getString(RESOURCE_NAME_NORM_COLUMN_NAME) != null) {
odo.setResourceName(new PolyString(
resultSet.getString(RESOURCE_NAME_ORIG_COLUMN_NAME),
resultSet.getString(RESOURCE_NAME_NORM_COLUMN_NAME)));
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
Expand Down
Expand Up @@ -575,10 +575,12 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
query.setParameter("oid", prismObject.getOid());
byte[] opResult = (byte[]) query.uniqueResult();
if (opResult != null) {
String xmlResult = RUtil.getSerializedFormFromBytes(opResult);
OperationResultType resultType = prismContext.parserFor(xmlResult).parseRealValue(OperationResultType.class);
String serializedResult = RUtil.getSerializedFormFromBytes(opResult);
OperationResultType resultType = prismContext.parserFor(serializedResult)
.parseRealValue(OperationResultType.class);

PrismProperty<OperationResultType> resultProperty = prismObject.findOrCreateProperty(TaskType.F_RESULT);
PrismProperty<OperationResultType> resultProperty =
prismObject.findOrCreateProperty(TaskType.F_RESULT);
resultProperty.setRealValue(resultType);
resultProperty.setIncomplete(false);

Expand Down Expand Up @@ -730,7 +732,7 @@ private <T extends ObjectType> Collection<ItemDefinition<?>> getIndexOnlyExtensi
if (prismObject.getDefinition() != null) {
PrismContainerDefinition<?> extensionDefinition = prismObject.getDefinition().getExtensionDefinition();
if (extensionDefinition != null) {
for (ItemDefinition definition : extensionDefinition.getDefinitions()) {
for (ItemDefinition<?> definition : extensionDefinition.getDefinitions()) {
if (definition.isIndexOnly()) {
rv.add(definition);
}
Expand All @@ -740,10 +742,11 @@ private <T extends ObjectType> Collection<ItemDefinition<?>> getIndexOnlyExtensi
return rv;
}

private void applyShadowAttributeDefinitions(Class<? extends RAnyValue> anyValueType,
PrismObject object, Session session) throws SchemaException {
private void applyShadowAttributeDefinitions(
Class<? extends RAnyValue> anyValueType, PrismObject object, Session session)
throws SchemaException {

PrismContainer attributes = object.findContainer(ShadowType.F_ATTRIBUTES);
PrismContainer<?> attributes = object.findContainer(ShadowType.F_ATTRIBUTES);

Query query = session.getNamedQuery("getDefinition." + anyValueType.getSimpleName());
query.setParameter("oid", object.getOid());
Expand Down Expand Up @@ -909,7 +912,7 @@ public <T extends ObjectType> void searchObjectsIterativeByPaging(Class<T> type,
main:
while (remaining > 0) {
paging.setOffset(offset);
paging.setMaxSize(remaining < batchSize ? remaining : batchSize);
paging.setMaxSize(Math.min(remaining, batchSize));

List<PrismObject<T>> objects = repositoryService.searchObjects(type, pagedQuery, options, result);

Expand Down

0 comments on commit 90d2825

Please sign in to comment.