Utility method to obtain {@link ODatabaseDocument} from {@link ODatabase}
@param db {@link ODatabase} to cast from
@return {@link ODatabaseDocument} for a specified {@link ODatabase}
8635
public static ODatabaseDocument castToODatabaseDocument(ODatabase<?> db)
	{
		while(db!=null && !(db instanceof ODatabaseDocument))
		{
			if(db instanceof ODatabaseInternal<?>)
			{
				db = ((ODatabaseInternal<?>)db).getUnderlying();
			}
		}
		return (ODatabaseDocument)db;
	}
1313913
@Override
	public synchronized List<RecordContext> getDataForContext (int contextId) throws DatabaseException {
    	try {
			List<RecordContext> result = new ArrayList<>();
			psGetAllDataForContext.setInt(1, contextId);
			try (ResultSet rs = psGetAllDataForContext.executeQuery()) {
				while (rs.next()) {
					result.add(new RecordContext(rs.getLong(DATAID), rs.getInt(CONTEXTID), rs.getInt(TYPE), rs.getString(DATA)));
				}
			}
			
			return result;
		} catch (SQLException e) {
			throw new DatabaseException(e);
		}
    }
785647
public static MongoDatabase createDatabaseProxy(final MongoDatabase database) {
		if (DISABLED) {
			return database;
		}
		SERVICES_COUNTER.setDisplayed(!COUNTER_HIDDEN);
		SERVICES_COUNTER.setUsed(true);
		return JdbcWrapper.createProxy(database, new MongoDatabaseHandler(database));
	}
377637
private MongoCollection<Document> getDBCollection(String docName) {
        if (docName == null || docName.length() == 0) {
            return null;
        }
        return mongoDatabase.getCollection(docName);
    }
835183
public static Vector getDatabaseURIs() {

        Vector   v  = new Vector();
        // A VoltDB extension to work around ENG-6044
        /* disable 1 line ...
        Iterator it = databaseIDMap.values().iterator();
           ... disabled 1 line */
        java.util.Iterator<Database> it = databaseIDMap.values().iterator();
        // End of VoltDB extension

        while (it.hasNext()) {
            Database db = (Database) it.next();

            v.addElement(db.getURI());
        }

        return v;
    }
957888
static synchronized SQLiteDatabase getDatabase() {
        if(sInstance == null) {
           throw new SprinklesNotInitializedException();
        }

        if(sDatabase == null) {
            DbOpenHelper dbOpenHelper = new DbOpenHelper(sInstance.mContext, sInstance.databaseName, sInstance.initialDatabaseVersion);
            sDatabase = dbOpenHelper.getWritableDatabase();
        }

        return sDatabase;
    }
513135
public Database getDatabase(String strDBName, int iDatabaseType, Map<String, Object> properties)
    {
        return m_databaseCollection.getDatabase(strDBName, iDatabaseType, properties);
    }
1056515
public static CathDatabase getCathDatabase(String version) {
		if (version == null) version = DEFAULT_VERSION;
		CathDatabase cath = versions.get(version);
		if (cath == null) {
			CathInstallation newCath = new CathInstallation();
			newCath.setCathVersion(version);
			cath = newCath;
		}
		return cath;
	}
717397
@InterfaceAudience.Public
    public Document getDocument() {
        if (getDocumentId() == null) {
            return null;
        }
        assert (database != null);
        Document document = database.getDocument(getDocumentId());
        document.loadCurrentRevisionFrom(this);
        return document;
    }
1343575
@NonNull
    public static As database(@NonNull com.couchbase.lite.Database database) {
        if (database == null) {
            throw new IllegalArgumentException("database cannot be null.");
        }
        return new As(database);
    }
991537
public CoreRemoteMongoDatabaseImpl getDatabase(final String databaseName) {
    return new CoreRemoteMongoDatabaseImpl(
      databaseName,
      service,
      dataSynchronizer,
      appInfo.getNetworkMonitor()
    );
  }
