Examples of MongoException


Examples of com.massivecraft.mcore.xlib.mongodb.MongoException

            throw new RuntimeException( "no gridfs!" );
       
        DBObject chunk = _fs._chunkCollection.findOne( BasicDBObjectBuilder.start( "files_id" , _id )
                                                       .add( "n" , i ).get() );
        if ( chunk == null )
            throw new MongoException( "can't find a chunk!  file id: " + _id + " chunk: " + i );

        return (byte[])chunk.get( "data" );
    }
View Full Code Here

Examples of com.massivecraft.mcore.xlib.mongodb.MongoException

     *            Size of chunks for file in bytes.
     * @throws MongoException
     */
    public void save( long chunkSize ) {
        if (_outputStream != null)
            throw new MongoException( "cannot mix OutputStream and regular save()" );

        // note that chunkSize only changes _chunkSize in case we actually save chunks
        // otherwise there is a risk file and chunks are not compatible
        if ( ! _savedChunks ) {
            try {
                saveChunks( chunkSize );
            } catch ( IOException ioe ) {
                throw new MongoException( "couldn't save chunks" , ioe );
            }
        }

        super.save();
    }
View Full Code Here

Examples of com.massivecraft.mcore.xlib.mongodb.MongoException

     *             {@link java.io.InputStream}.
     * @throws MongoException
     */
    public int saveChunks( long chunkSize ) throws IOException {
        if (_outputStream != null)
            throw new MongoException( "cannot mix OutputStream and regular save()" );
        if ( _savedChunks )
            throw new MongoException( "chunks already saved!" );

        if ( chunkSize <= 0 || chunkSize > GridFS.MAX_CHUNKSIZE ) {
            throw new MongoException( "chunkSize must be greater than zero and less than or equal to GridFS.MAX_CHUNKSIZE");
        }

        if ( _chunkSize != chunkSize ) {
            _chunkSize = chunkSize;
            _buffer = new byte[(int) _chunkSize];
View Full Code Here

Examples of com.massivecraft.mcore.xlib.mongodb.MongoException

     * Saves the file entry to the files collection
     * @throws MongoException
     */
    public void save(){
        if ( _fs == null )
            throw new MongoException( "need _fs" );
        _fs._filesCollection.save( this );
    }
View Full Code Here

Examples of com.massivecraft.mcore.xlib.mongodb.MongoException

     * This should be called after transferring a file.
     * @throws MongoException
     */
    public void validate(){
        if ( _fs == null )
            throw new MongoException( "no _fs" );
        if ( _md5 == null )
            throw new MongoException( "no _md5 stored" );
       
        DBObject cmd = new BasicDBObject( "filemd5" , _id );
        cmd.put( "root" , _fs._bucketName );
        DBObject res = _fs._db.command( cmd );
        if ( res != null && res.containsField( "md5" ) ) {
            String m = res.get( "md5" ).toString();
            if ( m.equals( _md5 ) )
                return;
            throw new MongoException( "md5 differ.  mine [" + _md5 + "] theirs [" + m + "]" );
        }

        // no md5 from the server
        throw new MongoException( "no md5 returned from server: " + res );

    }
View Full Code Here

Examples of com.mongodb.MongoException

     * @throws MongoException in case no connection to Mongo exists.
     */
    public DBCollection getCollection() {
        Mongo mongo = m_mongoRef.get();
        if (mongo == null) {
            throw new MongoException("Not connected to MongoDB!");
        }
        DB db = mongo.getDB(m_dbName);
        return db.getCollection(m_collectionName);
    }
View Full Code Here

Examples of com.mongodb.MongoException

    final Role findExistingMember(String name)
    {
        Role result = m_roleProvider.getRole(name);
        if (result == null)
        {
            throw new MongoException("No such role: " + name);
        }
        return result;
    }
View Full Code Here

Examples of com.mongodb.MongoException

     * @param password the (optional) password to use.
     * @throws MongoException in case the connection or authentication failed.
     */
    private void connectToDB(MongoDB mongoDB, String userName, String password) throws MongoException {
        if (!mongoDB.connect(userName, password)) {
            throw new MongoException("Failed to connect to MongoDB! Authentication failed!");
        }

        DBCollection collection = mongoDB.getCollection();
        if (collection == null) {
            throw new MongoException("Failed to connect to MongoDB! No collection returned!");
        }

        collection.ensureIndex(new BasicDBObject(NAME, 1).append("unique", true));
    }
View Full Code Here

Examples of com.mongodb.MongoException

     * @throws MongoException in case no connection to MongoDB exists.
     */
    private DBCollection getCollection() {
        MongoDB mongoDB = m_mongoDbRef.get();
        if (mongoDB == null) {
            throw new MongoException("No connection to MongoDB?!");
        }
        return mongoDB.getCollection();
    }
View Full Code Here

Examples of com.mongodb.MongoException

        authenticate(username, password);
        if (auth) {
            mongo = new Mongo(url, port);
            db = mongo.getDB(dbName);
        }else{
            throw new MongoException("Access Denied for the given credentials");
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.