zondag 29 december 2024

PostgreSQL: Making a stored procedure for retrieving groups

After this, ofcourse you want to do something like:

select * from allgroups(1000);

Then you need a function that returns a resultset in PostgreSQL:

CREATE OR REPLACE FUNCTION public.allgroups(p_id int8)

RETURNS table (res_group_id int8)

LANGUAGE plpgsql

AS $function$

begin


return query

with recursive groups AS (

select

g.id as group_id,

gm.member_group_id as member_group_id

from "group" g

left outer join group_member gm on gm.group_id = g.id and gm.member_group_id is not null -- welke groepen zijn members van de huidige groep?

where g.id = p_id

--

union

--

select

g.id as group_id,

gm.member_group_id as member_group_id

from "group" g

left outer join group_member gm on gm.group_id = g.id and gm.member_group_id is not null -- welke groepen zijn members van de huidige groep?

inner join groups rg on rg.member_group_id = g.id -- we doen de query vanuit de member_group_id van het resultaat van de recursie

)

select distinct(group_id) from groups;


end;

$function$

;

 And a count function:

CREATE OR REPLACE FUNCTION public.allgroupscount(p_id int8)

RETURNS int8

LANGUAGE plpgsql

AS $function$

begin

return (select count(*) from public.allgroups(p_id));

end;

$function$

;


PostgreSQL: recursive query

Suppose you have the following sql tables:
Table "group"
id: int8
name: varchar

Table "group_member"
id: int8
group_id: int8
member_user_id: int8
member_group_id: int8


The column member_group_id is filled when you have a group
that is part of the group identified with group_id.

Suppose you want to determine all groups that are part of a 
specific group. You need a recursive query for that:

-- Met deze query willen we alle groepen bepalen die in onze
-- groep zitten.
-- Als een groep lid is van onze groep, dan zijn dat ook 
-- users die we moeten ophalen.
-- we moeten dus de huidige groep en de groepen die lid 
-- zijn van onze groep bepalen. En dat recursief.
with recursive groups AS (
  select
    g.id as group_id,
    gm.member_group_id as member_group_id
  from "group" g
  -- welke groepen zijn members van de huidige groep?
  left outer join group_member gm on gm.group_id = g.id and gm.member_group_id is not null
  where g.id = specific_group_id
  --  
  union
  --
  select
    g.id as group_id,
    gm.member_group_id as member_group_id
  from "group" g
  -- welke groepen zijn members van de huidige groep?
  left outer join group_member gm on gm.group_id = g.id and gm.member_group_id is not null
  -- we doen de query vanuit de member_group_id van het resultaat van de recursie
  inner join groups rg on rg.member_group_id = g.id
)
select distinct(group_id) from groups;

zaterdag 14 december 2024

AxonServer: Table "token_entry" not found

When using AxonServer and you include a @EventHandler in your code, the AxonServer told me that the table "token_entry" was not available.

The problem was that I used Spring-JPA-NHibernate in my code. I defined an entitymanager for JPA and that messed up the entitymanager for Axon. After removing the JPA code and replacing it with jetbrains Exposed, the problem was gone.

An addition setting that I activated was in the application.properties:

spring.jpa.hibernate.ddl-auto=create-drop

You can download the AxonServer at this url: https://download.axoniq.io/axonserver/AxonServer.zip

woensdag 13 november 2024

Browser Debugging in Visual Studio Code made easy.

A couple years ago, it was difficult to setup debugging in Visual Studio Code for browser code. Now it is easy. 

zaterdag 2 november 2024

Using Java build tools

In Java/Kotlin land, Spring is big. See the projects here: https://spring.io/projects

There are two major build systems, Maven and Gradle. Gradle is newer and claims to be the successor, but that remains to be seen.

Using Gradle:
gradlew build
gradlew run
gradlew bootJar

Using Maven:
mvn spring-boot:run
mvn compile
mvn package
mvn clean install

Misc:
To start a spring-boot jar:
java -jar c:\kotlin\demo\target\demo-0.0.1-SNAPSHOT.jar

To start a local webserver:
py -m http.server

Axon:
java -jar axonserver-2024.1.0.jar
mvnw spring-boot:run
localhost:8024 -> webpage axonserver
localhost:8080 -> giftcard sample

Kotlin commandline:
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar


woensdag 18 september 2024

Fill remaining width using flex

<div class="container">
<div class="flexible">test</div>
<div class="fixed">test</div>
<div class="fixed">test</div>
</div>

.container {
  display: flex;
}

.fixed {
  flex: 0 0 100px;
  background-color: red;
}

.flexible {
  flex: 1
}

zondag 30 juni 2024

How to disable Microsoft Compatibility Telemetry

Microsoft Compatibility Telemetry is a feature that collects data about your computer's performance and usage. It can be helpful for diagnosing problems and improving software compatibility. However, some people may prefer to turn it off for privacy or performance.

1. Click Start, type Task Scheduler, and then press Enter.
2. On the TaskScheduler window, go to this path: Task Scheduler Library\Microsoft\Windows\Application Experience.
3. On the Application Experience folder, look for Microsoft Compatibility Appraiser.
4. Right-click on it, select Disable, and then confirm to complete the process.