This commit is contained in:
Peter Hormanns 2010-10-06 13:06:01 +00:00
parent 13151e2ab6
commit dda8fc11e7
13 changed files with 316 additions and 244 deletions

View File

@ -33,8 +33,10 @@ import de.hsadmin.core.model.onetier.TicketValidator;
*
*/
public class CLIClientConnectorServlet extends HttpServlet {
private static final long serialVersionUID = 7150004719303750077L;
public static final String version = "1.0.9 (2010/Oct/05 18:34)";
private Map<String, Class<?>> componentmap;
private Map<String, String> componentDescriptions;
private ArgumentParser parser;
@ -432,8 +434,8 @@ public class CLIClientConnectorServlet extends HttpServlet {
*/
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
try {
ModuleInterface module;
ModuleInterface module = null;
Transaction tx = null;
// check login
String auth = req.getHeader("authorization");
if (auth == null) {
@ -453,12 +455,11 @@ public class CLIClientConnectorServlet extends HttpServlet {
// try to log in
String login = a[0];
ticket = a[1];
module = null;
try {
if (TicketAuthentication.getInstance().login(login, ticket)) {
// login successful
module = new GenericModuleImpl(new Transaction(login));
tx = new Transaction(login);
module = new GenericModuleImpl(tx);
// read arguments
BufferedReader read = req.getReader();
@ -478,8 +479,8 @@ public class CLIClientConnectorServlet extends HttpServlet {
} catch (Exception e) {
resp.addHeader("X-hsadmin-error", "exception: " + e.getMessage());
} finally {
if (module != null && module.getTransaction() != null) {
module.getTransaction().close();
if (tx != null) {
tx.close();
}
}
}

View File

@ -336,15 +336,6 @@ public abstract class AbstractModuleImpl implements ModuleInterface {
return stack.toString();
}
/**
* determines if the login user is a hostmaster.
* @return
*/
public boolean isHostmaster() {
// TODO: dummy
return false;
}
public static void setQueryParameter(Query query, String queryString,
String argName, Object argValue) {
int argLen = argName.length();

View File

@ -13,7 +13,7 @@ public class EntitySessionHelper {
* @param entityClass
* @return
*/
public static AbstractModuleImpl createEntitySessionWrapper(Class<? extends AbstractEntity> entityClass) {
public static AbstractModuleImpl createEntitySessionWrapper(Class<? extends AbstractEntity> entityClass, Transaction tx) {
// get in instance
AbstractModuleImpl impl = null;
try {
@ -27,11 +27,13 @@ public class EntitySessionHelper {
}
// instantiate wrapper
impl = (AbstractModuleImpl) wrapperClass.newInstance();
impl.construct(tx);
} catch (ClassNotFoundException exc) {
log.info("entity class '"
+ entityClass.getCanonicalName()
+ "' has no session wrapper => using restrictive default access rights");
impl = new SecureDefaultModuleImpl();
impl.construct(tx);
} catch (Exception exc) {
throw new RuntimeException(exc);
}

View File

@ -23,8 +23,7 @@ public class GenericModuleImpl implements ModuleInterface {
public AbstractEntity initialize(AbstractEntity newEntity) throws HSAdminException {
log.trace("initialize(" + newEntity + ")");
AbstractModuleImpl wrapper =
EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass());
wrapper.construct(tx);
EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass(), tx);
return wrapper.initialize(newEntity);
}
@ -34,34 +33,28 @@ public class GenericModuleImpl implements ModuleInterface {
throw new HSAdminException("cannot add an already persistent entity");
log.trace("add(" + newEntity + ")");
AbstractModuleImpl wrapper =
EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass());
wrapper.construct(tx);
AbstractEntity result = null;
result = wrapper.add(newEntity);
return result;
EntitySessionHelper.createEntitySessionWrapper(newEntity.getClass(), tx);
return wrapper.add(newEntity);
}
@Override
public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException {
log.trace("find(" + entityClass + ", " + key + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass);
wrapper.construct(tx);
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass, tx);
return wrapper.find(entityClass, key);
}
@Override
public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException {
log.trace("find(" + entityClass + ", " + key + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass);
wrapper.construct(tx);
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass, tx);
return wrapper.findByString(entityClass, key);
}
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
log.trace("search(" + entityClass + ", " + condition + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass);
wrapper.construct(tx);
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(entityClass, tx);
return wrapper.search(entityClass, condition, orderBy);
}
@ -70,8 +63,7 @@ public class GenericModuleImpl implements ModuleInterface {
if (existingEntity.isNew())
return add(existingEntity);
log.debug("update(" + existingEntity + ")");
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(existingEntity.getClass());
wrapper.construct(tx);
AbstractModuleImpl wrapper = EntitySessionHelper.createEntitySessionWrapper(existingEntity.getClass(), tx);
return wrapper.update(existingEntity);
}
@ -79,8 +71,7 @@ public class GenericModuleImpl implements ModuleInterface {
public void delete(AbstractEntity existingEntity) throws HSAdminException {
log.trace("delete(" + existingEntity + ")");
AbstractModuleImpl wrapper =
EntitySessionHelper.createEntitySessionWrapper(existingEntity.getClass());
wrapper.construct(tx);
EntitySessionHelper.createEntitySessionWrapper(existingEntity.getClass(), tx);
wrapper.delete(existingEntity);
}

View File

@ -0,0 +1,25 @@
package de.hsadmin.core.model;
/**
* Transiente User-Klasse. Entkoppelt das core-Paket vom UnixUser-Modul.
* @author Peter Hormanns
*/
public class LoginUser {
// TODO UnixUser Referenzen im Core-Paket ersetzen
private String login;
public LoginUser(String loginName) {
login = loginName;
}
public String getLogin() {
return login;
}
public boolean hasHostmasterRole() {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -12,15 +12,14 @@ public class DNSCheck {
private String dnsServer;
public DNSCheck(String dnsServer) {
public DNSCheck(String dnsServer) throws HSAdminException {
this.dnsServer = dnsServer;
InetAddress dnsInetAddress;
try {
dnsInetAddress = InetAddress.getByName(dnsServer);
DNSService.SetDNSAddress(dnsInetAddress);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new HSAdminException(e);
}
}

View File

@ -4,32 +4,38 @@ import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "BaseComponents")
@javax.persistence.Table(name = " basecomponent")
@javax.persistence.SequenceGenerator(name = "BaseComponentsSeqGen", sequenceName = "basecomponent_basecomponent_seq")
@Entity(name = "BaseComponents")
@Table(name = " basecomponent")
@SequenceGenerator(name = "BaseComponentsSeqGen", sequenceName = "basecomponent_basecomponent_seq")
public class BaseComponent extends de.hsadmin.core.model.AbstractEntity implements Serializable {
private static final long serialVersionUID = -8161827018235142603L;
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "BaseComponentsSeqGen")
@javax.persistence.Column(name = "basecomponent_id", columnDefinition = "integer")
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "BaseComponentsSeqGen")
@Column(name = "basecomponent_id", columnDefinition = "integer")
private long id;
@javax.persistence.Column(name = "basecomponent_code", columnDefinition = "character varying(10)")
@Column(name = "basecomponent_code", columnDefinition = "character varying(10)")
private String feature;
@javax.persistence.Column(name = "description", columnDefinition = "character varying(100)")
@Column(name = "description", columnDefinition = "character varying(100)")
private String description;
@javax.persistence.Column(name = "sorting", columnDefinition = "integer")
@Column(name = "sorting", columnDefinition = "integer")
private int sorting;
@javax.persistence.Column(name = "valid", columnDefinition = "boolean")
@Column(name = "valid", columnDefinition = "boolean")
private boolean valid;
public BaseComponent() {

View File

@ -8,9 +8,19 @@ import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@javax.persistence.Entity(name = "BasePacs")
@javax.persistence.Table(name = "basepacket")
@javax.persistence.SequenceGenerator(name = "BasePacsSeqGen", sequenceName = "basepacket_basepacket_id_seq")
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
@Entity(name = "BasePacs")
@Table(name = "basepacket")
@SequenceGenerator(name = "BasePacsSeqGen", sequenceName = "basepacket_basepacket_id_seq")
public class BasePac implements Serializable {
private static final long serialVersionUID = 1491121619195513435L;
@ -25,28 +35,28 @@ public class BasePac implements Serializable {
this.valid = true;
}
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "BasePacsSeqGen")
@javax.persistence.Column(name = "basepacket_id", columnDefinition = "integer")
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "BasePacsSeqGen")
@Column(name = "basepacket_id", columnDefinition = "integer")
private long id;
@javax.persistence.Column(name = "basepacket_code", columnDefinition = "character varying(10)")
@Column(name = "basepacket_code", columnDefinition = "character varying(10)")
private String name;
@javax.persistence.Column(name = "description", columnDefinition = "character varying(100)")
@Column(name = "description", columnDefinition = "character varying(100)")
private String description;
@javax.persistence.Column(name = "sorting", columnDefinition = "integer")
@Column(name = "sorting", columnDefinition = "integer")
private int sorting;
@javax.persistence.Column(name = "valid", columnDefinition = "boolean")
@Column(name = "valid", columnDefinition = "boolean")
private boolean valid;
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL)
@OneToMany(fetch = LAZY, cascade = ALL)
private Set<Component> components;
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL)
@javax.persistence.JoinTable(name = "packet_component", joinColumns = @javax.persistence.JoinColumn(name = "packet_id"), inverseJoinColumns = @javax.persistence.JoinColumn(name = "basepacket_id"))
@OneToMany(fetch = LAZY, cascade = ALL)
@JoinTable(name = "packet_component", joinColumns = @JoinColumn(name = "packet_id"), inverseJoinColumns = @JoinColumn(name = "basepacket_id"))
private Set<Pac> pacs;
public long getId() {

View File

@ -2,37 +2,41 @@ package de.hsadmin.mods.pac;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;
@javax.persistence.Entity(name = "Components")
@javax.persistence.Table(name = "component")
@Entity(name = "Components")
@Table(name = "component")
@IdClass(ComponentId.class)
public class Component implements Serializable {
private static final long serialVersionUID = 970709621200712794L;
@javax.persistence.Id
@Id
private BasePac basePac;
@javax.persistence.Id
@Id
private BaseComponent baseComponent;
@javax.persistence.Column(name = "min_quantity", columnDefinition = "integer")
@Column(name = "min_quantity", columnDefinition = "integer")
private int minimumQuantity;
@javax.persistence.Column(name = "max_quantity", columnDefinition = "integer")
@Column(name = "max_quantity", columnDefinition = "integer")
private int maximimumQuantity;
@javax.persistence.Column(name = "default_quantity", columnDefinition = "integer")
@Column(name = "default_quantity", columnDefinition = "integer")
private int defaultQuantity;
@javax.persistence.Column(name = "increment_quantity", columnDefinition = "integer")
@Column(name = "increment_quantity", columnDefinition = "integer")
private int incrementQuantity;
@javax.persistence.Column(name = "include_quantity", columnDefinition = "integer")
@Column(name = "include_quantity", columnDefinition = "integer")
private int includedQuantity;
@javax.persistence.Column(name = "admin_only", columnDefinition = "boolean")
@Column(name = "admin_only", columnDefinition = "boolean")
private boolean adminOnly;
public Component() {

View File

@ -5,105 +5,129 @@ import static javax.persistence.FetchType.EAGER;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name="Hives")
@javax.persistence.Table(name="hive")
@javax.persistence.SequenceGenerator(name="HivesSeqGen", sequenceName="hive_hive_id_seq")
public class Hive
extends de.hsadmin.core.model.AbstractEntity
implements java.io.Serializable
{
@Entity(name = "Hives")
@Table(name = "hive")
@SequenceGenerator(name = "HivesSeqGen", sequenceName = "hive_hive_id_seq")
public class Hive extends AbstractEntity implements Serializable {
private static final long serialVersionUID = -2270234313165009590L;
/// bean ctor
public Hive()
{
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "HivesSeqGen")
@Column(name = "hive_id")
private long id;
@Column(name = "hive_name", columnDefinition = "character varying(3)", unique = true)
private String name;
@JoinColumn(name = "inet_addr_id")
@ManyToOne(fetch = EAGER)
private INetAddress inetAddr;
@Column(name = "description", columnDefinition = "character varying(100)")
private String description;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "hive")
@OrderBy("name")
private Set<Pac> pacs;
public Hive() {
}
public Hive( String name, INetAddress inetAddr )
{
public Hive(String name, INetAddress inetAddr) {
this.name = name;
this.inetAddr = inetAddr;
}
public Hive( String name, INetAddress inetAddr, String desc )
{
public Hive(String name, INetAddress inetAddr, String desc) {
this(name, inetAddr);
this.description = desc;
}
/// {@inheritDoc}
public static String createQueryFromStringKey(String humanKey)
{
public static String createQueryFromStringKey(String humanKey) {
return "hiveName='" + humanKey + "'";
}
/// {@inheritDoc}
@Override
public String createStringKey()
{
public String createStringKey() {
return getHiveName();
}
/// {@inheritDoc}
@Override
public long id()
{
return id;
public long id() {
return id;
}
// attribute id
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy=SEQUENCE, generator="HivesSeqGen")
@javax.persistence.Column(name="hive_id")
private long id;
public long getId() { return id; }
public void setId( long id ) { this.id = id; }
public long getId() {
return id;
}
// attribute hiveName
@javax.persistence.Column(name="hive_name", columnDefinition="character varying(3)", unique=true)
private String name;
public String getName() { return name; }
@Override
public String getHiveName() { return name; }
public void setName( String hiveName ) { this.name = hiveName; }
public void setId(long id) {
this.id = id;
}
// attribute inetAddr
@javax.persistence.JoinColumn(name="inet_addr_id")
@javax.persistence.ManyToOne(fetch=EAGER)
private INetAddress inetAddr;
public INetAddress getInetAddr() { return inetAddr; }
public void setInetAddr( INetAddress inetAddr ) { this.inetAddr = inetAddr; }
public String getName() {
return name;
}
// attribute description
@javax.persistence.Column(name="description", columnDefinition="character varying(100)")
private String description;
public String getDescription() { return description; }
public void setDescription( String description ) { this.description = description; }
// virtual attribute pacs
@javax.persistence.OneToMany(fetch=LAZY, cascade=ALL, mappedBy="hive")
@javax.persistence.OrderBy("name")
private Set<Pac> pacs;
public Set<Pac> getPacs() { return pacs; }
public void setPacs( Set<Pac> pacs) { this.pacs = pacs; }
/// {$inheritDoc}
@Override
public boolean isNew()
{
public String getHiveName() {
return name;
}
public void setName(String hiveName) {
this.name = hiveName;
}
public INetAddress getInetAddr() {
return inetAddr;
}
public void setInetAddr(INetAddress inetAddr) {
this.inetAddr = inetAddr;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<Pac> getPacs() {
return pacs;
}
public void setPacs(Set<Pac> pacs) {
this.pacs = pacs;
}
@Override
public boolean isNew() {
return id == 0;
}
/// {@inheritDoc}
@Override
public UnixUser owningUser( EntityManager em )
{
public UnixUser owningUser(EntityManager em) {
return null; // TODO: kinda somebody like root needed
}
}

View File

@ -2,86 +2,94 @@ package de.hsadmin.mods.pac;
import static javax.persistence.GenerationType.SEQUENCE;
import javax.persistence.EntityManager;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name="INetAddresses")
@javax.persistence.Table(name="inet_addr")
@javax.persistence.SequenceGenerator(name="INetAddressesSeqGen", sequenceName="inet_addr_inet_addr_id_seq")
public class INetAddress
extends de.hsadmin.core.model.AbstractEntity
implements java.io.Serializable
{
private static final long serialVersionUID = -5792279453911426607L;
@Entity(name = "INetAddresses")
@Table(name = "inet_addr")
@SequenceGenerator(name = "INetAddressesSeqGen", sequenceName = "inet_addr_inet_addr_id_seq")
public class INetAddress extends AbstractEntity implements Serializable {
/// bean ctor
public INetAddress()
{
private static final long serialVersionUID = -5792279453911426607L;
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "INetAddressesSeqGen")
@Column(name = "inet_addr_id")
private long id;
@Column(name = "inet_addr", columnDefinition = "inet", unique = true)
private String inetAddr;
@Column(name = "description", columnDefinition = "character varying(100)")
private String description;
public INetAddress() {
}
public INetAddress( String inetAddr )
{
public INetAddress(String inetAddr) {
this.inetAddr = inetAddr;
}
public INetAddress( String inetAddr, String desc )
{
this(inetAddr);
description = desc;
public INetAddress(String inetAddr, String desc) {
this(inetAddr);
description = desc;
}
/// {@inheritDoc}
public static String createQueryFromStringKey(String humanKey)
{
public static String createQueryFromStringKey(String humanKey) {
return "inetAddr='" + humanKey + "'";
}
/// {@inheritDoc}
@Override
public String createStringKey()
{
public String createStringKey() {
return getInetAddr();
}
/// {@inheritDoc}
@Override
public long id()
{
return id;
public long id() {
return id;
}
// attribute id
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy=SEQUENCE, generator="INetAddressesSeqGen")
@javax.persistence.Column(name="inet_addr_id")
private long id;
public long getId() { return id; }
public void setId( long id ) { this.id = id; }
public long getId() {
return id;
}
// attribute inetAddr
@javax.persistence.Column(name="inet_addr", columnDefinition="inet", unique=true)
private String inetAddr;
public String getInetAddr() { return inetAddr; }
public void setInetAddr( String inetAddr ) { this.inetAddr = inetAddr; }
public void setId(long id) {
this.id = id;
}
// attribute description
@javax.persistence.Column(name="description", columnDefinition="character varying(100)")
private String description;
public String getDescription() { return description; }
public void setDescription( String description ) { this.description = description; }
public String getInetAddr() {
return inetAddr;
}
public void setInetAddr(String inetAddr) {
this.inetAddr = inetAddr;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
/// {$inheritDoc}
@Override
public boolean isNew()
{
public boolean isNew() {
return id == 0;
}
/// {@inheritDoc}
@Override
public UnixUser owningUser( EntityManager em )
{
public UnixUser owningUser(EntityManager em) {
return null; // TODO: kinda somebody like root needed
}
}

View File

@ -8,61 +8,75 @@ import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.EntityInfo;
import de.hsadmin.mods.cust.Customer;
import de.hsadmin.mods.user.UnixUser;
@javax.persistence.Entity(name = "Pacs")
@javax.persistence.Table(name = "packet")
@javax.persistence.SequenceGenerator(name = "PacsSeqGen", sequenceName = "packet_packet_id_seq")
@de.hsadmin.core.model.EntityInfo(name = "Paket")
public class Pac extends de.hsadmin.core.model.AbstractEntity implements Serializable {
@Entity(name = "Pacs")
@Table(name = "packet")
@SequenceGenerator(name = "PacsSeqGen", sequenceName = "packet_packet_id_seq")
@EntityInfo(name = "Paket")
public class Pac extends AbstractEntity implements Serializable {
private static final long serialVersionUID = 1201899873300190132L;
@javax.persistence.Id
@javax.persistence.GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
@javax.persistence.Column(name = "packet_id")
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
@Column(name = "packet_id")
private long id;
@javax.persistence.Column(name = "packet_name", unique = true)
@Column(name = "packet_name", unique = true)
private String name;
@javax.persistence.JoinColumn(name = "bp_id")
@javax.persistence.ManyToOne(fetch = EAGER)
@JoinColumn(name = "bp_id")
@ManyToOne(fetch = EAGER)
private Customer customer;
@javax.persistence.JoinColumn(name = "hive_id")
@javax.persistence.ManyToOne(fetch = EAGER)
@JoinColumn(name = "hive_id")
@ManyToOne(fetch = EAGER)
private Hive hive;
@javax.persistence.Column(name = "created")
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
@Column(name = "created")
@Temporal(TemporalType.DATE)
private Date created;
@javax.persistence.Column(name = "cancelled", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
@Column(name = "cancelled", nullable = true)
@Temporal(TemporalType.DATE)
private Date cancelled;
@javax.persistence.Column(name = "order_number", nullable = true)
@Column(name = "order_number", nullable = true)
private String orderNo;
@javax.persistence.Column(name = "webserver_group", nullable = true)
@Column(name = "webserver_group", nullable = true)
private String webserverGroup;
@javax.persistence.JoinColumn(name = "cur_inet_addr_id", nullable = true)
@javax.persistence.ManyToOne(fetch = EAGER)
@JoinColumn(name = "cur_inet_addr_id", nullable = true)
@ManyToOne(fetch = EAGER)
private INetAddress curINetAddr;
@javax.persistence.JoinColumn(name = "old_inet_addr_id", nullable = true)
@javax.persistence.ManyToOne(fetch = EAGER)
@JoinColumn(name = "old_inet_addr_id", nullable = true)
@ManyToOne(fetch = EAGER)
private INetAddress oldINetAddr;
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL)
@OneToMany(fetch = LAZY, cascade = ALL)
private java.util.Set<PacComponent> pacComponents;
@javax.persistence.OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "pac")
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "pac")
private java.util.Set<UnixUser> unixUser;
public Pac() {
@ -89,18 +103,15 @@ public class Pac extends de.hsadmin.core.model.AbstractEntity implements Seriali
}
}
// / {@inheritDoc}
public static String createQueryFromStringKey(String humanKey) {
return "obj.name='" + humanKey + "'";
}
// / {@inheritDoc}
@Override
public String createStringKey() {
return getName();
}
// / {@inheritDoc}
@Override
public long id() {
return id;
@ -191,14 +202,14 @@ public class Pac extends de.hsadmin.core.model.AbstractEntity implements Seriali
* This does not work, JPA/Hibernate always wants to create an invalid row
* in packet_component
*
* @javax.persistence.ManyToOne(fetch=EAGER, optional=true) // optional
* @ManyToOne(fetch=EAGER, optional=true) // optional
* should be default anyway
*
* @javax.persistence.JoinTable( name="packet_component",
* joinColumns=@javax.persistence.JoinColumn(name="packet_id"),
* inverseJoinColumns=@javax.persistence.JoinColumn(name="basepacket_id") )
* @JoinTable( name="packet_component",
* joinColumns=@JoinColumn(name="packet_id"),
* inverseJoinColumns=@JoinColumn(name="basepacket_id") )
*/
@javax.persistence.Transient
@Transient
public BasePac getBasePac() {
return getPacComponents().iterator().next().getBasePac();
}
@ -230,18 +241,15 @@ public class Pac extends de.hsadmin.core.model.AbstractEntity implements Seriali
this.unixUser = unixUser;
}
// generic
public String toString() {
return super.toString() + "{ name=" + name + " }";
}
// / {$inheritDoc}
@Override
public boolean isNew() {
return id == 0;
}
// / {$inheritDoc}
@Override
public String getHiveName() {
if (isNew())
@ -250,7 +258,6 @@ public class Pac extends de.hsadmin.core.model.AbstractEntity implements Seriali
return getHive().getHiveName();
}
// / {@inheritDoc}
@Override
public UnixUser owningUser(EntityManager em) {
return customer.owningUser(em);
@ -261,20 +268,16 @@ public class Pac extends de.hsadmin.core.model.AbstractEntity implements Seriali
return null;
}
// / determines whether the given user has full read access on all merged
// fields of this entity
public boolean isReadAllowedFor(UnixUser loginUser) {
return getName().equals(loginUser.getName())
|| super.isReadAllowedFor(loginUser);
}
// / query restriction for access control
public static String restriction() {
return
// all pacs of customer
"obj.customer.name=:loginUserName OR " +
// pac of packet admin
"obj.name=:loginUserName";
// all pacs of customer
"obj.customer.name=:loginUserName OR " +
// pac of packet admin
"obj.name=:loginUserName";
}
}

View File

@ -5,34 +5,42 @@ import static javax.persistence.FetchType.EAGER;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@javax.persistence.Entity(name = "PacComponents")
@javax.persistence.Table(name = "packet_component")
@Entity(name = "PacComponents")
@Table(name = "packet_component")
@IdClass(PacComponentId.class)
public class PacComponent implements Serializable {
private static final long serialVersionUID = 5359873462163274873L;
@javax.persistence.Id
@Id
private Pac pac;
@javax.persistence.Id
@Id
private BaseComponent baseComponent;
@javax.persistence.JoinColumn(name = "basepacket_id", columnDefinition = "integer", nullable = false)
@javax.persistence.ManyToOne(fetch = EAGER)
@JoinColumn(name = "basepacket_id", columnDefinition = "integer", nullable = false)
@ManyToOne(fetch = EAGER)
private BasePac basePac;
@javax.persistence.Column(name = "quantity", columnDefinition = "integer")
@Column(name = "quantity", columnDefinition = "integer")
private int quantity;
@javax.persistence.Column(name = "created", columnDefinition = "date", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
@Column(name = "created", columnDefinition = "date", nullable = true)
@Temporal(TemporalType.DATE)
private Date created;
@javax.persistence.Column(name = "cancelled", columnDefinition = "date", nullable = true)
@javax.persistence.Temporal(javax.persistence.TemporalType.DATE)
@Column(name = "cancelled", columnDefinition = "date", nullable = true)
@Temporal(TemporalType.DATE)
private Date cancelled;
public PacComponent() {