http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java index 8bf36ed..e702e64 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/AccumuloRyaUtils.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.util; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. - * #L% + * 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.apache.rya.accumulo.mr.merge.util; import java.io.IOException; import java.text.ParseException; @@ -45,6 +43,7 @@ import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.Filter; import org.apache.accumulo.core.iterators.user.RegExFilter; import org.apache.accumulo.core.security.Authorizations; import org.apache.commons.lang.StringUtils; @@ -112,7 +111,7 @@ public final class AccumuloRyaUtils { * @param localName the URI's local name. * @return the {@link RyraURI}. */ - public static RyaURI createRyaUri(String localName) { + public static RyaURI createRyaUri(final String localName) { return createRyaUri(NAMESPACE, localName); } @@ -122,7 +121,7 @@ public final class AccumuloRyaUtils { * @param localName the URI's local name. * @return the {@link RyraURI}. */ - public static RyaURI createRyaUri(String namespace, String localName) { + public static RyaURI createRyaUri(final String namespace, final String localName) { return RdfToRyaConversions.convertURI(VALUE_FACTORY.createURI(namespace, localName)); } @@ -131,9 +130,9 @@ public final class AccumuloRyaUtils { * @param date the copy tool run time {@link Date}. * @return the {@link RyaStatement} for the copy tool run time. */ - public static RyaStatement createCopyToolRunTimeRyaStatement(Date date) { - Literal literal = VALUE_FACTORY.createLiteral(date != null ? date : DEFAULT_DATE); - RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); + public static RyaStatement createCopyToolRunTimeRyaStatement(final Date date) { + final Literal literal = VALUE_FACTORY.createLiteral(date != null ? date : DEFAULT_DATE); + final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_COPY_TOOL_RUN_TIME_PREDICATE_RYA, timeObject); } @@ -142,9 +141,9 @@ public final class AccumuloRyaUtils { * @param date the copy tool split time {@link Date}. * @return the {@link RyaStatement} for the copy tool split time. */ - public static RyaStatement createCopyToolSplitTimeRyaStatement(Date date) { - Literal literal = VALUE_FACTORY.createLiteral(date != null ? date : DEFAULT_DATE); - RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); + public static RyaStatement createCopyToolSplitTimeRyaStatement(final Date date) { + final Literal literal = VALUE_FACTORY.createLiteral(date != null ? date : DEFAULT_DATE); + final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_COPY_TOOL_SPLIT_TIME_PREDICATE_RYA, timeObject); } @@ -154,13 +153,13 @@ public final class AccumuloRyaUtils { * @return the copy tool run {@link Date}. * @throws RyaDAOException */ - public static Date getCopyToolRunDate(AccumuloRyaDAO dao) throws RyaDAOException { - String time = getCopyToolRunTime(dao); + public static Date getCopyToolRunDate(final AccumuloRyaDAO dao) throws RyaDAOException { + final String time = getCopyToolRunTime(dao); Date date = null; if (time != null) { try { date = TIME_FORMATTER.parse(time); - } catch (ParseException e) { + } catch (final ParseException e) { log.error("Unable to parse the copy tool run time found in table: " + time, e); } } @@ -173,13 +172,13 @@ public final class AccumuloRyaUtils { * @return the copy tool split {@link Date}. * @throws RyaDAOException */ - public static Date getCopyToolSplitDate(AccumuloRyaDAO dao) throws RyaDAOException { - String time = getCopyToolSplitTime(dao); + public static Date getCopyToolSplitDate(final AccumuloRyaDAO dao) throws RyaDAOException { + final String time = getCopyToolSplitTime(dao); Date date = null; if (time != null) { try { date = TIME_FORMATTER.parse(time); - } catch (ParseException e) { + } catch (final ParseException e) { log.error("Unable to parse the copy tool split time found in table: " + time, e); } } @@ -192,7 +191,7 @@ public final class AccumuloRyaUtils { * @return the copy tool run time value. * @throws RyaDAOException */ - public static String getCopyToolRunTime(AccumuloRyaDAO dao) throws RyaDAOException { + public static String getCopyToolRunTime(final AccumuloRyaDAO dao) throws RyaDAOException { return getMetadata(RTS_COPY_TOOL_RUN_TIME_PREDICATE_RYA, dao); } @@ -202,7 +201,7 @@ public final class AccumuloRyaUtils { * @return the copy tool split time value. * @throws RyaDAOException */ - public static String getCopyToolSplitTime(AccumuloRyaDAO dao) throws RyaDAOException { + public static String getCopyToolSplitTime(final AccumuloRyaDAO dao) throws RyaDAOException { return getMetadata(RTS_COPY_TOOL_SPLIT_TIME_PREDICATE_RYA, dao); } @@ -213,8 +212,8 @@ public final class AccumuloRyaUtils { * @return the string value of the object from the metadata key. * @throws RyaDAOException */ - private static String getMetadata(RyaURI predicateRyaUri, AccumuloRyaDAO dao) throws RyaDAOException { - RyaStatement ryaStatement = new RyaStatement(RTS_SUBJECT_RYA, predicateRyaUri, null); + private static String getMetadata(final RyaURI predicateRyaUri, final AccumuloRyaDAO dao) throws RyaDAOException { + final RyaStatement ryaStatement = new RyaStatement(RTS_SUBJECT_RYA, predicateRyaUri, null); return getMetadata(ryaStatement, dao); } @@ -225,10 +224,10 @@ public final class AccumuloRyaUtils { * @return the string value of the object from the metadata key. * @throws RyaDAOException */ - private static String getMetadata(RyaStatement ryaStatement, AccumuloRyaDAO dao) throws RyaDAOException { + private static String getMetadata(final RyaStatement ryaStatement, final AccumuloRyaDAO dao) throws RyaDAOException { String metadata = null; - AccumuloRdfConfiguration config = dao.getConf(); - CloseableIteration<RyaStatement, RyaDAOException> iter = dao.getQueryEngine().query(ryaStatement, config); + final AccumuloRdfConfiguration config = dao.getConf(); + final CloseableIteration<RyaStatement, RyaDAOException> iter = dao.getQueryEngine().query(ryaStatement, config); if (iter.hasNext()) { metadata = iter.next().getObject().getData(); } @@ -243,8 +242,8 @@ public final class AccumuloRyaUtils { * @param dao the {@link AccumuloRyaDAO}. * @throws RyaDAOException */ - public static RyaStatement setCopyToolRunDate(Date date, AccumuloRyaDAO dao) throws RyaDAOException { - RyaStatement ryaStatement = createCopyToolRunTimeRyaStatement(date); + public static RyaStatement setCopyToolRunDate(final Date date, final AccumuloRyaDAO dao) throws RyaDAOException { + final RyaStatement ryaStatement = createCopyToolRunTimeRyaStatement(date); dao.add(ryaStatement); return ryaStatement; } @@ -255,8 +254,8 @@ public final class AccumuloRyaUtils { * @param dao the {@link AccumuloRyaDAO}. * @throws RyaDAOException */ - public static RyaStatement setCopyToolSplitDate(Date date, AccumuloRyaDAO dao) throws RyaDAOException { - RyaStatement ryaStatement = createCopyToolSplitTimeRyaStatement(date); + public static RyaStatement setCopyToolSplitDate(final Date date, final AccumuloRyaDAO dao) throws RyaDAOException { + final RyaStatement ryaStatement = createCopyToolSplitTimeRyaStatement(date); dao.add(ryaStatement); return ryaStatement; } @@ -267,11 +266,11 @@ public final class AccumuloRyaUtils { * @param dao the {@link AccumuloRyaDAO}. * @throws RyaDAOException */ - public static RyaStatement setCopyToolRunTime(String time, AccumuloRyaDAO dao) throws RyaDAOException { + public static RyaStatement setCopyToolRunTime(final String time, final AccumuloRyaDAO dao) throws RyaDAOException { Date date = null; try { date = TIME_FORMATTER.parse(time); - } catch (ParseException e) { + } catch (final ParseException e) { log.error("Unable to parse the copy tool run time: ", e); } return setCopyToolRunDate(date, dao); @@ -283,11 +282,11 @@ public final class AccumuloRyaUtils { * @param dao the {@link AccumuloRyaDAO}. * @throws RyaDAOException */ - public static RyaStatement setCopyToolSplitTime(String time, AccumuloRyaDAO dao) throws RyaDAOException { + public static RyaStatement setCopyToolSplitTime(final String time, final AccumuloRyaDAO dao) throws RyaDAOException { Date date = null; try { date = TIME_FORMATTER.parse(time); - } catch (ParseException e) { + } catch (final ParseException e) { log.error("Unable to parse the copy tool split time: ", e); } return setCopyToolSplitDate(date, dao); @@ -298,9 +297,9 @@ public final class AccumuloRyaUtils { * @return the {@link RegExFilter} {@link IteratorSetting}. */ public static IteratorSetting getVersionRegExFilterSetting() { - IteratorSetting regex = new IteratorSetting(30, "version_regex", RegExFilter.class); + final IteratorSetting regex = new IteratorSetting(30, "version_regex", RegExFilter.class); RegExFilter.setRegexs(regex, "(.*)urn:(.*)#version[\u0000|\u0001](.*)", null, null, null, false); - RegExFilter.setNegate(regex, true); + Filter.setNegate(regex, true); return regex; } @@ -309,9 +308,9 @@ public final class AccumuloRyaUtils { * @return the {@link RegExFilter} {@link IteratorSetting}. */ public static IteratorSetting getCopyToolRunTimeRegExFilterSetting() { - IteratorSetting regex = new IteratorSetting(31, COPY_TOOL_RUN_TIME_LOCAL_NAME + "_regex", RegExFilter.class); + final IteratorSetting regex = new IteratorSetting(31, COPY_TOOL_RUN_TIME_LOCAL_NAME + "_regex", RegExFilter.class); RegExFilter.setRegexs(regex, "(.*)urn:(.*)#" + COPY_TOOL_RUN_TIME_LOCAL_NAME + "[\u0000|\u0001](.*)", null, null, null, false); - RegExFilter.setNegate(regex, true); + Filter.setNegate(regex, true); return regex; } @@ -320,9 +319,9 @@ public final class AccumuloRyaUtils { * @return the {@link RegExFilter} {@link IteratorSetting}. */ public static IteratorSetting getCopyToolSplitTimeRegExFilterSetting() { - IteratorSetting regex = new IteratorSetting(32, COPY_TOOL_SPLIT_TIME_LOCAL_NAME + "_regex", RegExFilter.class); + final IteratorSetting regex = new IteratorSetting(32, COPY_TOOL_SPLIT_TIME_LOCAL_NAME + "_regex", RegExFilter.class); RegExFilter.setRegexs(regex, "(.*)urn:(.*)#" + COPY_TOOL_SPLIT_TIME_LOCAL_NAME + "[\u0000|\u0001](.*)", null, null, null, false); - RegExFilter.setNegate(regex, true); + Filter.setNegate(regex, true); return regex; } @@ -331,9 +330,9 @@ public final class AccumuloRyaUtils { * @return the {@link RegExFilter} {@link IteratorSetting}. */ public static IteratorSetting getCopyToolTimeOffsetRegExFilterSetting() { - IteratorSetting regex = new IteratorSetting(33, COPY_TOOL_TIME_OFFSET_LOCAL_NAME + "_regex", RegExFilter.class); + final IteratorSetting regex = new IteratorSetting(33, COPY_TOOL_TIME_OFFSET_LOCAL_NAME + "_regex", RegExFilter.class); RegExFilter.setRegexs(regex, "(.*)urn:(.*)#" + COPY_TOOL_TIME_OFFSET_LOCAL_NAME + "[\u0000|\u0001](.*)", null, null, null, false); - RegExFilter.setNegate(regex, true); + Filter.setNegate(regex, true); return regex; } @@ -342,8 +341,8 @@ public final class AccumuloRyaUtils { * certain metadata keys in a table are ignored. * @param scanner the {@link Scanner} to add the regex filter {@link IteratorSetting}s to. */ - public static void addCommonScannerIteratorsTo(Scanner scanner) { - for (IteratorSetting iteratorSetting : COMMON_REG_EX_FILTER_SETTINGS) { + public static void addCommonScannerIteratorsTo(final Scanner scanner) { + for (final IteratorSetting iteratorSetting : COMMON_REG_EX_FILTER_SETTINGS) { scanner.addScanIterator(iteratorSetting); } } @@ -356,7 +355,7 @@ public final class AccumuloRyaUtils { * @return the {@link Scanner} for the table. * @throws IOException */ - public static Scanner getScanner(String tableName, Configuration config) throws IOException { + public static Scanner getScanner(final String tableName, final Configuration config) throws IOException { return getScanner(tableName, config, true); } @@ -369,22 +368,22 @@ public final class AccumuloRyaUtils { * @return the {@link Scanner} for the table. * @throws IOException */ - public static Scanner getScanner(String tableName, Configuration config, boolean shouldAddCommonIterators) throws IOException { + public static Scanner getScanner(final String tableName, final Configuration config, final boolean shouldAddCommonIterators) throws IOException { try { - String instanceName = config.get(ConfigUtils.CLOUDBASE_INSTANCE); - String zooKeepers = config.get(ConfigUtils.CLOUDBASE_ZOOKEEPERS); + final String instanceName = config.get(ConfigUtils.CLOUDBASE_INSTANCE); + final String zooKeepers = config.get(ConfigUtils.CLOUDBASE_ZOOKEEPERS); Instance instance; if (ConfigUtils.useMockInstance(config)) { instance = new MockInstance(config.get(ConfigUtils.CLOUDBASE_INSTANCE)); } else { instance = new ZooKeeperInstance(new ClientConfiguration().withInstance(instanceName).withZkHosts(zooKeepers)); } - String username = ConfigUtils.getUsername(config); - String password = ConfigUtils.getPassword(config); - Connector connector = instance.getConnector(username, new PasswordToken(password)); - Authorizations auths = ConfigUtils.getAuthorizations(config); + final String username = ConfigUtils.getUsername(config); + final String password = ConfigUtils.getPassword(config); + final Connector connector = instance.getConnector(username, new PasswordToken(password)); + final Authorizations auths = ConfigUtils.getAuthorizations(config); - Scanner scanner = connector.createScanner(tableName, auths); + final Scanner scanner = connector.createScanner(tableName, auths); if (shouldAddCommonIterators) { AccumuloRyaUtils.addCommonScannerIteratorsTo(scanner); } @@ -403,7 +402,7 @@ public final class AccumuloRyaUtils { * @param settings the additional {@link IteratorSetting}s to add besides the common ones. * @throws IOException */ - public static void printTable(String tableName, AccumuloRdfConfiguration config, IteratorSetting... settings) throws IOException { + public static void printTable(final String tableName, final AccumuloRdfConfiguration config, final IteratorSetting... settings) throws IOException { printTable(tableName, config, true, settings); } @@ -416,35 +415,35 @@ public final class AccumuloRyaUtils { * @param settings the additional {@link IteratorSetting}s to add besides the common ones. * @throws IOException */ - public static void printTable(String tableName, AccumuloRdfConfiguration config, boolean shouldAddCommonIterators, IteratorSetting... settings) throws IOException { - Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators); - for (IteratorSetting setting : settings) { + public static void printTable(final String tableName, final AccumuloRdfConfiguration config, final boolean shouldAddCommonIterators, final IteratorSetting... settings) throws IOException { + final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators); + for (final IteratorSetting setting : settings) { scanner.addScanIterator(setting); } - Iterator<Entry<Key, Value>> iterator = scanner.iterator(); + final Iterator<Entry<Key, Value>> iterator = scanner.iterator(); - String instance = config.get(MRUtils.AC_INSTANCE_PROP); + final String instance = config.get(MRUtils.AC_INSTANCE_PROP); log.info("=================="); log.info("TABLE: " + tableName + " INSTANCE: " + instance); log.info("------------------"); while (iterator.hasNext()) { - Entry<Key, Value> entry = iterator.next(); - Key key = entry.getKey(); - Value value = entry.getValue(); - String keyString = getFormattedKeyString(key); + final Entry<Key, Value> entry = iterator.next(); + final Key key = entry.getKey(); + final Value value = entry.getValue(); + final String keyString = getFormattedKeyString(key); log.info(keyString + " - " + value); } log.info("=================="); } - private static String getFormattedKeyString(Key key) { - StringBuilder sb = new StringBuilder(); - byte[] row = key.getRow().getBytes(); - byte[] colFamily = key.getColumnFamily().getBytes(); - byte[] colQualifier = key.getColumnQualifier().getBytes(); - byte[] colVisibility = key.getColumnVisibility().getBytes(); - int maxRowDataToPrint = 256; + private static String getFormattedKeyString(final Key key) { + final StringBuilder sb = new StringBuilder(); + final byte[] row = key.getRow().getBytes(); + final byte[] colFamily = key.getColumnFamily().getBytes(); + final byte[] colQualifier = key.getColumnQualifier().getBytes(); + final byte[] colVisibility = key.getColumnVisibility().getBytes(); + final int maxRowDataToPrint = 256; Key.appendPrintableString(row, 0, row.length, maxRowDataToPrint, sb); sb.append(" "); Key.appendPrintableString(colFamily, 0, colFamily.length, maxRowDataToPrint, sb); @@ -469,7 +468,7 @@ public final class AccumuloRyaUtils { * @param settings the additional {@link IteratorSetting}s to add besides the common ones. * @throws IOException */ - public static void printTablePretty(String tableName, Configuration config, IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException { + public static void printTablePretty(final String tableName, final Configuration config, final IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException { printTablePretty(tableName, config, true, settings); } @@ -482,23 +481,23 @@ public final class AccumuloRyaUtils { * @param settings the additional {@link IteratorSetting}s to add besides the common ones. * @throws IOException */ - public static void printTablePretty(String tableName, Configuration config, boolean shouldAddCommonIterators, IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException { - Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators); - for (IteratorSetting setting : settings) { + public static void printTablePretty(final String tableName, final Configuration config, final boolean shouldAddCommonIterators, final IteratorSetting... settings) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException { + final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config, shouldAddCommonIterators); + for (final IteratorSetting setting : settings) { scanner.addScanIterator(setting); } - String format = "| %-64s | %-24s | %-28s | %-20s | %-20s | %-10s |"; - int totalFormatLength = String.format(format, 1, 2, 3, 4, 5, 6).length(); - String instance = config.get(MRUtils.AC_INSTANCE_PROP); + final String format = "| %-64s | %-24s | %-28s | %-20s | %-20s | %-10s |"; + final int totalFormatLength = String.format(format, 1, 2, 3, 4, 5, 6).length(); + final String instance = config.get(MRUtils.AC_INSTANCE_PROP); log.info(StringUtils.rightPad("==================", totalFormatLength, "=")); log.info(StringUtils.rightPad("| TABLE: " + tableName + " INSTANCE: " + instance, totalFormatLength - 1) + "|"); log.info(StringUtils.rightPad("------------------", totalFormatLength, "-")); log.info(String.format(format, "--Row--", "--ColumnVisibility--", "--Timestamp--", "--ColumnFamily--", "--ColumnQualifier--", "--Value--")); log.info(StringUtils.rightPad("|-----------------", totalFormatLength - 1, "-") + "|"); - for (Entry<Key, Value> entry : scanner) { - Key k = entry.getKey(); - String rowString = Key.appendPrintableString(k.getRow().getBytes(), 0, k.getRow().getLength(), Constants.MAX_DATA_TO_PRINT, new StringBuilder()).toString(); + for (final Entry<Key, Value> entry : scanner) { + final Key k = entry.getKey(); + final String rowString = Key.appendPrintableString(k.getRow().getBytes(), 0, k.getRow().getLength(), Constants.MAX_DATA_TO_PRINT, new StringBuilder()).toString(); log.info(String.format(format, rowString, k.getColumnVisibility(), new Date(k.getTimestamp()), k.getColumnFamily(), k.getColumnQualifier(), entry.getValue())); } log.info(StringUtils.rightPad("==================", totalFormatLength, "=")); @@ -513,10 +512,10 @@ public final class AccumuloRyaUtils { * @throws AccumuloException * @throws AccumuloSecurityException */ - public static Authorizations addUserAuths(String user, SecurityOperations secOps, Authorizations auths) throws AccumuloException, AccumuloSecurityException { - List<String> authList = new ArrayList<>(); - for (byte[] authBytes : auths.getAuthorizations()) { - String auth = new String(authBytes); + public static Authorizations addUserAuths(final String user, final SecurityOperations secOps, final Authorizations auths) throws AccumuloException, AccumuloSecurityException { + final List<String> authList = new ArrayList<>(); + for (final byte[] authBytes : auths.getAuthorizations()) { + final String auth = new String(authBytes); authList.add(auth); } return addUserAuths(user, secOps, authList.toArray(new String[0])); @@ -531,16 +530,16 @@ public final class AccumuloRyaUtils { * @throws AccumuloException * @throws AccumuloSecurityException */ - public static Authorizations addUserAuths(String user, SecurityOperations secOps, String... auths) throws AccumuloException, AccumuloSecurityException { - Authorizations currentUserAuths = secOps.getUserAuthorizations(user); - List<byte[]> authList = new ArrayList<>(); - for (byte[] currentAuth : currentUserAuths.getAuthorizations()) { + public static Authorizations addUserAuths(final String user, final SecurityOperations secOps, final String... auths) throws AccumuloException, AccumuloSecurityException { + final Authorizations currentUserAuths = secOps.getUserAuthorizations(user); + final List<byte[]> authList = new ArrayList<>(); + for (final byte[] currentAuth : currentUserAuths.getAuthorizations()) { authList.add(currentAuth); } - for (String newAuth : auths) { + for (final String newAuth : auths) { authList.add(newAuth.getBytes()); } - Authorizations result = new Authorizations(authList); + final Authorizations result = new Authorizations(authList); return result; } @@ -552,15 +551,15 @@ public final class AccumuloRyaUtils { * @throws AccumuloSecurityException * @throws AccumuloException */ - public static void removeUserAuths(String userName, SecurityOperations secOps, String authsToRemove) throws AccumuloException, AccumuloSecurityException { - Authorizations currentUserAuths = secOps.getUserAuthorizations(userName); - List<String> authList = convertAuthStringToList(currentUserAuths.toString()); + public static void removeUserAuths(final String userName, final SecurityOperations secOps, final String authsToRemove) throws AccumuloException, AccumuloSecurityException { + final Authorizations currentUserAuths = secOps.getUserAuthorizations(userName); + final List<String> authList = convertAuthStringToList(currentUserAuths.toString()); - List<String> authsToRemoveList = convertAuthStringToList(authsToRemove); + final List<String> authsToRemoveList = convertAuthStringToList(authsToRemove); authList.removeAll(authsToRemoveList); - String authString = Joiner.on(",").join(authList); - Authorizations newAuths = new Authorizations(authString); + final String authString = Joiner.on(",").join(authList); + final Authorizations newAuths = new Authorizations(authString); secOps.changeUserAuthorizations(userName, newAuths); } @@ -570,10 +569,10 @@ public final class AccumuloRyaUtils { * @param authString the comma-separated string of authorizations. * @return a {@link List} of authorization strings. */ - public static List<String> convertAuthStringToList(String authString) { - List<String> authList = new ArrayList<>(); + public static List<String> convertAuthStringToList(final String authString) { + final List<String> authList = new ArrayList<>(); if (authString != null) { - String[] authSplit = authString.split(","); + final String[] authSplit = authString.split(","); authList.addAll(Arrays.asList(authSplit)); } return authList; @@ -584,7 +583,7 @@ public final class AccumuloRyaUtils { * @param accumuloRdfConfiguration the {@link AccumuloRdfConfiguration}. * @return the {@link Connector}. */ - public static Connector setupConnector(AccumuloRdfConfiguration accumuloRdfConfiguration) { + public static Connector setupConnector(final AccumuloRdfConfiguration accumuloRdfConfiguration) { Connector connector = null; try { connector = ConfigUtils.getConnector(accumuloRdfConfiguration); @@ -600,8 +599,8 @@ public final class AccumuloRyaUtils { * @param connector the {@link Connector}. * @return the {@link AccumuloRyaDAO}. */ - public static AccumuloRyaDAO setupDao(AccumuloRdfConfiguration accumuloRdfConfiguration) { - Connector connector = setupConnector(accumuloRdfConfiguration); + public static AccumuloRyaDAO setupDao(final AccumuloRdfConfiguration accumuloRdfConfiguration) { + final Connector connector = setupConnector(accumuloRdfConfiguration); return setupDao(connector, accumuloRdfConfiguration); } @@ -611,14 +610,14 @@ public final class AccumuloRyaUtils { * @param accumuloRdfConfiguration the {@link AccumuloRdfConfiguration}. * @return the {@link AccumuloRyaDAO}. */ - public static AccumuloRyaDAO setupDao(Connector connector, AccumuloRdfConfiguration accumuloRdfConfiguration) { - AccumuloRyaDAO accumuloRyaDao = new AccumuloRyaDAO(); + public static AccumuloRyaDAO setupDao(final Connector connector, final AccumuloRdfConfiguration accumuloRdfConfiguration) { + final AccumuloRyaDAO accumuloRyaDao = new AccumuloRyaDAO(); accumuloRyaDao.setConnector(connector); accumuloRyaDao.setConf(accumuloRdfConfiguration); try { accumuloRyaDao.init(); - } catch (RyaDAOException e) { + } catch (final RyaDAOException e) { log.error("Error initializing DAO", e); } @@ -630,9 +629,9 @@ public final class AccumuloRyaUtils { * @param timeOffset the copy tool parent time offset. (in milliseconds). * @return the {@link RyaStatement} for the copy tool parent time offset. */ - public static RyaStatement createTimeOffsetRyaStatement(long timeOffset) { - Literal literal = VALUE_FACTORY.createLiteral(timeOffset); - RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); + public static RyaStatement createTimeOffsetRyaStatement(final long timeOffset) { + final Literal literal = VALUE_FACTORY.createLiteral(timeOffset); + final RyaType timeObject = new RyaType(literal.getDatatype(), literal.stringValue()); return new RyaStatement(RTS_SUBJECT_RYA, RTS_TIME_OFFSET_PREDICATE_RYA, timeObject); } @@ -643,8 +642,8 @@ public final class AccumuloRyaUtils { * the NTP server's time or {@code null}. * @throws RyaDAOException */ - public static Long getTimeOffset(AccumuloRyaDAO dao) throws RyaDAOException { - String timeOffsetString = getMetadata(RTS_TIME_OFFSET_PREDICATE_RYA, dao); + public static Long getTimeOffset(final AccumuloRyaDAO dao) throws RyaDAOException { + final String timeOffsetString = getMetadata(RTS_TIME_OFFSET_PREDICATE_RYA, dao); Long timeOffset = null; if (timeOffsetString != null) { timeOffset = Long.valueOf(timeOffsetString); @@ -659,8 +658,8 @@ public final class AccumuloRyaUtils { * @param dao the {@link AccumuloRyaDAO}. * @throws RyaDAOException */ - public static RyaStatement setTimeOffset(long timeOffset, AccumuloRyaDAO dao) throws RyaDAOException { - RyaStatement ryaStatement = createTimeOffsetRyaStatement(timeOffset); + public static RyaStatement setTimeOffset(final long timeOffset, final AccumuloRyaDAO dao) throws RyaDAOException { + final RyaStatement ryaStatement = createTimeOffsetRyaStatement(timeOffset); dao.add(ryaStatement); return ryaStatement; }
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/CopyRule.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/CopyRule.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/CopyRule.java index eaf3636..2f78efa 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/CopyRule.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/CopyRule.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.util; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. - * #L% + * 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.apache.rya.accumulo.mr.merge.util; import java.util.HashMap; import java.util.Map; @@ -66,9 +64,9 @@ public class CopyRule extends QueryModelNodeBase { * @throws ValueExprEvaluationException * @throws QueryEvaluationException */ - public static boolean accept(Statement stmt, ValueExpr condition, EvaluationStrategy strategy) + public static boolean accept(final Statement stmt, final ValueExpr condition, final EvaluationStrategy strategy) throws ValueExprEvaluationException, QueryEvaluationException { - QueryBindingSet bindings = new QueryBindingSet(); + final QueryBindingSet bindings = new QueryBindingSet(); bindings.addBinding(SUBJ_VAR.getName(), stmt.getSubject()); bindings.addBinding(PRED_VAR.getName(), stmt.getPredicate()); bindings.addBinding(OBJ_VAR.getName(), stmt.getObject()); @@ -85,13 +83,13 @@ public class CopyRule extends QueryModelNodeBase { * @param expr Condition to be evaluated * @return true if the condition is trivial */ - private static boolean trivialCondition(ValueExpr expr) { + private static boolean trivialCondition(final ValueExpr expr) { // If the expression is null or the constant "true": if (expr == null || expr.equals(TRUE)) { return true; } // If the expression contains undefined variables: - VarSearchVisitor visitor = new VarSearchVisitor(UNDEFINED_VAR.getName()); + final VarSearchVisitor visitor = new VarSearchVisitor(UNDEFINED_VAR.getName()); expr.visit(visitor); if (visitor.found) { return true; @@ -105,18 +103,18 @@ public class CopyRule extends QueryModelNodeBase { */ private static class VarSearchVisitor extends QueryModelVisitorBase<RuntimeException> { boolean found = false; - private String queryVar; - public VarSearchVisitor(String queryVar) { + private final String queryVar; + public VarSearchVisitor(final String queryVar) { this.queryVar = queryVar; } @Override - public void meet(Var var) { + public void meet(final Var var) { if (queryVar.equals(var.getName())) { found = true; } } @Override - public void meetNode(QueryModelNode node) { + public void meetNode(final QueryModelNode node) { if (!found) { node.visitChildren(this); } @@ -129,13 +127,13 @@ public class CopyRule extends QueryModelNodeBase { * conditions. */ private static class RuleVisitor extends QueryModelVisitorBase<RuntimeException> { - private CopyRule rule; - RuleVisitor(CopyRule rule) { + private final CopyRule rule; + RuleVisitor(final CopyRule rule) { this.rule = rule; } @Override - public void meet(Var node) { - String oldName = node.getName(); + public void meet(final Var node) { + final String oldName = node.getName(); if (rule.varMap.containsKey(oldName)) { node.setName(rule.varMap.get(oldName).getName()); } @@ -153,12 +151,12 @@ public class CopyRule extends QueryModelNodeBase { * we must assume the statement is relevant. Otherwise, keep both sides. */ @Override - public void meet(And expr) { - ValueExpr left = expr.getLeftArg(); - ValueExpr right = expr.getRightArg(); + public void meet(final And expr) { + final ValueExpr left = expr.getLeftArg(); + final ValueExpr right = expr.getRightArg(); left.visit(this); right.visit(this); - QueryModelNode parent = expr.getParentNode(); + final QueryModelNode parent = expr.getParentNode(); if (trivialCondition(left)) { if (trivialCondition(right)) { // Both sides are trivial; replace whole node @@ -177,22 +175,22 @@ public class CopyRule extends QueryModelNodeBase { } } - private StatementPattern statement; + private final StatementPattern statement; private ValueExpr condition; - private Map<String, Var> varMap = new HashMap<>(); - private RuleVisitor visitor = new RuleVisitor(this); + private final Map<String, Var> varMap = new HashMap<>(); + private final RuleVisitor visitor = new RuleVisitor(this); /** * Instantiate a rule containing a StatementPattern, renaming any variables to canonical * subject/predicate/object forms and saving the mappings from the original variable names. * @param sp StatementPattern defining a set of triples to match */ - public CopyRule(StatementPattern sp) throws QueryRulesetException { + public CopyRule(final StatementPattern sp) throws QueryRulesetException { statement = sp; - Var subjVar = statement.getSubjectVar(); - Var predVar = statement.getPredicateVar(); - Var objVar = statement.getObjectVar(); - Var conVar = statement.getContextVar(); + final Var subjVar = statement.getSubjectVar(); + final Var predVar = statement.getPredicateVar(); + final Var objVar = statement.getObjectVar(); + final Var conVar = statement.getContextVar(); int variables = 0; if (subjVar == null || !subjVar.hasValue()) { sp.setSubjectVar(SUBJ_VAR); @@ -227,9 +225,9 @@ public class CopyRule extends QueryModelNodeBase { /** * Set the complete condition. */ - private void setCondition(ValueExpr newCondition) { - this.condition = newCondition; - this.condition.setParentNode(this); + private void setCondition(final ValueExpr newCondition) { + condition = newCondition; + condition.setParentNode(this); } /** @@ -239,13 +237,13 @@ public class CopyRule extends QueryModelNodeBase { * so that we are guaranteed to include all relevant statements. * @param condition A boolean filter expression */ - public void addCondition(ValueExpr condition) { - ValueExpr newCondition = condition.clone(); + public void addCondition(final ValueExpr condition) { + final ValueExpr newCondition = condition.clone(); if (this.condition == null) { setCondition(newCondition); } else { - this.setCondition(new And(this.condition, newCondition)); + setCondition(new And(this.condition, newCondition)); } this.condition.visit(visitor); // If, after rewriting, the condition still contains undefined variables, we can't @@ -292,7 +290,7 @@ public class CopyRule extends QueryModelNodeBase { * must be a ValueExpr or null. */ @Override - public void replaceChildNode(QueryModelNode current, QueryModelNode replacement) { + public void replaceChildNode(final QueryModelNode current, final QueryModelNode replacement) { if (current.equals(condition) && replacement instanceof ValueExpr) { setCondition(((ValueExpr) replacement).clone()); } @@ -308,7 +306,7 @@ public class CopyRule extends QueryModelNodeBase { * Apply a visitor to both the statement and any conditions. */ @Override - public <X extends Exception> void visit(QueryModelVisitor<X> visitor) throws X { + public <X extends Exception> void visit(final QueryModelVisitor<X> visitor) throws X { if (statement != null) { statement.visit(visitor); } @@ -319,7 +317,7 @@ public class CopyRule extends QueryModelNodeBase { @Override public String toString() { - StringBuilder sb = new StringBuilder(statement.toString().trim()); + final StringBuilder sb = new StringBuilder(statement.toString().trim()); if (condition != null) { sb.append("\n Condition:\n \t"); sb.append(condition.toString().trim().replace("\n", "\n \t")); @@ -328,17 +326,17 @@ public class CopyRule extends QueryModelNodeBase { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (!obj.getClass().equals(CopyRule.class)) { return false; } - CopyRule other = (CopyRule) obj; - if ((this.statement != null && !this.statement.equals(other.statement)) - || (this.statement == null && other.statement != null)) { + final CopyRule other = (CopyRule) obj; + if ((statement != null && !statement.equals(other.statement)) + || (statement == null && other.statement != null)) { return false; } - if ((this.condition != null && !this.condition.equals(other.condition)) - || (this.condition == null && other.condition != null)) { + if ((condition != null && !condition.equals(other.condition)) + || (condition == null && other.condition != null)) { return false; } return true; @@ -356,23 +354,23 @@ public class CopyRule extends QueryModelNodeBase { * @param other Rule to compare against * @return true if this rule will necessarily match everything the other rule would. */ - public boolean isGeneralizationOf(CopyRule other) { - if (this.statement == null || other.statement == null) { + public boolean isGeneralizationOf(final CopyRule other) { + if (statement == null || other.statement == null) { return false; } // If each component of the statement and the condition are at least as general // as the other rule's, then this rule is at least as general. - return varIsGeneralization(this.statement.getSubjectVar(), other.statement.getSubjectVar()) - && varIsGeneralization(this.statement.getPredicateVar(), other.statement.getPredicateVar()) - && varIsGeneralization(this.statement.getObjectVar(), other.statement.getObjectVar()) - && varIsGeneralization(this.statement.getContextVar(), other.statement.getContextVar()) - && (this.condition == null || this.condition.equals(other.condition)); + return varIsGeneralization(statement.getSubjectVar(), other.statement.getSubjectVar()) + && varIsGeneralization(statement.getPredicateVar(), other.statement.getPredicateVar()) + && varIsGeneralization(statement.getObjectVar(), other.statement.getObjectVar()) + && varIsGeneralization(statement.getContextVar(), other.statement.getContextVar()) + && (condition == null || condition.equals(other.condition)); } /** * Determine whether the first variable is at least as general as the second. */ - private static boolean varIsGeneralization(Var first, Var second) { + private static boolean varIsGeneralization(final Var first, final Var second) { if (first == null || !first.hasValue()) { // if first is a variable, it is at least as general return true; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/GroupedRow.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/GroupedRow.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/GroupedRow.java index 10b7d58..476408a 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/GroupedRow.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/GroupedRow.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.util; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. - * #L% + * 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.apache.rya.accumulo.mr.merge.util; import java.io.DataInput; import java.io.DataOutput; @@ -40,7 +38,7 @@ import org.apache.hadoop.io.WritableComparator; * GroupComparator sorts only based on group. */ public class GroupedRow implements WritableComparable<GroupedRow> { - private Text group = new Text(); + private final Text group = new Text(); private Key key = new Key(); private Value value = new Value(); @@ -48,7 +46,7 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Set the group that this row belongs to. * @param name A common label */ - public void setGroup(String name) { + public void setGroup(final String name) { group.set(name); } @@ -56,7 +54,7 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Set the Key * @param key Key associated with an Accumulo row */ - public void setKey(Key key) { + public void setKey(final Key key) { this.key = key; } @@ -64,7 +62,7 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Set the Value * @param value Value associated with an Accumulo row */ - public void setValue(Value value) { + public void setValue(final Value value) { this.value = value; } @@ -96,7 +94,7 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Serialize the group, key, and value */ @Override - public void write(DataOutput out) throws IOException { + public void write(final DataOutput out) throws IOException { group.write(out); key.write(out); value.write(out); @@ -106,7 +104,7 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Deserialize the group, key, and value */ @Override - public void readFields(DataInput in) throws IOException { + public void readFields(final DataInput in) throws IOException { group.readFields(in); key.readFields(in); value.readFields(in); @@ -116,11 +114,11 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Natural ordering; compares based on group and then key. */ @Override - public int compareTo(GroupedRow o) { + public int compareTo(final GroupedRow o) { if (o == null) { return 1; } - return new CompareToBuilder().append(this.group, o.group).append(this.key, o.key).append(this.value, o.value).toComparison(); + return new CompareToBuilder().append(group, o.group).append(key, o.key).append(value, o.value).toComparison(); } /** @@ -135,11 +133,11 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Test equality (group, key, value). */ @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (o == this) { return true; } if (o != null && o instanceof GroupedRow) { - GroupedRow other = (GroupedRow) o; - return new EqualsBuilder().append(this.group, other.group).append(this.key, other.key).append(this.value, other.value).isEquals(); + final GroupedRow other = (GroupedRow) o; + return new EqualsBuilder().append(group, other.group).append(key, other.key).append(value, other.value).isEquals(); } return false; } @@ -155,9 +153,9 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Compares the groups of two GroupedRow instances, and the keys if they share a group. */ @Override - public int compare(WritableComparable wc1, WritableComparable wc2) { - GroupedRow gk1 = (GroupedRow) wc1; - GroupedRow gk2 = (GroupedRow) wc2; + public int compare(final WritableComparable wc1, final WritableComparable wc2) { + final GroupedRow gk1 = (GroupedRow) wc1; + final GroupedRow gk2 = (GroupedRow) wc2; return gk1.compareTo(gk2); } } @@ -173,9 +171,9 @@ public class GroupedRow implements WritableComparable<GroupedRow> { * Compares the groups of two GroupedRow instances. */ @Override - public int compare(WritableComparable wc1, WritableComparable wc2) { - GroupedRow gk1 = (GroupedRow) wc1; - GroupedRow gk2 = (GroupedRow) wc2; + public int compare(final WritableComparable wc1, final WritableComparable wc2) { + final GroupedRow gk1 = (GroupedRow) wc1; + final GroupedRow gk2 = (GroupedRow) wc2; return gk1.group.compareTo(gk2.group); } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/QueryRuleset.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/QueryRuleset.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/QueryRuleset.java index b9b5af2..9627c54 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/QueryRuleset.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/QueryRuleset.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.util; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * 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 + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * 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. - * #L% + * 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.apache.rya.accumulo.mr.merge.util; import java.io.BufferedReader; import java.io.FileReader; @@ -83,10 +81,10 @@ public class QueryRuleset { */ public static class QueryRulesetException extends Exception { private static final long serialVersionUID = 1L; - public QueryRulesetException(String s) { + public QueryRulesetException(final String s) { super(s); } - public QueryRulesetException(String s, Throwable throwable) { + public QueryRulesetException(final String s, final Throwable throwable) { super(s, throwable); } } @@ -96,15 +94,15 @@ public class QueryRuleset { */ private static class RulesetVisitor extends QueryModelVisitorBase<QueryRulesetException> { List<CopyRule> rules = new LinkedList<>(); - private Set<Value> superclasses = new HashSet<>(); - private Set<Value> superproperties = new HashSet<>(); - private Set<Value> sameAs = new HashSet<>(); - private Set<Value> transitive = new HashSet<>(); - private Set<Value> schemaProperties = new HashSet<>(); + private final Set<Value> superclasses = new HashSet<>(); + private final Set<Value> superproperties = new HashSet<>(); + private final Set<Value> sameAs = new HashSet<>(); + private final Set<Value> transitive = new HashSet<>(); + private final Set<Value> schemaProperties = new HashSet<>(); @Override public void meet(StatementPattern node) throws QueryRulesetException { - Var predVar = node.getPredicateVar(); + final Var predVar = node.getPredicateVar(); // If this is a transitive property node, just match all statements with that property if (node instanceof TransitivePropertySP && predVar.hasValue()) { node = new StatementPattern(new Var("transitiveSubject"), predVar, @@ -116,11 +114,11 @@ public class QueryRuleset { } @Override - public void meet(Filter node) throws QueryRulesetException { - ValueExpr condition = node.getCondition(); + public void meet(final Filter node) throws QueryRulesetException { + final ValueExpr condition = node.getCondition(); // If the condition is a function call, and we don't know about the function, don't try to test for it. if (condition instanceof FunctionCall) { - String uri = ((FunctionCall) condition).getURI(); + final String uri = ((FunctionCall) condition).getURI(); if (FunctionRegistry.getInstance().get(uri) == null) { // Just extract statement patterns from the child as if there were no filter. node.getArg().visit(this); @@ -128,35 +126,35 @@ public class QueryRuleset { } // Otherwise, assume we can test for it: extract rules from below this node, and add the condition to each one. else { - RulesetVisitor childVisitor = new RulesetVisitor(); + final RulesetVisitor childVisitor = new RulesetVisitor(); node.getArg().visit(childVisitor); - for (CopyRule rule : childVisitor.rules) { + for (final CopyRule rule : childVisitor.rules) { rule.addCondition(condition); - this.rules.add(rule); + rules.add(rule); } - this.superclasses.addAll(childVisitor.superclasses); - this.superproperties.addAll(childVisitor.superproperties); + superclasses.addAll(childVisitor.superclasses); + superproperties.addAll(childVisitor.superproperties); } } @Override - public void meet(Join node) throws QueryRulesetException { - TupleExpr left = node.getLeftArg(); - TupleExpr right = node.getRightArg(); + public void meet(final Join node) throws QueryRulesetException { + final TupleExpr left = node.getLeftArg(); + final TupleExpr right = node.getRightArg(); // If this join represents the application of inference logic, use its children to add the // appropriate rules. if (node instanceof InferJoin && left instanceof FixedStatementPattern) { FixedStatementPattern fsp = (FixedStatementPattern) left; - Value predValue = fsp.getPredicateVar().getValue(); + final Value predValue = fsp.getPredicateVar().getValue(); // If this is a subClassOf relation, fetch all subClassOf and equivalentClass // relations involving the relevant classes. if (RDFS.SUBCLASSOF.equals(predValue) && right instanceof StatementPattern) { - StatementPattern dne = (StatementPattern) right; + final StatementPattern dne = (StatementPattern) right; // If a subClassOf b equivalentClass c subClassOf d, then fsp will contain a statement // for each class in the hierarchy. If we match every subClassOf and equivalentClass // relation to any of {a,b,c,d}, then the hierarchy can be reconstructed. - for (Statement st : fsp.statements) { - Value superclassVal = st.getSubject(); + for (final Statement st : fsp.statements) { + final Value superclassVal = st.getSubject(); // Rule to match the type assignment: rules.add(new CopyRule(new StatementPattern(dne.getSubjectVar(), dne.getPredicateVar(), @@ -169,12 +167,12 @@ public class QueryRuleset { // If this is a subPropertyOf relation, fetch all subPropertyOf and equivalentProperty // relations involving the relevant properties. else if (RDFS.SUBPROPERTYOF.equals(predValue) && right instanceof StatementPattern) { - StatementPattern dne = (StatementPattern) right; + final StatementPattern dne = (StatementPattern) right; // If p subPropertyOf q subPropertyOf r subPropertyOf s, then fsp will contain a statement // for each property in the hierarchy. If we match every subPropertyOf and equivalentProperty // relation to any of {p,q,r,s}, then the hierarchy can be reconstructed. - for (Statement st : fsp.statements) { - Value superpropVal = st.getSubject(); + for (final Statement st : fsp.statements) { + final Value superpropVal = st.getSubject(); // Rule to add the property: rules.add(new CopyRule(new StatementPattern(dne.getSubjectVar(), new Var(superpropVal.toString(), superpropVal), @@ -187,11 +185,11 @@ public class QueryRuleset { // If this is a sameAs expansion, it may have one or two levels if (OWL.SAMEAS.equals(predValue)) { StatementPattern stmt = null; - String replaceVar = fsp.getSubjectVar().getName(); + final String replaceVar = fsp.getSubjectVar().getName(); String replaceVarInner = null; - List<Value> replacements = new LinkedList<>(); - List<Value> replacementsInner = new LinkedList<>(); - for (Statement st : fsp.statements) { + final List<Value> replacements = new LinkedList<>(); + final List<Value> replacementsInner = new LinkedList<>(); + for (final Statement st : fsp.statements) { replacements.add(st.getSubject()); } if (right instanceof StatementPattern) { @@ -199,22 +197,22 @@ public class QueryRuleset { } else if (right instanceof InferJoin) { // Add the second set of replacements if given - InferJoin inner = (InferJoin) right; + final InferJoin inner = (InferJoin) right; if (inner.getLeftArg() instanceof FixedStatementPattern && inner.getRightArg() instanceof StatementPattern) { stmt = (StatementPattern) inner.getRightArg(); fsp = (FixedStatementPattern) inner.getLeftArg(); replaceVarInner = fsp.getSubjectVar().getName(); - for (Statement st : fsp.statements) { + for (final Statement st : fsp.statements) { replacementsInner.add(st.getSubject()); } } } // Add different versions of the original statement: if (stmt != null) { - for (Value replacementVal : replacements) { + for (final Value replacementVal : replacements) { if (replacementsInner.isEmpty()) { - StatementPattern transformed = stmt.clone(); + final StatementPattern transformed = stmt.clone(); if (transformed.getSubjectVar().equals(replaceVar)) { transformed.setSubjectVar(new Var(replaceVar, replacementVal)); } @@ -223,8 +221,8 @@ public class QueryRuleset { } rules.add(new CopyRule(transformed)); } - for (Value replacementValInner : replacementsInner) { - StatementPattern transformed = stmt.clone(); + for (final Value replacementValInner : replacementsInner) { + final StatementPattern transformed = stmt.clone(); if (transformed.getSubjectVar().equals(replaceVar)) { transformed.setSubjectVar(new Var(replaceVar, replacementVal)); } @@ -253,22 +251,22 @@ public class QueryRuleset { } @Override - public void meet(Union node) throws QueryRulesetException { + public void meet(final Union node) throws QueryRulesetException { node.visitChildren(this); if (node instanceof InferUnion) { // If this is the result of inference, search each tree for (non-standard) properties and add them // to the set of properties for which to include schema information. - QueryModelVisitorBase<QueryRulesetException> propertyVisitor = new QueryModelVisitorBase<QueryRulesetException>() { + final QueryModelVisitorBase<QueryRulesetException> propertyVisitor = new QueryModelVisitorBase<QueryRulesetException>() { @Override - public void meet(StatementPattern node) { + public void meet(final StatementPattern node) { if (node.getPredicateVar().hasValue()) { - URI predValue = (URI) node.getPredicateVar().getValue(); - String ns = predValue.getNamespace(); + final URI predValue = (URI) node.getPredicateVar().getValue(); + final String ns = predValue.getNamespace(); if (node instanceof FixedStatementPattern && (RDFS.SUBPROPERTYOF.equals(predValue) || OWL.EQUIVALENTPROPERTY.equals(predValue))) { // This FSP replaced a property, so find all the properties it entails - FixedStatementPattern fsp = (FixedStatementPattern) node; - for (Statement stmt : fsp.statements) { + final FixedStatementPattern fsp = (FixedStatementPattern) node; + for (final Statement stmt : fsp.statements) { schemaProperties.add(stmt.getSubject()); } } @@ -291,7 +289,7 @@ public class QueryRuleset { public void addSchema() throws QueryRulesetException { // Combine the relevant portions of the class hierarchy into one subclass rule and one equivalent class rule: if (!superclasses.isEmpty()) { - Var superClassVar = new Var("superClassVar"); + final Var superClassVar = new Var("superClassVar"); // Subclasses of the given classes: addListRule(new Var("subClassVar"), null, RDFS.SUBCLASSOF, superClassVar, superclasses); // Equivalent classes to the given classes (this might be stated in either direction): @@ -300,7 +298,7 @@ public class QueryRuleset { // Combine the relevant portions of the property hierarchy into one subproperty rule and one equivalent property rule: if (!superproperties.isEmpty()) { - Var superPropertyVar = new Var("superPropertyVar"); + final Var superPropertyVar = new Var("superPropertyVar"); // Subproperties of the given properties: addListRule(new Var("subPropertyVar"), null, RDFS.SUBPROPERTYOF, superPropertyVar, superproperties); // Equivalent properties to the given properties (this might be stated in either direction): @@ -309,20 +307,20 @@ public class QueryRuleset { // Get the relevant portions of the owl:sameAs graph if (!sameAs.isEmpty()) { - Var sameAsSubj = new Var("sameAsSubject"); - Var sameAsObj = new Var("sameAsObject"); + final Var sameAsSubj = new Var("sameAsSubject"); + final Var sameAsObj = new Var("sameAsObject"); addListRule(sameAsSubj, sameAs, OWL.SAMEAS, sameAsObj, sameAs); } // Get the potentially relevant owl:TransitiveProperty statements if (!transitive.isEmpty()) { - Var transitiveVar = new Var(OWL.TRANSITIVEPROPERTY.toString(), OWL.TRANSITIVEPROPERTY); + final Var transitiveVar = new Var(OWL.TRANSITIVEPROPERTY.toString(), OWL.TRANSITIVEPROPERTY); addListRule(new Var("transitiveProp"), transitive, RDF.TYPE, transitiveVar, null); } // Get any owl:SymmetricProperty and owl:inverseOf statements for relevant properties if (!schemaProperties.isEmpty()) { - Var symmetricVar = new Var(OWL.SYMMETRICPROPERTY.toString(), OWL.SYMMETRICPROPERTY); + final Var symmetricVar = new Var(OWL.SYMMETRICPROPERTY.toString(), OWL.SYMMETRICPROPERTY); addListRule(new Var("symmetricProp"), schemaProperties, RDF.TYPE, symmetricVar, null); addListRule(new Var("inverseSubject"), schemaProperties, OWL.INVERSEOF, new Var("inverseObject"), schemaProperties); } @@ -342,26 +340,26 @@ public class QueryRuleset { * @param objValues Either null or a Set of Values that the object variable can have, tested using a filter * @throws QueryRulesetException if the rule can't be created */ - private void addListRule(Var subjVar, Set<Value> subjValues, URI predicate, - Var objVar, Set<Value> objValues) throws QueryRulesetException { + private void addListRule(final Var subjVar, final Set<Value> subjValues, final URI predicate, + final Var objVar, final Set<Value> objValues) throws QueryRulesetException { ListMemberOperator subjCondition = null; ListMemberOperator objCondition = null; if (subjValues != null) { subjCondition = new ListMemberOperator(); subjCondition.addArgument(subjVar); - for (Value constant : subjValues) { + for (final Value constant : subjValues) { subjCondition.addArgument(new Var(constant.toString(), constant)); } } if (objValues != null) { objCondition = new ListMemberOperator(); objCondition.addArgument(objVar); - for (Value constant : objValues) { + for (final Value constant : objValues) { objCondition.addArgument(new Var(constant.toString(), constant)); } } - Var predVar = new Var(predicate.toString(), predicate); - CopyRule listRule = new CopyRule(new StatementPattern(subjVar, predVar, objVar)); + final Var predVar = new Var(predicate.toString(), predicate); + final CopyRule listRule = new CopyRule(new StatementPattern(subjVar, predVar, objVar)); if (subjCondition != null && objCondition != null) { listRule.addCondition(new Or(subjCondition, objCondition)); } @@ -395,7 +393,7 @@ public class QueryRuleset { * @param conf Configuration containing either the query string, or name of a file containing the query, plus inference parameters. * @throws QueryRulesetException if the query can't be read, parsed, and resolved to valid rules */ - public QueryRuleset(RdfCloudTripleStoreConfiguration conf) throws QueryRulesetException { + public QueryRuleset(final RdfCloudTripleStoreConfiguration conf) throws QueryRulesetException { this.conf = conf; setQuery(); setRules(); @@ -406,7 +404,7 @@ public class QueryRuleset { * @param query A SPARQL query string * @throws QueryRulesetException if the query can't be parsed and resolved to valid rules */ - public QueryRuleset(String query) throws QueryRulesetException { + public QueryRuleset(final String query) throws QueryRulesetException { this.query = query; setRules(); } @@ -431,12 +429,12 @@ public class QueryRuleset { throw new QueryRulesetException("No Configuration given"); } query = conf.get(CopyTool.QUERY_STRING_PROP); - String queryFile = conf.get(CopyTool.QUERY_FILE_PROP); + final String queryFile = conf.get(CopyTool.QUERY_FILE_PROP); if (query == null && queryFile != null) { try { - FileReader fileReader = new FileReader(queryFile); - BufferedReader reader = new BufferedReader(fileReader); - StringBuilder builder = new StringBuilder(); + final FileReader fileReader = new FileReader(queryFile); + final BufferedReader reader = new BufferedReader(fileReader); + final StringBuilder builder = new StringBuilder(); String line = reader.readLine(); while (line != null) { builder.append(line).append("\n"); @@ -446,7 +444,7 @@ public class QueryRuleset { reader.close(); conf.set(CopyTool.QUERY_STRING_PROP, query); } - catch (IOException e) { + catch (final IOException e) { throw new QueryRulesetException("Error loading query from file: " + queryFile, e); } } @@ -475,7 +473,7 @@ public class QueryRuleset { // that are OK because they won'd be converted to rules directly. te.visit(new QueryModelVisitorBase<QueryRulesetException>() { @Override - public void meet(StatementPattern node) throws QueryRulesetException { + public void meet(final StatementPattern node) throws QueryRulesetException { if (!(node.getSubjectVar().hasValue() || node.getPredicateVar().hasValue() || node.getObjectVar().hasValue())) { throw new QueryRulesetException("Statement pattern with no constants would match every statement:\n" + node + "\nFrom parsed query:\n" + te); @@ -488,7 +486,7 @@ public class QueryRuleset { try { log.info("Applying inference rules"); store = (RdfCloudTripleStore) RyaSailFactory.getInstance(conf); - InferenceEngine inferenceEngine = store.getInferenceEngine(); + final InferenceEngine inferenceEngine = store.getInferenceEngine(); // Apply in same order as query evaluation: te.visit(new TransitivePropertyVisitor(conf, inferenceEngine)); te.visit(new SymmetricPropertyVisitor(conf, inferenceEngine)); @@ -497,51 +495,51 @@ public class QueryRuleset { te.visit(new SubClassOfVisitor(conf, inferenceEngine)); te.visit(new SameAsVisitor(conf, inferenceEngine)); log.info("Query after inference:\n"); - for (String line : te.toString().split("\n")) { + for (final String line : te.toString().split("\n")) { log.info("\t" + line); } } - catch (Exception e) { + catch (final Exception e) { throw new QueryRulesetException("Error applying inference to parsed query:\n" + te, e); } finally { if (store != null) { try { store.shutDown(); - } catch (SailException e) { + } catch (final SailException e) { log.error("Error shutting down Sail after applying inference", e); } } } } // Extract the StatementPatterns and Filters and turn them into rules: - RulesetVisitor rv = new RulesetVisitor(); + final RulesetVisitor rv = new RulesetVisitor(); try { te.visit(rv); rv.addSchema(); } - catch (QueryRulesetException e) { + catch (final QueryRulesetException e) { throw new QueryRulesetException("Error extracting rules from parsed query:\n" + te, e); } - for (CopyRule candidateRule : rv.rules) { + for (final CopyRule candidateRule : rv.rules) { boolean unique = true; - for (CopyRule otherRule : rv.rules) { + for (final CopyRule otherRule : rv.rules) { if (!candidateRule.equals(otherRule) && otherRule.isGeneralizationOf(candidateRule)) { unique = false; break; } } if (unique) { - this.rules.add(candidateRule); + rules.add(candidateRule); } } } @Override public String toString() { - StringBuilder sb = new StringBuilder("Original Query:\n\n\t"); + final StringBuilder sb = new StringBuilder("Original Query:\n\n\t"); sb.append(query.replace("\n", "\n\t")).append("\n\nRuleset:\n"); - for (CopyRule rule : rules) { + for (final CopyRule rule : rules) { sb.append("\n\t").append(rule.toString().replace("\n", "\n\t")).append("\n"); } return sb.toString();