Esempio n. 1
0
 @Override
 public void write(org.apache.thrift.protocol.TProtocol prot, TRowSet struct)
     throws org.apache.thrift.TException {
   TTupleProtocol oprot = (TTupleProtocol) prot;
   oprot.writeI64(struct.startRowOffset);
   {
     oprot.writeI32(struct.rows.size());
     for (TRow _iter126 : struct.rows) {
       _iter126.write(oprot);
     }
   }
   BitSet optionals = new BitSet();
   if (struct.isSetColumns()) {
     optionals.set(0);
   }
   oprot.writeBitSet(optionals, 1);
   if (struct.isSetColumns()) {
     {
       oprot.writeI32(struct.columns.size());
       for (TColumn _iter127 : struct.columns) {
         _iter127.write(oprot);
       }
     }
   }
 }
  /**
   * Retrun List of cells of column X
   *
   * @param pColumnIndex
   * @return List of Cells
   */
  public ArrayList<TCell> getColumnCells(int pColumnIndex) {

    ArrayList<TCell> lListOfCells = new ArrayList<TCell>(getRowsCount());

    for (TRow row : _mListOfRows) {
      lListOfCells.add(row.getCell(pColumnIndex));
    }

    return lListOfCells;
  }
Esempio n. 3
0
    public void write(org.apache.thrift.protocol.TProtocol oprot, TRowSet struct)
        throws org.apache.thrift.TException {
      struct.validate();

      oprot.writeStructBegin(STRUCT_DESC);
      oprot.writeFieldBegin(START_ROW_OFFSET_FIELD_DESC);
      oprot.writeI64(struct.startRowOffset);
      oprot.writeFieldEnd();
      if (struct.rows != null) {
        oprot.writeFieldBegin(ROWS_FIELD_DESC);
        {
          oprot.writeListBegin(
              new org.apache.thrift.protocol.TList(
                  org.apache.thrift.protocol.TType.STRUCT, struct.rows.size()));
          for (TRow _iter124 : struct.rows) {
            _iter124.write(oprot);
          }
          oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
      }
      if (struct.columns != null) {
        if (struct.isSetColumns()) {
          oprot.writeFieldBegin(COLUMNS_FIELD_DESC);
          {
            oprot.writeListBegin(
                new org.apache.thrift.protocol.TList(
                    org.apache.thrift.protocol.TType.STRUCT, struct.columns.size()));
            for (TColumn _iter125 : struct.columns) {
              _iter125.write(oprot);
            }
            oprot.writeListEnd();
          }
          oprot.writeFieldEnd();
        }
      }
      if (struct.binaryColumns != null) {
        if (struct.isSetBinaryColumns()) {
          oprot.writeFieldBegin(BINARY_COLUMNS_FIELD_DESC);
          oprot.writeBinary(struct.binaryColumns);
          oprot.writeFieldEnd();
        }
      }
      if (struct.isSetColumnCount()) {
        oprot.writeFieldBegin(COLUMN_COUNT_FIELD_DESC);
        oprot.writeI32(struct.columnCount);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
  /**
   * Fill the client Data table from an Android Cursor Database
   *
   * @param pCursor
   */
  public void fillFromCursor(Cursor pCursor) {

    _mCursor = pCursor;
    _mCursorSize = pCursor.getCount();
    _mListOfRows.clear();
    _mListOfRows.ensureCapacity(_mCursorSize);

    String[] lCursorColumnsNames = pCursor.getColumnNames();
    int lNbrColumnsCDT = getColumnsCount();

    int lNbrColumnsCursor = lCursorColumnsNames.length;

    if (lNbrColumnsCDT == 0) {
      for (int i = 0; i < lNbrColumnsCursor; i++) {
        _mListOfColumns.add(new TColumn(lCursorColumnsNames[i], ValueType.TEXT));
      }
    }
    if (_mCursorSize > 0) {

      pCursor.moveToFirst();
      _mPosition = 0;
      while (!pCursor.isAfterLast()) {
        TRow lRow = new TRow();

        if (lNbrColumnsCDT > 0) {
          for (int i = 0; i < lNbrColumnsCDT; i++) {
            boolean lIsColumnFound = false;
            TColumn lColumn = _mListOfColumns.get(i);
            for (int j = 0; j < lNbrColumnsCursor; j++) {
              if (lColumn != null && lColumn.getName().equals(lCursorColumnsNames[j])) {
                lRow.addCell(_mContext, pCursor.getString(j), lColumn.getValueType(), _mCDTStatus);
                lIsColumnFound = true;
                break;
              }
            }
            if (!lIsColumnFound) lRow.addCell(_mContext, "", lColumn.getValueType(), _mCDTStatus);
          }
        } else {
          for (int i = 0; i < lNbrColumnsCursor; i++) {
            String lColumnName = lCursorColumnsNames[i];
            if (lColumnName != null && !lColumnName.equals(""))
              lRow.addCell(_mContext, pCursor.getString(i), ValueType.TEXT, _mCDTStatus);
          }
        }
        _mListOfRows.add(lRow);
        pCursor.moveToNext();
      }
    }
    Log.i("fillFromCursor", " Count :" + _mCursorSize);
  }
  /**
   * Add row from values with differents type : boolean, String etc...
   *
   * @param values
   */
  public void addRowFromValues(Object... values) {

    Iterator<TColumn> columnIt = _mListOfColumns.listIterator();
    TRow lRow = new TRow();

    for (int i = 0; i < values.length && columnIt.hasNext(); i++) {

      TColumn lCol = columnIt.next();
      if (_mSqliteDataBase == null)
        lRow.addCell(_mContext, values[i], lCol.getValueType(), _mCDTStatus);
      else lRow.addCell(_mContext, values[i], lCol.getValueType(), _mCDTStatus);
    }

    addRow(lRow);
  }
  /**
   * Set Cell on the table
   *
   * @param pRowIndex
   * @param pColumnIndex
   * @param pCell
   * @throws PuException
   * @throws IndexOutOfBoundsException
   */
  public void setCell(int pRowIndex, int pColumnIndex, TCell pCell)
      throws PuException, IndexOutOfBoundsException {

    TRow row = _mListOfRows.get(pRowIndex);

    if (!row.getCell(pColumnIndex).getValueType().equals(pCell.getValueType())) {
      throw new PuException(
          _mContext,
          "New cell value type does not match expected value type."
              + " Expected type: "
              + row.getCell(pColumnIndex).getValueType()
              + " but was: "
              + pCell.getValueType());
    }
    row.setCell(pColumnIndex, pCell);
  }
Esempio n. 7
0
 @Override
 public void read(org.apache.thrift.protocol.TProtocol prot, TRowSet struct)
     throws org.apache.thrift.TException {
   TTupleProtocol iprot = (TTupleProtocol) prot;
   struct.startRowOffset = iprot.readI64();
   struct.setStartRowOffsetIsSet(true);
   {
     org.apache.thrift.protocol.TList _list128 =
         new org.apache.thrift.protocol.TList(
             org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
     struct.rows = new ArrayList<TRow>(_list128.size);
     TRow _elem129;
     for (int _i130 = 0; _i130 < _list128.size; ++_i130) {
       _elem129 = new TRow();
       _elem129.read(iprot);
       struct.rows.add(_elem129);
     }
   }
   struct.setRowsIsSet(true);
   BitSet incoming = iprot.readBitSet(3);
   if (incoming.get(0)) {
     {
       org.apache.thrift.protocol.TList _list131 =
           new org.apache.thrift.protocol.TList(
               org.apache.thrift.protocol.TType.STRUCT, iprot.readI32());
       struct.columns = new ArrayList<TColumn>(_list131.size);
       TColumn _elem132;
       for (int _i133 = 0; _i133 < _list131.size; ++_i133) {
         _elem132 = new TColumn();
         _elem132.read(iprot);
         struct.columns.add(_elem132);
       }
     }
     struct.setColumnsIsSet(true);
   }
   if (incoming.get(1)) {
     struct.binaryColumns = iprot.readBinary();
     struct.setBinaryColumnsIsSet(true);
   }
   if (incoming.get(2)) {
     struct.columnCount = iprot.readI32();
     struct.setColumnCountIsSet(true);
   }
 }
    @Override
    public int compare(TRow pRow1, TRow pRow2) {

      int lCompare = 0;
      int lIndexOfCoulmn = 0;

      // init Cells to compare
      TCell lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));
      TCell lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));

      for (int i = 0; i < _mListOfSortedColumnsName.length; i++) {

        // Update cells with the differents values of columns names
        lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[i]));
        lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[i]));

        switch (lCellRow1.getValueType()) {
          case INTEGER:
            // If eguals , incremente lIndexOfColumn to pass to the next
            // columns comparaison
            if (lCellRow1.asInteger() == lCellRow2.asInteger())
              if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++;
              else break;
            break;
          case DOUBLE:
            // If eguals , incremente lIndexOfColumn to pass to the next columns comparaison
            if (lCellRow1.asDouble() == lCellRow2.asDouble())
              if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++;
              else break;
            break;

          case BOOLEAN:
          case TEXT:
            if (lCellRow1.asString().equals(lCellRow2.asString()))
              if (lIndexOfCoulmn < _mListOfSortedColumnsName.length - 1) lIndexOfCoulmn++;
              else break;
            break;

          default:
            break;
        }
        // Update cells with the differents values of columns names
        lCellRow1 = pRow1.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));
        lCellRow2 = pRow2.getCell(indexOfColumn(_mListOfSortedColumnsName[lIndexOfCoulmn]));

        switch (lCellRow1.getValueType()) {
          case INTEGER:
            lCompare = lCellRow1.asInteger() - lCellRow2.asInteger();
            break;
          case DOUBLE:
            lCompare = Double.compare(lCellRow1.asDouble(), lCellRow2.asDouble());
            break;
          case BOOLEAN:
          case TEXT:
            lCompare = lCellRow1.asString().compareTo(lCellRow2.asString());
            break;
          default:
            break;
        }
      }
      // inverse sort
      if (_mSortType == TRowSortOrder.DESC) lCompare = -lCompare;

      return lCompare;
    }
