Posts

Showing posts from 2016

পলিমরফিক ইন্টারফেরেন্স -> 1

‘চোখ খোল মেট্রাউস’প্রায় ধমকের সুরে বলল মেগাপল৫।
‘এরকম আনন্দের সংবাদ শুনে কেউ আতংকে অজ্ঞান হয়ে যায়? কি আশ্চর্য!! আসলে আমাদের ভেতর মানবিক অনুভূতি দিয়ে যাওয়াটা উচিত হয়নি। মানুষগুলো আসলেই অদূরদর্শী ছিল।‘আপসোসের মত শোনালো মেগাপলের যান্ত্রিক কন্ঠ।
মেট্রাউসের তখনো জ্ঞান ফেরেনি। আবেগে তার কপোট্রনের বা দিকের অংশটা ফেইল করেছে। তাই রিস্টোর করে পুনরায় আবেগ লোড করতে একটু সময় লাগছে।
সিস্টেম রিস্টোর করার এই এক ঝামেলা। সুস্থ্য হুওয়ার পরেও আরো কিছুক্ষন মাথা ঝিমঝিম করবে,বমি বমি ভাব চলে আসে। অবশ্য আজ অব্দি কোন এন্ড্রয়েড সত্যিকার অর্থে বমি করেছে বলে শোনা যায়নি। তবে এই ফালতু একটা অনুভূতি কেন তাদের মধ্যে দিয়ে গেল মানুষ ভেবে মনে মনে মানুষকে কতক্ষন গালাগাল দিল মেট্রাউস। আসলে সবদিক থেকে নিজেদের মত তৈরী করতে গিয়ে খানিকটা দূর্বল করে ফেলা হয়েছে তাদেরকে। তারপরেও নিজেদের পেশীশক্তি ব্যাবহার করে মানুষকে পৃথীবী থেকে তাড়ানো গেছে এই বা কম কি? শোনা যায় এন্ড্রমিডা গ্যালাক্সির কোন এক গ্রহে আবাস গড়েছে মানুষ। ভালমত সংগঠিত হতে পারলে আবার পৃথীবীতে এসে জ্বালাতন শুরু করবে ভ…

Deleting @ManyToMany parent entity without affecting child on Hibernate

Oh Dear!!

It's a nightmare getting MySQLIntegrityConstraintViolationException when you're designing complex relational database structure for your app. Most of the time hibernate won't complain with your approximation but this won't work when it comes to bidirectional relations.

Let me show an example.

But first consider a scenario that we're making a movie database application. We have two entities Movie.java and CustomList.java.

The use case is,

User can add multiple movies in a list.
And a movie can be added to multiple list.
User can execute CRUD operations on their list. that means user can create, edit and delete his list.
Admin can delete a Movie.

So it's a @ManyToMany relationship right?

Okay lets dig into the example.

Our two entities are:

Movie.java
@Entity(name = "movie")
public class Movie extends BaseEntity {
private String name;
private String type;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<CustomList&g…

EventBus API: Your complete event manager for Android

Did you ever heard about Publish-Subscribe pattern in Software architecture?

Yes. It's a messaging pattern where the senders of the message, called the publishers will never know who are going to receive those messages  and the receivers, also known as the subscribers, won't know who sent those messages as well.

The publishers will just send the message, without knowing who is gonna receive it. They do their work right.

On the other hand, the receivers, I mean the subscribers, will subscribe what kind of message they want to get. Doesn't matter who'll send them. Well, why should they care? They're gonna get what they need, right? :D

Okay, let's change the perspective a little. Think of an event as a message here. Now think about the publish-subscriber pattern. Yes, you got it right!

There will be event publishers instead of message publishers. And the subscribers will receive events instead of messages. So that whenever an event is published (of course by the publis…

How to deploy Spring boot app as .war file

Image
Hello from ToraCode.

If you find your cloud platform doesn't support container service or deploying standalone application you may find it annoying deploying your app in the cloud. But you can still try creating a traditional .war file to deploy into a container like Tomcat 8, Wildfly 10 or other container.

It's very easy to deploy Spring boot app as .war . You have to just follow those few steps.

Extend your application class with SpringBootServletInitializer and override configure() method like this:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
Next, update your configuration so that your project can produce .war file rather than .jar file.

If you're using Maven then …

Deploying sample spring boot app using Docker

Image
Hello from ToraCode.

Now that we are set up with Docker virtualisation software. Let's modify our pom.xml a little bit so that we can build our docker image.

We have to add Docker Maven Plugin in our pom.xml file.

Inside our <plugins> </plugins> tag we need to add this plugin.
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <configuration> <imageName>toracode/example-app</imageName> <baseImage>java:8</baseImage> <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint> <!-- copy the service's jar file from target into the root directory of the image --> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <in…

How to deploy Spring Boot application using Docker

Image
Welcome to the ToraCode blog. I'm Sayem and I'll discuss how to deploy Spring Boot app on your local machine using docker.

Wait, what is Docker? I didn't know about that!! why didn't you tell us about docker in the first place?

Well, if you don't know about docker yet, it's fine. Let me explain a little bit for you.

Docker is a virtualisation management software for managing containers and images.



Now what is containers and images? okay let me clear some concepts here

A container is a run time environment for images
An image is a software that you run within the containers.
Image is built using layers. Suppose you have an existing image, you added your app and built a new image and other people can build an image on top of your image.


Suppose you've a spring boot app and you built it using Java 8. So your base image is Java 8 and after adding your app you'll create a new image. Just like layers, you see? Java 8 api is base layer, and you added your code/la…