Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up support for Equal(x, y) a bit. Not really finished yet.
- Loading branch information
Showing
16 changed files
with
301 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query2/HqlDataInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2010-2015 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.query2; | ||
|
||
import com.evolveum.midpoint.repo.sql.query2.definition.JpaDataNodeDefinition; | ||
import com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition; | ||
import com.evolveum.midpoint.util.DebugDumpable; | ||
import com.evolveum.midpoint.util.DebugUtil; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import org.apache.commons.lang.Validate; | ||
|
||
/** | ||
* Describes result of ItemPath resolution: HQL property path + current data node definition. | ||
* Points to parent data item (i.e. the one that corresponds to parent ItemPath translation), | ||
* just in case we would like to go back via ".." operator. | ||
* | ||
* This differs from JpaDefinitions in that it points to a specific HQL property used in the | ||
* query being constructed. | ||
* | ||
* This object is unmodifiable. | ||
* | ||
* @author mederly | ||
*/ | ||
public class HqlDataInstance<D extends JpaDataNodeDefinition> implements DebugDumpable { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(HqlDataInstance.class); | ||
|
||
final protected String hqlPath; | ||
final protected D jpaDefinition; | ||
final protected HqlDataInstance parentDataItem; // optional | ||
|
||
public HqlDataInstance(String hqlPath, D jpaDefinition, | ||
HqlDataInstance parentDataItem) { | ||
Validate.notNull(hqlPath, "hqlPath"); | ||
Validate.notNull(jpaDefinition, "jpaDefinition"); | ||
this.hqlPath = hqlPath; | ||
this.jpaDefinition = jpaDefinition; | ||
this.parentDataItem = parentDataItem; | ||
} | ||
|
||
public String getHqlPath() { | ||
return hqlPath; | ||
} | ||
|
||
public D getJpaDefinition() { | ||
return jpaDefinition; | ||
} | ||
|
||
public HqlDataInstance getParentItem() { | ||
return parentDataItem; | ||
} | ||
|
||
@Override | ||
public String debugDump() { | ||
return debugDump(0); | ||
} | ||
|
||
public String debugDumpNoParent() { | ||
return debugDump(0, false); | ||
} | ||
|
||
@Override | ||
public String debugDump(int indent) { | ||
return debugDump(indent, true); | ||
} | ||
|
||
public String debugDump(int indent, boolean showParent) { | ||
StringBuilder sb = new StringBuilder(); | ||
DebugUtil.indentDebugDump(sb, indent); | ||
sb.append("HqlDataInstance:\n"); | ||
DebugUtil.indentDebugDump(sb, indent + 1); | ||
sb.append("HQL path: ").append(hqlPath).append("\n"); | ||
DebugUtil.indentDebugDump(sb, indent + 1); | ||
sb.append("JPA definition: ").append(jpaDefinition).append("\n"); | ||
DebugUtil.indentDebugDump(sb, indent + 1); | ||
sb.append("Previous result: "); | ||
if (parentDataItem != null) { | ||
if (showParent) { | ||
sb.append("\n"); | ||
sb.append(parentDataItem.debugDump(indent + 2)); | ||
} else { | ||
sb.append(parentDataItem).append("\n"); | ||
} | ||
} else { | ||
sb.append("(null)\n"); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HqlDataInstance{" + | ||
"hqlPath='" + hqlPath + '\'' + | ||
", jpaDefinition=" + jpaDefinition + | ||
", parentDataItem=(" + (parentDataItem != null ? parentDataItem.hqlPath : "none") + | ||
")}"; | ||
} | ||
|
||
public HqlEntityInstance asHqlEntityInstance() { | ||
return new HqlEntityInstance(hqlPath, (JpaEntityDefinition) jpaDefinition, parentDataItem); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/query2/HqlEntityInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2010-2015 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.query2; | ||
|
||
import com.evolveum.midpoint.repo.sql.query2.definition.JpaEntityDefinition; | ||
import org.apache.commons.lang.Validate; | ||
|
||
/** | ||
* @author mederly | ||
*/ | ||
public class HqlEntityInstance extends HqlDataInstance<JpaEntityDefinition> { | ||
|
||
public HqlEntityInstance(String hqlPath, JpaEntityDefinition jpaDefinition, HqlDataInstance parentPropertyPath) { | ||
super(hqlPath, jpaDefinition, parentPropertyPath); | ||
} | ||
|
||
public HqlEntityInstance narrowFor(JpaEntityDefinition overridingDefinition) { | ||
Validate.notNull(overridingDefinition, "overridingDefinition"); | ||
|
||
if (overridingDefinition.isAssignableFrom(jpaDefinition)) { | ||
// nothing to do here | ||
return this; | ||
} else if (jpaDefinition.isAssignableFrom(overridingDefinition)) { | ||
return new HqlEntityInstance(hqlPath, overridingDefinition, parentDataItem); | ||
} else { | ||
throw new IllegalStateException("Illegal attempt to narrow entity definition: from " + jpaDefinition + | ||
" to " + overridingDefinition + ". These two definitions are not compatible."); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.