コード例 #1
0
  protected Iterator<MessageForRender> getMessages(
      FacesContext context, String forClientId, UIComponent component) {

    Iterator<MessageForRender> msgIter;

    if (forClientId != null) {

      if (forClientId.length() != 0) {

        UIComponent result = RendererUtils.getInstance().findComponentFor(component, forClientId);
        if (result == null) {
          msgIter = Iterators.emptyIterator();
        } else {
          String clientId = result.getClientId(context);
          msgIter = getMessagesForId(context, clientId);
        }
      } else {
        msgIter = getMessagesForId(context, null);
      }
    } else {
      msgIter = Iterators.emptyIterator();
      Iterator<String> clientIdsWithMessages = context.getClientIdsWithMessages();
      while (clientIdsWithMessages.hasNext()) {
        String clientId = (String) clientIdsWithMessages.next();
        msgIter = Iterators.concat(msgIter, getMessagesForId(context, clientId));
      }
    }

    return msgIter;
  }
コード例 #2
0
 private void appendScanRow(StringBuilder buf, Bound bound) {
   ScanRanges scanRanges = context.getScanRanges();
   KeyRange minMaxRange = context.getMinMaxRange();
   Iterator<byte[]> minMaxIterator = Iterators.emptyIterator();
   if (minMaxRange != null) {
     RowKeySchema schema = tableRef.getTable().getRowKeySchema();
     if (!minMaxRange.isUnbound(bound)) {
       minMaxIterator = new RowKeyValueIterator(schema, minMaxRange.getRange(bound));
     }
   }
   int nRanges = scanRanges.getRanges().size();
   for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) {
     List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING : scanRanges.getRanges().get(minPos++);
     KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size() - 1);
     byte[] b = range.getRange(bound);
     Boolean isNull =
         KeyRange.IS_NULL_RANGE == range
             ? Boolean.TRUE
             : KeyRange.IS_NOT_NULL_RANGE == range ? Boolean.FALSE : null;
     if (minMaxIterator.hasNext()) {
       byte[] bMinMax = minMaxIterator.next();
       int cmp = Bytes.compareTo(bMinMax, b) * (bound == Bound.LOWER ? 1 : -1);
       if (cmp > 0) {
         minPos = nRanges;
         b = bMinMax;
         isNull = null;
       } else if (cmp < 0) {
         minMaxIterator = Iterators.emptyIterator();
       }
     }
     appendPKColumnValue(buf, b, isNull, i);
     buf.append(',');
   }
 }
コード例 #3
0
ファイル: JobDataList.java プロジェクト: nimbis/platformlayer
 @Override
 public Iterator<JobData> iterator() {
   if (jobs == null) {
     return Iterators.emptyIterator();
   }
   return jobs.iterator();
 }
コード例 #4
0
  public Iterator<RangeTombstone> getRangeTombstoneIterator(final ColumnFamily source) {
    final DeletionInfo delInfo = source.deletionInfo();
    if (!delInfo.hasRanges() || slices.length == 0) return Iterators.emptyIterator();

    return new AbstractIterator<RangeTombstone>() {
      private int sliceIdx = 0;
      private Iterator<RangeTombstone> sliceIter = currentRangeIter();

      protected RangeTombstone computeNext() {
        while (true) {
          if (sliceIter.hasNext()) return sliceIter.next();

          if (!nextSlice()) return endOfData();

          sliceIter = currentRangeIter();
        }
      }

      private Iterator<RangeTombstone> currentRangeIter() {
        ColumnSlice slice = slices[reversed ? (slices.length - 1 - sliceIdx) : sliceIdx];
        return reversed
            ? delInfo.rangeIterator(slice.finish, slice.start)
            : delInfo.rangeIterator(slice.start, slice.finish);
      }

      private boolean nextSlice() {
        return ++sliceIdx < slices.length;
      }
    };
  }
コード例 #5
0
  /**
   * Returns a valid instance selection for the current selection of the tree viewer. Returns <code>
   * null</code> if there is none.
   *
   * @return a valid instance selection for the current selection of the tree viewer or <code>null
   *     </code>
   */
  private InstanceSelection getValidSelection() {
    ISelection viewerSelection = treeViewer.getSelection();
    if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty()) return null;

    ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
    TreePath firstPath = treeSelection.getPaths()[0]; // XXX use all paths
    // instead of first
    // only?

    InstanceValidationMessage firstMessage;
    Iterator<InstanceValidationMessage> restIter;

    if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
      firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
      restIter = Iterators.emptyIterator();
    } else {
      Collection<InstanceValidationMessage> messages =
          contentProvider.getMessages(treeSelection.getPaths()[0]);
      if (messages.isEmpty()) return null; // shouldn't happen, but doesn't really matter
      restIter = messages.iterator();
      firstMessage = restIter.next();
    }

    InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
    // check first message for valid instance reference
    if (firstMessage.getInstanceReference() == null
        || is.getInstance(firstMessage.getInstanceReference()) == null) return null;

    Set<InstanceReference> references = new HashSet<InstanceReference>();
    references.add(firstMessage.getInstanceReference());
    while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());

    return new DefaultInstanceSelection(references.toArray());
  }
コード例 #6
0
  @Override
  public Iterator<? extends T> iterator(long first, long count) {
    Collection<T> data = dataModel.getObject();
    if (data == null || data.size() == 0) return Iterators.emptyIterator();
    Iterator<T> it;
    final SortParam<S> sortParam = getSort();
    if (sortParam != null && sortParam.getProperty() != null) {
      Ordering<T> ordering =
          Ordering.natural()
              .nullsFirst()
              .onResultOf(
                  new Function<T, Comparable<?>>() {

                    @Override
                    public Comparable<?> apply(T input) {
                      return comparableValue(input, sortParam.getProperty());
                    }
                  });
      if (!sortParam.isAscending()) ordering = ordering.reverse();
      it = ordering.sortedCopy(data).iterator();
    } else {
      it = data.iterator();
    }
    if (first > 0) Iterators.advance(it, (int) first);
    return count >= 0 ? Iterators.limit(it, (int) count) : it;
  }
コード例 #7
0
 @Override
 public Iterator<byte[]> iterator() {
   if (isEmpty()) {
     return Iterators.emptyIterator();
   }
   return Iterators.transform(entries.iterator(), ENTRY_TO_BYTE_ARRAY);
 }
コード例 #8
0
ファイル: MutationState.java プロジェクト: karel1980/phoenix
  private Iterator<Pair<byte[], List<Mutation>>> addRowMutations(
      final TableRef tableRef,
      final Map<ImmutableBytesPtr, Map<PColumn, byte[]>> values,
      long timestamp,
      boolean includeMutableIndexes) {
    final List<Mutation> mutations = Lists.newArrayListWithExpectedSize(values.size());
    Iterator<Map.Entry<ImmutableBytesPtr, Map<PColumn, byte[]>>> iterator =
        values.entrySet().iterator();
    while (iterator.hasNext()) {
      Map.Entry<ImmutableBytesPtr, Map<PColumn, byte[]>> rowEntry = iterator.next();
      ImmutableBytesPtr key = rowEntry.getKey();
      PRow row = tableRef.getTable().newRow(connection.getKeyValueBuilder(), timestamp, key);
      if (rowEntry.getValue() == PRow.DELETE_MARKER) { // means delete
        row.delete();
      } else {
        for (Map.Entry<PColumn, byte[]> valueEntry : rowEntry.getValue().entrySet()) {
          row.setValue(valueEntry.getKey(), valueEntry.getValue());
        }
      }
      mutations.addAll(row.toRowMutations());
    }
    final Iterator<PTable>
        indexes = // Only maintain tables with immutable rows through this client-side mechanism
        (tableRef.getTable().isImmutableRows() || includeMutableIndexes)
                ? IndexMaintainer.nonDisabledIndexIterator(
                    tableRef.getTable().getIndexes().iterator())
                : Iterators.<PTable>emptyIterator();
    return new Iterator<Pair<byte[], List<Mutation>>>() {
      boolean isFirst = true;

      @Override
      public boolean hasNext() {
        return isFirst || indexes.hasNext();
      }

      @Override
      public Pair<byte[], List<Mutation>> next() {
        if (isFirst) {
          isFirst = false;
          return new Pair<byte[], List<Mutation>>(
              tableRef.getTable().getPhysicalName().getBytes(), mutations);
        }
        PTable index = indexes.next();
        List<Mutation> indexMutations;
        try {
          indexMutations =
              IndexUtil.generateIndexData(
                  tableRef.getTable(), index, mutations, tempPtr, connection.getKeyValueBuilder());
        } catch (SQLException e) {
          throw new IllegalDataException(e);
        }
        return new Pair<byte[], List<Mutation>>(index.getPhysicalName().getBytes(), indexMutations);
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }
コード例 #9
0
 @Override
 public Iterator<Expression> visitEnter(ScalarFunction node) {
   return node.preservesOrder() == OrderPreserving.NO
       ? Iterators.<Expression>emptyIterator()
       : Iterators.singletonIterator(
           node.getChildren().get(node.getKeyFormationTraversalIndex()));
 }
コード例 #10
0
  /**
   * iterator over the Tokens in the given ring, starting with the token for the node owning start
   * (which does not have to be a Token in the ring)
   *
   * @param includeMin True if the minimum token should be returned in the ring even if it has no
   *     owner.
   */
  public static Iterator<Token> ringIterator(
      final ArrayList<Token> ring, Token start, boolean includeMin) {
    if (ring.isEmpty())
      return includeMin
          ? Iterators.singletonIterator(StorageService.getPartitioner().getMinimumToken())
          : Iterators.<Token>emptyIterator();

    final boolean insertMin = includeMin && !ring.get(0).isMinimum();
    final int startIndex = firstTokenIndex(ring, start, insertMin);
    return new AbstractIterator<Token>() {
      int j = startIndex;

      protected Token computeNext() {
        if (j < -1) return endOfData();
        try {
          // return minimum for index == -1
          if (j == -1) return StorageService.getPartitioner().getMinimumToken();
          // return ring token for other indexes
          return ring.get(j);
        } finally {
          j++;
          if (j == ring.size()) j = insertMin ? -1 : 0;
          if (j == startIndex)
            // end iteration
            j = -2;
        }
      }
    };
  }
コード例 #11
0
 @Override
 protected Iterator<File> resolveFiles(final URI fileURI) {
   if (fileURI.getScheme() != null
       && fileURI.getScheme().equals("file")
       && new File(fileURI).exists()) {
     return Iterators.singletonIterator(new File(fileURI));
   }
   if (fileURI.toString().startsWith(PREFIX)) {
     String path = fileURI.toString().substring(PREFIX_LENGTH);
     final String realPath = this.servletContext.getRealPath(path);
     if (realPath == null) {
       return Iterators.emptyIterator();
     }
     return Iterators.singletonIterator(new File(realPath));
   }
   return Iterators.emptyIterator();
 }
コード例 #12
0
 /**
  * Gets an iterator for the time-series stored under the given field name. This iterates over the
  * time-series in the same order as they were added.
  *
  * @param field the data field, not null
  * @return an iterator, not null
  */
 public Iterator<HistoricalTimeSeries> iterator(final String field) {
   ArgumentChecker.notNull(field, "field");
   final Entry e = _data.get(field);
   if (e == null) {
     return Iterators.emptyIterator();
   }
   return e.iterator();
 }
コード例 #13
0
 @Override
 public Iterator<Edge<I, E>> iterator() {
   if (edgeCount == 0) {
     return Iterators.emptyIterator();
   } else {
     return new ByteArrayEdgeIterator();
   }
 }
コード例 #14
0
 @Override
 public Iterator<Tree> childrenIterator() {
   return Iterators.<Tree>concat(
       Iterators.<Tree>forArray(
           ifKeyword, openParenToken, condition, closeParenToken, thenStatement),
       elseKeyword != null
           ? Iterators.<Tree>forArray(elseKeyword, elseStatement)
           : Iterators.<Tree>emptyIterator());
 }
コード例 #15
0
 public void testNullPointers() throws Exception {
   NullPointerTester tester = new NullPointerTester();
   tester.setDefault(Comparator.class, Ordering.natural());
   tester.setDefault(Comparable.class, "");
   tester.setDefault(Iterator.class, Iterators.emptyIterator());
   tester.setDefault(Iterable.class, Collections.emptySet());
   tester.setDefault(Comparable[].class, new Comparable[0]);
   tester.testAllPublicStaticMethods(ImmutableSortedMultiset.class);
 }
コード例 #16
0
ファイル: ScanUtil.java プロジェクト: hzg0102/phoenix
 public static Iterator<Filter> getFilterIterator(Scan scan) {
   Iterator<Filter> filterIterator;
   Filter topLevelFilter = scan.getFilter();
   if (topLevelFilter == null) {
     filterIterator = Iterators.emptyIterator();
   } else if (topLevelFilter instanceof FilterList) {
     filterIterator = ((FilterList) topLevelFilter).getFilters().iterator();
   } else {
     filterIterator = Iterators.singletonIterator(topLevelFilter);
   }
   return filterIterator;
 }
コード例 #17
0
  public Iterator<RangeTombstone> getRangeTombstoneIterator(final ColumnFamily source) {
    if (!source.deletionInfo().hasRanges()) return Iterators.<RangeTombstone>emptyIterator();

    return new AbstractIterator<RangeTombstone>() {
      private final Iterator<CellName> names = columns.iterator();
      private RangeTombstone lastFindRange;

      protected RangeTombstone computeNext() {
        while (names.hasNext()) {
          CellName next = names.next();
          if (lastFindRange != null && lastFindRange.includes(source.getComparator(), next))
            return lastFindRange;

          // We keep the last range around as since names are in sort order, it's
          // possible it will match the next name too.
          lastFindRange = source.deletionInfo().rangeCovering(next);
          if (lastFindRange != null) return lastFindRange;
        }
        return endOfData();
      }
    };
  }
コード例 #18
0
ファイル: MutationState.java プロジェクト: karel1980/phoenix
  public Iterator<Pair<byte[], List<Mutation>>> toMutations(final boolean includeMutableIndexes) {
    final Iterator<Map.Entry<TableRef, Map<ImmutableBytesPtr, Map<PColumn, byte[]>>>> iterator =
        this.mutations.entrySet().iterator();
    if (!iterator.hasNext()) {
      return Iterators.emptyIterator();
    }
    Long scn = connection.getSCN();
    final long timestamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn;
    return new Iterator<Pair<byte[], List<Mutation>>>() {
      private Map.Entry<TableRef, Map<ImmutableBytesPtr, Map<PColumn, byte[]>>> current =
          iterator.next();
      private Iterator<Pair<byte[], List<Mutation>>> innerIterator = init();

      private Iterator<Pair<byte[], List<Mutation>>> init() {
        return addRowMutations(
            current.getKey(), current.getValue(), timestamp, includeMutableIndexes);
      }

      @Override
      public boolean hasNext() {
        return innerIterator.hasNext() || iterator.hasNext();
      }

      @Override
      public Pair<byte[], List<Mutation>> next() {
        if (!innerIterator.hasNext()) {
          current = iterator.next();
        }
        return innerIterator.next();
      }

      @Override
      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }
コード例 #19
0
  @Override
  public Iterator<Feature> iterator() {

    Iterator<Ref> featureRefs = Iterators.emptyIterator();

    GeoGIT ggit = new GeoGIT(repository);
    VersionQuery versionQuery = new VersionQuery(ggit, featureType.getName());
    try {
      for (ResourceId rid : resourceIds) {
        Iterator<Ref> ridIterator;
        ridIterator = versionQuery.get(rid);
        featureRefs = Iterators.concat(featureRefs, ridIterator);
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    featureRefs = versionQuery.filterByQueryVersion(featureRefs, query);

    Iterator<Feature> features =
        Iterators.transform(featureRefs, new RefToFeature(repository, featureType));

    return features;
  }
コード例 #20
0
 private QueuedEntityPlacingIterator(Iterator<Object> entityIterator) {
   this.entityIterator = entityIterator;
   moveSelectorIterator = Iterators.emptyIterator();
 }
コード例 #21
0
ファイル: DebugInfo.java プロジェクト: 9hao/ZjDroid
 @Nonnull
 @Override
 public Iterator<String> getParameterNames(@Nullable DexReader reader) {
   return Iterators.emptyIterator();
 }
コード例 #22
0
ファイル: DebugInfo.java プロジェクト: 9hao/ZjDroid
 @Nonnull
 @Override
 public Iterator<DebugItem> iterator() {
   return Iterators.emptyIterator();
 }
コード例 #23
0
ファイル: ImmutableSortedSet.java プロジェクト: tintor/Meta2
 public Iterator<E> iterator() {
   return Iterators.emptyIterator();
 }
コード例 #24
0
 {
     val$inputs = iterator;
     super();
     current = Iterators.emptyIterator();
 }
コード例 #25
0
 public UnmodifiableIterator<Object> iterator() {
   return Iterators.emptyIterator();
 }
コード例 #26
0
ファイル: EmptyAtomicQuery.java プロジェクト: rlwu607/titan
 @Override
 public Iterator<TitanProperty> propertyIterator() {
   return Iterators.emptyIterator();
 }
コード例 #27
0
ファイル: EmptyAtomicQuery.java プロジェクト: rlwu607/titan
 @Override
 public Iterator<TitanEdge> edgeIterator() {
   return Iterators.emptyIterator();
 }
コード例 #28
0
ファイル: MetaDataClient.java プロジェクト: QimengZou/phoenix
  public MutationState createTable(CreateTableStatement statement, byte[][] splits)
      throws SQLException {
    PTableType tableType = statement.getTableType();
    boolean isView = tableType == PTableType.VIEW;
    if (isView && !statement.getProps().isEmpty()) {
      throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_WITH_TABLE_CONFIG)
          .build()
          .buildException();
    }
    connection.rollback();
    boolean wasAutoCommit = connection.getAutoCommit();
    try {
      connection.setAutoCommit(false);
      TableName tableNameNode = statement.getTableName();
      String schemaName = tableNameNode.getSchemaName();
      String tableName = tableNameNode.getTableName();

      PrimaryKeyConstraint pkConstraint = statement.getPrimaryKeyConstraint();
      String pkName = null;
      Set<String> pkColumns = Collections.<String>emptySet();
      Iterator<String> pkColumnsIterator = Iterators.emptyIterator();
      if (pkConstraint != null) {
        pkColumns = pkConstraint.getColumnNames();
        pkColumnsIterator = pkColumns.iterator();
        pkName = pkConstraint.getName();
      }

      List<ColumnDef> colDefs = statement.getColumnDefs();
      List<PColumn> columns = Lists.newArrayListWithExpectedSize(colDefs.size());
      PreparedStatement colUpsert = connection.prepareStatement(INSERT_COLUMN);
      int columnOrdinal = 0;
      Map<String, PName> familyNames = Maps.newLinkedHashMap();
      boolean isPK = false;
      for (ColumnDef colDef : colDefs) {
        if (colDef.isPK()) {
          if (isPK) {
            throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_ALREADY_EXISTS)
                .setColumnName(colDef.getColumnDefName().getColumnName().getName())
                .build()
                .buildException();
          }
          isPK = true;
        }
        PColumn column = newColumn(columnOrdinal++, colDef, pkConstraint);
        if (SchemaUtil.isPKColumn(column)) {
          // TODO: remove this constraint?
          if (!pkColumns.isEmpty()
              && !column.getName().getString().equals(pkColumnsIterator.next())) {
            throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_OUT_OF_ORDER)
                .setSchemaName(schemaName)
                .setTableName(tableName)
                .setColumnName(column.getName().getString())
                .build()
                .buildException();
          }
        }
        columns.add(column);
        if (colDef.getDataType() == PDataType.BINARY && colDefs.size() > 1) {
          throw new SQLExceptionInfo.Builder(SQLExceptionCode.BINARY_IN_ROW_KEY)
              .setSchemaName(schemaName)
              .setTableName(tableName)
              .setColumnName(column.getName().getString())
              .build()
              .buildException();
        }
        if (column.getFamilyName() != null) {
          familyNames.put(column.getFamilyName().getString(), column.getFamilyName());
        }
      }
      if (!isPK && pkColumns.isEmpty()) {
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.PRIMARY_KEY_MISSING)
            .setSchemaName(schemaName)
            .setTableName(tableName)
            .build()
            .buildException();
      }

      List<Pair<byte[], Map<String, Object>>> familyPropList =
          Lists.newArrayListWithExpectedSize(familyNames.size());
      Map<String, Object> commonFamilyProps = Collections.emptyMap();
      Map<String, Object> tableProps = Collections.emptyMap();
      if (!statement.getProps().isEmpty()) {
        if (statement.isView()) {
          throw new SQLExceptionInfo.Builder(SQLExceptionCode.VIEW_WITH_PROPERTIES)
              .build()
              .buildException();
        }
        for (String familyName : statement.getProps().keySet()) {
          if (!familyName.equals(QueryConstants.ALL_FAMILY_PROPERTIES_KEY)) {
            if (familyNames.get(familyName) == null) {
              throw new SQLExceptionInfo.Builder(SQLExceptionCode.PROPERTIES_FOR_FAMILY)
                  .setFamilyName(familyName)
                  .build()
                  .buildException();
            }
          }
        }
        commonFamilyProps = Maps.newHashMapWithExpectedSize(statement.getProps().size());
        tableProps = Maps.newHashMapWithExpectedSize(statement.getProps().size());

        Collection<Pair<String, Object>> props =
            statement.getProps().get(QueryConstants.ALL_FAMILY_PROPERTIES_KEY);
        // Somewhat hacky way of determining if property is for HColumnDescriptor or
        // HTableDescriptor
        HColumnDescriptor defaultDescriptor =
            new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES);
        for (Pair<String, Object> prop : props) {
          if (defaultDescriptor.getValue(prop.getFirst()) != null) {
            commonFamilyProps.put(prop.getFirst(), prop.getSecond());
          } else {
            tableProps.put(prop.getFirst(), prop.getSecond());
          }
        }
      }

      for (PName familyName : familyNames.values()) {
        Collection<Pair<String, Object>> props = statement.getProps().get(familyName.getString());
        if (props.isEmpty()) {
          familyPropList.add(
              new Pair<byte[], Map<String, Object>>(familyName.getBytes(), commonFamilyProps));
        } else {
          Map<String, Object> combinedFamilyProps =
              Maps.newHashMapWithExpectedSize(props.size() + commonFamilyProps.size());
          combinedFamilyProps.putAll(commonFamilyProps);
          for (Pair<String, Object> prop : props) {
            combinedFamilyProps.put(prop.getFirst(), prop.getSecond());
          }
          familyPropList.add(
              new Pair<byte[], Map<String, Object>>(familyName.getBytes(), combinedFamilyProps));
        }
      }

      // Bootstrapping for our SYSTEM.TABLE that creates itself before it exists
      if (tableType == PTableType.SYSTEM) {
        PTable table =
            new PTableImpl(
                new PNameImpl(tableName),
                tableType,
                MetaDataProtocol.MIN_TABLE_TIMESTAMP,
                0,
                QueryConstants.SYSTEM_TABLE_PK_NAME,
                null,
                columns);
        connection.addTable(schemaName, table);
      }

      for (PColumn column : columns) {
        addColumnMutation(schemaName, tableName, column, colUpsert);
      }

      Integer saltBucketNum = (Integer) tableProps.remove(PhoenixDatabaseMetaData.SALT_BUCKETS);
      if (saltBucketNum != null
          && (saltBucketNum <= 0 || saltBucketNum > SaltingUtil.MAX_BUCKET_NUM)) {
        throw new SQLExceptionInfo.Builder(SQLExceptionCode.INVALID_BUCKET_NUM)
            .build()
            .buildException();
      }

      PreparedStatement tableUpsert = connection.prepareStatement(CREATE_TABLE);
      tableUpsert.setString(1, schemaName);
      tableUpsert.setString(2, tableName);
      tableUpsert.setString(3, tableType.getSerializedValue());
      tableUpsert.setInt(4, 0);
      tableUpsert.setInt(5, columnOrdinal);
      if (saltBucketNum != null) {
        tableUpsert.setInt(6, saltBucketNum);
      } else {
        tableUpsert.setNull(6, Types.INTEGER);
      }
      tableUpsert.setString(7, pkName);
      tableUpsert.execute();

      final List<Mutation> tableMetaData = connection.getMutationState().toMutations();
      connection.rollback();

      MetaDataMutationResult result =
          connection
              .getQueryServices()
              .createTable(tableMetaData, isView, tableProps, familyPropList, splits);
      MutationCode code = result.getMutationCode();
      switch (code) {
        case TABLE_ALREADY_EXISTS:
          connection.addTable(schemaName, result.getTable());
          if (!statement.ifNotExists()) {
            throw new TableAlreadyExistsException(schemaName, tableName);
          }
          break;
        case NEWER_TABLE_FOUND:
          // TODO: add table if in result?
          throw new NewerTableAlreadyExistsException(schemaName, tableName);
        case UNALLOWED_TABLE_MUTATION:
          throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_MUTATE_TABLE)
              .setSchemaName(schemaName)
              .setTableName(tableName)
              .build()
              .buildException();
        default:
          PTable table =
              new PTableImpl(
                  new PNameImpl(tableName),
                  tableType,
                  result.getMutationTime(),
                  0,
                  pkName,
                  saltBucketNum,
                  columns);
          connection.addTable(schemaName, table);
          if (tableType == PTableType.USER) {
            connection.setAutoCommit(true);
            // Delete everything in the column. You'll still be able to do queries at earlier
            // timestamps
            Long scn = connection.getSCN();
            long ts = (scn == null ? result.getMutationTime() : scn);
            PSchema schema =
                new PSchemaImpl(
                    schemaName,
                    ImmutableMap.<String, PTable>of(table.getName().getString(), table));
            TableRef tableRef = new TableRef(null, table, schema, ts);
            byte[] emptyCF = SchemaUtil.getEmptyColumnFamily(table.getColumnFamilies());
            MutationPlan plan =
                new PostDDLCompiler(connection).compile(tableRef, emptyCF, null, ts);
            return connection.getQueryServices().updateData(plan);
          }
          break;
      }
      return new MutationState(0, connection);
    } finally {
      connection.setAutoCommit(wasAutoCommit);
    }
  }
コード例 #29
0
 public void testCopyOf_iterator_empty() {
   Iterator<String> iterator = Iterators.emptyIterator();
   List<String> list = ImmutableList.copyOf(iterator);
   assertEquals(Collections.emptyList(), list);
 }
コード例 #30
0
ファイル: EmptyAtomicQuery.java プロジェクト: rlwu607/titan
 @Override
 public Iterator<TitanRelation> relationIterator() {
   return Iterators.emptyIterator();
 }