piątek, 27 grudnia 2019

[DatabaseSpring] First think add two int

I want writing postgres simple function. I think a+b is good idea.
First I write function:
CREATE OR REPLACE FUNCTION public.addition (a INTEGER,b INTEGER)
RETURNS integer AS $$
BEGIN   RETURN a+b ;END;$$ LANGUAGE plpgsql;

Next I think how to sync in java. I create fake entity:
@Data@Entity@Immutable@Subselect(
        "SELECT 0 as ID")
public class FunctionRunner {

    @Id    @Column(name = "ID")
    private Integer id;
}

Always return 0. Simple by useful.

Run in spring jpa:
@Query(nativeQuery = true,value = "SELECT * FROM public.addition(:a,:b);")
Integer runAddition(@Param("a") Integer a,@Param("b") Integer b);


Link to github:
https://github.com/mikoxp/DbExamplesWithSpringBoot/commit/2917c00937b82ce7e7052b7887b14843ce7f083a

wtorek, 24 grudnia 2019

New idea start

I have a lot of ideas, but often only idea.
Maybe this time will be diffrent.
Now I start in new project in github. It show connect between Hibernate and Database.
Of course I am lazy so : Hibernate==Spring Boot Jpa , Database== Postgres
but solutions are similar .
 I wanted use gradle. but I got error and next and next, so I use maven :)

All stack now :

  • Java 11, Spring boot
  • Sql,PostgreSql
  • Wildfly
  • Ruby (I think by Go or Python)
No I do:
  • Spring boot api with widfly, lombok(I like this)
  • Parse data 9 thousand records, I find csv and parse-> training :)
Next step:
I dont know 

GITHUB:


środa, 29 maja 2019

Let`s go with go

What`s language:
https://en.wikipedia.org/wiki/Go_(programming_language)

No bad language, but I prefer Java. Maybe because I know it and I write every day.

I wrote program. Boring problem, but new language (I love image progressing but I`m start)

package main

import "fmt"

func main() {
var n int
var result int
var result2 int
n = 5
result = factorialLoop(n)
result2 = factorialRecursion(n)
fmt.Printf("Factorial loop : %d\n", result)
fmt.Printf("Factorial recursion : %d\n", result2)
}

func factorialLoop(n int) int {
result := 1
for i := 1; i <= n; i++ {
result *= i
}
return result
}

func factorialRecursion(n int) int {
if n <= 1 {
return 1
}
return n * factorialRecursion(n-1)
}