-
-
Save oksuz/21db191f09993894eefc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.generator; | |
import com.example.generator.entity.Brand; | |
import com.example.generator.entity.Model; | |
import com.example.generator.hibernate.HibernateSessionManager; | |
import org.hibernate.Session; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Set; | |
public class GeneratorImpl implements Generator { | |
private static final Logger LOGGER = LoggerFactory.getLogger(GeneratorImpl.class); | |
private Brand brand; | |
@Override | |
public void generate(Brand brand) { | |
Session session = HibernateSessionManager.getSessionFactory().openSession(); | |
// brand nesnesi yeniden aliniyor db'den | |
brand = (Brand) session.load(Brand.class, brand.getId()); | |
} | |
@Override | |
public void run() { | |
for (Model model : brand.getModels()) { // nullpointer exception | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.generator; | |
import com.example.entity.Brand; | |
import com.example.hibernate.HibernateSessionManager; | |
import org.hibernate.Session; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.util.List; | |
public class Main { | |
private final static Logger LOGGER = LoggerFactory.getLogger(Main.class); | |
public static void main(String[] args) { | |
LOGGER.info("Hi!"); | |
// markaların alindigi session | |
Session session = HibernateSessionManager.getSessionFactory().openSession(); | |
TaskExecutor taskExecutor = new TaskExecutorImpl(); | |
List brands = session.createCriteria(Brand.class).list(); | |
for (Object brand : brands) { | |
Generator generator = new GeneratorImpl(); | |
generator.generate((Brand) brand); // | |
taskExecutor.execute(generator); // thread-pool(10) | |
} | |
taskExecutor.shutdown(); | |
session.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment