Update a JDBC resource
770858
def update_jdbc_resource(name, server=None, **kwargs):
    '''
    
    '''
    # You're not supposed to update jndiName, if you do so, it will crash, silently
    if 'jndiName' in kwargs:
        del kwargs['jndiName']
    return _update_element(name, 'resources/jdbc-resource', kwargs, server)
1362538
public int update(DatabaseConnection databaseConnection, PreparedUpdate<T> preparedUpdate) throws SQLException {
		CompiledStatement compiledStatement = preparedUpdate.compile(databaseConnection, StatementType.UPDATE);
		try {
			int result = compiledStatement.runUpdate();
			if (dao != null && !localIsInBatchMode.get()) {
				dao.notifyChanges();
			}
			return result;
		} finally {
			IOUtils.closeThrowSqlException(compiledStatement, "compiled statement");
		}
	}
1208277
private void updateConfig() {
        // JDBC URL
        final String u = this.model.getUrl();
        final String url = (u != null) ? u.trim() : null;

        if (url == null || url.length() == 0) {
            this.conf.remove("jdbc.url");
        } else {
            this.conf.put("jdbc.url", url);
        } // end of else

        // DB user name
        final String n = this.model.getUser();
        final String user = (n != null) ? n.trim() : null;

        if (user == null || user.length() == 0) {
            this.conf.remove("db.user");
        } else {
            this.conf.put("db.user", user);
        } // end of else

        // DB charset
        final Charset charset = this.model.getCharset();

        if (charset == null) {
            this.conf.remove("db.charset");
        } else {
            this.conf.put("db.charset", charset.name());
        } // end of else

        // Persist configuration
        try {
            this.saveConf.call();
        } catch (Exception e) {
            e.printStackTrace();
        } // end of catch
    }
726700
@Override
	public synchronized void update(long sessionId, String sessionName) throws DatabaseException {
    	SqlPreparedStatementWrapper psUpdate = null;
        try {
        	psUpdate = DbSQL.getSingleton().getPreparedStatement("session.ps.update");
			psUpdate.getPs().setLong(2, sessionId);
			psUpdate.getPs().setString(1, sessionName);
			psUpdate.getPs().executeUpdate();
		} catch (SQLException e) {
			throw new DatabaseException(e);
		} finally {
			DbSQL.getSingleton().releasePreparedStatement(psUpdate);
		}
    }
604010
def update(self, *args, **kwargs):
        
        if request.method == 'PUT':
            logging.warning("Called not implemented resource method PUT")

        resource = super(JsonServerResource, self).update(*args, **kwargs)

        if resource:
            return resource
        else:
            return NOT_FOUND
30935
public int executeUpdate(Connection conn, DataObject object) throws SQLException {
        PreparedStatement statement = conn.prepareStatement(_sql);
        try {
            load(statement, object);
            return statement.executeUpdate();
        } finally {
            statement.close();
        }
    }
887743
public Optional<T> updateResource() {
        return JMOptional.getOptional(JMRestfulResource
                .getStringWithRestOrClasspathOrFilePath(restfulResourceUrl))
                .filter(getEquals(cachedJsonString).negate())
                .filter(peek(this::setJsonStringCache))
                .map(jsonString -> JMJson.withJsonString(jsonString,
                        typeReference))
                .filter(peek(resource -> this.cachedResource = resource));
    }
506969
public static int update(String sql, Object... args) {
		int result = 0;
		Connection con = getconnnection();
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sql);
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject((i + 1), args[i]);
				}
			}
			result = ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			close(ps, con);
		}

		return result;
	}
918496
protected int doInsert(JdbcTemplate jdbcTemplate, TaskRequest req, TaskResponse res) {
        //Setup the insert parameters and setter
        final List<Phrase> parametersInUse = insert_parameters != null ? insert_parameters : parameters;
        final PreparedStatementSetter preparedStatementSetter = new PhraseParameterPreparedStatementSetter(parametersInUse, req, res);
        
        //Get the insert sql and execute the insert
        final String fInsertSql = (String) insert_sql.evaluate(req, res);
        return jdbcTemplate.update(fInsertSql, preparedStatementSetter);
    }
725794
def update(self, resource, id_or_uri):
        
        return self._client.update(resource=resource, uri=id_or_uri)
470112
private void updateTable(Connection connection) throws DatabaseException {
        try {
			// Add the SOURCEHISTORYID column to the db if necessary
			if (!DbUtils.hasColumn(connection, TABLE_NAME, SOURCEHISTORYID)) {
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+SOURCEHISTORYID+" INT DEFAULT 0");
			}
			
			// Add the ATTACK column to the db if necessary
			if (!DbUtils.hasColumn(connection, TABLE_NAME, ATTACK)) {
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+ATTACK+" VARCHAR(32768) DEFAULT ''");
			}
			
			if (!DbUtils.hasColumn(connection, TABLE_NAME, EVIDENCE)) {
				// Evidence, cweId and wascId all added at the same time
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+EVIDENCE+" VARCHAR(16777216) DEFAULT ''");
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+CWEID+" INT DEFAULT -1");
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+WASCID+" INT DEFAULT -1");
			}
			
			if (!DbUtils.hasIndex(connection, TABLE_NAME, ALERT_INDEX)) {
				// this speads up session loading
				DbUtils.execute(connection, "CREATE INDEX "+ALERT_INDEX+" ON "+TABLE_NAME+" ("+SOURCEHISTORYID+")");
			}

			if (!DbUtils.hasColumn(connection, TABLE_NAME, SOURCEID)) {
				DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+SOURCEID+" INT DEFAULT 0");
				DbUtils.execute(connection, "CREATE INDEX INDEX_ALERT_SOURCEID ON "+TABLE_NAME+" ("+SOURCEID+")");
			}
		} catch (SQLException e) {
			throw new DatabaseException(e);
		}
        
    }
1306015
public void setDatasourceParams(JdbcDatabase database, ComboPooledDataSource dataSource)
    {
        if (dataSource != null)
        {   // Try pooled connection first
	        String strURL = database.getProperty(SQLParams.JDBC_URL_PARAM);
	        if ((strURL == null) || (strURL.length() == 0))
	            strURL = database.getProperty(SQLParams.DEFAULT_JDBC_URL_PARAM);    // Default
	        String strServer = database.getProperty(SQLParams.DB_SERVER_PARAM);
	        if ((strServer == null) || (strServer.length() == 0))
	            strServer = database.getProperty(SQLParams.DEFAULT_DB_SERVER_PARAM);    // Default
	        if ((strServer == null) || (strServer.length() == 0))
	            strServer = "localhost"; //this.getProperty(DBParams.SERVER);    // ??       
	        String strDatabaseName = database.getDatabaseName(true);
	        if (strURL != null)
	        {
	            if (strServer != null)
	                strURL = Utility.replace(strURL, "{dbserver}", strServer);
	            strURL = Utility.replace(strURL, "{dbname}", strDatabaseName);
	        }
	        String strUsername = database.getProperty(SQLParams.USERNAME_PARAM);
	        if ((strUsername == null) || (strUsername.length() == 0))
	            strUsername = database.getProperty(SQLParams.DEFAULT_USERNAME_PARAM); // Default
	        String strPassword = database.getProperty(SQLParams.PASSWORD_PARAM);
	        if ((strPassword == null) || (strPassword.length() == 0))
	            strPassword = database.getProperty(SQLParams.DEFAULT_PASSWORD_PARAM); // Default
	        
	        String strDriver = database.getProperty(SQLParams.JDBC_DRIVER_PARAM);
	
	    	try {
				dataSource.setDriverClass(strDriver); //loads the jdbc driver            
			} catch (PropertyVetoException e) {
				e.printStackTrace();
			}
	//        dataSource.setDatabaseName(strDatabaseName);
	//        if (strServer != null)
	//            dataSource.setServerName(strServer);
	//        else
	            dataSource.setJdbcUrl(strURL);
	        dataSource.setUser (strUsername);
	        dataSource.setPassword (strPassword);
	        
        	// the settings below are optional -- c3p0 can work with defaults
//?        	dataSource.setMinPoolSize(5);                                     
//?        	dataSource.setAcquireIncrement(5);
//?        	dataSource.setMaxPoolSize(20);
            //xMiniConnectionPoolManager poolMgr = new MiniConnectionPoolManager(poolDataSource, MAX_POOLED_CONNECTIONS, POOL_TIMEOUT);

        }
    }
745522
def update_resource(self, resource):
        ''''''
        index = self.resources.index(resource)
        data = {
            'resources__{index}'.format(index=index): resource
        }
        self.update(**data)
        self.reload()
        post_save.send(self.__class__, document=self)
