Skip to content

Instantly share code, notes, and snippets.

View tkfx's full-sized avatar

Alex Zhitnitsky tkfx

View GitHub Profile
@tkfx
tkfx / Dockerfile
Last active January 27, 2016 15:19
docker-takipi-alpine-java
# Takipi
FROM alpine:3.2
MAINTAINER Chen Harel "https://github.com/chook"
# Install dependencies
RUN apk --update add curl ca-certificates tar sqlite icu bash && \
curl -Ls https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk > /tmp/glibc-2.21-r2.apk && \
apk add --allow-untrusted /tmp/glibc-2.21-r2.apk
@tkfx
tkfx / Dockerfile
Created January 27, 2016 10:19
Adding glibc to Alpine through Docker
RUN apk --update add curl ca-certificates tar && \
curl -Ls https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk > /tmp/glibc-2.21-r2.apk && \
apk add --allow-untrusted /tmp/glibc-2.21-r2.apk
@tkfx
tkfx / ScalaFuture.scala
Created June 13, 2016 16:12
Scala Future
import scala.util.{Success, Failure}
val f: Future[List[String]] = Future {
session.getRecentPosts
}
f onComplete {
case Success(posts) => for (post <- posts) println(post)
case Failure(t) => println("An error has occured: " + t.getMessage)
}
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Author a = em.find(Author.class, 1L);
em.getTransaction().commit();
em.close();
log.info(a.getFirstName() + " " + a.getLastName() + " wrote "+a.getBooks().size() + " books.");
@NamedEntityGraph(name = "graph.AuthorBooks", attributeNodes = @NamedAttributeNode("books"))
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
EntityGraph<?> graph = em.getEntityGraph("graph.AuthorBooks");
HashMap<String, Object> properties = new HashMap<>();
properties.put("javax.persistence.fetchgraph", graph);
Author a = em.find(Author.class, 1L, properties);
em.getTransaction().commit();
// EntityManager and transaction 1
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
// EntityManager and transaction 2
EntityManager em2 = emf.createEntityManager();
em2.getTransaction().begin();
// update 1
Author a = em.find(Author.class, 1L);
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "authorSequence")
@Column(name = "id", updatable = false, nullable = false)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "authorSequence")
@SequenceGenerator(name = "authorSequence", sequenceName = "author_seq", initialValue = 1000)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
@Entity
@Table(name = "author", schema = "bookstore")
public class Author implements Serializable {
}