Updates the resource if it has missing or default apiGroupVersion values and the resource is currently
using API Groups with custom version strings

@param hasMetadata object whose api version needs to be updated
507555
protected void updateApiVersion(HasMetadata hasMetadata) {
    String version = getApiVersion();
    if (hasMetadata != null && version != null && version.length() > 0) {
      String current = hasMetadata.getApiVersion();
      // lets overwrite the api version if its currently missing, the resource uses an API Group with '/'
      // or we have the default of 'v1' when using an API group version like 'build.openshift.io/v1'
      if (current == null || "v1".equals(current) || current.indexOf('/') < 0 && version.indexOf('/') > 0) {
        hasMetadata.setApiVersion(version);
      }
    }
  }
1258227
public void updateMetadata(String tableName, String metadata){
		try {
			updateStatement.setString(1, metadata);
			updateStatement.setLong(2, tableName.hashCode());
			updateStatement.executeUpdate();
		} catch (SQLException e) {
			throw new BackendException("Could not update metadata for table '" + tableName + "'", e);
		}
	}
539846
@Override
    public boolean setVersion(String version) {
        // Update the version column in the database. This is a little weird looking because we want
        // to avoid modifying the database if the version didn't change, and because the row might
        // not exist yet.
        SQLiteStorageEngine storage = store.getStorageEngine();
        boolean hasView;
        Cursor cursor = null;
        try {
            String sql = "SELECT name, version FROM views WHERE name=?";
            String[] args = {name};
            cursor = storage.rawQuery(sql, args);
            hasView = cursor.moveToNext();
        } catch (SQLException e) {
            Log.e(Log.TAG_VIEW, "Error querying existing view name " + name, e);
            return false;
        } finally {
            if (cursor != null)
                cursor.close();
        }

        if (!hasView) {
            // no such record, so insert
            ContentValues insertValues = new ContentValues();
            insertValues.put("name", name);
            insertValues.put("version", version);
            insertValues.put("total_docs", 0);
            storage.insert("views", null, insertValues);
            createIndex();
            return true; // created new view
        }

        ContentValues updateValues = new ContentValues();
        updateValues.put("version", version);
        updateValues.put("lastSequence", 0);
        updateValues.put("total_docs", 0);
        String[] whereArgs = {name, version};
        int rowsAffected = storage.update("views",
                updateValues,
                "name=? AND version!=?",
                whereArgs);
        return (rowsAffected > 0);
    }
1156267
def check_has_version(self, api):
        ''''''
        if not hasattr(api, 'version'):
            msg = 'The Api class "{}" lacks a `version` attribute.'
            return [msg.format(api.__name__)]
1131352
public void setReplicaSettingsUpdate(java.util.Collection<ReplicaSettingsUpdate> replicaSettingsUpdate) {
        if (replicaSettingsUpdate == null) {
            this.replicaSettingsUpdate = null;
            return;
        }

        this.replicaSettingsUpdate = new java.util.ArrayList<ReplicaSettingsUpdate>(replicaSettingsUpdate);
    }
304483
@Override
	protected synchronized void checkDataMaps() throws IOException {
		if (lastUpdateCheck == 0 || lastUpdateCheck < System.currentTimeMillis() - updateInterval) {
			String versionOnServer = getVersionFromServer();
			if (currentVersion == null || versionOnServer.compareTo(currentVersion) > 0) {
				loadDataFromInternet();
				currentVersion = versionOnServer;
			}
			lastUpdateCheck = System.currentTimeMillis();
		}
	}
855591
public void addVariantDatasetMetadata(VariantStudyMetadata variantStudyMetadata) {
        if (variantStudyMetadata != null) {
            VariantStudyMetadata found = getVariantStudyMetadata(variantStudyMetadata.getId());
            // if there is not any study with that ID then we add the new one
            // TODO we need to think what to do when it exists, should we throw an exception?
            if (found == null) {
                if (variantMetadata.getStudies() == null) {
                    variantMetadata.setStudies(new ArrayList<>());
                }
                variantMetadata.getStudies().add(variantStudyMetadata);
            } else {
                logger.error("Study ID already exists");
            }
        }
    }
853168
protected void handleVersion(
      EntityDesc entityDesc, EntityPropertyDesc propertyDesc, ColumnMeta columnMeta) {
    if (isVersionAnnotatable(propertyDesc.getPropertyClassName())) {
      if (versionColumnNamePattern.matcher(columnMeta.getName()).matches()) {
        propertyDesc.setVersion(true);
      }
    }
  }
1037527
public static <T> String apiVersion(T item, String apiVersion) {
    if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) {
      return trimVersion(((HasMetadata) item).getApiVersion());
    } else if (apiVersion != null && !apiVersion.isEmpty()) {
      return trimVersion(apiVersion);
    }
    return null;
  }
370123
protected boolean checkIfModelMatches ( String groupId, String artifactId, String version, Model model )
    {
        // try these first.
        String modelGroup = model.getGroupId();
        String modelArtifactId = model.getArtifactId();
        String modelVersion = model.getVersion();

        try
        {
            if ( StringUtils.isEmpty( modelGroup ) )
            {
                modelGroup = model.getParent().getGroupId();
            }
            else
            {
                // MENFORCER-30, handle cases where the value is a property like ${project.parent.groupId}
                modelGroup = (String) helper.evaluate( modelGroup );
            }

            if ( StringUtils.isEmpty( modelVersion ) )
            {
                modelVersion = model.getParent().getVersion();
            }
            else
            {
                // MENFORCER-30, handle cases where the value is a property like ${project.parent.version}
                modelVersion = (String) helper.evaluate( modelVersion );
            }
            
            // Is this only required for Maven2?
            modelArtifactId = (String) helper.evaluate( modelArtifactId );
        }
        catch ( NullPointerException e )
        {
            // this is probably bad. I don't have a valid
            // group or version and I can't find a
            // parent????
            // lets see if it's what we're looking for
            // anyway.
        }
        catch ( ExpressionEvaluationException e )
        {
            // as above
        }
        return ( StringUtils.equals( groupId, modelGroup ) && StringUtils.equals( version, modelVersion ) && StringUtils
            .equals( artifactId, modelArtifactId ) );
    }
