-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement multi-schema support #727
base: main
Are you sure you want to change the base?
Changes from 3 commits
0385016
5396ef5
ca205e4
477bc66
21227fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro | |
Schema schema = (Schema) foundObject; | ||
HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase(); | ||
for (org.hibernate.boot.model.relational.Namespace namespace : database.getMetadata().getDatabase().getNamespaces()) { | ||
boolean namespaceMatchesSchema = (namespace.getName().getSchema() != null && namespace.getName().getSchema().matches(foundObject.getName())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is duplicated in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can extract the check. I don't think we need to move the check though, since from my understanding, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|| (namespace.getName().getSchema() == null && ((Schema) foundObject).isDefault()); | ||
if (!namespaceMatchesSchema) { | ||
continue; | ||
} | ||
|
||
for (org.hibernate.boot.model.relational.Sequence sequence : namespace.getSequences()) { | ||
schema.addDatabaseObject(new Sequence() | ||
.setName(sequence.getName().getSequenceName().getText()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.example.multischema.auction; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import java.util.Date; | ||
|
||
@Entity | ||
@Table(schema = "PUBLIC") | ||
public class AuctionInfo { | ||
private String id; | ||
private String description; | ||
private Date ends; | ||
private Float maxAmount; | ||
|
||
@Column(length = 1000) | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public Date getEnds() { | ||
return ends; | ||
} | ||
|
||
@Id | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
|
||
public Float getMaxAmount() { | ||
return maxAmount; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public void setEnds(Date ends) { | ||
this.ends = ends; | ||
} | ||
|
||
public void setMaxAmount(Float maxAmount) { | ||
this.maxAmount = maxAmount; | ||
} | ||
|
||
public AuctionInfo(String id, String description, Date ends, Float maxAmount) { | ||
this.id = id; | ||
this.description = description; | ||
this.ends = ends; | ||
this.maxAmount = maxAmount; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.example.multischema.auction; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Table(schema = "PUBLIC") | ||
public class AuctionItem extends Persistent { | ||
private String description; | ||
private String shortDescription; | ||
private List<Bid> bids; | ||
private Bid successfulBid; | ||
private User seller; | ||
private Date ends; | ||
private int condition; | ||
|
||
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL) | ||
public List<Bid> getBids() { | ||
return bids; | ||
} | ||
|
||
@Column(length = 1000) | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@ManyToOne | ||
public User getSeller() { | ||
return seller; | ||
} | ||
|
||
@ManyToOne | ||
public Bid getSuccessfulBid() { | ||
return successfulBid; | ||
} | ||
|
||
public void setBids(List<Bid> bids) { | ||
this.bids = bids; | ||
} | ||
|
||
public void setDescription(String string) { | ||
description = string; | ||
} | ||
|
||
public void setSeller(User user) { | ||
seller = user; | ||
} | ||
|
||
public void setSuccessfulBid(Bid bid) { | ||
successfulBid = bid; | ||
} | ||
|
||
public Date getEnds() { | ||
return ends; | ||
} | ||
|
||
public void setEnds(Date date) { | ||
ends = date; | ||
} | ||
|
||
public int getCondition() { | ||
return condition; | ||
} | ||
|
||
public void setCondition(int i) { | ||
condition = i; | ||
} | ||
|
||
public String toString() { | ||
return shortDescription + " (" + description + ": " + condition | ||
+ "/10)"; | ||
} | ||
|
||
@Column(length = 200) | ||
public String getShortDescription() { | ||
return shortDescription; | ||
} | ||
|
||
public void setShortDescription(String shortDescription) { | ||
this.shortDescription = shortDescription; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.multischema.auction; | ||
|
||
import jakarta.persistence.*; | ||
import org.hibernate.envers.Audited; | ||
|
||
@Audited | ||
@Entity | ||
@Table(schema = "PUBLIC") | ||
public class AuditedItem { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AUDITED_ITEM_SEQ") | ||
@SequenceGenerator(name = "AUDITED_ITEM_SEQ", sequenceName = "AUDITED_ITEM_SEQ") | ||
private long id; | ||
@Column(unique = true) | ||
private String name; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.example.multischema.auction; | ||
|
||
import jakarta.persistence.*; | ||
import org.hibernate.annotations.Cache; | ||
import org.hibernate.annotations.CacheConcurrencyStrategy; | ||
|
||
import java.util.Date; | ||
|
||
@Entity | ||
@Table(schema = "PUBLIC") | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorValue("Y") | ||
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | ||
public class Bid extends Persistent { | ||
private AuctionItem item; | ||
private float amount; | ||
private Date datetime; | ||
private User bidder; | ||
|
||
@ManyToOne | ||
public AuctionItem getItem() { | ||
return item; | ||
} | ||
|
||
public void setItem(AuctionItem item) { | ||
this.item = item; | ||
} | ||
|
||
public float getAmount() { | ||
return amount; | ||
} | ||
|
||
@Column(nullable = false, name = "datetime") | ||
public Date getDatetime() { | ||
return datetime; | ||
} | ||
|
||
public void setAmount(float f) { | ||
amount = f; | ||
} | ||
|
||
public void setDatetime(Date date) { | ||
datetime = date; | ||
} | ||
|
||
@ManyToOne(optional = false) | ||
public User getBidder() { | ||
return bidder; | ||
} | ||
|
||
public void setBidder(User user) { | ||
bidder = user; | ||
} | ||
|
||
public String toString() { | ||
return bidder.getUserName() + " $" + amount; | ||
} | ||
|
||
@Transient | ||
public boolean isBuyNow() { | ||
return false; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philipp-kleber-avelios Why
getConnectionCatalogName()
andgetConnectionSchemaName()
are being locked here to constants?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
getConnectionCatalogName()
, the behavior is the same as before just without one less indirection (it used to callgetDefaultCatalogName()
internally).For
getConnectionSchemaName()
, the behavior is slightly different from before:It used to call
getDefaultSchemaName()
internally, but we can't do this anymore: The newgetDefaultSchemaName()
implementation callssuper.getDefaultSchemaName()
and this then callsgetConnectionSchemaName()
, so we'd have a call-cycle.