Skip to content

Aux data #21

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

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft

Aux data #21

wants to merge 20 commits into from

Conversation

Puckoland
Copy link
Collaborator

No description provided.

@Puckoland Puckoland self-assigned this May 19, 2023
Comment on lines +399 to +401
@Type(type = "jsonb")
@Column(name = "aux_data", columnDefinition = "text")
public String getAuxData()
Copy link
Collaborator

@Medzikarp Medzikarp Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Máš to ako string. Na string nepotrebuješ jsonb. Ten využiješ keby si mal JsonNode, alebo List, a iné.
Naviac tam máš aj columDefinition z JPA a aj hibernatí @Type. :)

Copy link
Collaborator

@Medzikarp Medzikarp Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jo a miesto toho možeš použiť DB agnostic @Clob od JPA. Ten by mal fungovať dobre s TEXT type v Postgresql.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ako String to je iba kvoli tomu, ze API malo s JsonNode problemy (v DB je to skutocne jsonb). Preto tam musi byt aj @Type. Zatial som to teda urobil, ze entita ma JsonNode, API ma String a prevadza sa to v ramci fromApi()/toApi().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, tak aspoň odstrániť ten columnDefinition = "text".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ten tam zase musi byt kvoli testom, pretoze HSQLDB nema jsonb.

Comment on lines 50 to 51
@Type(type = "jsonb")
@Column(columnDefinition = "text")
public String getData()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rovnaký problém ako u auxData.

this.name = name;
}

@Type(type = "pgsql_enum")
Copy link
Collaborator

@Medzikarp Medzikarp Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bude stačiť @Enumerated(EnumType.STRING) a @Column od JPA na definovanie typu.
Ten @Type(type = "pgsql_enum") je hibernatí duplicita.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bolo to potrebne ked som vytvaral enum aj v postgrese. Ale pre konzistenciu som to zmenil a odstranil.

@Puckoland Puckoland force-pushed the auxData branch 2 times, most recently from 002cb71 to 4e81e85 Compare July 10, 2023 22:10
Comment on lines 19 to 73
public static Builder builder()
{
return new Builder();
}

public String getTagName()
{
return tagName;
}

public TagType getTagType()
{
return tagType;
}

public Boolean isEnabled()
{
return enabled;
}

public static class Builder
{

private String tagName;
private TagType tagType;
private boolean enabled;

private Builder()
{
}

public Builder tagName(String tagName)
{
this.tagName = tagName;
return this;
}

public Builder tagType(TagType tagType)
{
this.tagType = tagType;
return this;
}

public Builder enabled(boolean enabled)
{
this.enabled = enabled;
return this;
}

public AuxDataFilter build()
{
return new AuxDataFilter(tagName, tagType, enabled);
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toto sa dá celkom dobre skomprimovať. https://projectlombok.org/features/Builder

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O tom viem, akurat v momentalnej verzii shonga lombok nie je...
Aj tak som ho ale pridaval pri implementacii REST API, cize ho asi mozem pridat aj tu.

@Medzikarp
Copy link
Collaborator

Medzikarp commented Sep 29, 2023

Pls nepoužívaj git push -f :) Aspoň nie kým nie je pull request resolved.

@Setter
@Entity
@Immutable
@Table(name = "arr_aux_data")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu vytváraš tabuľku v DB s názvom arr_aux_data, ale zároveň v init.sql vytváraš view s rovnakým názvom. Ten view je zdá sa mi už len zabudnutý pozostatok na zmazanie?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arr_aux_data ma skutocne byt view (ktory jednoducho mapuje aux_data na jednotlive fieldy, aby som to nemusel robit v jave). V init.sql ho definujem a entita je potom vytvorena na pracu s nim.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nejak nikde nevidím kde sa ten view používa. A mal by sa volať nejak inak ako tá entita.
Snažím sa rozbehnúť projekt lokálne a dostávam potom error pri inicializácii že entita už existuje:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1614) at cz.cesnet.shongo.controller.util.NativeQuery.executeNativeUpdate(NativeQuery.java:275) at cz.cesnet.shongo.controller.Controller.initializeDatabase(Controller.java:945) at cz.cesnet.shongo.controller.Controller.main(Controller.java:1081) Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200) at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:107) at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1491) at org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:295) at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1605) ... 3 more Caused by: org.postgresql.util.PSQLException: ERROR: "arr_aux_data" is not a view

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pouziva sa v ReservationRequestManager ako nahrada AuxDataService, ktora sa ti predtym nepozdavala:

    private List<AuxDataMerged> getAuxData(AbstractReservationRequest reservationRequest, AuxDataFilter filter)
    {
        String queryString = "SELECT arr.tagName, rt.tag.type, arr.enabled, arr.data, rt.tag.data" +
                " FROM AbstractReservationRequestAuxData arr" +
                " JOIN ResourceSpecification res_spec ON res_spec.id = arr.specification.id" +
                " JOIN ResourceTag rt ON rt.resource.id = res_spec.resource.id" +
                " WHERE rt.tag.name = arr.tagName" +
                " AND arr.id = :id";
        ....
    }

Ten error vyskakuje preto, ze najprv sa vytvori table kvoli JPA az potom sa zavola init.sql kde sa vytvara ten view.
Pridaval som to kvoli tomu aj do migration, ale zabudol som to pushnut, moja chyba.

Comment on lines +13 to +15
@Setter
@Entity
@Immutable
Copy link
Collaborator

@Medzikarp Medzikarp Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@immutable (ktorý je mimochodom od Hibernate) a @Setter nad jedným POJO nedáva zmysel.
Najvačší zmysel mi dáva pridávať k všetkým @entity
@DaTa (namiesto @Getter a @Setter)
@NoArgsConstructor (potrebný pre Hibernate)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Immutable sa pouziva, pretoze je to entita k viewu. Je ale pravda, ze @Setter nedava zmysel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants