Monday, September 25, 2017

Mock super methods

I found a solution with PowerMock.
Unfortunately the design is not the best, the clients call one method of the abstract super class.
But we dont want to test the method of the super class one hundred times.

@RunWith(PowerMockRunner.class)
@PrepareForTest({Super.class})
public class ClientTest{

private Client client= new Client(createMock(RestClientBuilderProvider.class));

private static void mockGetResponse(final Response.Status status) {
   PowerMock.replace(PowerMock.method(Super.class, "getResponse", 
   String.class, String.class, Class.class, Map.class,
   Map.class)).with(new InvocationHandler() {
      @Override      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
         HTTPResponseWrapper response = new HTTPResponseWrapper();
         response.setStatusCode(status.getStatusCode());
         return response;
      }
   });
}

@Testpublic void testGetReferenceById() throws Exception {
   //given   mockGetResponse(NO_CONTENT);
   //when   HTTPResponseWrapper result = client.getPersonByReferenceId(ORG, REFERENCE_ID_VALUE);
   //then   assertEquals(NO_CONTENT.getStatusCode(), result.getStatusCode().intValue());
}

Thursday, August 24, 2017

monitor your oracle db session

There many popular reports or select statements to rech and understand what happen in the db. I usually use the built in function of PL/SQL developer application.

I collected what kind of privileges you have to ask to use it. because very often you dont have DBA rights. Just ask SELECT for these:

Main window: v_$session
Cursors tab: v_$open_cursor
SQL Text tab: v_$sqltext_with_newlines
Statistics tab: v_$sesstat, 
                      v_$statname
Locks tab: v_$lock

good to have also:
v$sql
v$transaction
v$mystat
v$sgainfo

Wednesday, August 23, 2017

Deadlock during an update

You thought before if you insert or update a row in a table, you do it parallel on different records.

My scenario is now to run a data transfer in PL/SQL and  keep running the Java - hibernate application. It is a paralel running, the data transfer is running on old records, and the application users create new content in the database, and modify only them.

In many cases we receive an exception on both part:
"SQLException: ORA-00060: deadlock detected while waiting for resource".

In fact the Oracle RDBMS use a lock in table level also for update and insert statements. You can read about here.

You can find these table lock modes in the session also, there are some exclusive and sharing modes.

The table indexes are coming to this topic, maybe for first it is strange.
"Indexing the foreign keys in child tables provides the following benefits:
  • Prevents a full table lock on the child table. Instead, the database acquires a row lock on the index.
"

If you have no index on foreign columns, the db will use full table lock instead of row lock.

"Oracle Database maximizes the concurrency control of parent keys in relation to dependent foreign keys. In heap-organized tables, locking behavior depends on the indexing of foreign key columns. If foreign keys are not indexed, then the child table will probably be locked more frequently, deadlocks will occur, and concurrency will be decreased. For this reason, Oracle recommends indexing foreign keys in most cases except when the matching unique or primary key is never updated or deleted."

Description of Figure 9-3 follows

Monday, July 10, 2017

being updated in IT

I faced with the relevant question on a job interview last week:

how do you keep yourself updated?



It is a really good question, I already liked this interview because of their technologies and methodologies.

I could not fulfill this question totally, but I promised myself to create a list here:

  • Social media posts:
    • Linkedin
    • Twitter
    • Facebook
  • Newsletters:
    • Java Magazin
    • Lerner.co.in
    • O'reilly newsletters
  • Online courses:
    • Coursera
    • Udemy
    • FutureLearn
    • Udacity
    • BigDataUniversity from IBM
    • DataCamp
    • Edx
  • Blogs:
    • Uncle Bob / Robert C. Martin
    • Mykong
  • IT news/ community sites:
    • Wired
    • MIT Technology review
    • Agile Connection
    • Open group
    • TechWell
  • Online tests
    • HackerRank
    • Codility
  • Books from amazon
  • Meetups

Feel free send me any suggestion!

AWS

I got a nice brochure from CloudHealth company: AWS migration.


There is a nice sentence, what you should keep in mind:


AWS workloads: "more than 35% of servers showed activity less than 5% of the time."



