Skip to content

Commit

Permalink
TextInfo table (unfinished).
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Feb 22, 2017
1 parent 77c27eb commit f6f74c6
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 1 deletion.
Expand Up @@ -628,7 +628,15 @@ public void caseInsensitiveSearchTest() throws Exception {
1);
}

@SuppressWarnings("SameParameterValue")
@Test
public void fullTextSearch() throws Exception {
assertObjectsFound(QueryBuilder.queryFor(UserType.class, prismContext)
.fullText("test userx00003")
.build(),
1);
}

@SuppressWarnings("SameParameterValue")
private void assertObjectsFound(ObjectQuery query, int expectedCount) throws Exception {
assertObjectsFoundBySearch(query, expectedCount);
assertObjectsFoundByCount(query, expectedCount);
Expand Down
Expand Up @@ -186,6 +186,8 @@ public abstract class RObject<T extends ObjectType> implements Metadata<RObjectR
private Set<ROExtPolyString> polys;
private Set<ROExtBoolean> booleans;

private Set<RObjectTextInfo> textInfoItems;

@Id
@GeneratedValue(generator = "ObjectOidGenerator")
@GenericGenerator(name = "ObjectOidGenerator", strategy = "com.evolveum.midpoint.repo.sql.util.ObjectOidGenerator")
Expand Down Expand Up @@ -558,6 +560,20 @@ public void setBooleans(Set<ROExtBoolean> booleans) {
this.booleans = booleans;
}

@NotQueryable
@OneToMany(mappedBy = "owner", orphanRemoval = true)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<RObjectTextInfo> getTextInfoItems() {
if (textInfoItems == null) {
textInfoItems = new HashSet<>();
}
return textInfoItems;
}

public void setTextInfoItems(Set<RObjectTextInfo> textInfoItems) {
this.textInfoItems = textInfoItems;
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down Expand Up @@ -600,6 +616,7 @@ public boolean equals(Object o) {
if (booleans != null ? !booleans.equals(rObject.booleans) : rObject.booleans != null) return false;
if (booleansCount != null ? !booleansCount.equals(rObject.booleansCount) : rObject.booleansCount != null)
return false;
if (textInfoItems != null ? !textInfoItems.equals(rObject.textInfoItems) : rObject.textInfoItems != null) return false;

return true;
}
Expand Down Expand Up @@ -674,6 +691,8 @@ public static <T extends ObjectType> void copyFromJAXB(ObjectType jaxb, RObject<
if (jaxb.getExtension() != null) {
copyFromJAXB(jaxb.getExtension().asPrismContainerValue(), repo, prismContext, RObjectExtensionType.EXTENSION);
}

repo.getTextInfoItems().addAll(RObjectTextInfo.createSet(jaxb, repo));
}

@Deprecated
Expand Down
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.repo.sql.data.common;

import com.evolveum.midpoint.repo.sql.query2.definition.NotQueryable;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.hibernate.annotations.ForeignKey;
import org.jetbrains.annotations.NotNull;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import static com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo.COLUMN_OWNER_OID;
import static com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo.TABLE_NAME;

/**
* @author mederly
*/
@Entity
@Table(name = TABLE_NAME, indexes = {
@Index(name = "iTextInfoOid", columnList = COLUMN_OWNER_OID)})
public class RObjectTextInfo implements Serializable {

public static final String TABLE_NAME = "m_object_text_info";
public static final String COLUMN_OWNER_OID = "owner_oid";

private Integer id;

private RObject owner;
private String ownerOid;

private String text;

public RObjectTextInfo() {
}

@Id
@GeneratedValue
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

@ForeignKey(name = "fk_reference_owner")
@MapsId("owner")
@ManyToOne(fetch = FetchType.LAZY)
@NotQueryable
public RObject getOwner() {
return owner;
}

@Id
@Column(name = COLUMN_OWNER_OID, length = RUtil.COLUMN_LENGTH_OID)
@NotQueryable
public String getOwnerOid() {
if (ownerOid == null && owner != null) {
ownerOid = owner.getOid();
}
return ownerOid;
}

public void setOwner(RObject owner) {
this.owner = owner;
}

public void setOwnerOid(String ownerOid) {
this.ownerOid = ownerOid;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RObjectTextInfo that = (RObjectTextInfo) o;
return Objects.equals(owner, that.owner) &&
Objects.equals(ownerOid, that.ownerOid) &&
Objects.equals(id, that.id) &&
Objects.equals(text, that.text);
}

@Override
public int hashCode() {
return Objects.hash(owner, ownerOid, id, text);
}

public static <T extends ObjectType> Set<RObjectTextInfo> createSet(@NotNull ObjectType object, @NotNull RObject repo) {
Set<RObjectTextInfo> rv = new HashSet<>();
if (object.getName() != null) {
rv.add(create(repo, object.getName().getOrig()));
}
if (object.getDescription() != null) {
rv.add(create(repo, object.getDescription()));
}
return rv;
}

private static RObjectTextInfo create(RObject repo, String text) {
RObjectTextInfo rv = new RObjectTextInfo();
rv.setOwner(repo);
rv.setText(text);
return rv;
}
}
Expand Up @@ -128,6 +128,47 @@ String addJoin(JpaLinkDefinition joinedItemDefinition, String currentHqlPath) th
return joinedItemAlias;
}

// String addTextInfoJoin(String currentHqlPath) throws QueryException {
// RootHibernateQuery hibernateQuery = context.getHibernateQuery();
// String joinedItemJpaName = "textInfoItems";
// String joinedItemFullPath = currentHqlPath + "." + joinedItemJpaName;
// String joinedItemAlias;
// if (!joinedItemDefinition.isMultivalued()) {
// /*
// * Let's check if we were already here i.e. if we had already created this join.
// * This is to avoid useless creation of redundant joins for singleton items.
// *
// * But how can we be sure that item is singleton if we look only at the last segment (which is single-valued)?
// * Imagine we are creating join for single-valued entity of u.abc.(...).xyz.ent where
// * ent is single-valued and not embedded (so we are to create something like "left join u.abc.(...).xyz.ent e").
// * Then "u" is certainly a single value: either the root object, or some value pointed to by Exists restriction.
// * Also, abc, ..., xyz are surely single-valued: otherwise they would be connected by a join. So,
// * u.abc.(...).xyz.ent is a singleton.
// *
// * Look at it in other way: if e.g. xyz was multivalued, then we would have something like:
// * left join u.abc.(...).uvw.xyz x
// * left join x.ent e
// * And, therefore we would not be looking for u.abc.(...).xyz.ent.
// */
//
// JoinSpecification existingJoin = hibernateQuery.getPrimaryEntity().findJoinFor(joinedItemFullPath);
// if (existingJoin != null) {
// // but let's check the condition as well
// String existingAlias = existingJoin.getAlias();
// // we have to create condition for existing alias, to be matched to existing condition
// Condition conditionForExistingAlias = createJoinCondition(existingAlias, joinedItemDefinition, hibernateQuery);
// if (ObjectUtils.equals(conditionForExistingAlias, existingJoin.getCondition())) {
// LOGGER.trace("Reusing alias '{}' for joined path '{}'", existingAlias, joinedItemFullPath);
// return existingAlias;
// }
// }
// }
// joinedItemAlias = hibernateQuery.createAlias(joinedItemDefinition);
// Condition condition = createJoinCondition(joinedItemAlias, joinedItemDefinition, hibernateQuery);
// hibernateQuery.getPrimaryEntity().addJoin(new JoinSpecification(joinedItemAlias, joinedItemFullPath, condition));
// return joinedItemAlias;
// }

private Condition createJoinCondition(String joinedItemAlias, JpaLinkDefinition joinedItemDefinition, RootHibernateQuery hibernateQuery) throws QueryException {
Condition condition = null;
if (joinedItemDefinition instanceof JpaAnyPropertyLinkDefinition) {
Expand Down

0 comments on commit f6f74c6

Please sign in to comment.