379390
@Deprecated
    Group updateGroup(String id, UpdateGroup updateGroup, AccessToken accessToken) {
        return updateResource(id, updateGroup.getScimConformUpdateGroup(), accessToken);
    }
1169903
def parse_api_groups(self, request_resources=False, update=False):
        
        if not self._cache.get('resources') or update:
            self._cache['resources'] = self._cache.get('resources', {})
            groups_response = load_json(self.client.request('GET', '/{}'.format(DISCOVERY_PREFIX)))['groups']

            groups = self.default_groups(request_resources=request_resources)

            for group in groups_response:
                new_group = {}
                for version_raw in group['versions']:
                    version = version_raw['version']
                    resource_group = self._cache.get('resources', {}).get(DISCOVERY_PREFIX, {}).get(group['name'], {}).get(version)
                    preferred = version_raw == group['preferredVersion']
                    resources = resource_group.resources if resource_group else {}
                    if request_resources:
                        resources = self.get_resources_for_api_version(DISCOVERY_PREFIX, group['name'], version, preferred)
                    new_group[version] = ResourceGroup(preferred, resources=resources)
                groups[DISCOVERY_PREFIX][group['name']] = new_group
            self._cache['resources'].update(groups)
            self._write_cache()

        return self._cache['resources']
506504
@SuppressWarnings("unchecked")
  protected <E> E updateWithOptimisticLockingInternal(E entity, PropertyMetadata versionMetadata) {
    Transaction transaction = null;
    try {
      entityManager.executeEntityListeners(CallbackType.PRE_UPDATE, entity);
      Entity nativeEntity = (Entity) Marshaller.marshal(entityManager, entity, Intent.UPDATE);
      transaction = datastore.newTransaction();
      Entity storedNativeEntity = transaction.get(nativeEntity.getKey());
      if (storedNativeEntity == null) {
        throw new OptimisticLockException(
            String.format("Entity does not exist: %s", nativeEntity.getKey()));
      }
      String versionPropertyName = versionMetadata.getMappedName();
      long version = nativeEntity.getLong(versionPropertyName) - 1;
      long storedVersion = storedNativeEntity.getLong(versionPropertyName);
      if (version != storedVersion) {
        throw new OptimisticLockException(
            String.format("Expecting version %d, but found %d", version, storedVersion));
      }
      transaction.update(nativeEntity);
      transaction.commit();
      E updatedEntity = (E) Unmarshaller.unmarshal(nativeEntity, entity.getClass());
      entityManager.executeEntityListeners(CallbackType.POST_UPDATE, updatedEntity);
      return updatedEntity;
    } catch (DatastoreException exp) {
      throw DatastoreUtils.wrap(exp);
    } finally {
      rollbackIfActive(transaction);
    }
  }
718040
static boolean shouldUpdate(AmazonInfo newInfo, AmazonInfo oldInfo) {
        if (newInfo.getMetadata().isEmpty()) {
            logger.warn("Newly resolved AmazonInfo is empty, skipping an update cycle");
        } else if (!newInfo.equals(oldInfo)) {
            if (isBlank(newInfo.get(AmazonInfo.MetaDataKey.instanceId))) {
                logger.warn("instanceId is blank, skipping an update cycle");
                return false;
            } else if (isBlank(newInfo.get(AmazonInfo.MetaDataKey.localIpv4))) {
                logger.warn("localIpv4 is blank, skipping an update cycle");
                return false;
            } else {
                Set<String> newKeys = new HashSet<>(newInfo.getMetadata().keySet());
                Set<String> oldKeys = new HashSet<>(oldInfo.getMetadata().keySet());

                Set<String> union = new HashSet<>(newKeys);
                union.retainAll(oldKeys);
                newKeys.removeAll(union);
                oldKeys.removeAll(union);

                for (String key : newKeys) {
                    logger.info("Adding new metadata {}={}", key, newInfo.getMetadata().get(key));
                }

                for (String key : oldKeys) {
                    logger.info("Removing old metadata {}={}", key, oldInfo.getMetadata().get(key));
                }
            }

            return true;
        }
        return false;
    }
148469
public void setPartitionReplicaVersions(int partitionId, ServiceNamespace namespace,
                                            long[] versions, int replicaOffset) {
        replicaVersions[partitionId].set(namespace, versions, replicaOffset);
    }
978200
public static String getResourceVersion(HasMetadata entity) {
    if (entity != null) {
      ObjectMeta metadata = entity.getMetadata();
      if (metadata != null) {
        String resourceVersion = metadata.getResourceVersion();
        if (!Utils.isNullOrEmpty(resourceVersion)) {
          return resourceVersion;
        }
      }
    }
    return null;
  }
899901
def update_metadata(self, scaling_group, metadata):
        
        if not isinstance(scaling_group, ScalingGroup):
            scaling_group = self.get(scaling_group)
        curr_meta = scaling_group.metadata
        curr_meta.update(metadata)
        return self.update(scaling_group, metadata=curr_meta)