Esempio n. 9
0
 public void read(org.apache.thrift.protocol.TProtocol iprot, TRowSet struct)
     throws org.apache.thrift.TException {
   org.apache.thrift.protocol.TField schemeField;
   iprot.readStructBegin();
   while (true) {
     schemeField = iprot.readFieldBegin();
     if (schemeField.type == org.apache.thrift.protocol.TType.STOP) {
       break;
     }
     switch (schemeField.id) {
       case 1: // START_ROW_OFFSET
         if (schemeField.type == org.apache.thrift.protocol.TType.I64) {
           struct.startRowOffset = iprot.readI64();
           struct.setStartRowOffsetIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 2: // ROWS
         if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
           {
             org.apache.thrift.protocol.TList _list118 = iprot.readListBegin();
             struct.rows = new ArrayList<TRow>(_list118.size);
             TRow _elem119;
             for (int _i120 = 0; _i120 < _list118.size; ++_i120) {
               _elem119 = new TRow();
               _elem119.read(iprot);
               struct.rows.add(_elem119);
             }
             iprot.readListEnd();
           }
           struct.setRowsIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 3: // COLUMNS
         if (schemeField.type == org.apache.thrift.protocol.TType.LIST) {
           {
             org.apache.thrift.protocol.TList _list121 = iprot.readListBegin();
             struct.columns = new ArrayList<TColumn>(_list121.size);
             TColumn _elem122;
             for (int _i123 = 0; _i123 < _list121.size; ++_i123) {
               _elem122 = new TColumn();
               _elem122.read(iprot);
               struct.columns.add(_elem122);
             }
             iprot.readListEnd();
           }
           struct.setColumnsIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 4: // BINARY_COLUMNS
         if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
           struct.binaryColumns = iprot.readBinary();
           struct.setBinaryColumnsIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       case 5: // COLUMN_COUNT
         if (schemeField.type == org.apache.thrift.protocol.TType.I32) {
           struct.columnCount = iprot.readI32();
           struct.setColumnCountIsSet(true);
         } else {
           org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
         }
         break;
       default:
         org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
     }
     iprot.readFieldEnd();
   }
   iprot.readStructEnd();
   struct.validate();
 }