Sunday, October 18, 2015

Oracle Troubleshooting: ORA-01114, ORA-01110, ORA-27091, ORA-27041

During troubleshooting on an issue in Oracle DB I was getting these errors:

sqlplus / as sysdba

SQL> startup
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size      2233344 bytes
Variable Size    809503744 bytes
Database Buffers   251658240 bytes
Redo Buffers      5541888 bytes
Database mounted.
ORA-01114: IO error writing block to file 5 (block # 1)
ORA-01110: data file 5: '/data/oracle/bb/bb1.dbf'
ORA-27091: unable to queue I/O
ORA-27041: unable to open file
Linux-x86_64 Error: 13: Permission denied
Additional information: 3

I changed the permissions to data file and problem solved:

sudo chmod 660 /data/oracle/bb/bb1.dbf

sqlplus / as sysdba

SQL*Plus: Release Production on Fri Oct 16 17:59:36 2015

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Express Edition Release - 64bit Production

SQL> startup
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size      2233344 bytes
Variable Size    809503744 bytes
Database Buffers   251658240 bytes
Redo Buffers      5541888 bytes
Database mounted.
Database opened.

Friday, September 18, 2015

ATG QueryBuilder: How to create nested queries / subqueries

I had to deal a good amount of time finding a way to query repositoy items that would match some relationships among different item descriptors. I was trying to look for a way to perform a join over different item descriptors, but at the end was able to solved it in a nested queries fashion. You know,

the typical thing in SQL where you filter by matching a column from the result of another query:

SELECT column_name [, column_name ]
FROM   table1 [, table2 ]
WHERE  column_name OPERATOR
      (SELECT column_name [, column_name ]
      FROM table1 [, table2 ]

This in ATG can be done using a query builder operation called: createIncludesItemQuery. You can pass as parameter another query and the colum matching expression.

// Get guide items where tabs in the guide matches some other tabs query
RepositoryItemDescriptor guideRepositoryItemDescriptor = 
RepositoryView guidesRepositoryView = guideRepositoryItemDescriptor.getRepositoryView();               

QueryBuilder guidesQueryBuilder = guidesRepositoryView.getQueryBuilder();
QueryExpression tabsPropertyExpression =     
// productTabsQuery is another query built
Query productGuidesQuery = 
      guidesQueryBuilder.createIncludesItemQuery(tabsPropertyExpression, productTabsQuery);
RepositoryItem[] guides = guidesRepositoryView.executeQuery(productGuidesQuery);

Friday, June 26, 2015

Reactive Programming: Reactive Extensions Library (Starting to learn this reactive thing)

I found a great video explanation of Reactive Programming in the flavour of Reactive Extensions Library done by Jafar Husain (Technical Lead at Netflix) . Here's a brief summary of the main concepts I extracted.

Event Reacting
The term Reactive can be associated by analogy with someone throwing a lot of balls at you at the same time. You need to react quickly to try to catch them all. You don't have control over when you want the balls to be thrown at you, you just need to be prepared to catch them.

To start understanding Rx (Reactive Extensions), we need to have two basic design patterns in consideration: Iterator and Observer.

In Java we have an Iterable interface, which is an interface any type of collection can implement to allow consumers of a collection obtain items one at the time. That's how in Java we can use the foreach operator to traverse a collection. Because the interface provides a specific Iterator for the data type we are consuming in the collection. Three things can happen when using an iterator:
  1. Get the next item
  2. No more items to consume (end of the data stream)
  3. An error can happen (using exception throwing in languages like Java)
The Observer pattern is another well known design pattern where suscribers get suscribed to subjects in order to be notified when a change occurs in the subject. If we analize this pattern, we can find that it's very similar to the Iterator pattern in the sense that there is a producer and a consumer. Main difference is that in the Observer the producer is in control for when sending the data, while in the Iterator the consumer is in control. He decides when to pull the data from the producer.

Iteratot Observer Fusion
But there are two main things "missing" from the Observer pattern that are present in the Iterator:
  • A way to indicate there is no more data
  • A way to indicate an error ocurred
In the Observer you can only suscribe callback to receive data, but you cannot register callbacks for the event where is indicated no more data is going to be pushed (completion event), or to indicate an error happened. Reactive extensions is basically about unifying the observable pipe with the iterable pipe producing a new type called the Observable. It gives the same semantics of both the Iterable and the Observable.

There are a lot of interesting operations that can be done over iterables. Similar to SQL where there are a lot of operations that can be done over sets: filter, select, order, etc. What about if all the same things we can do over data sets residing in a table, could also be done over events (data arriving in). That is not a dream with Rx. It is possible to write SQL style queries over events. The difference is that the query is evaluated as data arrives. You can evaluate data in real time.

More and more code is becoming evented. We have a lot of asynchrouns calls both in client side (JS), and server side (Node.JS). That adds a lot of complexity in the application trying to handle all these
callbacks. The reactive extensions library provides this new Observable data type that establishes a powerful way to model events. By completing the missing semantics (end of data stream and error), you can now apply operations familiar in collections like map, filter, reduce, merge, zip, etc. All those things that could be done over data streams we can pull, now can be done over streams of data we can push.

Imagine the new Java 8 Stream API over data that is arriving dynamically over events pushed to you. Lot of things can improve in an application like serving faster data to consumers just to cite an example.

Still need more learning for this new paradimg, but at least I think this video covers fundamental concepts we need to have before getting our hands into the code.

Friday, June 5, 2015

Apache2: Configuring a local page with custom host name (Virtual Host)

1. Create a folder /wwww/domain
sudo mkdir -p /www/domain 

2. Change permissions
sudo chown 755 /www/domain sudo chown -R www-data:www-data /www/domain 

3. Edit Apache2 conf
sudo gedit /etc/apache2/apache2.conf Add these lines:
<VirtualHost *:80>
    # This first-listed virtual host is also the default for *:80
    DocumentRoot /www/domain

<Directory /www/domain/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

4. Add DNS line in /etc/hosts 

 5. Create index file
touch /wwww/domain/index.html add HTML code:

6. Open domain in browser.

Monday, May 25, 2015

JSON Jackson custom deserializer to return empty String instead of null

Needed a way to deserialize null values in a JSON as emptry strings (""). This is the shortest I could come with.
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;

public class NullHandlerDeserializer extends UntypedObjectDeserializer {

  private static final long serialVersionUID = 1L;

  public Object deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException {
    switch (jp.getCurrentToken()) {
     case VALUE_NULL:      
      return "";
      return super.deserialize(jp, ctxt);

The class extends from an existing deserializer implementation to avoid having to code the handling of all JSON tokens. I needed to worry only about VALUE_NULL token.

And to configure the custom deserializer in the ObjectMapper:

ObjectMapper om = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(Object.class, new NullHandlerDeserializer());

Wednesday, May 20, 2015

XSLT Learnings

Just listing some XSLT learnings from a recent project where I had to learn from scratch.

Basic shelling:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="" version="2.0">
<xsl:output method="xml" encoding="utf-8" indent="no"/> 
<xsl:template match="/">
    <!-- XSL stuff -->

Converting a list of states from XML to HTML select input options:

Given an input like this:


Use XSL like this:

<select name="states">
    <xsl:for-each select="states/*">
             <xsl:attribute name="value"><xsl:value-of select="name(.)"/></xsl:attribute>
        <xsl:value-of select="string(.)"/>

To get this:

        <option value="AL">Alabama</option>
        <option value="AK">Alaska</option>
        <option value="AR">Arkansas</option>
        <option value="CA">California</option>
        <option value="CO">Colorado</option>

Some few things to note:

  • "name(.)" gives you the element (tag) name.
  • "string(.)" gives you the element value (what is between opening and closong tags).

Checking element has children or content

<xsl:if test="some/element-tag/text() != ''">