Skip to content

Instantly share code, notes, and snippets.

public class IntegerPool {
public static void main(String[] args) {
Integer i1 = 10;
Integer i2 = 10;
System.out.println(i1 == i2);// true, value < 128
System.out.println("======================");
Integer i3 = 300;
Integer i4 = 300;
System.out.println(i3 == i4); // false, value >= 128
import java.sql.SQLException;
public class ConstructorWithExceptions {
public class Parent {
public Parent() throws SQLException {
}
public void method() throws Exception {
}
@gitjs77
gitjs77 / SearchQueryWithTuple.java
Last active September 27, 2017 10:57
JPA @query with search to QueryDSL with Tuple
/* SQLQueryFactory for Querydsl querying8*/
private SQLQueryFactory queryFactory;
/* Q - generated objects for use in the Querydsl querying*/
private static QDeposit deposit = QDeposit.deposit;
private static QAccounts account = QAccounts.accounts;
private static QCustomer customer = QCustomer.customer;
/*@Query("select u from Deposit u" +
" where (u.currency=:depositCurrency or :depositCurrency is null)" +
"and(u.depositType=:depositType or :depositType is null)" +
@gitjs77
gitjs77 / SearchQueryWithProjectionsConstructor.java
Last active September 27, 2017 11:06
JPA @query with search to Querydsl with Projections.constructor
/* SQLQueryFactory for Querydsl querying*/
private SQLQueryFactory queryFactory;
/* Q - generated objects for use in the Querydsl querying*/
private static QCard card = QCard.card;
private static QAccounts account = QAccounts.accounts;
private static QCustomer customer = QCustomer.customer;
private static QBankBranch bankBranch = QBankBranch.bankBranch;
/**
* Gets accounts by parameters and searchText term.
@SuppressWarnings("Not presented method findByTwoLetterCode(). Fix it in shortest possible time.")
@Ignore
@Test
public void testFindByTwoLetterCode() {
CountryData countryData = new CountryData();
String twoLetterCode = "AZ";
countryData.code2 = twoLetterCode;
Long countryId = countryDB.create(countryData);
Country country = countryDB.findByTwoLetterCode("AZ");
Assert.assertEquals(countryId, country.id);
/**
* Gets List<T> from Mvc result Json path.
*
* @param mvcResult - MvcResult from resource test
* @param listJsonPath - list Json path
* @param <T> - types of elements of the list
* @return List<T>
*/
public <T> List<T> getListFromMvcResultJsonPath(final MvcResult mvcResult, final JsonPath listJsonPath) {
@Bean(name = "jdbcTemplateForFileH2DataBaseInRealisation")
public JdbcTemplate buildTemplate() throws SQLException, IOException {
try {
// For server with classpath: WEB-INF/classes/init_db2
RunScript.execute(dataSource.getConnection(), new FileReader(new ClassPathResource("init_db2").getFile()));
} catch (final IOException e) {
LOGGER.error("new ClassPathResource(\"init_db2\").getFile() NOT FOUND. USING CONFIGURATION FOR LOCAL MACHINE." , e);
// For local machine with resource: ./src/main/resources/init_db2
RunScript.execute(dataSource.getConnection(), new FileReader("./src/main/resources/init_db2"));
}