#21
authorVyacheslav Tyutyunkov <tyutyunkov@gmail.com>
Mon, 1 Apr 2013 05:24:41 +0000 (12:24 +0700)
committerVyacheslav Tyutyunkov <tyutyunkov@gmail.com>
Mon, 1 Apr 2013 05:24:41 +0000 (12:24 +0700)
13 files changed:
jejdb/Makefile
jejdb/src/java/org/ejdb/bson/BSONDecoder.java
jejdb/src/java/org/ejdb/bson/BSONEncoder.java
jejdb/src/java/org/ejdb/bson/BSONObject.java
jejdb/src/java/org/ejdb/bson/io/InputBuffer.java
jejdb/src/java/org/ejdb/bson/io/OutputBuffer.java
jejdb/src/java/org/ejdb/bson/types/ObjectId.java
jejdb/src/java/org/ejdb/bson/util/RegexFlag.java
jejdb/src/java/org/ejdb/driver/BSONQueryObject.java
jejdb/src/java/org/ejdb/driver/EJDB.java
jejdb/src/java/org/ejdb/driver/EJDBCollection.java
jejdb/src/java/org/ejdb/driver/EJDBQueryBuilder.java
jejdb/src/java/org/ejdb/driver/EJDBResultSet.java

index d1466d0..939a224 100644 (file)
@@ -28,7 +28,7 @@ SRCDIR = ./src/cpp/
 
 # Building configuration
 CC = gcc
-CPPFLAGS = -I. -I. -I../tcejdb -I/usr/lib/jvm/java-6-oracle/include -I/usr/lib/jvm/java-6-oracle/include/linux -I$(INCLUDEDIR) -I/home/tve/include -I/usr/local/include -D_UNICODE -DNDEBUG -D_GNU_SOURCE=1 -D_REENTRANT -D__EXTENSIONS__
+CPPFLAGS = -I. -I. -I../tcejdb -I/usr/lib/jvm/java-6-openjdk-amd64/include -I/usr/lib/jvm/java-6-openjdk-amd64/include/linux -I$(INCLUDEDIR) -I/home/tve/include -I/usr/local/include -D_UNICODE -DNDEBUG -D_GNU_SOURCE=1 -D_REENTRANT -D__EXTENSIONS__
 CFLAGS =  -std=c99 -Wall -fPIC -fsigned-char -O2
 LDFLAGS = -L. -L$(LIBDIR) -L/home/tve/lib -L/usr/local/lib
 LIBS = -lz -ltcejdb -lrt -lpthread -lm -lc 
