├── client └── client.vcproj ├── src ├── driver │ └── java │ │ ├── src │ │ ├── org │ │ │ └── bson │ │ │ │ ├── util │ │ │ │ ├── package.html │ │ │ │ ├── Function.java │ │ │ │ ├── annotations │ │ │ │ │ ├── NotThreadSafe.java │ │ │ │ │ ├── ThreadSafe.java │ │ │ │ │ ├── Immutable.java │ │ │ │ │ └── GuardedBy.java │ │ │ │ ├── AbstractObjectSerializer.java │ │ │ │ ├── ObjectSerializer.java │ │ │ │ ├── SimplePool.java │ │ │ │ ├── Assertions.java │ │ │ │ ├── JSONParseException.java │ │ │ │ ├── ClassAncestry.java │ │ │ │ ├── ClassMapBasedObjectSerializer.java │ │ │ │ ├── ComputingMap.java │ │ │ │ └── ClassMap.java │ │ │ │ ├── package.html │ │ │ │ ├── types │ │ │ │ ├── package.html │ │ │ │ ├── MinKey.java │ │ │ │ ├── MaxKey.java │ │ │ │ ├── CodeWScope.java │ │ │ │ ├── Code.java │ │ │ │ ├── Binary.java │ │ │ │ ├── Symbol.java │ │ │ │ └── BSONTimestamp.java │ │ │ │ ├── io │ │ │ │ ├── package.html │ │ │ │ └── BasicOutputBuffer.java │ │ │ │ ├── BSONLazyDecoder.java │ │ │ │ ├── Transformer.java │ │ │ │ ├── BSONEncoder.java │ │ │ │ ├── BSONDecoder.java │ │ │ │ ├── BSONException.java │ │ │ │ ├── BSONCallback.java │ │ │ │ └── BSONObject.java │ │ └── com │ │ │ ├── google │ │ │ └── gson │ │ │ │ ├── reflect │ │ │ │ └── package-info.java │ │ │ │ ├── annotations │ │ │ │ ├── package-info.java │ │ │ │ ├── Since.java │ │ │ │ ├── SerializedName.java │ │ │ │ └── Until.java │ │ │ │ ├── internal │ │ │ │ ├── package-info.java │ │ │ │ ├── ObjectConstructor.java │ │ │ │ ├── JsonReaderInternalAccess.java │ │ │ │ ├── $Gson$Preconditions.java │ │ │ │ ├── LazilyParsedNumber.java │ │ │ │ └── bind │ │ │ │ │ ├── TimeTypeAdapter.java │ │ │ │ │ ├── SqlDateTypeAdapter.java │ │ │ │ │ ├── TypeAdapterRuntimeTypeWrapper.java │ │ │ │ │ ├── ObjectTypeAdapter.java │ │ │ │ │ ├── ArrayTypeAdapter.java │ │ │ │ │ └── DateTypeAdapter.java │ │ │ │ ├── package-info.java │ │ │ │ ├── FieldNamingStrategy.java │ │ │ │ ├── JsonIOException.java │ │ │ │ ├── JsonSyntaxException.java │ │ │ │ ├── stream │ │ │ │ ├── MalformedJsonException.java │ │ │ │ ├── JsonScope.java │ │ │ │ ├── StringPool.java │ │ │ │ └── JsonToken.java │ │ │ │ ├── JsonNull.java │ │ │ │ ├── JsonDeserializationContext.java │ │ │ │ ├── LongSerializationPolicy.java │ │ │ │ ├── JsonSerializationContext.java │ │ │ │ ├── JsonParseException.java │ │ │ │ └── JsonParser.java │ │ │ └── emeralddb │ │ │ ├── net │ │ │ ├── IConnection.java │ │ │ └── ServerAddress.java │ │ │ ├── exception │ │ │ ├── EDBError.java │ │ │ └── BaseException.java │ │ │ └── util │ │ │ ├── HashAlgorithm.java │ │ │ ├── KetamaNodeLocator.java │ │ │ └── KetamaNodeLocatorTest.java │ │ ├── lib │ │ └── log4j-1.2.17.jar │ │ └── build.sh ├── build.sh ├── include │ ├── wininc.h │ ├── ossHash.hpp │ ├── dmsRecord.hpp │ ├── rtn.hpp │ ├── pmdEDUEvent.hpp │ ├── ossMmapFile.hpp │ ├── ixmBucket.hpp │ ├── ossQueue.hpp │ ├── core.hpp │ ├── msg.hpp │ ├── ossUtil.hpp │ ├── pd.hpp │ └── ossSocket.hpp ├── bson │ └── src │ │ ├── inline_decls.h │ │ ├── lib │ │ ├── nonce.h │ │ ├── md5.hpp │ │ ├── base64.h │ │ ├── nonce.cpp │ │ └── base64.cpp │ │ ├── bson.h │ │ ├── util │ │ ├── json.h │ │ ├── hex.h │ │ └── misc.h │ │ ├── ordering.h │ │ ├── stringdata.h │ │ ├── bsonassert.h │ │ ├── bson_db.h │ │ └── bsontypes.h ├── win │ └── emeralddb_win.cpp ├── Makefile.am ├── client │ ├── commandFactory.cpp │ ├── edb.hpp │ └── commandFactory.hpp ├── pmd │ └── pmd.cpp └── oss │ ├── ossHash.cpp │ └── ossMmapFile.cpp ├── emeralddb └── emeralddb.vcproj ├── Readme.txt ├── .gitattributes └── emeralddb.sln /client/client.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhonnew/emeralddb/HEAD/client/client.vcproj -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/package.html: -------------------------------------------------------------------------------- 1 | 2 |

Misc utils used by BSON.

3 | 4 | -------------------------------------------------------------------------------- /emeralddb/emeralddb.vcproj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhonnew/emeralddb/HEAD/emeralddb/emeralddb.vcproj -------------------------------------------------------------------------------- /src/driver/java/lib/log4j-1.2.17.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhonnew/emeralddb/HEAD/src/driver/java/lib/log4j-1.2.17.jar -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/package.html: -------------------------------------------------------------------------------- 1 | 2 |

Contains the base BSON classes and Encoder/Decoder.

3 | 4 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/package.html: -------------------------------------------------------------------------------- 1 | 2 |

Contains classes implementing various BSON types.

3 | 4 | -------------------------------------------------------------------------------- /Readme.txt: -------------------------------------------------------------------------------- 1 | EmeraldDB编译方式 2 | 3 | 1) download and extract boost 4 | 2) modify Makefile.am to use proper boost include/lib directories 5 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/Function.java: -------------------------------------------------------------------------------- 1 | package org.bson.util; 2 | 3 | interface Function { 4 | B apply(A a); 5 | } 6 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/io/package.html: -------------------------------------------------------------------------------- 1 | 2 |

Contains classes implementing I/O operations used by BSON objects.

3 | 4 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/reflect/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides utility classes for finding type information for generic types. 3 | * 4 | * @author Inderjeet Singh, Joel Leitch 5 | */ 6 | package com.google.gson.reflect; -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/annotations/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides annotations that can be used with {@link com.google.gson.Gson}. 3 | * 4 | * @author Inderjeet Singh, Joel Leitch 5 | */ 6 | package com.google.gson.annotations; -------------------------------------------------------------------------------- /src/build.sh: -------------------------------------------------------------------------------- 1 | ################################# 2 | # Build script for EmeraldDB # 3 | ################################# 4 | #!/bin/sh 5 | rm configure.in 6 | autoscan 7 | cp configure.in.bak configure.in 8 | aclocal 9 | autoconf 10 | autoheader 11 | automake --add-missing 12 | ./configure CXXFLAGS= CFLAGS= 13 | make 14 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Do NOT use any class in this package as they are meant for internal use in Gson. 3 | * These classes will very likely change incompatibly in future versions. You have been warned. 4 | * 5 | * @author Inderjeet Singh, Joel Leitch, Jesse Wilson 6 | */ 7 | package com.google.gson.internal; -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package provides the {@link com.google.gson.Gson} class to convert Json to Java and 3 | * vice-versa. 4 | * 5 | *

The primary class to use is {@link com.google.gson.Gson} which can be constructed with 6 | * {@code new Gson()} (using default settings) or by using {@link com.google.gson.GsonBuilder} 7 | * (to configure various options such as using versioning and so on).

8 | * 9 | * @author Inderjeet Singh, Joel Leitch 10 | */ 11 | package com.google.gson; -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /src/include/wininc.h: -------------------------------------------------------------------------------- 1 | #ifndef _EMERALDDB_WININC_H 2 | #define _EMERALDDB_WININC_H 3 | 4 | #ifdef _WINDOWS 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define PATH_MAX 512 12 | #define __func__ __FUNCTION__ 13 | #define STDOUT_FILENO 0 14 | #define MSG_NOSIGNAL 0 15 | #define EWOULDBLOCK WSAEWOULDBLOCK 16 | 17 | typedef __int64 ssize_t; 18 | typedef __int32 socklen_t; 19 | 20 | // function 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | unsigned sleep(unsigned seconds); 26 | unsigned getpid(void); 27 | unsigned pthread_self(); 28 | struct tm *localtime_r(const time_t *timer, struct tm *result); 29 | 30 | #define snprintf sprintf_s 31 | 32 | #endif // _WINDOWS 33 | 34 | #ifdef __cplusplus 35 | }; 36 | #endif 37 | 38 | #endif // _EMERALDDB_WININC_H -------------------------------------------------------------------------------- /src/driver/java/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # define compile 4 | JAVA_HOME=../../../java/jdk_linux64 5 | JAVAC=$JAVA_HOME/bin/javac 6 | JAR=$JAVA_HOME/bin/jar 7 | 8 | #define source directory 9 | SOURCE_DIR=./src 10 | 11 | #define bin directory 12 | BIN_DIR=./bin 13 | 14 | # define target directory 15 | TARGET_DIR=../../../bin 16 | 17 | if [ ! -d $BIN_DIR ]; then 18 | mkdir $BIN_DIR 19 | fi 20 | 21 | if [ ! -d $TARGET_DIR ]; then 22 | mkdir $TARGET_DIR 23 | fi 24 | 25 | # delete all .class file 26 | find . -name "*.class" |xargs rm -rf 27 | 28 | $JAVAC `find $SOURCE_DIR -name "*.java" -print` -d $BIN_DIR 29 | 30 | cd $BIN_DIR 31 | 32 | l=`find ./ -name "*.class" -print | sed 's/^..//'` 33 | ../$JAR -cf ../$TARGET_DIR/emeralddb.jar $l 34 | cd .. 35 | 36 | # clean 37 | find ./ -name "*.class" | xargs rm -rf 38 | rm -rf $BIN_DIR 39 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/BSONLazyDecoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2008 10gen Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.bson; 17 | 18 | /** 19 | * 20 | * @author antoine 21 | */ 22 | public class BSONLazyDecoder { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/Transformer.java: -------------------------------------------------------------------------------- 1 | // Transformer.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson; 20 | 21 | public interface Transformer { 22 | 23 | /** 24 | * @return the new object. return passed in object if no change 25 | */ 26 | public Object transform( Object o ); 27 | } 28 | -------------------------------------------------------------------------------- /src/bson/src/inline_decls.h: -------------------------------------------------------------------------------- 1 | // inline_decls.h 2 | 3 | /* Copyright 2010 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #if defined(__GNUC__) 21 | 22 | #define NOINLINE_DECL __attribute__((noinline)) 23 | 24 | #elif defined(_MSC_VER) 25 | 26 | #define NOINLINE_DECL __declspec(noinline) 27 | 28 | #else 29 | 30 | #define NOINLINE_DECL 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/BSONEncoder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008 - 2011 10gen, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 5 | * the License. You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 11 | * specific language governing permissions and limitations under the License. 12 | */ 13 | 14 | package org.bson; 15 | 16 | import org.bson.io.*; 17 | 18 | 19 | public interface BSONEncoder { 20 | public byte[] encode( BSONObject o ); 21 | 22 | public int putObject( BSONObject o ); 23 | 24 | public void done(); 25 | 26 | void set( OutputBuffer out ); 27 | } 28 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/annotations/NotThreadSafe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 3 | * Released under the Creative Commons Attribution License 4 | * (http://creativecommons.org/licenses/by/2.5) 5 | * Official home: http://www.jcip.net 6 | * 7 | * Any republication or derived work distributed in source code form 8 | * must include this copyright and license notice. 9 | */ 10 | 11 | package org.bson.util.annotations; 12 | 13 | import java.lang.annotation.*; 14 | 15 | 16 | /** 17 | * The class to which this annotation is applied is not thread-safe. 18 | * This annotation primarily exists for clarifying the non-thread-safety of a class 19 | * that might otherwise be assumed to be thread-safe, despite the fact that it is a bad 20 | * idea to assume a class is thread-safe without good reason. 21 | * @see ThreadSafe 22 | */ 23 | @Documented 24 | @Target(ElementType.TYPE) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | public @interface NotThreadSafe { 27 | } 28 | -------------------------------------------------------------------------------- /src/include/ossHash.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef OSSHASH_HPP_ 17 | #define OSSHASH_HPP_ 18 | 19 | unsigned int ossHash ( const char *data, int len ) ; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/annotations/ThreadSafe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 3 | * Released under the Creative Commons Attribution License 4 | * (http://creativecommons.org/licenses/by/2.5) 5 | * Official home: http://www.jcip.net 6 | * 7 | * Any republication or derived work distributed in source code form 8 | * must include this copyright and license notice. 9 | */ 10 | 11 | package org.bson.util.annotations; 12 | 13 | import java.lang.annotation.*; 14 | 15 | 16 | /** 17 | * The class to which this annotation is applied is thread-safe. This means that 18 | * no sequences of accesses (reads and writes to public fields, calls to public methods) 19 | * may put the object into an invalid state, regardless of the interleaving of those actions 20 | * by the runtime, and without requiring any additional synchronization or coordination on the 21 | * part of the caller. 22 | */ 23 | @Documented 24 | @Target(ElementType.TYPE) 25 | @Retention(RetentionPolicy.RUNTIME) 26 | public @interface ThreadSafe { 27 | } 28 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/AbstractObjectSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008 - 2011 10gen, Inc. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bson.util; 18 | 19 | abstract class AbstractObjectSerializer implements ObjectSerializer { 20 | 21 | @Override 22 | public String serialize(final Object obj) { 23 | StringBuilder builder = new StringBuilder(); 24 | serialize(obj, builder); 25 | return builder.toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/include/dmsRecord.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef DMSRECORD_HPP__ 17 | #define DMSRECORD_HPP__ 18 | 19 | typedef unsigned int PAGEID ; 20 | typedef unsigned int SLOTID ; 21 | // each record is represented by RID, which can be broken into page id and slot id 22 | struct dmsRecordID 23 | { 24 | PAGEID _pageID ; 25 | SLOTID _slotID ; 26 | } ; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/driver/java/src/com/emeralddb/net/IConnection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 SequoiaDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.emeralddb.net; 17 | 18 | import com.emeralddb.exception.BaseException; 19 | /** 20 | * @author Jacky Zhang 21 | * 22 | */ 23 | public interface IConnection { 24 | public void initialize() throws BaseException; 25 | public void close(); 26 | public void changeConfigOptions(ConfigOptions opts) throws BaseException; 27 | 28 | public long sendMessage(byte[] msg) throws BaseException; 29 | 30 | public byte[] receiveMessage() throws BaseException; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/win/emeralddb_win.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _WINDOWS 2 | 3 | #include "core.hpp" 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #ifdef WIN32 10 | #pragma comment(lib, "ws2_32.lib") 11 | #else 12 | #error("do not the appropriate library"); 13 | #endif 14 | 15 | const int SEC_PER_MSEC = 1000; 16 | 17 | unsigned sleep(unsigned seconds) 18 | { 19 | Sleep(seconds * SEC_PER_MSEC); 20 | return 0; 21 | } 22 | 23 | unsigned getpid(void) 24 | { 25 | return (unsigned)GetCurrentProcessId(); 26 | } 27 | 28 | unsigned pthread_self() 29 | { 30 | return (unsigned)GetCurrentThreadId(); 31 | } 32 | 33 | struct tm *localtime_r(const time_t *timer, struct tm *result) 34 | { 35 | if (0 == localtime_s(result, timer) ) 36 | { 37 | return result; 38 | } 39 | return NULL; 40 | } 41 | 42 | // initialize socket environment and release it 43 | class __CSocketEnvironment 44 | { 45 | public: 46 | __CSocketEnvironment() 47 | { 48 | WSADATA data; 49 | WSAStartup(MAKEWORD(2, 2), &data); 50 | } 51 | 52 | ~__CSocketEnvironment() 53 | { 54 | WSACleanup(); 55 | } 56 | }; 57 | 58 | static __CSocketEnvironment sgl_SocketEnvironment; 59 | 60 | #ifdef __cplusplus 61 | }; 62 | #endif 63 | 64 | #endif // _WINDOWS -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/internal/ObjectConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.internal; 18 | 19 | /** 20 | * Defines a generic object construction factory. The purpose of this class 21 | * is to construct a default instance of a class that can be used for object 22 | * navigation while deserialization from its JSON representation. 23 | * 24 | * @author Inderjeet Singh 25 | * @author Joel Leitch 26 | */ 27 | public interface ObjectConstructor { 28 | 29 | /** 30 | * Returns a new instance. 31 | */ 32 | public T construct(); 33 | } -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/BSONDecoder.java: -------------------------------------------------------------------------------- 1 | // BSONDecoder.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson; 20 | 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | 24 | public interface BSONDecoder { 25 | 26 | public BSONObject readObject( byte[] b ); 27 | 28 | public BSONObject readObject( InputStream in ) throws IOException; 29 | 30 | public int decode( byte[] b , BSONCallback callback ); 31 | 32 | public int decode( InputStream in , BSONCallback callback ) throws IOException; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/internal/JsonReaderInternalAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.internal; 18 | 19 | import com.google.gson.stream.JsonReader; 20 | import java.io.IOException; 21 | 22 | /** 23 | * Internal-only APIs of JsonReader available only to other classes in Gson. 24 | */ 25 | public abstract class JsonReaderInternalAccess { 26 | public static JsonReaderInternalAccess INSTANCE; 27 | 28 | /** 29 | * Changes the type of the current property name token to a string value. 30 | */ 31 | public abstract void promoteNameToValue(JsonReader reader) throws IOException; 32 | } 33 | -------------------------------------------------------------------------------- /src/bson/src/lib/nonce.h: -------------------------------------------------------------------------------- 1 | // nonce.h 2 | 3 | /* Copyright 2009 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | namespace Nonce { 23 | 24 | typedef unsigned long long nonce; 25 | 26 | struct Security { 27 | Security(); 28 | 29 | nonce getNonce(); 30 | /** safe during global var initialization */ 31 | nonce getNonceInitSafe() { 32 | init(); 33 | return getNonce(); 34 | } 35 | 36 | private: 37 | std::ifstream *_devrandom; 38 | static bool _initialized; 39 | void init(); 40 | 41 | }; 42 | 43 | extern Security security; 44 | 45 | } // namespace mongo 46 | -------------------------------------------------------------------------------- /src/bson/src/bson.h: -------------------------------------------------------------------------------- 1 | /** @file bson.h 2 | BSON classes 3 | */ 4 | 5 | /* 6 | * Copyright 2009 10gen Inc. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | /** 22 | bo and its helpers 23 | 24 | "BSON" stands for "binary JSON" -- ie a binary way to represent objects that 25 | would be represented in JSON (plus a few extensions useful for databases & 26 | other languages). 27 | 28 | http://www.bsonspec.org/ 29 | */ 30 | 31 | #pragma once 32 | 33 | #include "bsonassert.h" 34 | 35 | #include "bsontypes.h" 36 | #include "oid.h" 37 | #include "bsonelement.h" 38 | #include "bsonobj.h" 39 | #include "bsonmisc.h" 40 | #include "bsonobjbuilder.h" 41 | #include "bsonobjiterator.h" 42 | #include "bson-inl.h" 43 | #include "bson_db.h" -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/ObjectSerializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 10gen Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bson.util; 18 | 19 | /** 20 | * Interface describing methods for serializing an object to a string. 21 | */ 22 | public interface ObjectSerializer { 23 | /** 24 | * Serializes obj into buf. 25 | * 26 | * @param obj object to serialize 27 | * @param buf buffer to serialize into 28 | */ 29 | void serialize(Object obj, StringBuilder buf); 30 | 31 | /** 32 | * Serializes obj. 33 | * @param obj object to serialize 34 | * @return the serialized object 35 | */ 36 | String serialize(Object obj); 37 | } 38 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS=foreign 2 | bin_PROGRAMS=emeralddb edb 3 | emeralddb_SOURCES=\ 4 | pmd/pmdMain.cpp pmd/pmdTcpListener.cpp pmd/pmdOptions.cpp \ 5 | pmd/pmd.cpp pmd/pmdEDU.cpp pmd/pmdEDUMgr.cpp pmd/pmdAgent.cpp \ 6 | bson/src/bsonobj.cpp bson/src/util/json.cpp bson/src/oid.cpp \ 7 | bson/src/lib/base64.cpp bson/src/lib/md5.cpp bson/src/lib/nonce.cpp \ 8 | oss/ossSocket.cpp oss/ossPrimitiveFileOp.cpp oss/ossMmapFile.cpp \ 9 | oss/ossHash.cpp \ 10 | pd/pd.cpp msg/msg.cpp dms/dms.cpp rtn/rtn.cpp ixm/ixmBucket.cpp 11 | 12 | edb_SOURCES=\ 13 | client/edb.cpp client/command.cpp client/commandFactory.cpp \ 14 | bson/src/bsonobj.cpp bson/src/util/json.cpp bson/src/oid.cpp \ 15 | bson/src/lib/base64.cpp bson/src/lib/md5.cpp bson/src/lib/nonce.cpp \ 16 | oss/ossSocket.cpp oss/ossPrimitiveFileOp.cpp \ 17 | pd/pd.cpp msg/msg.cpp 18 | 19 | emeralddb_CXXFLAGS=-I../boost -Ibson/src -Iinclude -D_FILE_OFFSET_BITS=64 -ggdb -Wall -O0 20 | 21 | emeralddb_LDADD=-lpthread -lm -lboost_system -lboost_thread -lboost_program_options -lrt 22 | 23 | emeralddb_LDFLAGS=-fPIC -rdynamic -L../boost/stage/lib -pthread 24 | 25 | edb_CXXFLAGS=-I../boost -Ibson/src -Iinclude -D_FILE_OFFSET_BITS=64 -ggdb -Wall -O0 26 | edb_LDADD=-lm -lboost_system -lboost_thread -lrt 27 | edb_LDFLAGS=-fPIC -rdynamic -L../boost/stage/lib 28 | -------------------------------------------------------------------------------- /src/client/commandFactory.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #include "commandFactory.hpp" 17 | 18 | CommandFactory::CommandFactory() 19 | { 20 | addCommand(); 21 | } 22 | 23 | ICommand * CommandFactory::getCommandProcesser(const char * pCmd) 24 | { 25 | ICommand * pProcessor = NULL; 26 | do { 27 | COMMAND_MAP::iterator iter; 28 | iter = _cmdMap.find(pCmd); 29 | if( iter != _cmdMap.end() ) 30 | { 31 | pProcessor = iter->second; 32 | } 33 | }while(0); 34 | return pProcessor; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/MinKey.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Copyright (C) 2008 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bson.types; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * Represent the minimum key value regardless of the key's type 24 | */ 25 | public class MinKey implements Serializable { 26 | 27 | private static final long serialVersionUID = 4075901136671855684L; 28 | 29 | public MinKey() { 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | return o instanceof MinKey; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "MinKey"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/MaxKey.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Copyright (C) 2008 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.bson.types; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * Represent the maximum key value regardless of the key's type 24 | */ 25 | public class MaxKey implements Serializable { 26 | 27 | private static final long serialVersionUID = 5123414776151687185L; 28 | 29 | public MaxKey() { 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | return o instanceof MaxKey; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "MaxKey"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /emeralddb.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C++ Express 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "emeralddb", "emeralddb\emeralddb.vcxproj", "{4AA4AC33-EFA2-4D6B-BA84-2E5534CBAD53}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client\client.vcxproj", "{BC7A7064-C7B6-4885-89B5-ACE69AF4E3F9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4AA4AC33-EFA2-4D6B-BA84-2E5534CBAD53}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {4AA4AC33-EFA2-4D6B-BA84-2E5534CBAD53}.Debug|Win32.Build.0 = Debug|Win32 16 | {4AA4AC33-EFA2-4D6B-BA84-2E5534CBAD53}.Release|Win32.ActiveCfg = Release|Win32 17 | {4AA4AC33-EFA2-4D6B-BA84-2E5534CBAD53}.Release|Win32.Build.0 = Release|Win32 18 | {BC7A7064-C7B6-4885-89B5-ACE69AF4E3F9}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {BC7A7064-C7B6-4885-89B5-ACE69AF4E3F9}.Debug|Win32.Build.0 = Debug|Win32 20 | {BC7A7064-C7B6-4885-89B5-ACE69AF4E3F9}.Release|Win32.ActiveCfg = Release|Win32 21 | {BC7A7064-C7B6-4885-89B5-ACE69AF4E3F9}.Release|Win32.Build.0 = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /src/pmd/pmd.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #include "pmd.hpp" 17 | #include "pmdOptions.hpp" 18 | #include "pd.hpp" 19 | 20 | EDB_KRCB pmd_krcb ; 21 | extern char _pdDiagLogPath [ OSS_MAX_PATHSIZE+1 ] ; 22 | int EDB_KRCB::init ( pmdOptions *options ) 23 | { 24 | setDBStatus ( EDB_DB_NORMAL ) ; 25 | setDataFilePath ( options->getDBPath () ) ; 26 | setLogFilePath ( options->getLogPath () ) ; 27 | strncpy ( _pdDiagLogPath, getLogFilePath(), sizeof(_pdDiagLogPath) ) ; 28 | setSvcName ( options->getServiceName () ) ; 29 | setMaxPool ( options->getMaxPool () ) ; 30 | return _rtnMgr.rtnInitialize() ; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/internal/$Gson$Preconditions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.internal; 18 | 19 | /** 20 | * A simple utility class used to check method Preconditions. 21 | * 22 | *