They mention four ideal goal or state for AWS migration:

  1. workload separation
  2. workload balancing
  3. disaster recovery
  4. all-in

Monday, April 24, 2017

you need some digital skills

If you what kind of skills are necessary for the next generations, they need the online life, consuming information and networking: 



  • collaboration and co-working also in remote distances, sometimes also unknown and/or different culture person 
  • get quickly an overview. you can not analyze big data row by row anymore. you have to find the trends, the reasons, to estimate the possible consequences 
  • find the information, the right place, the right person, don not be lost in the always changing, challenging world 
  • continuously be prepared for learning by doing. If you meet new or strange situation, you have to able to handle it, even accept or ignore it. 
  • produce new information in many different level: sharing emotions and experiences, easy consumable stories, guidelines, overviews, studies. the information sharing via popular tools like Twitter, Wikipedia, Scribd are getting more and more important in the personal and profeesional instant life
Wheeler’s engagement pyramid of digital learning (Source: adapted from Wheeler, 2013)


Tuesday, April 4, 2017

Search with Compass

Hey, we use an xml based compass in a project, working very well. Sometimes we run a reindexation, not more then two times a year.

The search is very easy:
CompassSearchHelper compassSearchHelper = new CompassSearchHelper(...);
CompassQuery query = compassSearchHelper.buildQuery(criteria);
CompassSearchCommand command = new CompassSearchCommand(query, pageNumber);
CompassSearchResults searchResults = compassSearchHelper.searchLocal(command);

You can also highlight the keywords in the search result.

run the indexation:
SingleCompassGps compassGps;
compassGps.index();

and the optimization:
compassGps.getIndexCompass().getSearchEngineOptimizer().optimize(numberOfSegments);

Tuesday, March 28, 2017

Oracle full text search in JPA level

So let's go back to our Oracle full text search. i found the performance is not so bad, you can read in the previous post what to in database level.



I usually build Predicates for Specifications. whit this solution it is very easy to extend a query if you have many criteria.

We saw that for the full text search we used the CONTAINS Oracle function in the SELECT statement. We can call Oracle predefined functions by the CriteriaBuilder.function() method. Check the solution here:

public static Specification<TDocuLanguageFO> textContains(final String text) {
return new Specification<TDocuLanguageFO>() {
@Override
public Predicate toPredicate(Root<TDocuLanguageFO> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Expression<String> x = root.get(TDocuLanguageFO_.contentTxtCb);

Expression<BigDecimal> function = cb.function("CONTAINS",
                                                  BigDecimal.class, 
                                                  x, 
                                                  cb.literal(text));

return cb.greaterThan(function, BigDecimal.ZERO);
}
};
}

In this example I want to highlight also the literal() method of the Criteriabuilder. We have the text parameter for the search, with this literal() function we can convert it to Expression<String> from String.

And we can put the condition to the WHERE clause like this:

Specifications<TDocuLanguageFO> spec =                                                       Specifications.where(textContains(KEYWORD));

List<TDocuLanguageFO> result = dao.findAll(spec);

Wednesday, March 22, 2017

select null

Once you feel, you do not need the projection of a select statement, when you use the exits operator.



1) Select * from apple a where a.id = 1;

2) Select * from apple a where exists (select * from status s where s.id = a.status_id and s.code
='RED');

3) Select * from apple a where exists (select s.id from status s where s.id = a.status_id and s.code ='RED');

4) Select * from apple a where exists (select null from status s where s.id = a.status_id and s.code ='RED');

Really, we do not need that data to read, fetch, put to the memory, etc.

But the Hibernate does not allow you to skip:
4) subquery.select(null);
3) subquery.select(s.get(Status_.id));
2) subquery.select(s);

In fact he will force you to call the select() function. if you put there the root object, he will put to the SELECT statement the ID, primary key and run another select to get the data.


Wednesday, January 25, 2017

Rolled back transaction after test execution for test context?

So this issue is default. You run your test with Spring-test and after executing all the transactions he rollbacks the modifications.



What a funny thing! But sometimes you need the data.

You can add an extra annotation for prevention this problem to your class:
@TransactionConfiguration(defaultRollback = false)

and you can check all the results in your DB.