2012-01-31

My Master Thesis

I have been admitted for a master thesis topic called "Autonomous Placement and Migration of
Services in Heterogeneous Environments" at Technical University of Munich(TUM). The topic is about live software migration autonomously at smart spaces.

I will be working on this topic with Marc-Oliver Pahl who is a research staff member and a PhD student at the chair of Network Architectures and Services at TUM.

The following questions should be answered in this thesis:
Which approaches of moving services inside a network do exist and are currently in use?
Which are existing algorithms for deciding on which node to place a service?
Which are existing algorithms for splitting and merging services?
Which are the domains this functionality is used today?
What are the prerequisites of the respective approaches?

Concerning the specification:
Which components are needed?
How can the solution be realized in the most decentralized way?
Which base functionality is needed for a service to be movable, splittable and mergable?
How can it be ensured that a service moves with no or minimized interruption?
How can the overall load be balanced?

2011-12-06

Steganalysis: Chi-Square Attack & LSB Enhancement

I have developed a small Java program to perform Chi-Square attack and LSB Enhancement attack on 24-bit BMP images.
What does LSB Enhancement mean?
Well, it is the process of manipulating the least-significant-bit(LSB) of image data in order to produce an output to discover the embedded data.
How it works?
First of all we need to read the image data in Java. I used an already implemented Java class which was based on the code from authors Abdul Bezrati and Pepijn Van Eeckhoudt. The class is called BitmapLoader and it can read both 8-bit and 24-bit BMP images. The method loadBitmap(String file) returns a BufferedImage of type BufferedImage.TYPE_4BYTE_ABGR which means that when a pixel value is read using image.getRGB(x, y) it will return a 32-bit integer value of which the left most 8 bits will represent the ALPHA component, next 8 bits BLUE component, next 8 bits GREEN component and the least significant 8 bits will represent the RED component of the pixel. We can read these components individually by performing bitwise shift operations on the RGB value as 

int pRGB = image.getRGB(x, y);
int alpha = (pRGB >> 24) & 0xFF;
int blue = (pRGB >> 16) & 0xFF;
int green = (pRGB >> 8) & 0xFF;
int red = pRGB & 0xFF;

LSB enhancement means setting the component value to 255 if the least-significant-bit is 1 or leave as it is if 0. As a result of this operation, the image will have some flashy colours in the parts where the LSBs were 1s.
How it works in java? First we need to set the alpha component to 255 or the background of the image will be transparent. Then we need to check the red, green and blue components if the LSBs are 1, if they are, we will set these values to 255. It is performed with the following lines of code in Java:

int pRGB = 255 << 24; //set the alpha component
int temp = 0;
if ((red & 0x01) == 1) {//check if the LSB is 1
    pRGB += 255;
}
if ((green & 0x01) == 1) {//check if the LSB is 1
    temp = pRGB;
    pRGB = 255 << 8;
    pRGB += temp;
}
if ((blue & 0x01) == 1) {//check if the LSB is 1
    temp = pRGB;
    pRGB = 255 << 16;
    pRGB += temp;
}
lsbImage.setRGB(x, y, pRGB);//set the RGB value of the image.

When the above operation is performed on all pixels of the image, the resulting lsbImage which is of type BufferedImage will reveal the parts of the image with the hidden data.



How Chi-Square attack works?
This attack was developed by Andreas Westfeld and Andreas Pfitzmann in 2000 (Andreas Westfeld and Andreas Pfitzmann, Attacks on Steganographic Systems. Breaking the Steganographic Utilities EzStego, Jsteg,Steganos, and S-Toolsand Some Lessons Learned, 2000).
First of all, we need to know what is Chi-Square analysis? It is a statistical test to measure if a given set of observed data and an expected set of data are similar or not. This is the main idea, you can read about it in more details in any statistics book.
The idea of this attack is to compare Pair-of-Values' observed frequencies with their expected frequencies and calculate p value which will represent the probability of having some embedded data in an image.
What do we mean by Pair-of-Values? According to Westfeld & Pfitzmann, when some data like encrypted text is embedded into an image the LSB values of the original data change in a way that the number of these pairs become nearly equal while they differ so much when there is no embedding. We can see pairs of values as the following bit sequences in our case where we have 8-bit components. As a result we have 128 pairs of values like 0-1, 2-3, 4-5, ..., 254-255. What we do with these values? We will count the occurrences of the individual colour values in the image and we will come up with the observed frequencies data set which will be used in the chi-square test. But we also need an expected data set which is explained by Westfeld & Pfitzmann as the average of the occurrences of the values in a pair.
00000000
00000001
00000010
00000011
00000100
00000101
........
11111110
11111111
For the observed data set we just need to take the frequency of one of the pairs. It will not make any difference because the expected value is the average of both values in a pair which means that both of the values are in the same distance to the average. For example, we counted 800 occurrences for value 0 and 200 occurrences for value 1. The expected value will be the average of these two values which will result in 500. Both of the observed values are at the same distance to the average which is 300. 

How is it implemented in Java?
I have a class named PoV which has only the following attribute
private long[] pov = new long[256];
and three methods as

public double[] getExpected() {
        double[] result = new double[pov.length / 2];
        for (int i = 0; i < result.length; i++) {
            double avg = (pov[2 * i] + pov[2 * i + 1]) / 2;
            result[i] = avg;
        }
        return result;
}
public void incPov(int i) {
        pov[i]++;
}
public long[] getPov() {
        long[] result = new long[pov.length / 2];
        for (int i = 0; i < result.length; i++) {
            result[i] = pov[2 * i + 1];
        }
        return result;

How do we perform the Chi-square test on the image?
The performed test is the iterated version of the above described attack and it is performed after reading a predefined amount of data(chunk size) is read. I chose chunk-size as 128 bytes which means after reading 128 bytes of image data, a test is performed and its result is stored. The total number of tests/chunks in the image is
numOfChunks=(int)(Math.floor((width*height*3)/chunkSize)+1);
which will also be the width in pixels of the output generated at the end. Sample outputs of the program are given below.

480x360 embedded with 6 KB data
LSB Enhancement output
Chi-square attack output


Download available at: https://sourceforge.net/projects/chi-square/

2010-02-06

JAVA PERSISTENCE FRAMEWORKS

1- ) INTRODUCTION
In its relatively short lifetime the Java™ platform has achieved an unprecedented degree of acceptance by industry and academia. The Java programming language synthesized many good
ideas from earlier languages and married these with the unassailable heritage of the C family.
The simple but pragmatic package mechanism has supported the construction of a large collection
of reusable software packages that allows the Java platform to be applied to virtually all segments of the computing landscape.
The language provides a simple, yet powerful, object model, a strong, mostly static, type system, automatic storage management, and concurrency through built-in synchronization mechanisms. These language features are a major factor in the robustness and reliability of applications. However, the Java platform does not extend these virtues to the domain of persistent data (objects). Rather, the Java platform supports the traditional approach, that of input, computation and output, with an explicit transformation to an external representation occurring at the input/output points. In practice, this model is increasingly less applicable, as most applications now require access to volumes of data that demand an incremental approach, for which the transformation code becomes both a source of errors and a time and effort sink.
To mitigate this deficiency, several persistence mechanisms have been developed, many of which are written in the Java programming language. The natural desire to implement the mechanisms in the Java programming language, coupled with a strong resistance to additions to the Java virtual machine (JVM™), inevitably affects the extent to which a mechanism can support the full language and the performance that can be achieved. In addition, although the mechanism itself can leverage the portability of the Java platform, application development and deployment often become correspondingly more complex.

2- ) WHAT IS PERSISTENCE
To define a persistence framework in a few words and some properties, a persistence framework moves the program data in its most natural form (in memory objects) to and from a permanent data store, the database. The persistence framework manages the database and the mapping between the database and the objects. Persistence framework simplifies the development process.

3- ) PERSISTENCE IN THE JAVA PLATFORM
The first version of the Java Language Specification (JLS) did not address object persistence directly; the only reference to the concept appears in the specification of the transient modifier, a keyword that was essentially reserved for future use. With each evolution of the Java platform, the range of available persistence mechanisms increased, and we will briefly review the history of these developments.
The initial release of the Java platform, JDK™ 1.0, provided very limited support for persistence. There was the conventional mechanism to encode and decode basic types using input/output streams that could be connected to files in an external file system. There was also support for encoding and decoding a table of properties (java.util.Properties) to and from a stream.
With the JDK 1.1 release came support for Java Object Serialization (JOS), a mechanism that supports the automatic encoding and decoding of nearly any object to and from a stream, respectively. Unlike the property table encoding, which is textual, object serialization uses a standard binary encoding format. JOS is effectively the default persistence mechanism for the Java platform, and the second edition of the JLS refers to it in the specification of the transient modifier. JOS is also used as the argument marshalling protocol for Java™ Remote Method Invocation (Java RMI). At its lowest levels, JOS builds on the platform support for encoding and decoding basic types. As we shall discuss later, serialization suffers some serious problems with class evolution, and this led to a new system called “Long-term Persistence for JavaBeans™” that debuted in Java 1.4.
JDK 1.1 also introduced the Java™ Database Connectivity (JDBC) API as a standard way to communicate with a relational database through the SQL language. JDBC provided the springboard for a major assault by the Java platform on the enterprise computing domain and arguably is by far the most successful API in the Java platform. The designers were remarkably successful in marrying the Java programming language to SQL and, consequently, JDBC is very easy to use for straightforward database access. However, in the situation where the application requires an object-oriented view of the underlying data, for example, transforming foreign key relationships into equivalent inter-object references, the programming is considerably more complicated and error-prone. To address this issue many systems have been developed that attempt to automate the process, which is generally referred to as object-relational mapping. Most development environments provide some degree of support for this process. The JDBC API continues to evolve and has recently added support for directly mapping a class in the Java programming language to the equivalent type in the object-relational extensions to SQL.
In parallel with the JDBC development, the Object Database Management Group (ODMG) defined a binding of its object model to the Java programming language, and several object-database vendors provided implementations of the binding. Since object-databases are much less widely deployed than relational databases, and are less standard, which is reflected in the ODMG binding, this exercise was less successful. With the advent of the Java Community Process (JCP), the focus of this effort was replaced by a broader proposal, Java™ Data Objects (JDO). JDO aims to support a wide range of underlying persistent stores, including relational databases, while presenting an object model to the programmer that is similar to that defined by the JLS, but with a small number of restrictions and a few additions. Many of the object database vendors now support JDO in their products.
Paralleling these efforts was the collaborative research project between Sun Microsystems Laboratories and Glasgow University to specify and prototype orthogonal persistence for the Java platform (OPJ). This approach aimed for complete support for all aspects of the language with a very high degree of transparency. In essence OPJ added support for stable memory to the JVM, and the implications of this requirement on JVM implementations ultimately prevented its acceptance.
Finally, the success of the Java platform in the enterprise domain, begun by JDBC, led to the development of Enterprise JavaBeans™ (EJB), an ambitious attempt to marry a component model for application development with support for distributed transactions and legacy datastores. EJB forms part of the Java Enterprise Edition (J2EE™) [Sun03a] and is supported by all the major vendors. EJB provides transparency for persistence and transactions at the cost of a rigid and complex framework that limits the use of many of the standard features of the Java programming language.

