com.quamto.jira.data.config.dao.AddOnSettingsDAO Maven / Gradle / Ivy
The newest version!
package com.quamto.jira.data.config.dao;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.quamto.core.QException;
import com.quamto.core.QException.ExceptionType;
import com.quamto.core.Result;
import com.quamto.db.DbConnection;
import com.quamto.db.SQLParameter.SQLDataType;
import com.quamto.entity.BaseEntity;
import com.quamto.entity.BaseEntityDAO;
import com.quamto.jira.data.common.JEnumerators;
import com.quamto.jira.data.config.entity.AddOnSettingsEntity;
public class AddOnSettingsDAO extends BaseEntityDAO {
public AddOnSettingsDAO(DbConnection dbConnection){
super(dbConnection, "atlassian_host", "id", AddOnSettingsDAO.class);
}
/**
* Get an instance of the entity with data loaded according to Id provided
*/
@Override
public AddOnSettingsEntity get(Long id) throws QException {
AddOnSettingsEntity entity = null;
try {
try {
entity = (AddOnSettingsEntity)getEntityLoaded(id);
} catch (Exception e) {
if(validateTableIdentifier().isSuccessful()){
entity = (AddOnSettingsEntity)getEntityLoaded(id);
}
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-get");
}
return entity;
}
/**
* Validate if the table identifier is present on the table
* @return Operation result
*/
private Result validateTableIdentifier(){
Result result = new Result();
try {
logger.error("Validating addon table");
logger.info("Trying to update table");
String updateTableQuery = "ALTER TABLE " + entityTableName +
" ADD COLUMN id BIGINT(10) NOT NULL AUTO_INCREMENT AFTER last_modified_by," +
"DROP PRIMARY KEY," +
" ADD PRIMARY KEY (id, client_key)";
if(executeQuery(updateTableQuery).isSuccessful()){
logger.info("Addon table updated!");
}
} catch (Exception e) {
result = new Result(e, subClassName + "-validateTableIdentifier");
}
return result;
}
/**
* Get an instance of the entity with data loaded according to the cliente key provided
*/
public AddOnSettingsEntity getByClientKey(String clientKey) throws QException {
AddOnSettingsEntity entity = null;
try {
String filter = " client_key='" + clientKey + "'";
try {
entity = (AddOnSettingsEntity)getEntityLoadedFiltered(filter);
} catch (Exception e) {
if(validateTableIdentifier().isSuccessful()){
entity = (AddOnSettingsEntity)getEntityLoadedFiltered(filter);
}
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getByClientKey");
}
return entity;
}
/**
* Return a list of entities elements stored in the database
*/
@Override
public List getAll() throws QException {
ArrayList listTimeRegistrationTypes = new ArrayList();
try {
ResultSet rs = getResultSet();
String query = "SELECT * "
+ " FROM " + entityTableName;
rs = dbOperator.getResultSet(query);
while(rs.next()){
listTimeRegistrationTypes.add(loadEntityAttributesFromRs(rs));
}
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-getAll");
}
return listTimeRegistrationTypes;
}
/**
* Make assignments of fields and values of entity to be used in
* insertion and update database operations
*/
@Override
public void loadQueryParameters(BaseEntity entity)
throws QException {
try {
AddOnSettingsEntity ent = (AddOnSettingsEntity) entity;
addQueryParameter(entityIdFieldName, ent.getID(), SQLDataType.Long_sdt);
addQueryParameter("client_key", ent.getClientKey(), SQLDataType.String_sdt);
addQueryParameter("public_key", ent.getPublicKey(), SQLDataType.String_sdt);
addQueryParameter("shared_secret", ent.getSharedSecret(), SQLDataType.String_sdt);
addQueryParameter("base_url", ent.getBaseUrl(), SQLDataType.String_sdt);
addQueryParameter("product_type", ent.getProductType(), SQLDataType.String_sdt);
addQueryParameter("description", ent.getDescription(), SQLDataType.String_sdt);
addQueryParameter("service_entitlement_number", ent.getServiceEntitlementNumber(), SQLDataType.String_sdt);
addQueryParameter("addon_installed", ent.getAddonInstalled(), SQLDataType.Integer_sdt);
addQueryParameter("created_date", ent.getCreatedDate(), SQLDataType.DateTime_sdt);
addQueryParameter("last_modified_date", ent.getLastModifiedDate(), SQLDataType.DateTime_sdt);
addQueryParameter("created_by", ent.getCreatedBy(), SQLDataType.String_sdt);
addQueryParameter("last_modified_by", ent.getLastModifiedBy(), SQLDataType.String_sdt);
addQueryParameter("oauth_client_id", ent.getOauthClientId(), SQLDataType.String_sdt);
addQueryParameter("first_configuration", ent.getFirstConfiguration().getInt(), SQLDataType.Integer_sdt);
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadQueryParameters");
}
}
/**
* Load the values of ResultSet of table from entity in to returned object.
*/
@Override
public AddOnSettingsEntity loadEntityAttributesFromRs(ResultSet rs) throws QException {
AddOnSettingsEntity entity = new AddOnSettingsEntity();
try {
entity.setID(rs.getLong(entityIdFieldName));
entity.setClientKey(rs.getString("client_key"));
entity.setPublicKey(rs.getString("public_key"));
entity.setSharedSecret(rs.getString("shared_secret"));
entity.setBaseUrl(rs.getString("base_url"));
entity.setProductType(rs.getString("product_type"));
entity.setDescription(rs.getString("description"));
entity.setServiceEntitlementNumber(rs.getString("service_entitlement_number"));
entity.setAddonInstalled(rs.getInt("addon_installed"));
entity.setCreatedDate(rs.getTimestamp("created_date"));
entity.setLastModifiedDate(rs.getTimestamp("last_modified_date"));
entity.setCreatedBy(rs.getString("created_by"));
entity.setLastModifiedBy(rs.getString("last_modified_by"));
entity.setOauthClientId(rs.getString("oauth_client_id"));
entity.setFirstConfiguration(JEnumerators.YesNo.Yes.getEnumValue(rs.getInt("first_configuration")));
} catch (Exception e) {
throw new QException(e, ExceptionType.LoadData_err, subClassName + "-loadEntityAttributesFromRs");
}
return entity;
}
@Override
public void close() throws Exception {
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy