com.geotab.model.enumeration.DbUnavailableState Maven / Gradle / Ivy
/*
*
* 2020 Copyright (C) Geotab Inc. All rights reserved.
*/
package com.geotab.model.enumeration;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@Slf4j
public enum DbUnavailableState {
/**
* The none.
*/
NONE("None", 0),
/**
* The database server connection failure (for any reason).
*/
CONNECTION_FAILURE("ConnectionFailure", 1),
/**
* The unknown database.
*/
UNKNOWN_DATABASE("UnknownDatabase", 2),
/**
* The database is being initialized.
*/
INITIALIZING("Initializing", 3),
/**
* The database operation aborted (for any reason: Timeout, inconsistent transaction, concurrency,
* cache busy, etc.
*/
OPERATION_ABORTED("OperationAborted", 4);
private String name;
private int code;
DbUnavailableState(String name, int code) {
this.name = name;
this.code = code;
}
public int getCode() {
return code;
}
@JsonValue
public String getName() {
return name;
}
public static DbUnavailableState findOrDefault(String name) {
if (StringUtils.isEmpty(name)) {
log.warn("Empty value is not recognized for {} enum; returning default {}",
DbUnavailableState.class.getSimpleName(), DbUnavailableState.NONE);
return NONE;
}
for (DbUnavailableState dbUnavailableState : values()) {
if (dbUnavailableState.getName().equalsIgnoreCase(name.trim())) {
return dbUnavailableState;
}
}
log.warn("{} is not recognized for {} enum; returning default {}",
name, DbUnavailableState.class.getSimpleName(), DbUnavailableState.NONE);
return NONE;
}
}