Adds a database to the registry. Returns
null if there is none.
438038
private static synchronized void addDatabaseObject(String type,
            String path, Database db) {

        // A VoltDB extension to work around ENG-6044
        /* disable 15 lines ...
        Object  key = path;

        HashMap databaseMap;

        if (type == DatabaseURL.S_FILE) {
            databaseMap = fileDatabaseMap;
            key         = filePathToKey(path);
        } else if (type == DatabaseURL.S_RES) {
            databaseMap = resDatabaseMap;
        } else if (type == DatabaseURL.S_MEM) {
            databaseMap = memDatabaseMap;
        } else {
            throw Error.runtimeError(ErrorCode.U_S0500,
                                     "DatabaseManager.addDatabaseObject()");
        }
           ... disabled 15 lines */

        assert(type == DatabaseURL.S_MEM);
        java.util.HashMap<String, Database> databaseMap = memDatabaseMap;
        String key = path;
        // End of VoltDB extension

        databaseIDMap.put(db.databaseID, db);
        databaseMap.put(key, db);
    }
714571
public void loadDatabaseProperties()
    {
        if (this.getProperty(STARTING_ID) != null)
            return; // Already read (This value will be cached in the environment database cache)
        int iStartID = 1;
        /* This code works, but I prefer to use the DatabaseInfo record.
        try {
            Statement queryStatement = this.getJDBCConnection().createStatement();
    
            String strSQL = "select StartID from DatabaseInfo where ID=1;";
            queryStatement.execute(strSQL);
            
            ResultSet resultset = queryStatement.getResultSet();
            boolean more = resultset.next();
            if (more)
            {
                iStartID = resultset.getInt(1);
            }
            resultset.close();
            queryStatement.close();
        } catch (SQLException e) {
            // Ignore table not found error.
        }
        */
    	if ((this.getDatabaseType() & (DBConstants.SHARED_DATA | DBConstants.USER_DATA)) != DBConstants.SHARED_DATA)
    		return;		// DatabaseInfo would only exist for shared databases

    	RecordOwner recordOwner = null; // ((BaseApplication)this.getDatabaseOwner().getEnvironment().getDefaultApplication()).getMainTask().; // For now
        DatabaseInfo recDatabaseInfo = new DatabaseInfo();
        recDatabaseInfo.setTable(this.doMakeTable(recDatabaseInfo));    // This makes a jdbc table
        String dbName = this.getDatabaseName(true);
        if (dbName.endsWith(SHARED_SUFFIX))
        	dbName = dbName.substring(0, dbName.length() - SHARED_SUFFIX.length());	// Always
        else if (dbName.endsWith(USER_SUFFIX))
        	dbName = dbName.substring(0, dbName.length() - USER_SUFFIX.length());	// Never
        recDatabaseInfo.setDatabaseName(dbName);

        int iOldOpenMode = recDatabaseInfo.getOpenMode();
        //x recDatabaseInfo.setOpenMode(recDatabaseInfo.getOpenMode() | DBConstants.OPEN_DONT_CREATE); // Removed 

        recDatabaseInfo.init(recordOwner);

        recDatabaseInfo.setOpenMode(iOldOpenMode);
        
        if (recDatabaseInfo.getEditMode() == DBConstants.EDIT_CURRENT)
        {
            iStartID = (int)recDatabaseInfo.getField(DatabaseInfo.START_ID).getValue();
            if (!recDatabaseInfo.getField(DatabaseInfo.END_ID).isNull())
                this.addDatabaseProperty(ENDING_ID, Integer.toString((int)recDatabaseInfo.getField(DatabaseInfo.END_ID).getValue()));
            if (!recDatabaseInfo.getField(DatabaseInfo.BASE_DATABASE).isNull())
                this.addDatabaseProperty(BaseDatabase.BASE_DATABASE, recDatabaseInfo.getField(DatabaseInfo.BASE_DATABASE).toString());
        }
        if (iStartID <= 0)
            iStartID = 1;
        recDatabaseInfo.free();
        this.addDatabaseProperty(STARTING_ID, Integer.toString(iStartID));
        
        if (m_databaseBase == null) // Always
            if (this.getProperty(BASE_DATABASE) != null)
        {
            Map<String,Object> properties = new HashMap<String,Object>();
            properties.putAll(this.getProperties());
            properties.remove(BASE_DATABASE);
            properties.put(BASE_DATABASE_JDBC_DRIVER, properties.remove(SQLParams.JDBC_DRIVER_PARAM));
            properties.put(DBConstants.DB_USER_PREFIX, DBConstants.BLANK);
            properties.remove(DBConstants.SYSTEM_NAME);
            properties.put(DBConstants.MODE, DBConstants.BLANK);
            m_databaseBase = (BaseDatabase)m_databaseOwner.getDatabase(this.getProperty(BASE_DATABASE), this.getDatabaseType() & DBConstants.TABLE_MASK, properties);
        }
    }
498088
private Referenceable registerDatabase(String databaseName) throws Exception {
        Referenceable dbRef = getDatabaseReference(clusterName, databaseName);
        Database db = hiveClient.getDatabase(databaseName);

        if (db != null) {
            if (dbRef == null) {
                dbRef = createDBInstance(db);
                dbRef = registerInstance(dbRef);
            } else {
                LOG.info("Database {} is already registered with id {}. Updating it.", databaseName, dbRef.getId().id);
                dbRef = createOrUpdateDBInstance(db, dbRef);
                updateInstance(dbRef);
            }
        }
        return dbRef;
    }
1310149
public synchronized ODatabaseComplex<?> register(final ODatabaseComplex<?> db) {
		instances.put(db, Thread.currentThread());
		return db;
	}
812112
def set_database(self, db):
        '''
        
        '''
        # This can not be imported globally due to circular import
        from .database import Database
        assert isinstance(db, Database), "database must be database.Database instance"
        self._database = db
603436
public void init(BaseDatabase database, Record record)
    {
        m_pTable = null;
        super.init(database, record);
        m_pTable = ((PhysicalDatabase)database).getPDatabase().getPTable(record, true);
        m_pTable.addPTableOwner(this);
    }
519867
def add(self, entry):
        
        # Empty or None values for organizations are not allowed
        if not entry:
            return CMD_SUCCESS

        try:
            api.add_to_matching_blacklist(self.db, entry)
        except InvalidValueError as e:
            # If the code reaches here, something really wrong has happened
            # because entry cannot be None or empty
            raise RuntimeError(str(e))
        except AlreadyExistsError as e:
            msg = "%s already exists in the registry" % entry
            self.error(msg)
            return e.code

        return CMD_SUCCESS
1360864
@InterfaceAudience.Private
    public Database getDatabase(String name, boolean mustExist) {
        synchronized (lockDatabases) {
            if (options.isReadOnly())
                mustExist = true;
            Database db = databases.get(name);
            if (db == null) {
                if (!isValidDatabaseName(name))
                    throw new IllegalArgumentException("Invalid database name: " + name);
                String path = pathForDatabaseNamed(name);
                if (path == null)
                    return null;
                db = new Database(path, name, this, options.isReadOnly());
                if (mustExist && !db.exists()) {
                    Log.i(Database.TAG, "mustExist is true and db (%s) does not exist", name);
                    return null;
                }
                db.setName(name);
                databases.put(name, db);
            }
            Log.v(Log.TAG_DATABASE, "getDatabase() %s %s", this, db);
            return db;
        }
    }
1156761
public void add_server(Database database, String serverName, DbDevInfo[] devinfo)
            throws DevFailed {
        if (!database.isAccess_checked()) checkAccess(database);

        //	Convert data from DbDevInfos to a string array
        //----------------------------------------------
        //System.out.println("creating " + serverName);
        String[] array;
        array = new String[1 + 2 * devinfo.length];

        array[0] = serverName;
        for (int i = 0 ; i<devinfo.length ; i++) {
            array[2 * i + 1] = devinfo[i].name;
            array[2 * i + 2] = devinfo[i]._class;
        }

        //	Send command
        //-----------------------
        DeviceData argIn = new DeviceData();
        argIn.insert(array);
        command_inout(database, "DbAddServer", argIn);
    }
821342
def _database_create(self, engine, database):
        
        logger.info('Creating database "%s" in "%s"', database, engine)
        database_operation(engine, 'create', database)
        url = copy(engine.url)
        url.database = database
        return str(url)
1355379
def init_db(db_path):
    """"""
    logger.info("Creating database")
    with closing(connect_database(db_path)) as db:
        with open(SCHEMA, 'r') as f:
            db.cursor().executescript(f.read())
        db.commit()
    return
27553
def add(self, instance):
        '''
        
        '''

        table = instance.__class__.__name__.lower()
        keys = ", ".join(vars(instance).keys())
        values = tuple(vars(instance).values())

        SQL = """INSERT INTO %s (%s) VALUES(""" % (table, keys)
        SQL += """ "%s",""" * len(values) % (values)
        SQL = SQL[:-1] + ")"

        if self.DEBUG: print(SQL)

        with Session(self.settings) as conn:
            try:
                c = conn.cursor()
                c.execute(SQL)
                conn.commit()
                return True
            except mysql.Error as e:
                if e.errno==1062:
                    print("Already saved to the database")
                    return True
                elif e.errno == 1146:
                    # Table does not exist
                    return True
                else:
                    raise e

                return True
1227809
def database(self):
        
        #1. Initialize
        self.callback.im_self.db = sql.setup(self.settings)
        if self.callback.im_self.db:
            module = '.'.join(self.callback.im_self.__module__.split('.')[:-1])
            sql.init(module, self.callback.im_self.db)
            self.callback.im_self.db.connect()
        yield
        #2. Cleanup
        if self.callback.im_self.db:
            self.callback.im_self.db.close()
917728
def load_from_db(self, cache=False):
        """"""
        a = {}
        db_prefs = {p.preference.identifier(): p for p in self.queryset}
        for preference in self.registry.preferences():
            try:
                db_pref = db_prefs[preference.identifier()]
            except KeyError:
                db_pref = self.create_db_pref(
                    section=preference.section.name,
                    name=preference.name,
                    value=preference.get('default'))
            else:
                # cache if create_db_pref() hasn't already done so
                if cache:
                    self.to_cache(db_pref)

            a[preference.identifier()] = db_pref.value

        return a
911440
def init_db():
    """"""
    import reana_db.models
    if not database_exists(engine.url):
        create_database(engine.url)
    Base.metadata.create_all(bind=engine)
1215662
public synchronized Database get_db_obj() throws DevFailed {
        if (ApiUtil.getOrb() == null) {
            create_orb();
        }

        // If first time, create vector
        // ---------------------------------------------------------------
        if (db_list == null) {
            db_list = new ArrayList<Database>();
        }
        // If first time, create Database object
        // -----------------------------------------------------------
        if (defaultDatabase == null) {
            defaultDatabase = new Database();
            db_list.add(defaultDatabase);
        }
        return db_list.get(0);
    }
65573
def rdb_repository(_context, name=None, make_default=False,
                   aggregate_class=None, repository_class=None,
                   db_string=None, metadata_factory=None):
    
    cnf = {}
    if not db_string is None:
        cnf['db_string'] = db_string
    if not metadata_factory is None:
        cnf['metadata_factory'] = metadata_factory
    _repository(_context, name, make_default,
                aggregate_class, repository_class,
                REPOSITORY_TYPES.RDB, 'add_rdb_repository', cnf)