23 |  * public long divideBy(long value) {
24 |  *   Preconditions.checkArgument(value != 0);
25 |  *   return this.value / value;
26 |  * }
27 |  * 
28 | * 29 | * @author Inderjeet Singh 30 | * @author Joel Leitch 31 | */ 32 | public final class $Gson$Preconditions { 33 | public static T checkNotNull(T obj) { 34 | if (obj == null) { 35 | throw new NullPointerException(); 36 | } 37 | return obj; 38 | } 39 | 40 | public static void checkArgument(boolean condition) { 41 | if (!condition) { 42 | throw new IllegalArgumentException(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/include/rtn.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef RTN_HPP__ 17 | #define RTN_HPP__ 18 | 19 | #include "bson.h" 20 | #include "dms.hpp" 21 | #include "ixmBucket.hpp" 22 | // define the storage file name 23 | #define RTN_FILE_NAME "data.1" 24 | 25 | class rtn 26 | { 27 | private : 28 | dmsFile *_dmsFile ; 29 | ixmBucketManager *_ixmBucketMgr ; 30 | public : 31 | rtn () ; 32 | ~rtn() ; 33 | int rtnInitialize () ; 34 | int rtnInsert ( bson::BSONObj &record ) ; 35 | int rtnFind ( bson::BSONObj &inRecord, bson::BSONObj &outRecord ) ; 36 | int rtnRemove ( bson::BSONObj &record ) ; 37 | } ; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/FieldNamingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | /** 22 | * A mechanism for providing custom field naming in Gson. This allows the client code to translate 23 | * field names into a particular convention that is not supported as a normal Java field 24 | * declaration rules. For example, Java does not support "-" characters in a field name. 25 | * 26 | * @author Inderjeet Singh 27 | * @author Joel Leitch 28 | * @since 1.3 29 | */ 30 | public interface FieldNamingStrategy { 31 | 32 | /** 33 | * Translates the field name into its JSON field name representation. 34 | * 35 | * @param f the field object that we are translating 36 | * @return the translated field name. 37 | * @since 1.3 38 | */ 39 | public String translateName(Field f); 40 | } 41 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/annotations/Immutable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 3 | * Released under the Creative Commons Attribution License 4 | * (http://creativecommons.org/licenses/by/2.5) 5 | * Official home: http://www.jcip.net 6 | * 7 | * Any republication or derived work distributed in source code form 8 | * must include this copyright and license notice. 9 | */ 10 | 11 | package org.bson.util.annotations; 12 | 13 | import java.lang.annotation.*; 14 | 15 | /** 16 | * The class to which this annotation is applied is immutable. This means that 17 | * its state cannot be seen to change by callers, which implies that 18 | *
    19 | *
  • all public fields are final,
  • 20 | *
  • all public final reference fields refer to other immutable objects, and
  • 21 | *
  • constructors and methods do not publish references to any internal state 22 | * which is potentially mutable by the implementation.
  • 23 | *
24 | * Immutable objects may still have internal mutable state for purposes of performance 25 | * optimization; some state variables may be lazily computed, so long as they are computed 26 | * from immutable state and that callers cannot tell the difference. 27 | *

28 | * Immutable objects are inherently thread-safe; they may be passed between threads or 29 | * published without synchronization. 30 | */ 31 | @Documented 32 | @Target(ElementType.TYPE) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | public @interface Immutable { 35 | } 36 | -------------------------------------------------------------------------------- /src/client/edb.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef _EDB_HPP_ 17 | #define _EDB_HPP_ 18 | 19 | #include "core.hpp" 20 | #include "ossSocket.hpp" 21 | #include "commandFactory.hpp" 22 | const int CMD_BUFFER_SIZE = 512; 23 | class Edb { 24 | public: 25 | Edb(){} 26 | ~Edb(){}; 27 | public: 28 | void start(void); 29 | protected: 30 | void prompt(void); 31 | private: 32 | void split(const std::string &text, char delim, std::vector &result); 33 | char* readLine(char *p, int length); 34 | int readInput(const char *pPrompt, int numIndent); 35 | private: 36 | ossSocket _sock; 37 | CommandFactory _cmdFactory; 38 | char _cmdBuffer[CMD_BUFFER_SIZE]; 39 | }; 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/JsonIOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.gson; 17 | 18 | /** 19 | * This exception is raised when Gson was unable to read an input stream 20 | * or write to one. 21 | * 22 | * @author Inderjeet Singh 23 | * @author Joel Leitch 24 | */ 25 | public final class JsonIOException extends JsonParseException { 26 | private static final long serialVersionUID = 1L; 27 | 28 | public JsonIOException(String msg) { 29 | super(msg); 30 | } 31 | 32 | public JsonIOException(String msg, Throwable cause) { 33 | super(msg, cause); 34 | } 35 | 36 | /** 37 | * Creates exception with the specified cause. Consider using 38 | * {@link #JsonIOException(String, Throwable)} instead if you can describe what happened. 39 | * 40 | * @param cause root exception that caused this exception to be thrown. 41 | */ 42 | public JsonIOException(Throwable cause) { 43 | super(cause); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/JsonSyntaxException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.gson; 17 | 18 | /** 19 | * This exception is raised when Gson attempts to read (or write) a malformed 20 | * JSON element. 21 | * 22 | * @author Inderjeet Singh 23 | * @author Joel Leitch 24 | */ 25 | public final class JsonSyntaxException extends JsonParseException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | public JsonSyntaxException(String msg) { 30 | super(msg); 31 | } 32 | 33 | public JsonSyntaxException(String msg, Throwable cause) { 34 | super(msg, cause); 35 | } 36 | 37 | /** 38 | * Creates exception with the specified cause. Consider using 39 | * {@link #JsonSyntaxException(String, Throwable)} instead if you can 40 | * describe what actually happened. 41 | * 42 | * @param cause root exception that caused this exception to be thrown. 43 | */ 44 | public JsonSyntaxException(Throwable cause) { 45 | super(cause); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/CodeWScope.java: -------------------------------------------------------------------------------- 1 | // CodeWScope.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson.types; 20 | 21 | import org.bson.*; 22 | 23 | /** 24 | * for using the CodeWScope type 25 | */ 26 | public class CodeWScope extends Code { 27 | 28 | private static final long serialVersionUID = -6284832275113680002L; 29 | 30 | public CodeWScope( String code , BSONObject scope ){ 31 | super( code ); 32 | _scope = scope; 33 | } 34 | 35 | public BSONObject getScope(){ 36 | return _scope; 37 | } 38 | 39 | public boolean equals( Object o ){ 40 | if ( ! ( o instanceof CodeWScope ) ) 41 | return false; 42 | 43 | CodeWScope c = (CodeWScope)o; 44 | return _code.equals( c._code ) && _scope.equals( c._scope ); 45 | } 46 | 47 | public int hashCode(){ 48 | return _code.hashCode() ^ _scope.hashCode(); 49 | } 50 | 51 | final BSONObject _scope; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/SimplePool.java: -------------------------------------------------------------------------------- 1 | // SimplePool.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson.util; 20 | 21 | import java.util.*; 22 | import java.util.concurrent.*; 23 | 24 | public abstract class SimplePool { 25 | 26 | public SimplePool( int max ){ 27 | _max = max; 28 | } 29 | 30 | public SimplePool(){ 31 | _max = 1000; 32 | } 33 | 34 | protected abstract T createNew(); 35 | 36 | protected boolean ok( T t ){ 37 | return true; 38 | } 39 | 40 | public T get(){ 41 | T t = _stored.poll(); 42 | if ( t != null ) 43 | return t; 44 | return createNew(); 45 | } 46 | 47 | public void done( T t ){ 48 | if ( ! ok( t ) ) 49 | return; 50 | 51 | if ( _stored.size() > _max ) 52 | return; 53 | _stored.add( t ); 54 | } 55 | 56 | final int _max; 57 | private Queue _stored = new ConcurrentLinkedQueue(); 58 | } 59 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/Code.java: -------------------------------------------------------------------------------- 1 | // Code.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson.types; 20 | 21 | import java.io.Serializable; 22 | import java.util.*; 23 | 24 | import org.bson.*; 25 | 26 | /** 27 | * for using the Code type 28 | */ 29 | public class Code implements Serializable { 30 | 31 | private static final long serialVersionUID = 475535263314046697L; 32 | 33 | public Code( String code ){ 34 | _code = code; 35 | } 36 | 37 | public String getCode(){ 38 | return _code; 39 | } 40 | 41 | public boolean equals( Object o ){ 42 | if ( ! ( o instanceof Code ) ) 43 | return false; 44 | 45 | Code c = (Code)o; 46 | return _code.equals( c._code ); 47 | } 48 | 49 | public int hashCode(){ 50 | return _code.hashCode(); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return getCode(); 56 | } 57 | 58 | final String _code; 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/Assertions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2008 Atlassian Pty Ltd 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bson.util; 18 | 19 | /** 20 | * Design by contract assertions. 21 | */ 22 | public class Assertions { 23 | public static T notNull(final String name, final T notNull) throws IllegalArgumentException { 24 | if (notNull == null) { 25 | throw new NullArgumentException(name); 26 | } 27 | return notNull; 28 | } 29 | 30 | public static void isTrue(final String name, final boolean check) throws IllegalArgumentException { 31 | if (!check) { 32 | throw new IllegalArgumentException(name); 33 | } 34 | } 35 | 36 | // /CLOVER:OFF 37 | private Assertions() {} 38 | 39 | // /CLOVER:ON 40 | 41 | static class NullArgumentException extends IllegalArgumentException { 42 | private static final long serialVersionUID = 6178592463723624585L; 43 | 44 | NullArgumentException(final String name) { 45 | super(name + " should not be null!"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/bson/src/util/json.h: -------------------------------------------------------------------------------- 1 | /** @file json.h */ 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License, version 3, 8 | * as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Affero General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Affero General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #pragma once 20 | 21 | #include "../bson.h" 22 | 23 | namespace bson { 24 | 25 | /** Create a BSONObj from a JSON string. In addition 26 | to the JSON extensions extensions described here 27 | , 28 | this function accepts certain unquoted field names and allows single quotes 29 | to optionally be used when specifying field names and string values instead 30 | of double quotes. JSON unicode escape sequences (of the form \uXXXX) are 31 | converted to utf8. 32 | \throws MsgAssertionException if parsing fails. The message included with 33 | this assertion includes a rough indication of where parsing failed. 34 | */ 35 | BSONObj fromjson(const string &str); 36 | 37 | /** len will be size of JSON object in text chars. */ 38 | BSONObj fromjson(const char *str, int* len=NULL); 39 | 40 | } // namespace mongo 41 | -------------------------------------------------------------------------------- /src/client/commandFactory.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef _COMMAND_FACTORY_HPP_ 17 | #define _COMMAND_FACTORY_HPP_ 18 | 19 | #include "command.hpp" 20 | #define COMMAND_BEGIN void CommandFactory::addCommand() { 21 | #define COMMAND_END } 22 | #define COMMAND_ADD(cmdName,cmdClass) { \ 23 | ICommand* pObj = new cmdClass(); \ 24 | std::string str = cmdName; \ 25 | _cmdMap.insert(COMMAND_MAP::value_type(str,pObj)); \ 26 | } \ 27 | 28 | class CommandFactory { 29 | typedef std::map COMMAND_MAP; 30 | public: 31 | CommandFactory(); 32 | ~CommandFactory(){} 33 | void addCommand(); 34 | ICommand * getCommandProcesser(const char * pcmd); 35 | private: 36 | COMMAND_MAP _cmdMap; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/stream/MalformedJsonException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.stream; 18 | 19 | import java.io.IOException; 20 | 21 | /** 22 | * Thrown when a reader encounters malformed JSON. Some syntax errors can be 23 | * ignored by calling {@link JsonReader#setLenient(boolean)}. 24 | */ 25 | public final class MalformedJsonException extends IOException { 26 | private static final long serialVersionUID = 1L; 27 | 28 | public MalformedJsonException(String msg) { 29 | super(msg); 30 | } 31 | 32 | public MalformedJsonException(String msg, Throwable throwable) { 33 | super(msg); 34 | // Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException 35 | // with a constructor with Throwable. This was done in Java 1.6 36 | initCause(throwable); 37 | } 38 | 39 | public MalformedJsonException(Throwable throwable) { 40 | // Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException 41 | // with a constructor with Throwable. This was done in Java 1.6 42 | initCause(throwable); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/driver/java/src/com/emeralddb/exception/EDBError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 SequoiaDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.emeralddb.exception; 17 | 18 | /** 19 | * @author Jacky Zhang 20 | * 21 | */ 22 | 23 | public class EDBError { 24 | private String errorType; 25 | private int errorCode; 26 | private String errorDescription; 27 | 28 | /** 29 | * @return 30 | */ 31 | public String getErrorType() { 32 | return errorType; 33 | } 34 | 35 | /** 36 | * @param errorType 37 | */ 38 | public void setErrorType(String errorType) { 39 | this.errorType = errorType; 40 | } 41 | 42 | /** 43 | * @return 44 | */ 45 | public int getErrorCode() { 46 | return errorCode; 47 | } 48 | 49 | /** 50 | * @param errorCode 51 | */ 52 | public void setErrorCode(int errorCode) { 53 | this.errorCode = errorCode; 54 | } 55 | 56 | /** 57 | * @return 58 | */ 59 | public String getErrorDescription() { 60 | return errorDescription; 61 | } 62 | 63 | /** 64 | * @param errorDescription 65 | */ 66 | public void setErrorDescription(String errorDescription) { 67 | this.errorDescription = errorDescription; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/JsonNull.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson; 18 | 19 | /** 20 | * A class representing a Json {@code null} value. 21 | * 22 | * @author Inderjeet Singh 23 | * @author Joel Leitch 24 | * @since 1.2 25 | */ 26 | public final class JsonNull extends JsonElement { 27 | /** 28 | * singleton for JsonNull 29 | * 30 | * @since 1.8 31 | */ 32 | public static final JsonNull INSTANCE = new JsonNull(); 33 | 34 | /** 35 | * Creates a new JsonNull object. 36 | * Deprecated since Gson version 1.8. Use {@link #INSTANCE} instead 37 | */ 38 | @Deprecated 39 | public JsonNull() { 40 | // Do nothing 41 | } 42 | 43 | @Override public JsonNull deepCopy() { 44 | return INSTANCE; 45 | } 46 | 47 | /** 48 | * All instances of JsonNull have the same hash code since they are indistinguishable 49 | */ 50 | @Override 51 | public int hashCode() { 52 | return JsonNull.class.hashCode(); 53 | } 54 | 55 | /** 56 | * All instances of JsonNull are the same 57 | */ 58 | @Override 59 | public boolean equals(Object other) { 60 | return this == other || other instanceof JsonNull; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/JsonDeserializationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson; 18 | 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * Context for deserialization that is passed to a custom deserializer during invocation of its 23 | * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)} 24 | * method. 25 | * 26 | * @author Inderjeet Singh 27 | * @author Joel Leitch 28 | */ 29 | public interface JsonDeserializationContext { 30 | 31 | /** 32 | * Invokes default deserialization on the specified object. It should never be invoked on 33 | * the element received as a parameter of the 34 | * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)} method. Doing 35 | * so will result in an infinite loop since Gson will in-turn call the custom deserializer again. 36 | * 37 | * @param json the parse tree. 38 | * @param typeOfT type of the expected return value. 39 | * @param The type of the deserialized object. 40 | * @return An object of type typeOfT. 41 | * @throws JsonParseException if the parse tree does not contain expected data. 42 | */ 43 | public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException; 44 | } -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/JSONParseException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2008 10gen Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bson.util; 18 | 19 | /** 20 | * Exception throw when invalid JSON is passed to JSONParser. 21 | * 22 | * This exception creates a message that points to the first 23 | * offending character in the JSON string: 24 | *

25 |  * { "x" : 3, "y" : 4, some invalid json.... }
26 |  *                     ^
27 |  * 
28 | */ 29 | public class JSONParseException extends RuntimeException { 30 | 31 | private static final long serialVersionUID = -4415279469780082174L; 32 | 33 | String s; 34 | int pos; 35 | 36 | public String getMessage() { 37 | StringBuilder sb = new StringBuilder(); 38 | sb.append("\n"); 39 | sb.append(s); 40 | sb.append("\n"); 41 | for(int i=0;i 22 | #include 23 | 24 | namespace md5 { 25 | 26 | typedef unsigned char md5digest[16]; 27 | 28 | inline void md5(const void *buf, int nbytes, md5digest digest) { 29 | md5_state_t st; 30 | md5_init(&st); 31 | md5_append(&st, (const md5_byte_t *) buf, nbytes); 32 | md5_finish(&st, digest); 33 | } 34 | 35 | inline void md5(const char *str, md5digest digest) { 36 | md5(str, strlen(str), digest); 37 | } 38 | 39 | inline std::string digestToString( md5digest digest ){ 40 | static const char * letters = "0123456789abcdef"; 41 | std::stringstream ss; 42 | for ( int i=0; i<16; i++){ 43 | unsigned char c = digest[i]; 44 | ss << letters[ ( c >> 4 ) & 0xf ] << letters[ c & 0xf ]; 45 | } 46 | return ss.str(); 47 | } 48 | 49 | inline std::string md5simpledigest( const void* buf, int nbytes){ 50 | md5digest d; 51 | md5( buf, nbytes , d ); 52 | return digestToString( d ); 53 | } 54 | 55 | inline std::string md5simpledigest( std::string s ){ 56 | return md5simpledigest(s.data(), s.size()); 57 | } 58 | 59 | 60 | } // namespace md5 61 | -------------------------------------------------------------------------------- /src/driver/java/src/com/emeralddb/util/HashAlgorithm.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 SequoiaDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.emeralddb.util; 17 | 18 | import java.io.UnsupportedEncodingException; 19 | import java.security.MessageDigest; 20 | import java.security.NoSuchAlgorithmException; 21 | /*** 22 | * 23 | * @author zhouzhengle 24 | * 25 | */ 26 | public enum HashAlgorithm { 27 | /*** 28 | * MD5-based hash algorithm used by ketama. 29 | */ 30 | KETAMA_HASH; 31 | 32 | public long hash( byte[] digest, int nTime ) { 33 | long rv = ( (long) (digest[3 + nTime*4] & 0xFF) << 24 ) 34 | | ( (long) (digest[2 + nTime*4] & 0xFF ) << 16 ) 35 | | ( (long) (digest[1 + nTime*4] & 0xFF) << 8 ) 36 | | (digest[0 + nTime*4] & 0xFF); 37 | return rv & 0xFFFFFFFFL; 38 | } 39 | 40 | /*** 41 | * Get the md5 of the given key. 42 | */ 43 | public byte[] md5(String k) { 44 | MessageDigest md5; 45 | try { 46 | md5 = MessageDigest.getInstance("MD5"); 47 | } catch( NoSuchAlgorithmException e ) { 48 | throw new RuntimeException("MD5 not supported", e); 49 | } 50 | 51 | md5.reset(); 52 | byte[] keyBytes = null; 53 | try { 54 | keyBytes = k.getBytes("UTF-8"); 55 | } catch( UnsupportedEncodingException e ) { 56 | throw new RuntimeException("Unknown string :" + k, e); 57 | } 58 | 59 | md5.update(keyBytes); 60 | return md5.digest(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/LongSerializationPolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson; 18 | 19 | /** 20 | * Defines the expected format for a {@code long} or {@code Long} type when its serialized. 21 | * 22 | * @since 1.3 23 | * 24 | * @author Inderjeet Singh 25 | * @author Joel Leitch 26 | */ 27 | public enum LongSerializationPolicy { 28 | /** 29 | * This is the "default" serialization policy that will output a {@code long} object as a JSON 30 | * number. For example, assume an object has a long field named "f" then the serialized output 31 | * would be: 32 | * {@code {"f":123}}. 33 | */ 34 | DEFAULT() { 35 | public JsonElement serialize(Long value) { 36 | return new JsonPrimitive(value); 37 | } 38 | }, 39 | 40 | /** 41 | * Serializes a long value as a quoted string. For example, assume an object has a long field 42 | * named "f" then the serialized output would be: 43 | * {@code {"f":"123"}}. 44 | */ 45 | STRING() { 46 | public JsonElement serialize(Long value) { 47 | return new JsonPrimitive(String.valueOf(value)); 48 | } 49 | }; 50 | 51 | /** 52 | * Serialize this {@code value} using this serialization policy. 53 | * 54 | * @param value the long value to be serialized into a {@link JsonElement} 55 | * @return the serialized version of {@code value} 56 | */ 57 | public abstract JsonElement serialize(Long value); 58 | } 59 | -------------------------------------------------------------------------------- /src/include/pmdEDUEvent.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef PMDEDUEVENT_HPP__ 17 | #define PMDEDUEVENT_HPP__ 18 | 19 | #include "core.hpp" 20 | enum pmdEDUEventTypes 21 | { 22 | PMD_EDU_EVENT_NONE = 0, 23 | PMD_EDU_EVENT_TERM, // terminate EDU 24 | PMD_EDU_EVENT_RESUME, // resume a EDU, the data is startEDU's argv 25 | PMD_EDU_EVENT_ACTIVE, 26 | PMD_EDU_EVENT_DEACTIVE, 27 | PMD_EDU_EVENT_MSG, 28 | PMD_EDU_EVENT_TIMEOUT, // timeout 29 | PMD_EDU_EVENT_LOCKWAKEUP // transaction lock wake up 30 | } ; 31 | 32 | class pmdEDUEvent 33 | { 34 | public : 35 | pmdEDUEvent () : 36 | _eventType(PMD_EDU_EVENT_NONE), 37 | _release(false), 38 | _Data(NULL) 39 | { 40 | } 41 | 42 | pmdEDUEvent ( pmdEDUEventTypes type ) : 43 | _eventType(type), 44 | _release(false), 45 | _Data(NULL) 46 | { 47 | } 48 | 49 | pmdEDUEvent ( pmdEDUEventTypes type, bool release, void *data ) : 50 | _eventType(type), 51 | _release(release), 52 | _Data(data) 53 | { 54 | } 55 | 56 | void reset () 57 | { 58 | _eventType = PMD_EDU_EVENT_NONE ; 59 | _release = false ; 60 | _Data = NULL ; 61 | } 62 | 63 | pmdEDUEventTypes _eventType ; 64 | bool _release ; 65 | void *_Data ; 66 | } ; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/JsonSerializationContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson; 18 | 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * Context for serialization that is passed to a custom serializer during invocation of its 23 | * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method. 24 | * 25 | * @author Inderjeet Singh 26 | * @author Joel Leitch 27 | */ 28 | public interface JsonSerializationContext { 29 | 30 | /** 31 | * Invokes default serialization on the specified object. 32 | * 33 | * @param src the object that needs to be serialized. 34 | * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}. 35 | */ 36 | public JsonElement serialize(Object src); 37 | 38 | /** 39 | * Invokes default serialization on the specified object passing the specific type information. 40 | * It should never be invoked on the element received as a parameter of the 41 | * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method. Doing 42 | * so will result in an infinite loop since Gson will in-turn call the custom serializer again. 43 | * 44 | * @param src the object that needs to be serialized. 45 | * @param typeOfSrc the actual genericized type of src object. 46 | * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}. 47 | */ 48 | public JsonElement serialize(Object src, Type typeOfSrc); 49 | } 50 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/Symbol.java: -------------------------------------------------------------------------------- 1 | // Symbol.java 2 | 3 | /** 4 | * Copyright (C) 2009 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson.types; 20 | 21 | import java.io.Serializable; 22 | 23 | /** 24 | * Class to hold a BSON symbol object, which is an interned string in Ruby 25 | */ 26 | public class Symbol implements Serializable { 27 | 28 | private static final long serialVersionUID = 1326269319883146072L; 29 | 30 | public Symbol(String s) { 31 | _symbol = s; 32 | } 33 | 34 | public String getSymbol(){ 35 | return _symbol; 36 | } 37 | 38 | /** 39 | * Will compare equal to a String that is equal to the String that this holds 40 | * @param o 41 | * @return 42 | */ 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) return true; 46 | if (o == null) return false; 47 | 48 | String otherSymbol; 49 | if (o instanceof Symbol) { 50 | otherSymbol = ((Symbol) o)._symbol; 51 | } 52 | else if (o instanceof String) { 53 | otherSymbol = (String) o; 54 | } 55 | else { 56 | return false; 57 | } 58 | 59 | if (_symbol != null ? !_symbol.equals(otherSymbol) : otherSymbol != null) return false; 60 | 61 | return true; 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return _symbol != null ? _symbol.hashCode() : 0; 67 | } 68 | 69 | public String toString(){ 70 | return _symbol; 71 | } 72 | 73 | private final String _symbol; 74 | } 75 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/annotations/GuardedBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005 Brian Goetz and Tim Peierls 3 | * Released under the Creative Commons Attribution License 4 | * (http://creativecommons.org/licenses/by/2.5) 5 | * Official home: http://www.jcip.net 6 | * 7 | * Any republication or derived work distributed in source code form 8 | * must include this copyright and license notice. 9 | */ 10 | 11 | package org.bson.util.annotations; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * The field or method to which this annotation is applied can only be accessed 20 | * when holding a particular lock, which may be a built-in (synchronization) lock, 21 | * or may be an explicit java.util.concurrent.Lock. 22 | * 23 | * The argument determines which lock guards the annotated field or method: 24 | *
    25 | *
  • 26 | * this : The intrinsic lock of the object in whose class the field is defined. 27 | *
  • 28 | *
  • 29 | * class-name.this : For inner classes, it may be necessary to disambiguate 'this'; 30 | * the class-name.this designation allows you to specify which 'this' reference is intended 31 | *
  • 32 | *
  • 33 | * itself : For reference fields only; the object to which the field refers. 34 | *
  • 35 | *
  • 36 | * field-name : The lock object is referenced by the (instance or static) field 37 | * specified by field-name. 38 | *
  • 39 | *
  • 40 | * class-name.field-name : The lock object is reference by the static field specified 41 | * by class-name.field-name. 42 | *
  • 43 | *
  • 44 | * method-name() : The lock object is returned by calling the named nil-ary method. 45 | *
  • 46 | *
  • 47 | * class-name.class : The Class object for the specified class should be used as the lock object. 48 | *
  • 49 | */ 50 | @Target({ElementType.FIELD, ElementType.METHOD}) 51 | @Retention(RetentionPolicy.RUNTIME) 52 | public @interface GuardedBy { 53 | String value(); 54 | } 55 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/stream/JsonScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.stream; 18 | 19 | /** 20 | * Lexical scoping elements within a JSON reader or writer. 21 | * 22 | * @author Jesse Wilson 23 | * @since 1.6 24 | */ 25 | final class JsonScope { 26 | 27 | /** 28 | * An array with no elements requires no separators or newlines before 29 | * it is closed. 30 | */ 31 | static final int EMPTY_ARRAY = 1; 32 | 33 | /** 34 | * A array with at least one value requires a comma and newline before 35 | * the next element. 36 | */ 37 | static final int NONEMPTY_ARRAY = 2; 38 | 39 | /** 40 | * An object with no name/value pairs requires no separators or newlines 41 | * before it is closed. 42 | */ 43 | static final int EMPTY_OBJECT = 3; 44 | 45 | /** 46 | * An object whose most recent element is a key. The next element must 47 | * be a value. 48 | */ 49 | static final int DANGLING_NAME = 4; 50 | 51 | /** 52 | * An object with at least one name/value pair requires a comma and 53 | * newline before the next element. 54 | */ 55 | static final int NONEMPTY_OBJECT = 5; 56 | 57 | /** 58 | * No object or array has been started. 59 | */ 60 | static final int EMPTY_DOCUMENT = 6; 61 | 62 | /** 63 | * A document with at an array or object. 64 | */ 65 | static final int NONEMPTY_DOCUMENT = 7; 66 | 67 | /** 68 | * A document that's been closed and cannot be accessed. 69 | */ 70 | static final int CLOSED = 8; 71 | } 72 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/stream/StringPool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.stream; 18 | 19 | /** 20 | * A pool of string instances. Unlike the {@link String#intern() VM's 21 | * interned strings}, this pool provides no guarantee of reference equality. 22 | * It is intended only to save allocations. This class is not thread safe. 23 | */ 24 | final class StringPool { 25 | 26 | private final String[] pool = new String[512]; 27 | 28 | /** 29 | * Returns a string equal to {@code new String(array, start, length)}. 30 | */ 31 | public String get(char[] array, int start, int length) { 32 | // Compute an arbitrary hash of the content 33 | int hashCode = 0; 34 | for (int i = start; i < start + length; i++) { 35 | hashCode = (hashCode * 31) + array[i]; 36 | } 37 | 38 | // Pick a bucket using Doug Lea's supplemental secondaryHash function (from HashMap) 39 | hashCode ^= (hashCode >>> 20) ^ (hashCode >>> 12); 40 | hashCode ^= (hashCode >>> 7) ^ (hashCode >>> 4); 41 | int index = hashCode & (pool.length - 1); 42 | 43 | String pooled = pool[index]; 44 | if (pooled == null || pooled.length() != length) { 45 | String result = new String(array, start, length); 46 | pool[index] = result; 47 | return result; 48 | } 49 | 50 | for (int i = 0; i < length; i++) { 51 | if (pooled.charAt(i) != array[start + i]) { 52 | String result = new String(array, start, length); 53 | pool[index] = result; 54 | return result; 55 | } 56 | } 57 | 58 | return pooled; 59 | } 60 | } -------------------------------------------------------------------------------- /src/bson/src/lib/base64.h: -------------------------------------------------------------------------------- 1 | // util/base64.h 2 | 3 | /* Copyright 2009 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace base64 { 27 | 28 | class Alphabet { 29 | public: 30 | Alphabet() 31 | : encode((unsigned char*) 32 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 33 | "abcdefghijklmnopqrstuvwxyz" 34 | "0123456789" 35 | "+/") 36 | , decode(new unsigned char[257]) { 37 | memset( decode.get() , 0 , 256 ); 38 | for ( int i=0; i<64; i++ ) { 39 | decode[ encode[i] ] = i; 40 | } 41 | 42 | test(); 43 | } 44 | void test() { 45 | assert( strlen( (char*)encode ) == 64 ); 46 | for ( int i=0; i<26; i++ ) 47 | assert( encode[i] == toupper( encode[i+26] ) ); 48 | } 49 | 50 | char e( int x ) { 51 | return encode[x&0x3f]; 52 | } 53 | 54 | private: 55 | const unsigned char * encode; 56 | public: 57 | boost::scoped_array decode; 58 | }; 59 | 60 | extern Alphabet alphabet; 61 | 62 | void encode( std::stringstream& ss , const char * data , int size ); 63 | std::string encode( const char * data , int size ); 64 | std::string encode( const std::string& s ); 65 | 66 | void decode( std::stringstream& ss , const std::string& s ); 67 | std::string decode( const std::string& s ); 68 | 69 | void testAlphabet(); 70 | } 71 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/BSONException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011, 10gen Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.bson; 18 | 19 | /** 20 | * A general runtime exception raised in BSON processing. 21 | */ 22 | public class BSONException extends RuntimeException { 23 | 24 | private static final long serialVersionUID = -4415279469780082174L; 25 | 26 | /** 27 | * @param msg The error message. 28 | */ 29 | public BSONException( final String msg ) { 30 | super( msg ); 31 | } 32 | 33 | /** 34 | * @param errorCode The error code. 35 | * @param msg The error message. 36 | */ 37 | public BSONException( final int errorCode, final String msg ) { 38 | super( msg ); 39 | _errorCode = errorCode; 40 | } 41 | 42 | /** 43 | * @param msg The error message. 44 | * @param t The throwable cause. 45 | */ 46 | public BSONException( final String msg , final Throwable t ) { 47 | super( msg, t ); 48 | } 49 | 50 | /** 51 | * @param errorCode The error code. 52 | * @param msg The error message. 53 | * @param t The throwable cause. 54 | */ 55 | public BSONException( final int errorCode, final String msg, final Throwable t ) { 56 | super( msg, t ); 57 | _errorCode = errorCode; 58 | } 59 | 60 | /** 61 | * Returns the error code. 62 | * @return The error code. 63 | */ 64 | public Integer getErrorCode() { return _errorCode; } 65 | 66 | /** 67 | * Returns true if the error code is set (i.e., not null). 68 | */ 69 | public boolean hasErrorCode() { return (_errorCode != null); } 70 | 71 | private Integer _errorCode = null; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/bson/src/ordering.h: -------------------------------------------------------------------------------- 1 | // ordering.h 2 | 3 | /* Copyright 2009 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace bson { 21 | 22 | /** A precomputation of a BSON key pattern. 23 | The constructor is private to make conversion more explicit so we notice 24 | where we call make(). Over time we should push this up higher and 25 | higher. 26 | */ 27 | class Ordering { 28 | const unsigned bits; 29 | const unsigned nkeys; 30 | Ordering(unsigned b,unsigned n) : bits(b),nkeys(n) { } 31 | public: 32 | /** so, for key pattern { a : 1, b : -1 } 33 | get(0) == 1 34 | get(1) == -1 35 | */ 36 | int get(int i) const { 37 | return ((1 << i) & bits) ? -1 : 1; 38 | } 39 | 40 | // for woCompare... 41 | unsigned descending(unsigned mask) const { return bits & mask; } 42 | 43 | operator string() const { 44 | StringBuilder buf(32); 45 | for ( unsigned i=0; i 0 ? "+" : "-" ); 47 | return buf.str(); 48 | } 49 | 50 | static Ordering make(const BSONObj& obj) { 51 | unsigned b = 0; 52 | BSONObjIterator k(obj); 53 | unsigned n = 0; 54 | while( 1 ) { 55 | BSONElement e = k.next(); 56 | if( e.eoo() ) 57 | break; 58 | uassert( 13103, "too many compound keys", n <= 31 ); 59 | if( e.number() < 0 ) 60 | b |= (1 << n); 61 | n++; 62 | } 63 | return Ordering(b,n); 64 | } 65 | }; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/util/ClassAncestry.java: -------------------------------------------------------------------------------- 1 | package org.bson.util; 2 | 3 | import static java.util.Collections.unmodifiableList; 4 | import static org.bson.util.CopyOnWriteMap.newHashMap; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collections; 8 | import java.util.List; 9 | import java.util.concurrent.ConcurrentMap; 10 | 11 | class ClassAncestry { 12 | private static final ConcurrentMap, List>> _ancestryCache = newHashMap(); 13 | 14 | /** 15 | * getAncestry 16 | * 17 | * Walks superclass and interface graph, superclasses first, then 18 | * interfaces, to compute an ancestry list. Supertypes are visited left to 19 | * right. Duplicates are removed such that no Class will appear in the list 20 | * before one of its subtypes. 21 | * 22 | * Does not need to be synchronized, races are harmless as the Class graph 23 | * does not change at runtime. 24 | */ 25 | public static List> getAncestry(Class c) { 26 | final ConcurrentMap, List>> cache = getClassAncestryCache(); 27 | while (true) { 28 | List> cachedResult = cache.get(c); 29 | if (cachedResult != null) { return cachedResult; } 30 | cache.putIfAbsent(c, computeAncestry(c)); 31 | } 32 | } 33 | 34 | /** 35 | * computeAncestry, starting with children and going back to parents 36 | */ 37 | private static List> computeAncestry(Class c) { 38 | final List> result = new ArrayList>(); 39 | result.add(Object.class); 40 | computeAncestry(c, result); 41 | Collections.reverse(result); 42 | return unmodifiableList(new ArrayList>(result)); 43 | } 44 | 45 | private static void computeAncestry(Class c, List> result) { 46 | if ((c == null) || (c == Object.class)) { return; } 47 | 48 | // first interfaces (looks backwards but is not) 49 | Class[] interfaces = c.getInterfaces(); 50 | for (int i = interfaces.length - 1; i >= 0; i--) { 51 | computeAncestry(interfaces[i], result); 52 | } 53 | 54 | // next superclass 55 | computeAncestry(c.getSuperclass(), result); 56 | 57 | if (!result.contains(c)) result.add(c); 58 | } 59 | 60 | /** 61 | * classAncestryCache 62 | */ 63 | private static ConcurrentMap, List>> getClassAncestryCache() { 64 | return (_ancestryCache); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/bson/src/util/hex.h: -------------------------------------------------------------------------------- 1 | // util/hex.h 2 | 3 | /* Copyright 2009 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../bsonassert.h" 21 | #include "builder.h" 22 | 23 | namespace bson { 24 | 25 | //can't use hex namespace because it conflicts with hex iostream function 26 | inline int fromHex( char c ) { 27 | if ( '0' <= c && c <= '9' ) 28 | return c - '0'; 29 | if ( 'a' <= c && c <= 'f' ) 30 | return c - 'a' + 10; 31 | if ( 'A' <= c && c <= 'F' ) 32 | return c - 'A' + 10; 33 | assert( false ); 34 | return 0xff; 35 | } 36 | inline char fromHex( const char *c ) { 37 | return (char)(( fromHex( c[ 0 ] ) << 4 ) | fromHex( c[ 1 ] )); 38 | } 39 | 40 | inline string toHex(const void* inRaw, int len) { 41 | static const char hexchars[] = "0123456789ABCDEF"; 42 | 43 | StringBuilder out; 44 | const char* in = reinterpret_cast(inRaw); 45 | for (int i=0; i> 4]; 48 | char lo = hexchars[(c & 0x0F)]; 49 | 50 | out << hi << lo; 51 | } 52 | 53 | return out.str(); 54 | } 55 | 56 | inline string toHexLower(const void* inRaw, int len) { 57 | static const char hexchars[] = "0123456789abcdef"; 58 | 59 | StringBuilder out; 60 | const char* in = reinterpret_cast(inRaw); 61 | for (int i=0; i> 4]; 64 | char lo = hexchars[(c & 0x0F)]; 65 | 66 | out << hi << lo; 67 | } 68 | 69 | return out.str(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/BSONCallback.java: -------------------------------------------------------------------------------- 1 | // BSONCallback.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson; 20 | 21 | import org.bson.types.ObjectId; 22 | 23 | public interface BSONCallback { 24 | 25 | void objectStart(); 26 | void objectStart(String name); 27 | void objectStart(boolean array); 28 | Object objectDone(); 29 | 30 | void reset(); 31 | Object get(); 32 | BSONCallback createBSONCallback(); 33 | 34 | void arrayStart(); 35 | void arrayStart(String name); 36 | Object arrayDone(); 37 | 38 | void gotNull( String name ); 39 | void gotUndefined( String name ); 40 | void gotMinKey( String name ); 41 | void gotMaxKey( String name ); 42 | 43 | void gotBoolean( String name , boolean v ); 44 | void gotDouble( String name , double v ); 45 | void gotInt( String name , int v ); 46 | void gotLong( String name , long v ); 47 | 48 | void gotDate( String name , long millis ); 49 | void gotString( String name , String v ); 50 | void gotSymbol( String name , String v ); 51 | void gotRegex( String name , String pattern , String flags ); 52 | 53 | void gotTimestamp( String name , int time , int inc ); 54 | void gotObjectId( String name , ObjectId id ); 55 | void gotDBRef( String name , String ns , ObjectId id ); 56 | 57 | /** 58 | * 59 | */ 60 | @Deprecated 61 | void gotBinaryArray( String name , byte[] data ); 62 | void gotBinary( String name , byte type , byte[] data ); 63 | /** 64 | * subtype 3 65 | */ 66 | void gotUUID( String name , long part1, long part2); 67 | 68 | void gotCode( String name , String code ); 69 | void gotCodeWScope( String name , String code , Object scope ); 70 | } 71 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/internal/LazilyParsedNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.gson.internal; 17 | 18 | import java.io.ObjectStreamException; 19 | import java.math.BigDecimal; 20 | import java.math.BigInteger; 21 | 22 | /** 23 | * This class holds a number value that is lazily converted to a specific number type 24 | * 25 | * @author Inderjeet Singh 26 | */ 27 | @SuppressWarnings("serial") 28 | public final class LazilyParsedNumber extends Number { 29 | private final String value; 30 | 31 | public LazilyParsedNumber(String value) { 32 | this.value = value; 33 | } 34 | 35 | @Override 36 | public int intValue() { 37 | try { 38 | return Integer.parseInt(value); 39 | } catch (NumberFormatException e) { 40 | try { 41 | return (int) Long.parseLong(value); 42 | } catch (NumberFormatException nfe) { 43 | return new BigInteger(value).intValue(); 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | public long longValue() { 50 | try { 51 | return Long.parseLong(value); 52 | } catch (NumberFormatException e) { 53 | return new BigInteger(value).longValue(); 54 | } 55 | } 56 | 57 | @Override 58 | public float floatValue() { 59 | return Float.parseFloat(value); 60 | } 61 | 62 | @Override 63 | public double doubleValue() { 64 | return Double.parseDouble(value); 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return value; 70 | } 71 | 72 | /** 73 | * If somebody is unlucky enough to have to serialize one of these, serialize 74 | * it as a BigDecimal so that they won't need Gson on the other side to 75 | * deserialize it. 76 | */ 77 | private Object writeReplace() throws ObjectStreamException { 78 | return new BigDecimal(value); 79 | } 80 | } -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/stream/JsonToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.stream; 18 | 19 | /** 20 | * A structure, name or value type in a JSON-encoded string. 21 | * 22 | * @author Jesse Wilson 23 | * @since 1.6 24 | */ 25 | public enum JsonToken { 26 | 27 | /** 28 | * The opening of a JSON array. Written using {@link JsonWriter#beginObject} 29 | * and read using {@link JsonReader#beginObject}. 30 | */ 31 | BEGIN_ARRAY, 32 | 33 | /** 34 | * The closing of a JSON array. Written using {@link JsonWriter#endArray} 35 | * and read using {@link JsonReader#endArray}. 36 | */ 37 | END_ARRAY, 38 | 39 | /** 40 | * The opening of a JSON object. Written using {@link JsonWriter#beginObject} 41 | * and read using {@link JsonReader#beginObject}. 42 | */ 43 | BEGIN_OBJECT, 44 | 45 | /** 46 | * The closing of a JSON object. Written using {@link JsonWriter#endObject} 47 | * and read using {@link JsonReader#endObject}. 48 | */ 49 | END_OBJECT, 50 | 51 | /** 52 | * A JSON property name. Within objects, tokens alternate between names and 53 | * their values. Written using {@link JsonWriter#name} and read using {@link 54 | * JsonReader#nextName} 55 | */ 56 | NAME, 57 | 58 | /** 59 | * A JSON string. 60 | */ 61 | STRING, 62 | 63 | /** 64 | * A JSON number represented in this API by a Java {@code double}, {@code 65 | * long}, or {@code int}. 66 | */ 67 | NUMBER, 68 | 69 | /** 70 | * A JSON {@code true} or {@code false}. 71 | */ 72 | BOOLEAN, 73 | 74 | /** 75 | * A JSON {@code null}. 76 | */ 77 | NULL, 78 | 79 | /** 80 | * The end of the JSON stream. This sentinel value is returned by {@link 81 | * JsonReader#peek()} to signal that the JSON-encoded value has no more 82 | * tokens. 83 | */ 84 | END_DOCUMENT 85 | } 86 | -------------------------------------------------------------------------------- /src/driver/java/src/com/emeralddb/util/KetamaNodeLocator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2012 SequoiaDB Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.emeralddb.util; 17 | 18 | import java.util.List; 19 | import java.util.SortedMap; 20 | import java.util.TreeMap; 21 | import com.emeralddb.net.ServerAddress; 22 | public final class KetamaNodeLocator { 23 | private TreeMap _ketamaNodes; 24 | private HashAlgorithm _hashAlg; 25 | private int _numReps = 160; 26 | 27 | public KetamaNodeLocator(List nodeList, HashAlgorithm alg, int nodeCopies) { 28 | _hashAlg = alg; 29 | _ketamaNodes = new TreeMap(); 30 | 31 | _numReps = nodeCopies; 32 | 33 | for(ServerAddress node : nodeList) { 34 | for(int i=0; i<_numReps/4; i++) { 35 | byte[] digest = _hashAlg.md5(node.getHost() + ":" + node.getPort() + i); 36 | for(int h=0; h<4; h++) { 37 | long m = _hashAlg.hash(digest,h); 38 | _ketamaNodes.put(m, node); 39 | } 40 | } 41 | } 42 | } 43 | 44 | public ServerAddress getPrimary(final String str) { 45 | byte[] digest = _hashAlg.md5(str); 46 | ServerAddress rv = getNodeForKey(_hashAlg.hash(digest, 0)); 47 | return rv; 48 | } 49 | 50 | ServerAddress getNodeForKey(long hash) { 51 | final ServerAddress rv; 52 | Long key = hash; 53 | if(_ketamaNodes.isEmpty()) { 54 | return null; 55 | } 56 | if(!_ketamaNodes.containsKey(key)) { 57 | SortedMap tailMap = _ketamaNodes.tailMap(key); 58 | if(tailMap.isEmpty()) { 59 | key = _ketamaNodes.firstKey(); 60 | } else { 61 | key = tailMap.firstKey(); 62 | } 63 | } 64 | rv = _ketamaNodes.get(key); 65 | return rv; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/driver/java/src/org/bson/types/BSONTimestamp.java: -------------------------------------------------------------------------------- 1 | // BSONTimestamp.java 2 | 3 | /** 4 | * Copyright (C) 2008 10gen Inc. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.bson.types; 20 | 21 | import java.io.Serializable; 22 | import java.util.Date; 23 | 24 | /** 25 | * this is used for internal increment values. 26 | * for storing normal dates in MongoDB, you should use java.util.Date 27 | * time is seconds since epoch 28 | * inc is an ordinal 29 | */ 30 | public class BSONTimestamp implements Serializable { 31 | 32 | private static final long serialVersionUID = -3268482672267936464L; 33 | 34 | static final boolean D = Boolean.getBoolean( "DEBUG.DBTIMESTAMP" ); 35 | 36 | public BSONTimestamp(){ 37 | _inc = 0; 38 | _time = null; 39 | } 40 | 41 | public BSONTimestamp(int time, int inc ){ 42 | _time = new Date( time * 1000L ); 43 | _inc = inc; 44 | } 45 | 46 | /** 47 | * @return get time in seconds since epoch 48 | */ 49 | public int getTime(){ 50 | if ( _time == null ) 51 | return 0; 52 | return (int)(_time.getTime() / 1000); 53 | } 54 | 55 | public int getInc(){ 56 | return _inc; 57 | } 58 | 59 | public String toString(){ 60 | return "TS time:" + _time + " inc:" + _inc; 61 | } 62 | 63 | public Date getDate() { 64 | if(_time == null) 65 | return null; 66 | return _time; 67 | } 68 | 69 | @Override 70 | public boolean equals(Object obj) { 71 | if (obj == this) 72 | return true; 73 | if (obj instanceof BSONTimestamp) { 74 | BSONTimestamp t2 = (BSONTimestamp) obj; 75 | return getTime() == t2.getTime() && getInc() == t2.getInc(); 76 | } 77 | return false; 78 | } 79 | 80 | final int _inc; 81 | final Date _time; 82 | } 83 | -------------------------------------------------------------------------------- /src/oss/ossHash.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #include "ossHash.hpp" 17 | #include "pd.hpp" 18 | #undef get16bits 19 | #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ 20 | || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) 21 | #define get16bits(d) (*((const unsigned short *) (d))) 22 | #endif 23 | 24 | #if !defined (get16bits) 25 | #define get16bits(d) ((((unsigned int)(((const unsigned char *)(d))[1])) << 8)\ 26 | +(unsigned int)(((const unsigned char *)(d))[0]) ) 27 | #endif 28 | unsigned int ossHash ( const char *data, int len ) 29 | { 30 | unsigned int hash = len, tmp ; 31 | int rem ; 32 | if ( len <= 0 || data == NULL ) return 0 ; 33 | rem = len&3 ; 34 | len >>= 2 ; 35 | for (; len > 0 ; --len ) 36 | { 37 | hash += get16bits (data) ; 38 | tmp = (get16bits (data+2) << 11) ^ hash; 39 | hash = (hash<<16)^tmp ; 40 | data += 2*sizeof(unsigned short) ; 41 | hash += hash>>11 ; 42 | } 43 | switch ( rem ) 44 | { 45 | case 3: 46 | hash += get16bits (data) ; 47 | hash ^= hash<<16 ; 48 | hash ^= ((char)data[sizeof (unsigned short)])<<18 ; 49 | hash += hash>>11 ; 50 | break ; 51 | case 2: 52 | hash += get16bits(data) ; 53 | hash ^= hash <<11 ; 54 | hash += hash >>17 ; 55 | break ; 56 | case 1: 57 | hash += (char)*data ; 58 | hash ^= hash<<10 ; 59 | hash += hash>>1 ; 60 | } 61 | hash ^= hash<<3 ; 62 | hash += hash>>5 ; 63 | hash ^= hash<<4 ; 64 | hash += hash>>17 ; 65 | hash ^= hash<<25 ; 66 | hash += hash>>6 ; 67 | return hash ; 68 | } 69 | #undef get16bits 70 | 71 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/annotations/Since.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.annotations; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * An annotation that indicates the version number since a member or a type has been present. 26 | * This annotation is useful to manage versioning of your Json classes for a web-service. 27 | * 28 | *

    29 | * This annotation has no effect unless you build {@link com.google.gson.Gson} with a 30 | * {@link com.google.gson.GsonBuilder} and invoke 31 | * {@link com.google.gson.GsonBuilder#setVersion(double)} method. 32 | * 33 | *

    Here is an example of how this annotation is meant to be used:

    34 | *
    35 |  * public class User {
    36 |  *   private String firstName;
    37 |  *   private String lastName;
    38 |  *   @Since(1.0) private String emailAddress;
    39 |  *   @Since(1.0) private String password;
    40 |  *   @Since(1.1) private Address address;
    41 |  * }
    42 |  * 
    43 | * 44 | *

    If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()} 45 | * methods will use all the fields for serialization and deserialization. However, if you created 46 | * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.0).create()} then the 47 | * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code address} field 48 | * since it's version number is set to {@code 1.1}.

    49 | * 50 | * @author Inderjeet Singh 51 | * @author Joel Leitch 52 | */ 53 | @Retention(RetentionPolicy.RUNTIME) 54 | @Target({ElementType.FIELD, ElementType.TYPE}) 55 | public @interface Since { 56 | /** 57 | * the value indicating a version number since this member 58 | * or type has been present. 59 | */ 60 | double value(); 61 | } 62 | -------------------------------------------------------------------------------- /src/include/ossMmapFile.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Copyright (C) 2013 SequoiaDB Software Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License, version 3, 6 | as published by the Free Software Foundation. 7 | 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU Affero General Public License for more details. 12 | 13 | You should have received a copy of the GNU Affero General Public License 14 | along with this program. If not, see . 15 | *******************************************************************************/ 16 | #ifndef OSSMMAPFILE_HPP_ 17 | #define OSSMMAPFILE_HPP_ 18 | 19 | #include "core.hpp" 20 | #include "ossLatch.hpp" 21 | #include "ossPrimitiveFileOp.hpp" 22 | 23 | class _ossMmapFile 24 | { 25 | protected : 26 | class _ossMmapSegment 27 | { 28 | public : 29 | void *_ptr ; 30 | unsigned int _length ; 31 | unsigned long long _offset ; 32 | _ossMmapSegment ( void *ptr, 33 | unsigned int length, 34 | unsigned long long offset ) 35 | { 36 | _ptr = ptr ; 37 | _length = length ; 38 | _offset = offset ; 39 | } 40 | } ; 41 | typedef _ossMmapSegment ossMmapSegment ; 42 | 43 | ossPrimitiveFileOp _fileOp ; 44 | ossXLatch _mutex ; 45 | bool _opened ; 46 | std::vector _segments ; 47 | char _fileName [ OSS_MAX_PATHSIZE ] ; 48 | public : 49 | typedef std::vector::const_iterator CONST_ITR ; 50 | 51 | inline CONST_ITR begin () 52 | { 53 | return _segments.begin () ; 54 | } 55 | 56 | inline CONST_ITR end () 57 | { 58 | return _segments.end() ; 59 | } 60 | 61 | inline unsigned int segmentSize () 62 | { 63 | return _segments.size() ; 64 | } 65 | public : 66 | _ossMmapFile () 67 | { 68 | _opened = false ; 69 | memset ( _fileName, 0, sizeof(_fileName) ) ; 70 | } 71 | ~_ossMmapFile () 72 | { 73 | close () ; 74 | } 75 | 76 | int open ( const char *pFilename, unsigned int options ) ; 77 | void close () ; 78 | int map ( unsigned long long offset, unsigned int length, void **pAddress ) ; 79 | } ; 80 | typedef class _ossMmapFile ossMmapFile ; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/bson/src/lib/nonce.cpp: -------------------------------------------------------------------------------- 1 | // nonce.cpp 2 | 3 | /* Copyright 2009 10gen Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #ifdef _WINDOWS 18 | #define _CRT_RAND_S 19 | #endif 20 | 21 | #include "nonce.h" 22 | 23 | #ifdef _WINDOWS 24 | #include // rand_s 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | namespace Nonce { 31 | 32 | BOOST_STATIC_ASSERT( sizeof(nonce) == 8 ); 33 | 34 | Security::Security() { 35 | static int n; 36 | assert(++n == 1 && "Security is a singleton class"); 37 | init(); 38 | } 39 | 40 | void Security::init() { 41 | if( _initialized ) return; 42 | _initialized = true; 43 | 44 | #if defined(__linux__) || defined(__sunos__) 45 | _devrandom = new std::ifstream("/dev/urandom", std::ios::binary|std::ios::in); 46 | assert(_devrandom->is_open() && "can't open dev/urandom"); 47 | #elif defined(_WIN32) 48 | srand(time(NULL)); 49 | #else 50 | srandomdev(); 51 | #endif 52 | } 53 | 54 | nonce Security::getNonce() { 55 | static boost::mutex m; 56 | boost::mutex::scoped_lock lk(m); 57 | 58 | /* question/todo: /dev/random works on OS X. is it better 59 | to use that than random() / srandom()? 60 | */ 61 | 62 | nonce n; 63 | #if defined(__linux__) || defined(__sunos__) 64 | _devrandom->read((char*)&n, sizeof(n)); 65 | assert(!_devrandom->fail() && "devrandom failed"); 66 | #elif defined(_WIN32) 67 | unsigned a=0, b=0; 68 | assert( rand_s(&a) == 0 ); 69 | assert( rand_s(&b) == 0 ); 70 | n = (((unsigned long long)a)<<32) | b; 71 | #else 72 | n = (((unsigned long long)random())<<32) | random(); 73 | #endif 74 | return n; 75 | } 76 | unsigned getRandomNumber() { return (unsigned) security.getNonce(); } 77 | 78 | bool Security::_initialized; 79 | Security security; 80 | 81 | 82 | } // namespace mongo 83 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/JsonParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson; 18 | 19 | /** 20 | * This exception is raised if there is a serious issue that occurs during parsing of a Json 21 | * string. One of the main usages for this class is for the Gson infrastructure. If the incoming 22 | * Json is bad/malicious, an instance of this exception is raised. 23 | * 24 | *

    This exception is a {@link RuntimeException} because it is exposed to the client. Using a 25 | * {@link RuntimeException} avoids bad coding practices on the client side where they catch the 26 | * exception and do nothing. It is often the case that you want to blow up if there is a parsing 27 | * error (i.e. often clients do not know how to recover from a {@link JsonParseException}.

    28 | * 29 | * @author Inderjeet Singh 30 | * @author Joel Leitch 31 | */ 32 | public class JsonParseException extends RuntimeException { 33 | static final long serialVersionUID = -4086729973971783390L; 34 | 35 | /** 36 | * Creates exception with the specified message. If you are wrapping another exception, consider 37 | * using {@link #JsonParseException(String, Throwable)} instead. 38 | * 39 | * @param msg error message describing a possible cause of this exception. 40 | */ 41 | public JsonParseException(String msg) { 42 | super(msg); 43 | } 44 | 45 | /** 46 | * Creates exception with the specified message and cause. 47 | * 48 | * @param msg error message describing what happened. 49 | * @param cause root exception that caused this exception to be thrown. 50 | */ 51 | public JsonParseException(String msg, Throwable cause) { 52 | super(msg, cause); 53 | } 54 | 55 | /** 56 | * Creates exception with the specified cause. Consider using 57 | * {@link #JsonParseException(String, Throwable)} instead if you can describe what happened. 58 | * 59 | * @param cause root exception that caused this exception to be thrown. 60 | */ 61 | public JsonParseException(Throwable cause) { 62 | super(cause); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/driver/java/src/com/google/gson/internal/bind/TimeTypeAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.gson.internal.bind; 18 | 19 | import com.google.gson.Gson; 20 | import com.google.gson.JsonSyntaxException; 21 | import com.google.gson.TypeAdapter; 22 | import com.google.gson.TypeAdapterFactory; 23 | import com.google.gson.reflect.TypeToken; 24 | import com.google.gson.stream.JsonReader; 25 | import com.google.gson.stream.JsonToken; 26 | import com.google.gson.stream.JsonWriter; 27 | import java.io.IOException; 28 | import java.sql.Time; 29 | import java.text.DateFormat; 30 | import java.text.ParseException; 31 | import java.text.SimpleDateFormat; 32 | import java.util.Date; 33 | 34 | /** 35 | * Adapter for Time. Although this class appears stateless, it is not. 36 | * DateFormat captures its time zone and locale when it is created, which gives 37 | * this class state. DateFormat isn't thread safe either, so this class has 38 | * to synchronize its read and write methods. 39 | */ 40 | public final class TimeTypeAdapter extends TypeAdapter