4- ) PERSISTENCE FRAMEWORKS IN JAVA
  1. Apache OpenJPA
  2. Castor
  3. TJDO
  4. JDBM
  5. pBeans
  6. SimpleORM
  7. Speedo
  8. XORM
  9. Java Ultra-Lite Framework
  10. Smyle
  11. Space4J
  12. O/R Broker
  13. PAT
  14. Super CSV
  15. JGrinder
  16. QLOR
  17. Ibatis SQL Maps
  18. HIBERNATE
  19. Oracle Toplink JPA
  20. OJB
  21. Torque
  22. Cayenne
  23. Jaxor
  24. Prevayler
  25. JPOX Java Persistence Objects
  26. JDBCPersistence
  27. Ammentos
  28. Daozero
  29. Velosurf
  30. ODAL
  31. jPersist
  32. Mr. Persister
  33. SeQuaLite
  34. BeanKeeper
  35. Persist
  36. Ebean ORM
  37. LightweightModelLayer
 4.1 -) Java Persistence API (JPA)
The Java Persistence API provides an object/relational mapping facility to Java developers for managing relational data in Java applications. Java Persistence consists of three areas:
  1. the Java Persistence API
  2. the query language
  3. Object/relational mapping metadata
4.1.1 -) Persistence Entities
An entity is a lightweight persistence domain object. Typically an entity represents a table in a relational database, and each entity instance corresponds to a row in that table. The primary programming artifact of an entity is the entity class, although entities can use helper classes. The persistent state of an entity is represented either through persistent fields or persistent properties. These fields or properties use object/relational mapping annotations to map the entities and entity relationships to the relational data in the underlying data store.

