001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.db.table;
030:
031: class Row {
032: // bit of the first null mask, i.e. skipping the allocation bits
033: private static final int NULL_OFFSET = 2;
034:
035: private Column[] _columns = new Column[0];
036: private int _rowLength = 1;
037: private int _nullOffset = 0;
038:
039: /**
040: * Returns the current row length
041: */
042: int getLength() {
043: return _rowLength;
044: }
045:
046: /**
047: * Returns the current null offset.
048: */
049: int getNullOffset() {
050: return _nullOffset;
051: }
052:
053: /**
054: * Returns the current null mask.
055: */
056: byte getNullMask() {
057: return (byte) (1 << ((_columns.length + NULL_OFFSET) % 8));
058: }
059:
060: /**
061: * Returns the columns.
062: */
063: Column[] getColumns() {
064: return _columns;
065: }
066:
067: /**
068: * Returns the named column.
069: */
070: Column getColumn(String name) {
071: for (int i = 0; i < _columns.length; i++)
072: if (name.equals(_columns[i].getName()))
073: return _columns[i];
074:
075: return null;
076: }
077:
078: /**
079: * Allocates space for a column.
080: */
081: void allocateColumn() {
082: if ((_columns.length + NULL_OFFSET) % 8 == 0) {
083: _nullOffset = _rowLength;
084: _rowLength++;
085: }
086: }
087:
088: /**
089: * Adds a new column to the table.
090: */
091: Column addColumn(Column column) {
092: Column[] newColumns = new Column[_columns.length + 1];
093:
094: System.arraycopy(_columns, 0, newColumns, 0, _columns.length);
095: _columns = newColumns;
096:
097: _columns[_columns.length - 1] = column;
098:
099: _rowLength += column.getLength();
100:
101: return column;
102: }
103: }
|