Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@
// under the License.
package com.cloud.upgrade.dao;

import java.util.List;

import com.cloud.upgrade.dao.VersionVO.Step;
import com.cloud.utils.db.GenericDao;

public interface VersionDao extends GenericDao<VersionVO, Long> {
VersionVO findByVersion(String version, Step step);

String getCurrentVersion();

List<VersionVO> getAllVersions();

/**
* @return the oldest row of the version table, which records the version the
* database was originally created with and when, or null if the table
* is empty
*/
VersionVO getInitialVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,22 @@ public String getCurrentVersion() {
}

}

@Override
@DB
public List<VersionVO> getAllVersions() {
SearchCriteria<VersionVO> sc = AllFieldsSearch.create();
sc.setParameters("step", Step.Complete);

return listBy(sc);
}

@Override
@DB
public VersionVO getInitialVersion() {
final Filter filter = new Filter(VersionVO.class, "id", true, 0L, 1L);
final List<VersionVO> versions = listAll(filter);

return versions.isEmpty() ? null : versions.get(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.report;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.common.util.concurrent.AtomicLongMap;
import java.util.Map;
import java.io.IOException;

public class AtomicGsonAdapter extends TypeAdapter<AtomicLongMap> {

public AtomicLongMap<Object> read(JsonReader reader) throws IOException {
reader.nextNull();
return null;
}

public void write(JsonWriter writer, AtomicLongMap value) throws IOException {
if (value == null) {
writer.nullValue();
return;
}

@SuppressWarnings("unchecked")
Map<Object, Long> map = value.asMap();

writer.beginObject();
for (Map.Entry<Object, Long> entry : map.entrySet()) {
writer.name(String.valueOf(entry.getKey())).value(entry.getValue());
}
writer.endObject();
}
}
Loading
Loading