4.1.1.1 -) Requirements for Entity Classes
An entity class must follow these requirements:
  • The class must be annotated with the javax.persistence.Entity annotation.
  • The class must have a public or protected, no-argument constructor. The class may have other constructors.
  • the class must not be declared final. No methods or persistent instance variables must be declared final.
  • if an entity instance be passed by value as a detached object, such as through a session bean’s remote business interface, the class must implement the Serializable interface.
  • Entities may extend both entity and non-entity classes and non-entity classes may extend entity classes.
  • Persistent instance variables must be declared private, protected, or package-private, and can only be accessed directly by the entity class’s methods. Clients must access the entity’s state through accessor or business methods.

    4.1.1.2 -) Persistent Fields and Properties in Entity Classes
    The persistent state of an entity can be accessed either through the entity’s instance variables or through JavaBeans-style properties. The fields or properties must be of the following Java language types:
    ■ Java primitive types
    ■ java.lang.String
    ■ Other serializable types including:
    ■ Wrappers of Java primitive types
    ■ java.math.BigInteger
    ■ java.math.BigDecimal
    ■ java.util.Date
    ■ java.util.Calendar
    ■ java.sql.Date
    ■ java.sql.Time
    ■ java.sql.TimeStamp
    ■ User-defined serializable types
    ■ byte[]
    ■ Byte[]
    ■ char[]
    ■ Character[]
    ■ Enumerated types[]
    ■ Other entities and/or collections of entities
    ■ Embeddable classes

    Entities may either use persistent fields or persistent properties. If the mapping annotations are
    applied to the entity’s instance variables, the entity uses persistent fields. If the mapping
    annotations are applied to the entity’s getter methods for JavaBeans-style properties, the entity
    uses persistent properties. You cannot apply mapping annotations to both fields and properties
    in a single entity.

    4.1.1.2.1 -) Persistent Fields
    If the entity class uses persistent fields, the Persistence runtime accesses entity class instance variables directly. All fields not annotated javax.persistence.Transient or not marked as Java transient will be persisted to the data store. The object/relational mapping annotations must be applied to the instance variables.

    4.1.1.2.2 -) Persistent Properties
    If the entity uses persistent properties, the entity must follow the method conventions of JavaBeans components. JavaBeans-style properties use getter and setter methods that are typically named after the entity class’s instance variable names. For every persistent property property of type Type of the entity, there is a getter method getProperty and setter method setProperty. If the property is a boolean, you may use isProperty instead of getProperty. For example, if a Customer entity uses persistent properties, and has a private instance variable called firstName, the class defines a getFirstName and setFirstName method for retrieving and setting the state of the firstName instance variable. The method signature for single-valued persistent properties is as follows:
    Type getProperty()
    void setProperty(Type type)
    Collection-valued persistent fields and properties must use the supported Java collection interfaces regardless of whether the entity uses persistent fields or properties. The following collection interfaces may be used:
    ■ java.util.Collection
    ■ java.util.Set
    ■ java.util.List
    ■ java.util.Map
    If the entity class uses persistent fields, the type in the above method signatures must be one of these collection types. Generic variants of these collection types may also be used. For example, if the Customer entity has a persistent property that contains a set of phone numbers, it would have the following methods:

    Set getPhoneNumbers() {}
    void setPhoneNumbers(Set) {}

    The object/relational mapping annotations for must be applied to the getter methods. Mapping annotations cannot be applied to fields or properties annotated @Transient or marked transient.

    4.1.2 -) Persistence Units
    A persistence unit defines a set of all entity classes that are managed by EntityManager instances in an application. This set of entity classes represents the data contained within a single data store.
    Persistence units are defined by the persistence.xml configuration file. The JAR file or directory whose META-INF directory contains persistence.xml is called the root of the persistence unit. The scope of the persistence unit is determined by the persistence unit’s root. Each persistence unit must be identified with a name that is unique to the persistence unit’s scope.
    Persistent units can be packaged as part of a WAR or EJB JAR file, or can be packaged as a JAR file that can then be included in a WAR or EAR file. If you package the persistent unit as a set of classes in an EJB JAR file, persistence.xml should be put in the EJB JAR’s META-INF directory. If you package the persistence unit as a set of classes in a WAR file, persistence.xml should be located in the WAR file’s WEB-INF/classes/META-INF directory. If you package the persistence unit in a JAR file that will be included in a WAR or EAR file, the JAR file should be located:
    • In the WEB-INF/lib directory of a WAR.
    • In the top-level of an EAR file.
    • In the EAR file’s library directory.

    4.2 -) Enterprise JavaBeans (EJB)
    EJB is a component architecture for the development of distributed business applications and forms part of the Java™ 2 Platform Enterprise Edition (J2EE™ platform). In exchange for following the EJB architecture, developers are provided transparent support for distribution, persistence, transactions and security. There is also the promise of a “write-once, run-anywhere” guarantee for EJBs, similar to that for standard Java classes, in any J2EE-compliant implementation. Beans are deployed in a container that forms part of a J2EE implementation, provides life-cycle support for the bean and interposes on all access to beans. Beans come in three forms: session, entity and message.
    Session beans model workflow and typically support a specific client that is interacting with the system. Session beans are not intended to model persistent data although they may access datastores and may survive crashes. Session beans come in two forms, stateless and stateful. The former carry no data specific to a particular client and can be pooled and used for any invocation, whereas the former carry client-specific state and are bound to that client for the duration of the session. Since session beans do not model persistent data, we do not consider them further.
    Entity beans are intended to correspond to persistent data, typically a row in a relational database table8 and have strong availability guarantees in the face of system failures. The persistence of entity beans can be managed directly by the bean (bean-managed) typically using JDBC, or managed automatically by the container (container-managed). Container-managed persistence might itself be implemented using a mechanism like JDO.
    The EJB framework is relatively complex and involves the creation - at a minimum - of two interfaces, called home and remote and also an implementation class, referred to as the bean class.
    This set is collectively referred to as the bean. The home interface is used for locating or creating bean instances and the remote interface is used by clients to invoke a bean’s business methods.
    The bean class provides implementations for (some of) these methods as well as a number of callback methods required by the framework. The J2EE implementation will typically provide additional implementation classes, for example, of the remote interface.
    Similar to JDO, EJBs follow a defined life-cycle, but it is more visible to the programmer because it is reflected by required callbacks from the container to the bean implementation class.
    The programmer-provided bean implementation class must implement these callbacks. The lifecycle includes an explicit pooled state, which corresponds to an allocated but unassigned bean class instance. Pooled instances are activated as needed, for example, when a new persistent entity is created or when retrieved by a finder method from the underlying datastore. To support scalability, the life-cycle also includes passivation and activation transitions that allow a bean instance to be freed up, similar to memory paging in a virtual memory system.
    EJB provides a query language, EJBQL, which can be used to implement finder methods directly. EJBQL supports the relational model, with some syntactic sugar to close the gap with the Java programming language.
    In addition to the bean code, a developer must also provide a deployment descriptor, in XML, that provides information on the bean. This is used by bean assemblers and bean deployers and can be used to customize the bean to a particular environment. In EJB 1.0 this information was
    coded in the Java programming language and used JOS as the persistence mechanism. The switch to XML in EJB 1.1 is indicative of the general trend away from JOS to XML.

    4.3 -) Java Data Objects (JDO)
    JDO is an attempt to provide “transparent persistence” for developers of Java applications, across a wide range of underlying datastores including relational databases, object databases and other custom datastores. It is an outgrowth of the work that was begun by the ODMG on the binding between the Java platform and object databases.
    JDO therefore shares some similarities with OPJ in that both aim for transparency. The essential difference is that JDO explicitly introduces the existence of an external datastore that may be accessed concurrently by unknown third-parties, and that an explicit mapping exists between the JVM environment and the external store. OPJ, in contrast, addresses the stability of the Java object memory and associated JVM state. This difference is reflected in two key aspects of the JDO specification, namely the introduction of an additional form of object identity, JDO-identity, that subsumes JVM object-identity, and the specification of an object-model life cycle that introduces states, potentially visible to an application, such as “hollow,” where the object fields are not filled in from the corresponding data in the datastore. JDO-identity comes in three forms: Datastore, which is managed by the external store and unrelated to the fields of an object; Application, which is managed by the application and based on certain (primary-key) fields of the class; and Nondurable, which is managed by the JDO implementation for data that has no natural unique identifier, for example entries in a log file.
    JDO is not transparent for all data types and explicitly introduces first-class and second-class objects for persistence purposes. These transparency limitations arise from two sources: firstly from the constraints imposed by the underlying datastores, which have to be treated as immutable legacy systems, and secondly from the fact that a JDO implementation must treat the JVM as a black box. In particular, although arrays in the Java programming language have some object-like features, they cannot be handled by the standard JDO bytecode post-processing (“enhancement”) as they are not full-fledged classes in the JVM. In consequence, arrays are second-class objects in JDO, and must be encapsulated inside a (persistent) class. In particular, if such an array is passed outside the class, modifications to the array will not be detected by the JDO implementation, leading to incorrect behaviour.
    JDO includes a query subsystem that is accessed programmatically via the Query class. It operates over collections of objects and allows simple boolean conditions to be expressed using Java programming language syntax. JDO provides a way to access the entire extent of a class, and this typically forms the starting point for queries. JDO also allows objects to be looked up using JDO object identity, which is the other way to locate objects.
    JDO defines a standard way to describe the details of the persistence of a class or package specified in XML. At a minimum this must specify which classes can be made persistent but may include details such as exactly which fields are to be persisted.
    JDO defines the PersistenceManager class as the main client interface for controlling the system. Instances of PersistenceManager are themselves created by a PersistenceManagerFactory class that is created either from a properties file or by explicit instantiation in the code. Object creation and access must run inside a transaction bracketed by the begin and commit methods of the Transaction class. The current transaction can be accessed from the PersistenceManager instance.

    4.4 -) Hibernate
    Hibernate is an object persistence framework that simplifies object-relational mapping between a Java application and an underlying relational database. It does so by providing transparent persistence of POJOs, working as a "mediator" layer to provide automatic persistence and loading of objects from a Java application to database tables. With Hibernate, saving object state to and loading object state from a database is as easy as calling methods in Java objects. You don't have to manage low-level database operations from your application code; the Hibernate framework takes care of all the intermediate steps for you.
    Its primary feature is mapping from Java classes to database tables (and from Java data types to SQL data types). Hibernate also provides data query and retrieval facilities. Hibernate generates the SQL calls and relieves the developer from manual result set handling and object conversion, keeping the application portable to all supported SQL databases, with database portability delivered at very little performance overhead.
    Mapping Java classes to database tables is accomplished through the configuration of an XML file or by using Java Annotation. When using an XML file, Hibernate can generate skeletal source code for the persistence classes. This is unnecessary when annotation is used. Hibernate can use the XML file or the annotation to maintain the database schema. Facilities to arrange one-to-many and many-to-many relationships between classes are provided. In addition to managing association between objects, Hibernate can also manage reflexive associations where an object has a one-to-many relationship with other instances of its own type. Hibernate supports the mapping of custom value types. This makes the following scenarios possible:
    • Overriding the default SQL type that Hibernate chooses when mapping a column to a property
    • Mapping Java Enum to columns as if they were regular properties
    • Mapping a single property to multiple columns
    Hibernate provides transparent persistence for Plain Old Java Objects (POJOs). The only strict requirement for a persistent class is a no-argument constructor, not necessarily public. Proper behaviour in some applications also requires special attention to the equals() and hashCode() methods.
    Collections of data objects are typically stored in Java collection objects such as Set and List. Java generics, introduced in Java 5, are supported. Hibernate can be configured to lazy load associated collections. Lazy loading is the default as of Hibernate 3.
    Related objects can be configured to cascade operations from one to the other. For example, a parent such as an Album object can be configured to cascade its save and/or delete operation to its child Track objects. This can reduce development time and ensure referential integrity. A dirty checking feature avoids unnecessary database write actions by performing SQL updates only on the modified fields of persistent objects.
    Hibernate provides a SQL inspired language called Hibernate Query Language (HQL) which allows SQL-like queries to be written against Hibernate's data objects. Criteria Queries are provided as an object-oriented alternative to HQL.
    Hibernate can be used both in standalone Java applications and in Java EE applications using servlets or EJB session beans.
    In Hibernate jargon, an entity is a stand-alone object in Hibernate's persistent mechanism which can be manipulated independently of other objects. In contrast, a component is subordinate to other entities and can be manipulated only with respect to other entities. For example, an Album object may represent an entity but the Tracks object associated with the Album objects would represent a component of the Album entity if it is assumed that Tracks can only be saved or retrieved from the database through the Album object.
    Hibernate was developed by a team of Java software developers around the world led by Gavin King. JBoss, Inc. (now part of Red Hat) later hired the lead Hibernate developers and worked with them in supporting Hibernate.
    The current version of Hibernate is Version 3.x. This version has new features like a new Interceptor/Callback architecture, user defined filters, and JDK 5.0 Annotations (Java's metadata feature). Hibernate 3 is now a certified implementation of the Java Persistence API 1.0 specification via a wrapper for the Core module which provides conformity with the JSR 220 JPA standard.

    5-) CONCLUSION
    Object relational mapping became important due to increasing coupling between relational database management systems and object oriented application concepts and development. In conclusion, it is clear that the impact of persistence on application code covers a wide spectrum, as does the performance of the resulting system. Access to persistent data is an important aspect of virtually all applications. The Java programming language follows the traditional approach of separating persistent data and transient data, leaving the management of persistence to applications or layered mechanisms. As today, this is the point where the technology on persistence frameworks have reached but we all know that everything but the change itself changes. I am sure that the point where these frameworks will reach in a year will be very far away from the current one.

    2009-08-26

    FFMPEG COMPILATION IN WINDOWS USING MINGW32/MSYS

    FFMPEG COMPILATION IN WINDOWS USING MINGW32/MSYS

    1-)Minimal SYStem (MSYS) installation
    Download the MSYS executable from here and install into c:\msys. Do not continue with the postinstall operation.
    2-)Update MSYS
    Update the MSYS to a more recent version (1.0.11) by downloading the package from here and copy mount.exe, msys-1.0.dll and ps.exe into c:\msys\bin directory.
    3-)MSYS DTK(Developer Tool Kit)
    Download the DTK from here and install into c:\msys.
    4-)Update BASH
    Download bash version 3.1 from here and copy bash.exe and sh.exe from the bin subdirectory to c:\msys\bin directory and replace sh.exe with the old one.
    5-)Install MINGW
    Download MINGW 5.1.4 from here and follow the instructions as follows:
    -Download only
    -Candidate
    -Check the followings
    MinGW base tools (autoselected)
    g++ compiler
    and run the exe again but this time follow the instructions as follows
    -Download and install
    -Candidate
    -Check the followings
    MinGW base tools (autoselected)
    g++ compiler
    make the installation folder as c:\msys\mingw it will download the following packages
    mingw-runtime-3.10.tar.gz
    w32api-3.7.tar.gz
    binutils-2.16.91-20060119-1.tar.gz
    gcc-core-3.4.5-20060117-1.tar.gz
    gcc-g++-3.4.5-20060117-1.tar.gz
    6-)Configuring FSTAB
    Rename the file in c:\msys\etc\fstab.sample as fstab and replace the the line c:/mingw to c:/msys/mingw using a text editor like Notepad++. Notepad++ is recommended as the text editor for all of the editing operations. It can be downloaded from here Note:Open c:\msys\msys.bat with Notepad++ and replace “-fn Courier-12” to “-fn Courier-16” to make the fonts larger in the msys window.
    7-)Update MAKE
    Download the MAKE MSYS v 3.81 from here and copy the files in the bin and share folder into the same folders under
    c:\msys\mingw\bin and c:\msys\mingw\share.
    8-)Coreutils
    Download the coreutils package from here and copy the whomai.exe to c:\msys\minw\bin
    9-)MINGW Utils
    Downlaod the package from here and copy the unix2dos.exe to c:\msys\mingw\bin.
    10-)Update GCC 3.4.5 to 4.3.3
    Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
    11-)Update GCC Core 3.4.5 to 4.3.3
    Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
    12-)ICONV
    Download the package from here and install it into c:\msys\mingw.
    13-)MINGW RUNTIME Update From 3.10 to 3.15.2
    Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
    14-)W32 API Update from 3.7 to 3.13
    Download the package from here and copy all of the directories to c:\msys\mingw\<correponding directory>
    15-)BINUTILS Update from 2.16.91 to 2.19.1
    Download the package from here and copy all of the directories
    to c:\msys\mingw\<correponding directory>

    AFTER ALL OF THESE OPERATIONS ITS TIME TO GET FFMPEG FROM SVN

    In order to get ffmpeg from svn, first we have to download and install a SVN client, TortoiseSVN is recommended. TortoiseSVN can be downloaded from http://tortoisesvn.tigris.org/.
    After installing SVN client we can download the ffmpeg SVN by performing a checkout to the address svn://svn.mplayerhq.hu/ffmpeg/trunk

    COMPILING FFMPEG WITHOUT ADDITIONAL LIBRARIES

    After installing MSYS and MINGW there will be a shortcut on your desktop with a blue M icon. Just double click on it to run MSYS or run C:\msys\msys.bat Assuming that the ffmpeg is downloaded to c:\ffmpeg just type
    cd c:\ffmpeg
    ./configure --enable-memalign-hack --extra-cflags=-fno-common --enable-static --disable-shared
    If an error occurs like “pr: Command not found” copy the pr.exe file in the bin directory of coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2 that you previously downloaded to c:\msys\bin.
    make
    After the make operation, if you see “strip ffmpeg.exe” as the last line of the terminal, it means that the compilation is successful and its turn for the next command:
    make install

    COMPILING FFMPEG WITH ADDITIONAL STATIC LIBRARIES

    For all of the configure commands we will use the following instruction
    ./configure --prefix=/mingw --enable-static --disable-shared
    make
    make install

    1-)ZLIB-1.2.3
    Download the package from here and extract the package to c:\msys\zlib-1.2.3 and follow the instructions:
    cd c:\msys\zlib-1.2.3
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the zlib-1.2.3 directory after installation.

    2-)XVIDCORE-1.2.1
    Download the package from here and
    extract the package to c:\msys\xvidcore-1.2.1 and follow the instructions:
    cd c:\msys\xvidcore-1.2.1
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the xvidcore-1.2.1 directory after installation.

    3-)SPEEX-1.2rc1
    Download the package from here and extract the package to c:\msys\speex-1.2rc1 and follow the instructions:
    cd c:\msys\speex-1.2rc1
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the speex-1.2rc1 directory after installation.

    4-)LIBOGG-1.1.3
    Download the package from http://www.xiph.org/downloads/ and extract the package to
    c:\msys\libogg-1.1.3 and follow the instructions:
    cd c:\msys\libogg-1.1.3
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the libogg-1.1.3 directory after installation.

    5-)LIBOIL-0.3.16
    Dwonload the package from here and extract the package to c:\msys\liboil-0.3.16 and follow the instructions:
    cd c:\msys\liboil-0.3.16
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the liboil-0.3.16 directory after installation.

    6-)GLIB-2.18.3 and PKG-CONFIG-0.23-2
    Download the glib package from here and extract the files into c:\msys\mingw\<corresponding directory>
    Download the package from here and extract the files into c:\msys\mingw\<corresponding directory>

    7-)LIBSCHROEDINGER-1.0.7
    Download the package from here and extract the package into c:\msys\schroedinger-1.0.7and follow the instructions:
    cd c:\msys\schroedinger-1.0.7
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the schroedinger-1.0.7 directory after installation.

    8-)LIBTHEORA-1.0
    Download the package from http://www.theora.org/downloads/ and extract the package into c:\msys\libtheora-1.0 and follow the instructions:
    cd c:\msys\libtheora-1.0
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the libtheora-1.0 directory after installation.

    9-)LIBMP3LAME
    Download the package from here and extract to c:\msys\lame-398 and follow the instructions:
    cd c:\msys\lame-398
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the lame-398 directory after installation.

    10-)AMRNB-7.0.0.2
    Download the package from here and extract th epackage to c:\msys\amrnb-7.0.0.2 and follow the instructions:
    cd c:\msys\amrnb-7.0.0.2
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the amrnb-7.0.0.2 directory after installation.

    11-)AMRWB-7.0.0.3
    Download the package from here and extract the package into c:\msys\amrwb-7.0.0.3 and follow the instructions:
    cd c:\msys\amrwb-7.0.0.3
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the amrwb-7.0.0.3 directory after installation.

    12-)FAAD-2.6.1
    Download the packge from here and extract the package into c:\msys\faad-2.6.1 and follow the instructions:
    cd c:\msys\faad-2.6.1
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the faad-2.6.1 directory after installation.

    13-)FAAC-1.26
    Download the package from here and extract the package into c:\msys\faac-1.26 and follow the instructions:
    cd c:\msys\faac-1.26
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the faac-1.26 directory after installation.

    14-)BZIP2
    Download the package from here and extract the package into c:\msys\bzip2-1.0.5 and download the patch from here and save into c:\msys\bzip2-1.0.5 and follow the instructions:
    cd c:\msys\bzip2-1.0.5
    patch -p0 < bzip2-1.0.5-extensions.diff
    make
    make install PREFIX=/mingw
    Delete the bzip2-1.0.5 directory after installation.

    15-)LIBGSM-1.0.12
    Download the package from here and extract the cabinet file components to the corresponding directories in c:\msys\mingw\

    16-)LIBVORBIS-1.2.2
    Download the package from http://www.xiph.org/downloads/ and extract the package into c:\msys\libvorbis-1.2.2 and follow the instructions:
    cd c:\msys\libvorbis-1.2.2
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the libvorbis-1.2.2 directory after installation.

    17-)NASM-2.06rc1(May be needed before installing one of the previous libraries-libmp3lame-)

    Download the package from here and extract the package to c:\msys\nasm-2.06rc1 and follow the instructions:
    cd c:\msys\nasm-2.06rc1
    ./configure --prefix=/mingw --enable-static –disable-shared
    make
    make install
    Delete the nasm-2.06rc1 directory after installation.


    PROBLEMS THAT CAN OCCUR WHILE COMPILATION/INSTALLATION


    Note: The order of installation of the above libraries may be different but its most likely as above. If any other library or component is needed while installation of a library, just apply the required step there. The order may be different because it took me 3 days to compile and apply the configuration above :)

    1-)Assembler Needed-If an error occurs like nasm or yasm is needed or not found, just apply the step #17 explained above.
    2-)Error pr:Command not found- This can occur while configuration.Copy the pr.exe file in the bin directory of coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2 that you previously downloaded to c:\msys\bin.
    3-)Schroedinger Not Found: This can poccur while configuration. Apply the steps 4-5-6-7 under


    COMPILING FFMPEG WITH ADDITIONAL STATIC LIBRARIES in exact order.

    ATTACHING FFMPEG TO FOBJ_JMFSTUDIO MEDIA PLAYER

    1-)Download FOBS
    Download FOBS-0.4.2 from here both the source code and the binaries.

    2-)Install Python
    Download Python2.6.2 from http://www.python.org/ and install into c:\Python.

    3-)Download SCONS
    Download SCONS-local-1.2.0.d20090223 from http://www.scons.org/

    4-)Unpacking
    Unpack the FOBS under c:\msys\fobs.
    Unpack SCONS-local-1.2.0.d20090223 into the c:\msys\fobs\scons-local\.
    Unpack the FOBS\fobs-0.4.2\resources\current-ffmpeg.tar.bz2 into c:\msys\fobs\ffmpeg .

    5-)FFMPEG Recompilation
    -Run MSYS and follow the instructions:
    $ cd /fobs/ffmpeg
    $ ./configure --enable-memalign-hack --extra-cflags=-fno-common --enable-static --disable-shared
    --disable-debug --enable-gpl --enable-nonfree --enable-avfilter --enable-avfilter-lavf --enable-avisynth
    --enable-postproc --enable-libamr-nb --enable-libamr-wb --enable-libgsm --enable-libfaac --enablelibfaad
    --enable-libmp3lame --enable-libschroedinger --enable-libtheora --enable-libvorbis --enablelibxvid
    –prefix=/fobs/external
    $ make
    $ make install
    $ cp libavformat/avi.h /fobs/external/include/libavformat/
    $ cp libavformat/riff.h /fobs/external/include/libavformat/
    $ mkdir /fobs/external/include/libswscale
    $ cp libswscale/swscale.h /fobs/external/include/libswscale/swscale.h

    6-)Environment Variables
    Check whether the environment variables of Python and Java are existent in your system path. If not : Go to
    MyComputer->Properties->Advanced->Environment Variables->System Variables->PATH and append the paths where your python and java JDK bin directory is. Mine is C:\Python; and C:\Program Files\Java\jdk1.6.0_13\bin;
    RESTART THE COMPUTER AFTER APPLYING THE CHANGES

    7-)Build Script
    $ cd /fobs
    $ ./buildFobs.sh FFMPEG_HOME=/fobs/external FOBS4JMF=yes

    After the project has been built, the "fobs/dist" directory will contain the following:
    dist/include, dist/lib : Static library with C++ API classes and header files needed to use Fobs in your C++ project dist/jmf/ : Dynamic library with JMF plugin and Jar with Java part of the implementation. dist/test/ : Some example applications to get help learning the Fobs API.
    If you want to use the ffmpeg you've build with Fobs_jmstudio just copy
    /fobs/jmf/fobs4jmf.dll,/fobs/jmf/fobs4jmf.jar,/fobs/jmf/jmf.jar and /fobs/jmf/jmf.properties into the folder where Fobs_jmstudio exists in the downloaded Fobs binaries folder and the media player is ready to use.

    ERRORS THAT CAN OCCUR WHILE BUILDING FOBS
    Value Error: too many values to unpack:
    File “C:\msys\fobs\SConstruct”, line 29: …
    Solution : Go to c:\msys\fobs\external\lib\pkgconfig and delete the entry “-Lc:\msys\fobs\external\lib” from the line Libs: -L${libdir} int the files libavcodec.pc,libacdevice.pc,libavfilter.pc and libavformat.pc
    Errors in Decoder.cpp , Encoder.cpp and Transcoder.cpp
    Note : Do these steps if errors including 'strcpy','memcpy','memset','abs','INT_MAX', etc occur.
    Decoder.cpp -> Just add the following lines into the file where the #include lines are:
    #include <string.h>
    #include <cmath>
    Change the following lines
    if(isVideoPresent()) res = ::abs(t2-t1) <= 1000.0/getFrameRate();
    else res = ::abs(t2-t1) <= 1000.0/getAudioSampleRate();
    with
    if(isVideoPresent()) res = ::abs((float)(t2-t1)) <= 1000.0/getFrameRate();
    else res = ::abs((float)(t2-t1)) <= 1000.0/getAudioSampleRate();

    Encoder.cpp ->Just add the following lines into the file where the #include lines are:
    #include <string.h>
    #include <limits.h>

    Transcoder.cpp->Just add the following lines into the file where the #include lines are:
    #include <string.h>
    #include <stdlib.h>

    Redefinition Errors->videohdr_tag,CAPTUREPARMS,WM_CAP_SET_CALLBACK_VIDEOSTREAM,WM_CAP_DRIVER_CONNECT,
    WM_CAP_DRIVER_DISCONNECT ,WM_CAP_GET_VIDEOFORMAT, WM_CAP_SET_VIDEOFORMAT, WM_CAP_SET_PREVIEW, WM_CAP_SET_OVERLAY,WM_CAP_SEQUENCE_NOFILE,WM_CAP_SET_SEQUENCE_SETUP,WM_CAP_GET_SEQUENCE_SETUP,...
    Solution->Open the file c:\msys\fobs\ffmpeg\libavdevice\vfwcap.c and make the followinf lines as comment lines.

    //#define WM_CAP_SET_CALLBACK_VIDEOSTREAM (WM_CAP_START + 6)
    //#define WM_CAP_DRIVER_CONNECT (WM_CAP_START + 10)
    //#define WM_CAP_DRIVER_DISCONNECT (WM_CAP_START + 11)
    //#define WM_CAP_GET_VIDEOFORMAT (WM_CAP_START + 44)
    //#define WM_CAP_SET_VIDEOFORMAT (WM_CAP_START + 45)
    //#define WM_CAP_SET_PREVIEW (WM_CAP_START + 50)
    //#define WM_CAP_SET_OVERLAY (WM_CAP_START + 51)
    //#define WM_CAP_SEQUENCE_NOFILE (WM_CAP_START + 63)
    //#define WM_CAP_SET_SEQUENCE_SETUP (WM_CAP_START + 64)
    //#define WM_CAP_GET_SEQUENCE_SETUP (WM_CAP_START + 65)
    // typedef struct videohdr_tag {
    // LPBYTE lpData;
    // DWORD dwBufferLength;
    // DWORD dwBytesUsed;
    // DWORD dwTimeCaptured;
    // DWORD dwUser;
    // DWORD dwFlags;
    // DWORD_PTR dwReserved[4];
    // } VIDEOHDR, NEAR *PVIDEOHDR, FAR * LPVIDEOHDR;

    // typedef struct {
    // DWORD dwRequestMicroSecPerFrame;
    // BOOL fMakeUserHitOKToCapture;
    // UINT wPercentDropForError;
    // BOOL fYield;
    // DWORD dwIndexSize;
    // UINT wChunkGranularity;
    // BOOL fUsingDOSMemory;
    // UINT wNumVideoRequested;
    // BOOL fCaptureAudio;
    // UINT wNumAudioRequested;
    // UINT vKeyAbort;
    // BOOL fAbortLeftMouse;
    // BOOL fAbortRightMouse;
    // BOOL fLimitEnabled;
    // UINT wTimeLimit;
    // BOOL fMCIControl;
    // BOOL fStepMCIDevice;
    // DWORD dwMCIStartTime;
    // DWORD dwMCIStopTime;
    // BOOL fStepCaptureAt2x;
    // UINT wStepCaptureAverageFrames;
    // DWORD dwAudioBufferSize;
    // BOOL fDisableWriteCache;
    // UINT AVStreamMaster;
    // } CAPTUREPARMS;