Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from barmintor/reduceLookups
Reduce node lookups in event processing Resolves: https://www.pivotaltracker.com/story/show/61411396
- Loading branch information
Showing
8 changed files
with
259 additions
and
119 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
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
41 changes: 41 additions & 0 deletions
41
fcrepo-kernel/src/main/java/org/fcrepo/kernel/services/functions/AllTypesPredicate.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,41 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* 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 org.fcrepo.kernel.services.functions; | ||
|
||
/** | ||
* Predicate to match nodes with all of the given mixin types | ||
* @author armintor@gmail.com | ||
* | ||
*/ | ||
public class AllTypesPredicate extends BooleanTypesPredicate { | ||
|
||
private final int test; | ||
|
||
/** | ||
* True if all the types specified match. | ||
* @param types | ||
*/ | ||
public AllTypesPredicate(String...types) { | ||
super(types); | ||
this.test = types.length; | ||
} | ||
|
||
@Override | ||
protected boolean test(final int matched) { | ||
return matched == test; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
fcrepo-kernel/src/main/java/org/fcrepo/kernel/services/functions/AnyTypesPredicate.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,38 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* 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 org.fcrepo.kernel.services.functions; | ||
|
||
|
||
/** | ||
* Predicate to match nodes with any of the given mixin types | ||
* @author armintor@gmail.com | ||
* | ||
*/ | ||
public class AnyTypesPredicate extends BooleanTypesPredicate { | ||
/** | ||
* True if any of the types specified match. | ||
* @param types | ||
*/ | ||
public AnyTypesPredicate(String...types) { | ||
super(types); | ||
} | ||
|
||
@Override | ||
protected boolean test(final int matched) { | ||
return matched > 0; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
fcrepo-kernel/src/main/java/org/fcrepo/kernel/services/functions/BooleanTypesPredicate.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,68 @@ | ||
/** | ||
* Copyright 2013 DuraSpace, Inc. | ||
* | ||
* 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 org.fcrepo.kernel.services.functions; | ||
|
||
import static com.google.common.base.Throwables.propagate; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.nodetype.NodeType; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
/** | ||
* Base class for matching sets of node types | ||
* @author armintor@gmail.com | ||
* | ||
*/ | ||
public abstract class BooleanTypesPredicate implements Predicate<Node> { | ||
|
||
protected final Collection<String> nodeTypes; | ||
|
||
/** | ||
* Base constructor for function peforming boolean ops on matched node types. | ||
* @param types | ||
*/ | ||
public BooleanTypesPredicate(String... types) { | ||
nodeTypes = Arrays.asList(types); | ||
} | ||
|
||
@Override | ||
public boolean apply(Node input) { | ||
if (input == null) { | ||
throw new IllegalArgumentException( | ||
"null node passed to" + getClass().getName() | ||
); | ||
} | ||
int matched = 0; | ||
try { | ||
for (NodeType nodeType: input.getMixinNodeTypes()) { | ||
if (nodeTypes.contains(nodeType.getName())) { | ||
matched++; | ||
} | ||
} | ||
} catch (RepositoryException e) { | ||
propagate(e); | ||
} | ||
return test(matched); | ||
} | ||
|
||
protected abstract boolean test(int matched); | ||
|
||
} |
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.