Skip to content
Snippets Groups Projects
Commit 5d53990c authored by Mike Hodge's avatar Mike Hodge
Browse files

Fix XNAT-3749 - Site ID change doesn't take effect for IDGenerators. Add Javadocs

parent c902d99d
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,13 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -13,6 +13,13 @@ import org.springframework.transaction.annotation.Transactional;
@Repository @Repository
public class HostInfoDAO extends AbstractHibernateDAO<HostInfo> { public class HostInfoDAO extends AbstractHibernateDAO<HostInfo> {
/**
* Gets the host number.
*
* @param hostName the host name
* @param setValue the set value
* @return the host number
*/
@Transactional @Transactional
public String getHostNumber(String hostName, boolean setValue) { public String getHostNumber(String hostName, boolean setValue) {
Criteria criteria = getCriteriaForType(); Criteria criteria = getCriteriaForType();
......
...@@ -8,33 +8,50 @@ import javax.persistence.Entity; ...@@ -8,33 +8,50 @@ import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
/**
* The Class HostInfo.
*/
@Entity @Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"hostName"})) @Table(uniqueConstraints = @UniqueConstraint(columnNames = {"hostName"}))
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "nrg") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "nrg")
public class HostInfo extends AbstractHibernateEntity { public class HostInfo extends AbstractHibernateEntity {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -1264374836830855705L; private static final long serialVersionUID = -1264374836830855705L;
/** The host name. */
private String hostName; private String hostName;
/**
* Instantiates a new host info.
*/
public HostInfo() { public HostInfo() {
super(); super();
} }
/**
* Instantiates a new host info.
*
* @param hostName the host name
*/
public HostInfo(String hostName) { public HostInfo(String hostName) {
super(); super();
this.hostName = hostName; this.hostName = hostName;
} }
/** /**
* @param name Sets the hostname property. * Sets the host name.
*
* @param hostName the new host name
*/ */
public void setHostName(String hostName) { public void setHostName(String hostName) {
this.hostName = hostName; this.hostName = hostName;
} }
/** /**
* @return Returns the name property. * Gets the host name.
*
* @return the host name
*/ */
public String getHostName() { public String getHostName() {
return this.hostName; return this.hostName;
......
/*
*
*/
package org.nrg.xnat.services.impl.hibernate; package org.nrg.xnat.services.impl.hibernate;
import org.nrg.framework.orm.hibernate.AbstractHibernateEntityService; import org.nrg.framework.orm.hibernate.AbstractHibernateEntityService;
...@@ -7,15 +10,27 @@ import org.nrg.xnat.entities.HostInfo; ...@@ -7,15 +10,27 @@ import org.nrg.xnat.entities.HostInfo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/**
* The Class HibernateHostInfoService.
*/
@Service @Service
public class HibernateHostInfoService extends AbstractHibernateEntityService<HostInfo, HostInfoDAO> { public class HibernateHostInfoService extends AbstractHibernateEntityService<HostInfo, HostInfoDAO> {
/** The _instance. */
private static HibernateHostInfoService _instance; private static HibernateHostInfoService _instance;
/**
* Instantiates a new hibernate host info service.
*/
public HibernateHostInfoService() { public HibernateHostInfoService() {
_instance = this; _instance = this;
} }
/**
* Gets the service.
*
* @return the service
*/
public static HibernateHostInfoService getService() { public static HibernateHostInfoService getService() {
if (_instance == null) { if (_instance == null) {
_instance = XDAT.getContextService().getBean(HibernateHostInfoService.class); _instance = XDAT.getContextService().getBean(HibernateHostInfoService.class);
...@@ -23,11 +38,22 @@ public class HibernateHostInfoService extends AbstractHibernateEntityService<Hos ...@@ -23,11 +38,22 @@ public class HibernateHostInfoService extends AbstractHibernateEntityService<Hos
return _instance; return _instance;
} }
/**
* Gets the host number.
*
* @return the host number
*/
@Transactional @Transactional
public String getHostNumber() { public String getHostNumber() {
return getDao().getHostNumber(); return getDao().getHostNumber();
} }
/**
* Gets the host number.
*
* @param hostName the host name
* @return the host number
*/
@Transactional @Transactional
public String getHostNumber(String hostName) { public String getHostNumber(String hostName) {
return getDao().getHostNumber(hostName); return getDao().getHostNumber(hostName);
......
/* /*
* org.nrg.xnat.turbine.utils.IDGenerator * org.nrg.xnat.turbine.utils.IDGenerator
* XNAT http://www.xnat.org * XNAT http://www.xnat.org
* Copyright (c) 2014, Washington University School of Medicine * Copyright (c) 2016, Washington University School of Medicine
* All Rights Reserved * All Rights Reserved
* *
* Released under the Simplified BSD. * Released under the Simplified BSD.
* *
* Last modified 7/10/13 9:04 PM * Last modified 3/2/16 3:04 PM
*/ */
package org.nrg.xnat.turbine.utils; package org.nrg.xnat.turbine.utils;
...@@ -14,34 +14,37 @@ import org.nrg.xft.XFT; ...@@ -14,34 +14,37 @@ import org.nrg.xft.XFT;
import org.nrg.xft.XFTTable; import org.nrg.xft.XFTTable;
import org.nrg.xft.identifier.IDGeneratorI; import org.nrg.xft.identifier.IDGeneratorI;
import org.nrg.xft.utils.StringUtils; import org.nrg.xft.utils.StringUtils;
import org.nrg.xnat.daos.HostInfoDAO;
import org.nrg.xnat.services.impl.hibernate.HibernateHostInfoService; import org.nrg.xnat.services.impl.hibernate.HibernateHostInfoService;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
// TODO: Auto-generated Javadoc
/**
* The Class IDGenerator.
*/
public class IDGenerator implements IDGeneratorI { public class IDGenerator implements IDGeneratorI {
/** The column. */
String column=null; String column=null;
/** The table name. */
String tableName=null; String tableName=null;
/** The digits. */
Integer digits=null; Integer digits=null;
/** The code. */
String code=null; String code=null;
private static String site_id=null;
private static String hostInfo=null;
private static String getSiteID(){ /** The host info. */
if(site_id==null){ private static String hostInfo=null;
site_id = XFT.GetSiteID();
site_id = StringUtils.ReplaceStr(site_id, " ", "");
site_id = StringUtils.ReplaceStr(site_id, "-", "_");
site_id = StringUtils.ReplaceStr(site_id, "\"", "");
site_id = StringUtils.ReplaceStr(site_id, "'", "");
site_id = StringUtils.ReplaceStr(site_id, "^", "");
}
return site_id;
}
/**
* Gets the host info.
*
* @return the host info
*/
private static String getHostInfo(){ private static String getHostInfo(){
if (hostInfo==null || hostInfo.isEmpty()) { if (hostInfo==null || hostInfo.isEmpty()) {
hostInfo = HibernateHostInfoService.getService().getHostNumber(); hostInfo = HibernateHostInfoService.getService().getHostNumber();
...@@ -49,13 +52,18 @@ public class IDGenerator implements IDGeneratorI { ...@@ -49,13 +52,18 @@ public class IDGenerator implements IDGeneratorI {
return hostInfo; return hostInfo;
} }
/** The claimed i ds. */
private static List<String> claimedIDs=new ArrayList<String>(); private static List<String> claimedIDs=new ArrayList<String>();
/** The Constant lock. */
private static final Object lock=new Object(); private static final Object lock=new Object();
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#generateIdentifier()
*/
public String generateIdentifier() throws Exception{ public String generateIdentifier() throws Exception{
synchronized (lock){ synchronized (lock){
String site= IDGenerator.getSiteID(); String site= getSiteID();
String hostInfo = IDGenerator.getHostInfo(); String hostInfo = IDGenerator.getHostInfo();
// Let's keep the usual ID for the main server and append the host information for shadow/secondary servers // Let's keep the usual ID for the main server and append the host information for shadow/secondary servers
if (Integer.valueOf(hostInfo)>1) { if (Integer.valueOf(hostInfo)>1) {
...@@ -100,36 +108,76 @@ public class IDGenerator implements IDGeneratorI { ...@@ -100,36 +108,76 @@ public class IDGenerator implements IDGeneratorI {
} }
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#getColumn()
*/
public String getColumn() { public String getColumn() {
return column; return column;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#getDigits()
*/
public Integer getDigits() { public Integer getDigits() {
return digits; return digits;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#getTable()
*/
public String getTable() { public String getTable() {
return tableName; return tableName;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#setColumn(java.lang.String)
*/
public void setColumn(String s) { public void setColumn(String s) {
this.column=s; this.column=s;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#setDigits(java.lang.Integer)
*/
public void setDigits(Integer i) { public void setDigits(Integer i) {
this.digits=i; this.digits=i;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#setTable(java.lang.String)
*/
public void setTable(String s) { public void setTable(String s) {
this.tableName=s; this.tableName=s;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#getCode()
*/
public String getCode() { public String getCode() {
return code; return code;
} }
/* (non-Javadoc)
* @see org.nrg.xft.identifier.IDGeneratorI#setCode(java.lang.String)
*/
public void setCode(String s) { public void setCode(String s) {
this.code=s; this.code=s;
} }
/**
* Gets the site id.
*
* @return the site id
*/
private String getSiteID(){
String site_id = XFT.GetSiteID();
site_id = StringUtils.ReplaceStr(site_id, " ", "");
site_id = StringUtils.ReplaceStr(site_id, "-", "_");
site_id = StringUtils.ReplaceStr(site_id, "\"", "");
site_id = StringUtils.ReplaceStr(site_id, "'", "");
site_id = StringUtils.ReplaceStr(site_id, "^", "");
return site_id;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment