Posts

Showing posts from August, 2020

configuration for reading static.messages properties files in project

Image
Assume that we have Resource Bundle 'message' and Resource Bundle 'validation' folders (there are properties files inside them), under static.messages folder , then we can configure for read this properties from resource folders like that:  @Bean     public ResourceBundleMessageSource messageSource() {         ResourceBundleMessageSource source = new ResourceBundleMessageSource();         source.setBasenames("static/messages/message", "static/messages/validation");         source.setDefaultLocale(new Locale("az"));         source.setUseCodeAsDefaultMessage(true);         source.setDefaultEncoding("UTF-8");         return source;     }     @Bean     public LocalValidatorFactoryBean getValidator() {         LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();         bean.se...

make update process without setter methods with BeanUtils.copyProperties(source,target,editableColumns)

This is just code sample that is why some imports some injections are missed! import static com.company.project.util.EntityUtil.copyPropertiesExceptId;  public class OfficeServiceImpl implementes OfficeService{ public OfficePhoto update(Long companyId, Long officeId, Long id, OfficePhotoEditableColumn      officePhotoEditableColumn) throws EntityNotFountException {     OfficePhoto byId = findById(companyId, officeId, id);     copyPropertiesExceptId(byId, officePhotoEditableColumn, OfficePhotoEditableColumn.class);     return officePhotoRepo.save(byId); } } this method does update proses without using any setter methods: we just give (target,source,editableColumsObject) : public class EntityUtil{ public static void copyPropertiesExceptId(BaseEntity target, BaseEntity source, Class editableColumns) {     long targetOriginalId = target.getId();     BeanUtils.copyProperties(source, target, editableColumns);     ...

removing object from many side in @OneToMany relation

  @ManyToOne (fetch = FetchType. LAZY ) private Company company ; @PreRemove private void preRemove () { // Office silinmezden once Company ile olan elaqesini kesmek lazimdir this . company .getOffices().remove( this ) ; } using this @PreRemove in Office entity which is many side in @OneToMany relation adi halda silmeye chalisanda error verirki one terefi silinmeyine icaze vermir ona gore de bu annotation ile hell etmek olur problemi problemi bunnla hell etmek olar, amma bu yaxsi solutuon deyil , chunki eksine One da olan datani silmek isteyende ConcurrentMapp... nese qeribe error verir bunun evezine , burda bash veren emelyati delete metodunda etmek lazimdir

object to json , json to object for controller integration testing

import com.fasterxml.jackson.core.JsonProcessingException ; import com.fasterxml.jackson.databind.ObjectMapper ; import com.fasterxml.jackson.databind.SerializationFeature ; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule ; public class TestsHelper { public static String getJsonString (Object object) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper() ; mapper.registerModule( new JavaTimeModule()) ; mapper.disable(SerializationFeature. WRITE_DATES_AS_TIMESTAMPS ) ; return mapper.writeValueAsString(object) ; } public static < T > T getObjectFromJson (String json , Class< T > type) throws JsonProcessingException{ ObjectMapper mapper = new ObjectMapper() ; mapper.registerModule( new JavaTimeModule()) ; mapper.disable(SerializationFeature. WRITE_DATES_AS_TIMESTAMPS ) ; return mapper.readValue(json , type) ; } } use case in testing class : private OfficePhoto request...

Data Structures and Algorithms

  Binary Search Tree, Balanced 2-3 trees, Red-Black Tree: https://www.baeldung.com/cs/red-black-trees Binary Tree, Tree Operations, Depth Search Tree, Bredth Search Tree https://www.baeldung.com/java-binary-tree Tree Traversals Inorder,Preorder,Postorder https://www.geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/ Visual explanation of famous algorithms: https://www.youtube.com/c/MichaelSambol/playlists/ Complexity for sort algorithms: https://www.geeksforgeeks.org/time-complexities-of-all-sorting-algorithms/?ref=lbp/

Java Interview questions resources

https://www.edureka.co/blog/interview-questions/java-interview-questions/ https://www.softwaretestinghelp.com/core-java-interview-questions/ https://www.interviewbit.com/java-interview-questions/ https://www.interviewbit.com/spring-interview-questions/ About Garbage collector and finalize method: ( explicity finalize() method has been deprecated since java 9 ) https://javaconceptoftheday.com/garbage-collection-finalize-method-java/ Saga Pattern https://www.baeldung.com/cs/saga-pattern-microservices https://www.youtube.com/watch?v=YPbGW3Fnmbc https://www.youtube.com/watch?v=WnZ7IcaN_JA CascadeType.REMOVE and orphanRemoval = true difference https://stackoverflow.com/questions/18813341/what-is-the-difference-between-cascadetype-remove-and-orphanremoval-in-jpa JPA Persistence Context https://www.baeldung.com/jpa-hibernate-persistence-context JPA, Hibernate Cascade Types https://www.baeldung.com/jpa-cascade-types Xmx,Xms,Xss and others https://alvinalexander.com/blog/post/java/java-xmx-x...