Merge remote-tracking branch 'upstream/master' into BAEL-2440

This commit is contained in:
mherbaghinyan 2018-12-07 13:17:07 +04:00
commit dcc903eba1
24 changed files with 145 additions and 4 deletions

View File

@ -12,4 +12,4 @@
- [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide)
- [How to Invert an Array in Java](http://www.baeldung.com/java-invert-array)
- [Array Operations in Java](http://www.baeldung.com/java-common-array-operations)
- [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection)

View File

@ -51,3 +51,4 @@
- [Java List Initialization in One Line](https://www.baeldung.com/java-init-list-one-line)
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
- [A Guide to EnumMap](https://www.baeldung.com/java-enum-map)
- [Ways to Iterate Over a List in Java](https://www.baeldung.com/java-iterate-list)

View File

@ -31,3 +31,4 @@
- [Runnable vs. Callable in Java](http://www.baeldung.com/java-runnable-callable)
- [Brief Introduction to Java Thread.yield()](https://www.baeldung.com/java-thread-yield)
- [Print Even and Odd Numbers Using 2 Threads](https://www.baeldung.com/java-even-odd-numbers-with-2-threads)
- [Java CyclicBarrier vs CountDownLatch](https://www.baeldung.com/java-cyclicbarrier-countdownlatch)

View File

@ -58,4 +58,4 @@
- [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition)
- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors)
- [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name)
- [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts)

View File

@ -89,3 +89,6 @@
- [Java Try with Resources](https://www.baeldung.com/java-try-with-resources)
- [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class)
- [Guide to Character Encoding](https://www.baeldung.com/java-char-encoding)
- [Calculate the Area of a Circle in Java](https://www.baeldung.com/java-calculate-circle-area)
- [A Guide to the Java Math Class](https://www.baeldung.com/java-lang-math)
- [Graphs in Java](https://www.baeldung.com/java-graphs)

View File

@ -47,3 +47,4 @@
- [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort)
- [Dependency Injection for Kotlin with Injekt](https://www.baeldung.com/kotlin-dependency-injection-with-injekt)
- [Implementing a Binary Tree in Kotlin](https://www.baeldung.com/kotlin-binary-tree)
- [Generate a Random Alphanumeric String in Kotlin](https://www.baeldung.com/kotlin-random-alphanumeric-string)

View File

@ -24,4 +24,5 @@
- [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date)
- [Guide to DateTimeFormatter](https://www.baeldung.com/java-datetimeformatter)
- [Format ZonedDateTime to String](https://www.baeldung.com/java-format-zoned-datetime-string)
- [Convert Between java.time.Instant and java.sql.Timestamp](Convert Between java.time.Instant and java.sql.Timestamp)
- [Convert Between java.time.Instant and java.sql.Timestamp](https://www.baeldung.com/java-time-instant-to-java-sql-timestamp)
- [Convert between String and Timestamp](https://www.baeldung.com/java-string-to-timestamp)

View File

@ -39,3 +39,7 @@
- [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password)
- [Removing Repeated Characters from a String](https://www.baeldung.com/java-remove-repeated-char)
- [Join Array of Primitives with Separator in Java](https://www.baeldung.com/java-join-primitive-array)
- [Convert String to Byte Array and Reverse in Java](https://www.baeldung.com/java-string-to-byte-array)
- [Pad a String with Zeros or Spaces in Java](https://www.baeldung.com/java-pad-string)
- [Adding a Newline Character to a String in Java](https://www.baeldung.com/java-string-newline)
- [Remove or Replace part of a String in Java](https://www.baeldung.com/java-remove-replace-string-part)

View File

@ -8,3 +8,4 @@
- [Kotlin with Ktor](http://www.baeldung.com/kotlin-ktor)
- [Guide to the Kotlin Exposed Framework](https://www.baeldung.com/kotlin-exposed-persistence)
- [Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates)
- [Introduction to Arrow in Kotlin](https://www.baeldung.com/kotlin-arrow)

View File

@ -14,3 +14,4 @@
- [Building a Data Pipeline with Flink and Kafka](https://www.baeldung.com/kafka-flink-data-pipeline)
- [Intro to Apache Storm](https://www.baeldung.com/apache-storm)
- [Guide to Ebean ORM](https://www.baeldung.com/ebean-orm)
- [Introduction to Kafka Connectors](https://www.baeldung.com/kafka-connectors-guide)

View File

@ -10,3 +10,4 @@
- [A Guide to Jdbi](http://www.baeldung.com/jdbi)
- [Pessimistic Locking in JPA](http://www.baeldung.com/jpa-pessimistic-locking)
- [Get All Data from a Table with Hibernate](https://www.baeldung.com/hibernate-select-all)
- [Spring Data with Reactive Cassandra](https://www.baeldung.com/spring-data-cassandra-reactive)

View File

@ -19,3 +19,5 @@
- [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy)
- [Proxy in Hibernate load() Method](https://www.baeldung.com/hibernate-proxy-load-method)
- [Custom Types in Hibernate](https://www.baeldung.com/hibernate-custom-types)
- [Criteria API An Example of IN Expressions](https://www.baeldung.com/jpa-criteria-api-in-expressions)
- [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby)

View File

@ -0,0 +1,10 @@
CREATE ALIAS UPDATE_EMPLOYEE_DESIGNATION AS $$
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
@CODE
void updateEmployeeDesignation(final Connection conn, final String employeeNumber, final String title) throws SQLException {
CallableStatement updateStatement = conn.prepareCall("update deptemployee set title = '" + title + "' where employeeNumber = '" + employeeNumber + "'");
updateStatement.execute();
}
$$;

View File

@ -0,0 +1,98 @@
package com.baeldung.hibernate;
import com.baeldung.hibernate.entities.Department;
import com.baeldung.hibernate.entities.DeptEmployee;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.junit.*;
import java.io.IOException;
public class NamedQueryIntegrationTest {
private static Session session;
private Transaction transaction;
private Long purchaseDeptId;
@BeforeClass
public static void setUpClass() throws IOException {
session = HibernateUtil.getSessionFactory("hibernate-namedquery.properties").openSession();
}
@Before
public void setUp() throws IOException {
transaction = session.beginTransaction();
session.createNativeQuery("delete from deptemployee").executeUpdate();
session.createNativeQuery("delete from department").executeUpdate();
Department salesDepartment = new Department("Sales");
Department purchaseDepartment = new Department("Purchase");
DeptEmployee employee1 = new DeptEmployee("John Wayne", "001", salesDepartment);
DeptEmployee employee2 = new DeptEmployee("Sarah Vinton", "002", salesDepartment);
DeptEmployee employee3 = new DeptEmployee("Lisa Carter", "003", salesDepartment);
session.persist(salesDepartment);
session.persist(purchaseDepartment);
purchaseDeptId = purchaseDepartment.getId();
session.persist(employee1);
session.persist(employee2);
session.persist(employee3);
transaction.commit();
transaction = session.beginTransaction();
}
@After
public void tearDown() {
if(transaction.isActive()) {
transaction.rollback();
}
}
@Test
public void whenNamedQueryIsCalledUsingCreateNamedQuery_ThenOk() {
Query<DeptEmployee> query = session.createNamedQuery("DeptEmployee_FindByEmployeeNumber", DeptEmployee.class);
query.setParameter("employeeNo", "001");
DeptEmployee result = query.getSingleResult();
Assert.assertNotNull(result);
Assert.assertEquals("John Wayne", result.getName());
}
@Test
public void whenNamedNativeQueryIsCalledUsingCreateNamedQuery_ThenOk() {
Query<DeptEmployee> query = session.createNamedQuery("DeptEmployee_FindByEmployeeName", DeptEmployee.class);
query.setParameter("name", "John Wayne");
DeptEmployee result = query.getSingleResult();
Assert.assertNotNull(result);
Assert.assertEquals("001", result.getEmployeeNumber());
}
@Test
public void whenNamedNativeQueryIsCalledUsingGetNamedNativeQuery_ThenOk() {
@SuppressWarnings("rawtypes")
NativeQuery query = session.getNamedNativeQuery("DeptEmployee_FindByEmployeeName");
query.setParameter("name", "John Wayne");
DeptEmployee result = (DeptEmployee) query.getSingleResult();
Assert.assertNotNull(result);
Assert.assertEquals("001", result.getEmployeeNumber());
}
@Test
public void whenUpdateQueryIsCalledWithCreateNamedQuery_ThenOk() {
Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDepartment");
spQuery.setParameter("employeeNo", "001");
Department newDepartment = session.find(Department.class, purchaseDeptId);
spQuery.setParameter("newDepartment", newDepartment);
spQuery.executeUpdate();
transaction.commit();
}
@Test
public void whenNamedStoredProcedureIsCalledWithCreateNamedQuery_ThenOk() {
Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDesignation");
spQuery.setParameter("employeeNumber", "002");
spQuery.setParameter("newDesignation", "Supervisor");
spQuery.executeUpdate();
transaction.commit();
}
}

View File

@ -0,0 +1,9 @@
hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/main/resources/init_database.sql'
hibernate.connection.username=sa
hibernate.connection.autocommit=true
jdbc.password=
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create-drop

View File

@ -2,3 +2,4 @@
- [A Guide to SqlResultSetMapping](http://www.baeldung.com/jpa-sql-resultset-mapping)
- [A Guide to Stored Procedures with JPA](http://www.baeldung.com/jpa-stored-procedures)
- [Fixing the JPA error “java.lang.String cannot be cast to [Ljava.lang.String;”](https://www.baeldung.com/jpa-error-java-lang-string-cannot-be-cast)

View File

@ -16,6 +16,7 @@
- [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd)
- [Spring Data CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save)
- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results)
- [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:

View File

@ -19,6 +19,7 @@
- [Obtaining Auto-generated Keys in Spring JDBC](http://www.baeldung.com/spring-jdbc-autogenerated-keys)
- [Transactions with Spring 4 and JPA](http://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
- [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries)
- [Many-To-Many Relationship in JPA](https://www.baeldung.com/jpa-many-to-many)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:

View File

@ -4,3 +4,4 @@
- [Thin JARs with Spring Boot](http://www.baeldung.com/spring-boot-thin-jar)
- [Deploying a Spring Boot Application to Cloud Foundry](https://www.baeldung.com/spring-boot-app-deploy-to-cloud-foundry)
- [Deploy a Spring Boot Application to Google App Engine](https://www.baeldung.com/spring-boot-google-app-engine)
- [Deploy a Spring Boot Application to OpenShift](https://www.baeldung.com/spring-boot-deploy-openshift)

View File

@ -2,6 +2,7 @@
- [Introduction to Spring Integration](http://www.baeldung.com/spring-integration)
- [Security In Spring Integration](http://www.baeldung.com/spring-integration-security)
- [Spring Integration Java DSL](https://www.baeldung.com/spring-integration-java-dsl)
- [Using Subflows in Spring Integration](https://www.baeldung.com/spring-integration-subflows)
### Running the Sample
Executing the `mvn exec:java` maven command (either from the command line or from an IDE) will start up the application. Follow the command prompt for further instructions.

View File

@ -7,3 +7,4 @@
- [Apache Tiles Integration with Spring MVC](http://www.baeldung.com/spring-mvc-apache-tiles)
- [Guide to Spring Email](http://www.baeldung.com/spring-email)
- [Request Method Not Supported (405) in Spring](https://www.baeldung.com/spring-request-method-not-supported-405)
- [Spring @RequestParam Annotation](https://www.baeldung.com/spring-request-param)

View File

@ -14,3 +14,4 @@
- [JSON Schema Validation with REST-assured](http://www.baeldung.com/rest-assured-json-schema)
- [Testing Callbacks with Mockito](http://www.baeldung.com/mockito-callbacks)
- [Running JUnit Tests in Parallel with Maven](https://www.baeldung.com/maven-junit-parallel-tests)
- [Gatling vs JMeter vs The Grinder: Comparing Load Test Tools](https://www.baeldung.com/gatling-jmeter-grinder-comparison)

View File

@ -2,3 +2,4 @@
- [Mockito.mock() vs @Mock vs @MockBean](http://www.baeldung.com/java-spring-mockito-mock-mockbean)
- [A Quick Guide to @TestPropertySource](https://www.baeldung.com/spring-test-property-source)
- [Guide to ReflectionTestUtils for Unit Testing](https://www.baeldung.com/spring-reflection-test-utils)