1026930
public Status do_GET_Database(Database _db, String _docID, String _attachmentName) {
        // http://wiki.apache.org/couchdb/HTTP_database_API#Database_Information
        Status status = openDB();
        if (!status.isSuccessful()) {
            return status;
        }
        // NOTE: all methods are read operation. not necessary to be synchronized
        int num_docs = db.getDocumentCount();
        long update_seq = db.getLastSequenceNumber();
        long instanceStartTimeMicroseconds = db.getStartTime() * 1000;
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("db_name", db.getName());
        result.put("db_uuid", db.publicUUID());
        result.put("doc_count", num_docs);
        result.put("update_seq", update_seq);
        result.put("disk_size", db.totalDataSize());
        result.put("instance_start_time", instanceStartTimeMicroseconds);

        connection.setResponseBody(new Body(result));
        return new Status(Status.OK);
    }
1094910
public Document getDocument(@NonNull String id) {
        if (id == null) { throw new IllegalArgumentException("id cannot be null."); }

        synchronized (lock) {
            mustBeOpen();
            try {
                return new Document((Database) this, id, false);
            }
            catch (CouchbaseLiteException ex) {
                // only 404 - Not Found error throws CouchbaseLiteException
                return null;
            }
        }
    }
1008133
@FFDCIgnore(InvocationTargetException.class)
    Object getDB(String databaseName) throws Exception {
        final boolean trace = TraceComponent.isAnyTracingEnabled();

        lock.readLock().lock();
        try {
            if (mongoClient == null) {
                // Switch to write lock for lazy initialization
                lock.readLock().unlock();
                lock.writeLock().lock();
                try {
                    if (mongoClient == null)
                        init();
                } finally {
                    // Downgrade to read lock for rest of method
                    lock.readLock().lock();
                    lock.writeLock().unlock();
                }
            }

            Object db = MongoClient_getDB.invoke(mongoClient, databaseName);

            // authentication
            String user = (String) props.get(USER);
            if (user != null) {
                if ((Boolean) DB_isAuthenticated.invoke(db)) {
                    if (trace && tc.isDebugEnabled())
                        Tr.debug(this, tc, "already authenticated");
                } else {
                    if (trace && tc.isDebugEnabled())
                        Tr.debug(this, tc, "authenticate as: " + user);
                    SerializableProtectedString password = (SerializableProtectedString) props.get(PASSWORD);
                    String pwdStr = password == null ? null : String.valueOf(password.getChars());
                    pwdStr = PasswordUtil.getCryptoAlgorithm(pwdStr) == null ? pwdStr : PasswordUtil.decode(pwdStr);
                    char[] pwdChars = pwdStr == null ? null : pwdStr.toCharArray();
                    try {
                        if (!(Boolean) DB_authenticate.invoke(db, user, pwdChars))
                            if ((Boolean) DB_isAuthenticated.invoke(db)) {
                                if (trace && tc.isDebugEnabled())
                                    Tr.debug(this, tc, "another thread must have authenticated first");
                            } else
                                throw new IllegalArgumentException(Tr.formatMessage(tc, "CWKKD0012.authentication.error", MONGO, id, databaseName));
                    } catch (InvocationTargetException x) {
                        // If already authenticated, Mongo raises:
                        // IllegalStateException: can't authenticate twice on the same database
                        // Maybe another thread did the authentication right after we checked, so check again.
                        Throwable cause = x.getCause();
                        if (cause instanceof IllegalStateException && (Boolean) DB_isAuthenticated.invoke(db)) {
                            if (trace && tc.isDebugEnabled())
                                Tr.debug(this, tc, "another thread must have authenticated first", cause);
                        } else
                            throw cause;
                    }
                }
            } else if (useCertAuth) {
                // If we specified a certificate we will already have used the client constructor that
                // specified the credential so if we have got to here we are already authenticated and
                // JIT should remove this so it will not be an overhead.
            }
            return db;
        } catch (Throwable x) {
            // rethrowing the exception allows it to be captured in FFDC and traced automatically
            x = x instanceof InvocationTargetException ? x.getCause() : x;
            if (x instanceof Exception)
                throw (Exception) x;
            else if (x instanceof Error)
                throw (Error) x;
            else
                throw new RuntimeException(x);
        } finally {
            lock.readLock().unlock();
        }
    }
1274419
private function createXMLDoc(Database $database)
    {
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->formatOutput = true; // pretty printing
        $doc->appendChild($doc->createComment("Created by PropelDataDumpTask."));

        $dsNode = $doc->createElement("dataset");
        $dsNode->setAttribute("name", "all");
        $doc->appendChild($dsNode);

        $platform = $this->getGeneratorConfig()->getConfiguredPlatform($this->conn);

        $this->log("Building DOM tree containing data from tables:");

        foreach ($database->getTables() as $tbl) {
            $this->log("\t+ " . $tbl->getName());
            $stmt = $this->getTableDataStmt($tbl->getName(), $platform);
            while ($row = $stmt->fetch()) {
                $rowNode = $doc->createElement($tbl->getPhpName());
                foreach ($tbl->getColumns() as $col) {
                    $cval = $row[$col->getName()];
                    if ($cval !== null) {
                        $rowNode->setAttribute($col->getPhpName(), iconv($this->dbEncoding, 'utf-8', $cval));
                    }
                }
                $dsNode->appendChild($rowNode);
                unset($rowNode);
            }
            unset($stmt);
        }

        return $doc;
    }
350176
@Override
	public LinkedHashMap<String, ArrayList<DBReferenceInfo>> getDatabaseReferences()  {
		LinkedHashMap<String, ArrayList<DBReferenceInfo>> databaseReferencesHashMap = new LinkedHashMap<String, ArrayList<DBReferenceInfo>>();
		if (uniprotDoc == null) {
			return databaseReferencesHashMap;
		}

		try {
			Element uniprotElement = uniprotDoc.getDocumentElement();
			Element entryElement = XMLHelper.selectSingleElement(uniprotElement, "entry");
			ArrayList<Element> dbreferenceElementList = XMLHelper.selectElements(entryElement, "dbReference");
			for (Element element : dbreferenceElementList) {
				String type = element.getAttribute("type");
				String id = element.getAttribute("id");
				ArrayList<DBReferenceInfo> idlist = databaseReferencesHashMap.get(type);
				if (idlist == null) {
					idlist = new ArrayList<DBReferenceInfo>();
					databaseReferencesHashMap.put(type, idlist);
				}
				DBReferenceInfo dbreferenceInfo = new DBReferenceInfo(type, id);
				ArrayList<Element> propertyElementList = XMLHelper.selectElements(element, "property");
				for (Element propertyElement : propertyElementList) {
					String propertyType = propertyElement.getAttribute("type");
					String propertyValue = propertyElement.getAttribute("value");
					dbreferenceInfo.addProperty(propertyType, propertyValue);
				}

				idlist.add(dbreferenceInfo);
			}
		} catch (XPathExpressionException e) {
			logger.error("Problems while parsing db references in UniProt XML: {}. No db references will be available.",e.getMessage());
			return new LinkedHashMap<String, ArrayList<DBReferenceInfo>>();
		}

		return databaseReferencesHashMap;
	}
941172
public static DBObject getDBObject(EntityMetadata m, String tableName, Map<String, DBObject> dbObjects,
            MetamodelImpl metaModel, Object id)
    {
        tableName = tableName != null ? tableName : m.getTableName();
        DBObject dbObj = dbObjects.get(tableName);
        if (dbObj == null)
        {
            dbObj = new BasicDBObject();
            dbObjects.put(tableName, dbObj);
        }

        if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
        {
            MongoDBUtils.populateCompoundKey(dbObj, m, metaModel, id);
        }
        else
        {
            dbObj.put("_id", MongoDBUtils.populateValue(id, id.getClass()));
        }
        return dbObj;
    }