Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Main {

* Menu
* submenu
* submenu
* submenu
* Menu
* submenu
* subsubmenu
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>${hibernate.version}</version>
</dependency>

<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.3.1</version>
</dependency>

<!-- Junit -->
<dependency>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/io/khasang/eshop/config/HibernateConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ private Properties properties() {
properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.use_second_level_cache", environment.getRequiredProperty("hibernate.use_second_level_cache"));
properties.put("hibernate.cache.region.factory_class", environment.getRequiredProperty("hibernate.cache.region.factory_class"));
properties.put("hibernate.hibernate.javax.cache.provider", environment.getRequiredProperty("hibernate.hibernate.javax.cache.provider"));
properties.put("show_sql", environment.getRequiredProperty("hibernate.format_sql"));
return properties;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/khasang/eshop/controller/AppController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.khasang.eshop.controller;

import io.khasang.eshop.model.CreateTable;
import io.khasang.eshop.util.CheckText;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
Expand All @@ -9,10 +10,14 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.MalformedURLException;

@Controller
public class AppController {
@Autowired
private CreateTable createTable;
@Autowired
private CheckText checkText;

// http://localhost:8080/
@RequestMapping("/")
Expand Down Expand Up @@ -43,4 +48,10 @@ public String getEncryptedPassword(@PathVariable("password") String password) {
return new BCryptPasswordEncoder().encode(password);
}

@ResponseBody
@RequestMapping(value = {"/text/{text}"}, method = RequestMethod.GET)
public String checkText(@PathVariable("text") String text) throws MalformedURLException {
return checkText.checkWord(text);
}

}
14 changes: 14 additions & 0 deletions src/main/java/io/khasang/eshop/dao/impl/BasicDaoImpl.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.khasang.eshop.dao.impl;

import io.khasang.eshop.dao.BasicDao;
import io.khasang.eshop.entity.Cat;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.stat.Statistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -44,7 +46,15 @@ public T getById(long id) {

@Override
public T add(T entity) {
Statistics statistics = sessionFactory.getStatistics();

if (!statistics.isStatisticsEnabled()) {
statistics.setStatisticsEnabled(true);
}

getSession().save(entity);
getSession().get(Cat.class, 1L);

return entity;
}

Expand All @@ -59,4 +69,8 @@ public T delete(T entity) {
getSession().delete(entity);
return entity;
}

void check(){

}
}
16 changes: 16 additions & 0 deletions src/main/java/io/khasang/eshop/entity/Cat.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package io.khasang.eshop.entity;

import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Cacheable
@org.hibernate.annotations.Cache(region = "catCache", usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "cats")
public class Cat {
@Id
Expand All @@ -12,6 +18,16 @@ public class Cat {

private String name;
private String description;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
private List<CatWoman> catWomanList = new ArrayList<>();

public List<CatWoman> getCatWomanList() {
return catWomanList;
}

public void setCatWomanList(List<CatWoman> catWomanList) {
this.catWomanList = catWomanList;
}

public String getDescription() {
return description;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/io/khasang/eshop/entity/CatWoman.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.khasang.eshop.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class CatWoman {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public long getId() {

return id;
}

public void setId(long id) {
this.id = id;
}
}
37 changes: 37 additions & 0 deletions src/main/java/io/khasang/eshop/util/CheckText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.khasang.eshop.util;

import net.yandex.speller.services.spellservice.CheckTextRequest;
import net.yandex.speller.services.spellservice.SpellServiceSoap;
import org.springframework.stereotype.Component;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.MalformedURLException;
import java.net.URL;

@Component
public class CheckText {

private final static String ADDRESS = "http://speller.yandex.net/services/spellservice?WSDL";

public String checkWord(String text) throws MalformedURLException {
URL url = new URL(ADDRESS);
QName qName = new QName("http://speller.yandex.net/services/spellservice", "SpellService");

Service service = Service.create(url, qName);

SpellServiceSoap serviceSoap = service.getPort(SpellServiceSoap.class);

CheckTextRequest checkTextRequest = new CheckTextRequest();
checkTextRequest.setText(text);
checkTextRequest.setFormat("plain");
checkTextRequest.setLang("en");

if (serviceSoap.checkText(checkTextRequest).getSpellResult().getError().size() != 0) {
return serviceSoap.checkText(checkTextRequest).getSpellResult().getError().get(0).getS().toString();
} else {
return "Word correct!";
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

package net.yandex.speller.services.spellservice;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
* <p>Java class for ArrayOfSpellResult complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="ArrayOfSpellResult">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="SpellResult" type="{http://speller.yandex.net/services/spellservice}SpellResult" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfSpellResult", propOrder = {
"spellResult"
})
public class ArrayOfSpellResult {

@XmlElement(name = "SpellResult")
protected List<SpellResult> spellResult;

/**
* Gets the value of the spellResult property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the spellResult property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getSpellResult().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link SpellResult }
*
*
*/
public List<SpellResult> getSpellResult() {
if (spellResult == null) {
spellResult = new ArrayList<SpellResult>();
}
return this.spellResult;
}

}
Loading