1315208
protected void internalUpdateVersions(CmsDbContext dbc, CmsResource resource) throws CmsDataAccessException {

        if (dbc.getRequestContext() == null) {
            // no needed during initialization
            return;
        }
        if (dbc.currentProject().isOnlineProject()) {
            // this method is supposed to be used only in the offline project
            return;
        }

        // read the online version numbers
        Map<String, Integer> onlineVersions = readVersions(
            dbc,
            CmsProject.ONLINE_PROJECT_ID,
            resource.getResourceId(),
            resource.getStructureId());
        int onlineStructureVersion = onlineVersions.get("structure").intValue();
        int onlineResourceVersion = onlineVersions.get("resource").intValue();

        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet res = null;

        try {
            conn = m_sqlManager.getConnection(dbc);

            // update the resource version
            stmt = m_sqlManager.getPreparedStatement(conn, dbc.currentProject(), "C_RESOURCES_UPDATE_RESOURCE_VERSION");
            stmt.setInt(1, onlineResourceVersion);
            stmt.setString(2, resource.getResourceId().toString());
            stmt.executeUpdate();
            m_sqlManager.closeAll(dbc, null, stmt, null);

            // update the structure version
            stmt = m_sqlManager.getPreparedStatement(
                conn,
                dbc.currentProject(),
                "C_RESOURCES_UPDATE_STRUCTURE_VERSION");
            stmt.setInt(1, onlineStructureVersion);
            stmt.setString(2, resource.getStructureId().toString());
            stmt.executeUpdate();
            m_sqlManager.closeAll(dbc, null, stmt, null);

        } catch (SQLException e) {
            throw new CmsDbSqlException(
                Messages.get().container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)),
                e);
        } finally {
            m_sqlManager.closeAll(dbc, conn, stmt, res);
        }
    }
1056190
def update_value_from_mapping(source_resource_attr_id, target_resource_attr_id, source_scenario_id, target_scenario_id, **kwargs):
    
    user_id = int(kwargs.get('user_id'))

    rm = aliased(ResourceAttrMap, name='rm')
    #Check the mapping exists.
    mapping = db.DBSession.query(rm).filter(
        or_(
            and_(
                rm.resource_attr_id_a == source_resource_attr_id,
                rm.resource_attr_id_b == target_resource_attr_id
            ),
            and_(
                rm.resource_attr_id_a == target_resource_attr_id,
                rm.resource_attr_id_b == source_resource_attr_id
            )
        )
    ).first()

    if mapping is None:
        raise ResourceNotFoundError("Mapping between %s and %s not found"%
                                    (source_resource_attr_id,
                                     target_resource_attr_id))

    #check scenarios exist
    s1 = _get_scenario(source_scenario_id, user_id)
    s2 = _get_scenario(target_scenario_id, user_id)

    rs = aliased(ResourceScenario, name='rs')
    rs1 = db.DBSession.query(rs).filter(rs.resource_attr_id == source_resource_attr_id,
                                    rs.scenario_id == source_scenario_id).first()
    rs2 = db.DBSession.query(rs).filter(rs.resource_attr_id == target_resource_attr_id,
                                    rs.scenario_id == target_scenario_id).first()

    #3 possibilities worth considering:
    #1: Both RS exist, so update the target RS
    #2: Target RS does not exist, so create it with the dastaset from RS1
    #3: Source RS does not exist, so it must be removed from the target scenario if it exists
    return_value = None#Either return null or return a new or updated resource scenario
    if rs1 is not None:
        if rs2 is not None:
            log.info("Destination Resource Scenario exists. Updating dastaset ID")
            rs2.dataset_id = rs1.dataset_id
        else:
            log.info("Destination has no data, so making a new Resource Scenario")
            rs2 = ResourceScenario(resource_attr_id=target_resource_attr_id, scenario_id=target_scenario_id, dataset_id=rs1.dataset_id)
            db.DBSession.add(rs2)
        db.DBSession.flush()
        return_value = rs2
    else:
        log.info("Source Resource Scenario does not exist. Deleting destination Resource Scenario")
        if rs2 is not None:
            db.DBSession.delete(rs2)

    db.DBSession.flush()
    return return_value
379505
public int updateId(DatabaseConnection databaseConnection, T data, ID newId, ObjectCache objectCache)
			throws SQLException {
		if (mappedUpdateId == null) {
			mappedUpdateId = MappedUpdateId.build(dao, tableInfo);
		}
		int result = mappedUpdateId.execute(databaseConnection, data, newId, objectCache);
		if (dao != null && !localIsInBatchMode.get()) {
			dao.notifyChanges();
		}
		return result;
	}
727135
public int update(String sql, Object value) {
        Class<?> parameterType = value != null ? value.getClass() : null;
        String msId = msUtils.updateDynamic(sql, parameterType);
        return sqlSession.update(msId, value);
    }