index 5007838..559c188 100644 (file)
@@ -39,7 +39,8 @@ class BSONDecoder {
     }
 
     /**
-     * @return <code>true</code> if decoder currently in use
+     * Returns <code>true</code> if decoder is currently in use
+     * @return <code>true</code> if decoder is currently in use
      */
     public boolean isBusy() {
         return input != null;
index ffd0a9c..c602b36 100644 (file)
@@ -46,7 +46,8 @@ class BSONEncoder {
     }
 
     /**
-     * @return <code>true</code> if encoder currently in use
+     * Returns <code>true</code> if encoder is currently in use
+     * @return <code>true</code> if encoder is currently in use
      */
     public boolean isBusy() {
         return output != null;
index 8656f41..1416e79 100644 (file)
@@ -16,7 +16,7 @@ import java.util.Set;
  * BSON object.
  * <p/>
  * NOTE:
- * - {@link BSONObject#ID_KEY} must be valid {@link ObjectId}((@link ObjectId} instance or valid <code>byte[]</code> or <code>String</code>)
+ *   {@link BSONObject#ID_KEY} must be valid {@link ObjectId} ({@link ObjectId} instance or valid <code>byte[]</code> or <code>String</code>)
  *
  * @author Tyutyunkov Vyacheslav (tve@softmotions.com)
  * @version $Id$
@@ -140,6 +140,7 @@ public class BSONObject {
     }
 
     /**
+     * Returns fields in adding order
      * @return fields in adding order
      */
     public List<String> fields() {
@@ -147,6 +148,7 @@ public class BSONObject {
     }
 
     /**
+     * Returns id of BSON object (if specified)
      * @return id of BSON object (if specified)
      */
     public ObjectId getId() {
@@ -154,6 +156,7 @@ public class BSONObject {
     }
 
     /**
+     * Returns value of specified field if exists, or <code>null</code> otherwise
      * @return value of specified field if exists, or <code>null</code> otherwise
      */
     public Object get(String key) {
@@ -161,6 +164,7 @@ public class BSONObject {
     }
 
     /**
+     * Returns fields count
      * @return fields count
      */
     public int size() {
@@ -199,6 +203,9 @@ public class BSONObject {
         return false;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public boolean equals(Object o) {
         if (this != o && (null == o || !(o instanceof BSONObject))) {
@@ -264,11 +271,17 @@ public class BSONObject {
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public int hashCode() {
         return data.hashCode();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
index 48af376..9690676 100644 (file)
@@ -6,6 +6,8 @@ import org.ejdb.bson.BSONObject;
 import java.io.UnsupportedEncodingException;
 
 /**
+ * Utility class for reading BSON object data
+ *
  * @author Tyutyunkov Vyacheslav (tve@softmotions.com)
  * @version $Id$
  */
@@ -22,6 +24,9 @@ public class InputBuffer {
         this.limit = limit;
     }
 
+    /**
+     * Reads one byte from buffer
+     */
     public byte read() {
         ensure(1);
 
@@ -31,6 +36,9 @@ public class InputBuffer {
         return result;
     }
 
+    /**
+     * Reads 4 bytes from buffer as integer value
+     */
     public int readInt() {
         ensure(4);
 
@@ -43,6 +51,9 @@ public class InputBuffer {
         return result;
     }
 
+    /**
+     * Reads 8 bytes from buffer as long value
+     */
     public long readLong() {
         ensure(8);
 
@@ -55,6 +66,10 @@ public class InputBuffer {
         return result;
     }
 
+    /**
+     * Reads bytes from buffer
+     * @param count count of bytes to read
+     */
     public byte[] readBytes(int count) {
         ensure(count);
         byte[] bytes = new byte[count];
@@ -64,10 +79,16 @@ public class InputBuffer {
         return bytes;
     }
 
+    /**
+     * Reads c-string (null-terminated) from buffer
+     */
     public String readString() {
         return readString(0);
     }
 
+    /**
+     * Reads c-string from buffer with specified length
+     */
     public String readString(int length) {
         if (length > 0) {
             ensure(length);
@@ -98,10 +119,17 @@ public class InputBuffer {
         return s;
     }
 
+    /**
+     * Returns <code>true</code> if any bytes available to read from buffer or <code>false</code> otherwise
+     * @return <code>true</code> if any bytes available to read from buffer or <code>false</code> otherwise
+     */
     public boolean isAvailable() {
         return position < limit;
     }
 
+    /**
+     * Get sub buffer with specified length
+     */
     public InputBuffer subBuffer(int limit) {
         ensure(limit);
 
@@ -111,12 +139,19 @@ public class InputBuffer {
         return result;
     }
 
+    /**
+     * Checks is buffer contains needed bytes
+     */
     protected void ensure(int size) {
         if (size > limit - position) {
             throw new BSONException("can not allocate sub buffer: not enought bytes");
         }
     }
 
+
+    /**
+     * Creates {@link InputBuffer} from byte array
+     */
     public static InputBuffer createFromByteArray(byte[] data) {
         return new InputBuffer(data, 0, data.length);
     }
index 549b8bf..3a293d3 100644 (file)
@@ -5,6 +5,8 @@ import org.ejdb.bson.BSONException;
 import java.io.UnsupportedEncodingException;
 
 /**
+ * Utility class for serialize BSON object
+ *
  * @author Tyutyunkov Vyacheslav (tve@softmotions.com)
  * @version $Id$
  */
@@ -21,34 +23,62 @@ public class OutputBuffer {
         actualSize = 0;
     }
 
+    /**
+     * Returns current position in output
+     * @return current position in output
+     */
     public int getPosition() {
         return position;
     }
 
+    /**
+     * Sets position
+     */
     public void setPosition(int position) {
         this.position = position;
     }
 
+    /**
+     * Returns actual (full) size of buffer (currently writed bytes)
+     * @return actual (full) size of buffer (currently writed bytes)
+     */
     public int getActualSize() {
         return actualSize;
     }
 
+    /**
+     * Returns buffer as byte array
+     * @return buffer as byte array
+     */
     public byte[] getResult() {
         byte[] result = new byte[getActualSize()];
         System.arraycopy(buffer, 0, result, 0, getActualSize());
         return result;
     }
 
+    /**
+     * Writes single byte to buffer
+     */
     public void write(byte data) {
         ensureLength(1);
         buffer[position++] = data;
         actualSize = Math.max(actualSize, position);
     }
 
+    /**
+     * Writes byte array to buffer
+     */
     public void write(byte[] data) {
         this.write(data, 0, data.length);
     }
 
+    /**
+     * Writes part of byte array to buffer
+     *
+     * @param data   source byte array
+     * @param offset start position in source
+     * @param length count bytes to write
+     */
     public void write(byte[] data, int offset, int length) {
         ensureLength(length);
         System.arraycopy(data, offset, buffer, position, length);
@@ -56,6 +86,11 @@ public class OutputBuffer {
         actualSize = Math.max(actualSize, position);
     }
 
+    /**
+     * Writes integer value (4 bytes) at specified position
+     * @param position position to write
+     * @param value value
+     */
     public void writeIntAt(int position, int value) {
         int save = getPosition();
         setPosition(position);
@@ -63,6 +98,9 @@ public class OutputBuffer {
         setPosition(save);
     }
 
+    /**
+     * Writes integer value to buffer as 4 bytes
+     */
     public void writeInt(int value) {
         this.write(new byte[]{
                 (byte) ((value >>> 0) & 0xFF),
@@ -72,6 +110,9 @@ public class OutputBuffer {
         });
     }
 
+    /**
+     * Writes long value to buffer as 8 bytes
+     */
     public void writeLong(long value) {
         this.write(new byte[]{
                 (byte) ((value >>> 0) & 0xFF),
@@ -85,10 +126,17 @@ public class OutputBuffer {
         });
     }
 
+    /**
+     * Writes double value to buffers as 8 bytes
+     */
     public void writeDouble(double value) {
         this.writeLong(Double.doubleToRawLongBits(value));
     }
 
+    /**
+     * Writes {@link String} to buffer as c-style string (null-terminated)
+     * @return count of writed bytes
+     */
     public int writeString(String value) {
         int start = getPosition();
         try {
@@ -101,6 +149,9 @@ public class OutputBuffer {
         return getPosition() - start;
     }
 
+    /**
+     * Checks internal array size to hold needed data and expand it if need.
+     */
     protected void ensureLength(int need) {
         if (need <= buffer.length - position) {
             return;
index 0d9328a..1609586 100644 (file)
@@ -51,17 +51,26 @@ public class ObjectId {
         return result;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public boolean equals(Object o) {
         return this == o || null != o && o instanceof ObjectId && Arrays.equals(data, ((ObjectId) o).data);
 
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public int hashCode() {
         return Arrays.hashCode(data);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder(34);
index 86c62ae..f98c61f 100644 (file)
@@ -68,6 +68,7 @@ public final class RegexFlag {
     }
 
     /**
+     * Returns Java flag
      * @return Java flag
      */
     public int getFlag() {
@@ -75,6 +76,7 @@ public final class RegexFlag {
     }
 
     /**
+     * Returns BSON character for associated Java regex flag
      * @return BSON character for associated Java regex flag
      */
     public char getCharacter() {
@@ -82,6 +84,7 @@ public final class RegexFlag {
     }
 
     /**
+     * Returns <code>true</code> if BSON supported current Java flag
      * @return <code>true</code> if BSON supported current Java flag
      */
     public boolean isSupported() {
index 2384c59..63fb623 100644 (file)
@@ -29,11 +29,17 @@ public class BSONQueryObject extends BSONObject {
         super(src);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Object put(String key, Object value) {
         return registerField(key, value);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public BSONQueryObject append(String key, Object value) {
         super.append(key, value);
@@ -41,8 +47,9 @@ public class BSONQueryObject extends BSONObject {
     }
 
     /**
-     * BSON Query objects can not contains dedicated ObjectID
-     * @return
+     * {@inheritDoc}
+     *
+     * @deprecated BSON Query objects can not contains dedicated ObjectID
      */
     @Deprecated
     @Override
@@ -50,6 +57,9 @@ public class BSONQueryObject extends BSONObject {
         return null;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected boolean isFieldsOrderImportant() {
         return true;
index 2f2c0bc..3433507 100644 (file)
@@ -64,6 +64,7 @@ public class EJDB {
     }
 
     /**
+     * Returns EJDB path
      * @return EJDB path
      */
     public String getPath() {
@@ -233,7 +234,9 @@ public class EJDB {
         return collections.values();
     }
 
-
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder();
@@ -244,6 +247,9 @@ public class EJDB {
         return sb.toString();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void finalize() throws Throwable {
         this.close();
index 78b992e..ccafe0f 100644 (file)
@@ -65,6 +65,7 @@ public class EJDBCollection {
     }
 
     /**
+     * Returns EJDB object
      * @return EJDB object
      */
     public EJDB getDB() {
@@ -72,6 +73,7 @@ public class EJDBCollection {
     }
 
     /**
+     * Returns collection name
      * @return collection name
      */
     public String getName() {
@@ -79,6 +81,7 @@ public class EJDBCollection {
     }
 
     /**
+     * Returns collection exists status
      * @return collection exists status
      */
     public boolean isExists() {
@@ -86,6 +89,7 @@ public class EJDBCollection {
     }
 
     /**
+     * Returns collection options {@link Options}
      * @return collection options {@link Options}
      */
     public Options getOptions() {
@@ -93,6 +97,7 @@ public class EJDBCollection {
     }
 
     /**
+     * Returns indexes info
      * @return indexes info
      */
     public Collection<Index> getIndexes() {
@@ -430,6 +435,9 @@ public class EJDBCollection {
 
     protected native boolean txControl(int mode) throws EJDBException;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder();
@@ -455,8 +463,8 @@ public class EJDBCollection {
         }
 
         /**
-         * @param compressed       If true collection records will be compressed with DEFLATE compression. Default: false.
-         * @param large            Specifies that the size of the database can be larger than 2GB. Default: false
+         * @param compressed       If <code>true</code> collection records will be compressed with DEFLATE compression. Default: <code>false</code>.
+         * @param large            Specifies that the size of the database can be larger than 2GB. Default: <code>false</code>.
          * @param records          Estimated number of records in this collection. Default: 65535.
          * @param cachedRecords    Max number of cached records in shared memory segment. Default: 0
          */
@@ -483,6 +491,9 @@ public class EJDBCollection {
             return cachedRecords;
         }
 
+        /**
+         * {@inheritDoc}
+         */
         @Override
         public String toString() {
             final StringBuilder sb = new StringBuilder();
@@ -515,26 +526,44 @@ public class EJDBCollection {
         private String file;
         private int records;
 
+        /**
+         * Returns index name
+         */
         public String getName() {
             return name;
         }
 
+        /**
+         * Returns index field path
+         */
         public String getField() {
             return field;
         }
 
+        /**
+         * Returns index type
+         */
         public IndexType getType() {
             return type;
         }
 
+        /**
+         * Returns index file path
+         */
         public String getFile() {
             return file;
         }
 
+        /**
+         * Returns records count in index
+         */
         public int getRecords() {
             return records;
         }
 
+        /**
+         * {@inheritDoc}
+         */
         @Override
         public String toString() {
             final StringBuilder sb = new StringBuilder();
index 9e7d93f..17a09b8 100644 (file)
@@ -38,6 +38,7 @@ public class EJDBQueryBuilder {
     }
 
     /**
+     * Returns main BSON query object
      * @return main BSON query object
      */
     public BSONObject getMainQuery() {
@@ -45,6 +46,7 @@ public class EJDBQueryBuilder {
     }
 
     /**
+     * Returns BSON objects for additional OR queries
      * @return BSON objects for additional OR queries
      */
     public BSONObject[] getOrQueries() {
@@ -62,6 +64,7 @@ public class EJDBQueryBuilder {
     }
 
     /**
+     * Returns BSON hints object
      * @return BSON hints object
      */
     public BSONObject getQueryHints() {
@@ -254,8 +257,9 @@ public class EJDBQueryBuilder {
     }
 
     /**
-     * Make {@se http://github.com/Softmotions/ejdb/wiki/Collection-joins collection join} for select queries.
+     * Make <a href="http://github.com/Softmotions/ejdb/wiki/Collection-joins">collection join</a> for select queries.
      */
+    @SuppressWarnings("JavadocReference")
     public EJDBQueryBuilder join(String fpath, String collname) {
         return new Constraint("$join", new Constraint(fpath, new Constraint("$do", false))).addOperation(collname);
     }
@@ -488,7 +492,7 @@ public class EJDBQueryBuilder {
         }
 
         /**
-         * Field existence matching {@link Constraint#exists(boolean = true)}
+         * Field existence matching {@link Constraint#exists(boolean)}
          */
         public EJDBQueryBuilder exists() {
             return this.exists(true);
index ee3a38e..2bf9cdf 100644 (file)
@@ -30,14 +30,23 @@ public class EJDBResultSet implements Iterable<BSONObject>, Iterator<BSONObject>
      */
     public native int length();
 
+    /**
+     * {@inheritDoc}
+     */
     public Iterator<BSONObject> iterator() {
         return this;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasNext() {
         return position < this.length();
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public BSONObject next() throws EJDBException {
         if (!hasNext()) {
             throw new NoSuchElementException();
@@ -46,6 +55,9 @@ public class EJDBResultSet implements Iterable<BSONObject>, Iterator<BSONObject>
         return get(position++);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public void remove() {
         throw new UnsupportedOperationException();
     }
@@ -55,6 +67,9 @@ public class EJDBResultSet implements Iterable<BSONObject>, Iterator<BSONObject>
      */
     public native void close() throws EJDBException;
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     protected void finalize() throws Throwable {
         this.close();