package io.lumify.sql.model.workspace;

import io.lumify.core.model.workspace.Workspace;
import io.lumify.sql.model.user.SqlUser;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "workspace")
public class SqlWorkspace implements Workspace {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "workspace_id", unique = true)
    private int workspaceId;

    @Column(name = "display_title")
    private String displayTitle;

    @OneToOne(fetch = FetchType.EAGER)
    private SqlUser creator;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "sqlWorkspaceUserId.workspace")
    public Set<SqlWorkspaceUser> sqlWorkspaceUser = new HashSet<SqlWorkspaceUser>(0);

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private Set<SqlWorkspaceVertex> sqlWorkspaceVertices = new HashSet<SqlWorkspaceVertex>(0);

    public String getId() {
        return Integer.toString(workspaceId);
    }

    public void setId(int workspaceId) {
        this.workspaceId = workspaceId;
    }

    public String getDisplayTitle() {
        return displayTitle;
    }

    public void setDisplayTitle(String displayTitle) {
        this.displayTitle = displayTitle;
    }

    public SqlUser getCreator() {
        return creator;
    }

    public void setCreator(SqlUser creator) {
        this.creator = creator;
    }

    public Set<SqlWorkspaceUser> getSqlWorkspaceUser() {
        return sqlWorkspaceUser;
    }

    public void setSqlWorkspaceUser(Set<SqlWorkspaceUser> sqlWorkspaceUser) {
        this.sqlWorkspaceUser = sqlWorkspaceUser;
    }

    public Set<SqlWorkspaceVertex> getSqlWorkspaceVertices() {
        return sqlWorkspaceVertices;
    }

    public void setSqlWorkspaceVertices(Set<SqlWorkspaceVertex> sqlWorkspaceVertices) {
        this.sqlWorkspaceVertices = sqlWorkspaceVertices;
    }
}

@@ -155,56 +155,8 @@
 e.*;
-%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0A@E
@@ -245,252 +245,65 @@
     
-@Id%0A    @GeneratedValue(strategy = GenerationType.AUTO)%0A    @Column(name = %22workspace_id%22, unique = true)%0A    private int workspaceId;%0A%0A    @Column(name = %22display_title%22)%0A    private String displayTitle;%0A%0A    @OneToOne(fetch = FetchType.EAGER)
+private int workspaceId;%0A    private String displayTitle;
 %0A   
@@ -315,25 +315,34 @@
 ate SqlUser 
-c
+workspaceC
 reator;%0A%0A   
@@ -348,360 +348,221 @@
   @O
-neToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = %22sqlWorkspaceUserId.workspace%22)%0A    public Set%3CSqlWorkspaceUser%3E sqlWorkspaceUser = new HashSet%3CSqlWorkspaceUser%3E(0);%0A%0A    @OneToMany(fetch = FetchType.EAGER, cascade = Cascade
+verride%0A    @Transient%0A    public String getId() %7B%0A        return Integer.toString(workspaceId);%0A    %7D%0A%0A    @Id%0A    @GeneratedValue(strategy = Generation
 Type.A
-LL
+UTO
 )%0A    
-private Set%3CSqlWorkspaceVertex%3E sqlWorkspaceVertices = new HashSet%3CSqlWorkspaceVertex%3E(0);%0A
+@Column(name = %22workspace_id%22, unique = true)
 %0A   
@@ -565,34 +565,40 @@
 %0A    public 
-Str
 in
-g
+t
  get
+Workspace
 Id() %7B%0A     
@@ -607,33 +607,16 @@
  return 
-Integer.toString(
 workspac
@@ -610,33 +610,32 @@
 turn workspaceId
-)
 ;%0A    %7D%0A%0A    pub
@@ -646,16 +646,25 @@
 void set
+Workspace
 Id(int w
@@ -716,32 +716,82 @@
 spaceId;%0A    %7D%0A%0A
+    @Override%0A    @Column(name = %22display_title%22)%0A
     public Strin
@@ -960,153 +960,93 @@
     
-public SqlUser getCreator() %7B%0A        return creator;%0A    %7D%0A%0A    public void setCreator(SqlUser creator) %7B%0A        this.creator
+@OneToOne%0A    @JoinColumn(referencedColumnName = %22user_id%22, name
  = 
+%22
 creator
-;%0A    %7D%0A
+_user_id%22)
 %0A   
@@ -1058,35 +1058,18 @@
 ic S
-et%3CSqlWorkspace
+ql
 User
-%3E
  get
-Sql
 Work
@@ -1073,20 +1073,24 @@
 orkspace
-User
+Creator 
 () %7B%0A   
@@ -1101,28 +1101,25 @@
  return 
-sqlW
+w
 orkspace
 User;%0A  
@@ -1102,35 +1102,38 @@
 return workspace
-Use
+Creato
 r;%0A    %7D%0A%0A    pu
@@ -1137,35 +1137,32 @@
  public void set
-Sql
 WorkspaceUser(Se
@@ -1158,363 +1158,93 @@
 pace
-User(Set%3CSqlWorkspaceUser%3E sqlWorkspaceUser) %7B%0A        this.sqlWorkspaceUser = sqlWorkspaceUser;%0A    %7D%0A%0A    public Set%3CSqlWorkspaceVertex%3E getSqlWorkspaceVertices() %7B%0A        return sqlWorkspaceVertices;%0A    %7D%0A%0A    public void setSqlWorkspaceVertices(Set%3CSqlWorkspaceVertex%3E sqlWorkspaceVertices) %7B%0A        this.sqlWorkspaceVertices = sqlWorkspaceVertices
+Creator (SqlUser workspaceCreator) %7B%0A        this.workspaceCreator = workspaceCreator
 ;%0A  

format annotations