суббота, 27 июля 2013 г.

create maven project

Maven

#create maven project
mvn archetype:generate -DgroupId=my.company.project -DartifactId=modulename -DarchetypeArtifactId=maven-archetype-quickstart -Dversion=0.1 -DinteractiveMode=false


GIT

git init
git add *
git commit -a -m"Initial commit"
git remote add origin https://username@bitbucket.org/username/myrepo.git
git push -u origin --all
mvn idea:idea

пятница, 12 июля 2013 г.

Expand LVM volume after install

Sometimes it is necessary to expand / partition after default installation and truncate /home partition using LVM.

umount /home
lvremove /dev/VolGroup/lv_home
lvextend -l +100%FREE  /dev/VolGroup/lv_root
resize2fs  /dev/VolGroup/lv_root

delete line about /home in /etc/fstab

Install GNOME after RHEL 6 minimal installation

#if u use oracle repo then
rpm -e redhat-release-server.x86_64 --nodeps
yum install oraclelinux-release.x86_64

#
yum -y groupinstall "X Window System" "Fonts" "Desktop"
vi /etc/inittab
        change id:3:initdefault: to id:5:initdefault:
init 6

понедельник, 8 апреля 2013 г.

RHEL 6 / Centos 6 and Python 3

Here are some instructions, how to install Python 3 on RHEL 6 / Centos 6 .

------------------------------------------------------------------------------------

yum update
yum groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
cd /opt
wget http://python.org/ftp/python/3.3.1/Python-3.3.1.tar.bz2
tar xf Python-3.3.1.tar.bz2
rm Python-3.3.1.tar.bz2
cd Python-3.3.1/
./configure --prefix=/usr/local
make && make altinstall
cd ..
rm -rf ./Python-3.3.1
wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.36.tar.gz
tar xvf distribute-0.6.36.tar.gz
cd distribute-0.6.36
python3.3 setup.py install
easy_install-3.3 virtualenv
easy_install-3.3 pip
cd ..
rm -rf ./distribute-0.6.36*

Warning - "altinstall" is very important


Safely usage different versions of python on the same machine:

virtualenv-3.3 --distribute projectfolder
source projectfolder/bin/activate

deactivate

воскресенье, 22 июля 2012 г.

OrientDB - Java sample 1

1. The first step it is need to create a simple POJO. An empty constructor is mandatory.


public class Organization {
    String  name;
    String  description;


    public Organization() {
    }

    public Organization(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}

2. Next step, we open  a database and save POJO

    public void createNewOrg() {

//Open the database in a thread-safe way i.e. in every thread we must create new db object this way
//A database mydb must exist.
        OObjectDatabaseTx db = OObjectDatabasePool.global().acquire("remote:localhost/mydb", "admin", "admin");
        try {

            //Register our class in OrientDB Entity manager to work with POJO's
            db.getEntityManager().registerEntityClass(Organization.class);

            // create a new proxied object and fill its properties
            Organization org = db.newInstance(Organization.class);
            org.setName("MyOrg");
            org.setDescription("This is my good org.");
            db.save(org);
        } finally {

    //ALWAYS CLOSE TO RELEASE CONNECTION POOL RESOURCES
            db.close();
        }

    }

3. Next step we demonstrate a simple query


   public void browseAllOrgs() {
        // Open a database
        OObjectDatabaseTx db = OObjectDatabasePool.global().acquire("remote:localhost/mydb", "admin", "admin");
        try {
            //Register the class to work with it with Entity Manager
            db.getEntityManager().registerEntityClass(Organization.class);

            //Select all objects of class Organization and print their properties
            for (Organization orgItem : db.browseClass(Organization.class)) {
                System.out.print(orgItem.getName() + ' ');
                System.out.println(orgItem.getDescription());
            }

            System.out.println("-------------------");

            //Select all objects of class Organization were description contains word good
            // and print their properties
            List result = db.query(
                    new OSQLSynchQuery("select * from Organization where description like '%good%'"));

            for (Organization org : result) {
                System.out.print(org.getName() + ' ');
                System.out.println(org.getDescription());
            }
        } finally {
            //ALWAYS CLOSE
            db.close();
        }

    }

That's all.

PS. OObjectDatabasePool.global().acquire reuses the database connection to avoid to create it every time. db.close() doesn't close the database but release it to the owner pool. It could be reused in the future.

PPS. It is not necessary to create table (class) type of Organization before run this sample. New table (class) with name Organization  will be created during the first run.

PPPS. If you add a new property (field) to class Organization then at next run a new object  will appear in database with this new field. Older objects will remain unchanged.

пятница, 13 июля 2012 г.

Maven - add custom jar to maven project

...based on (http://blog.dub.podval.org/2010/01/maven-in-project-repository.html)

In this example I will add custom log4j-1.2.1234.jar to my project

1. Create folder with name lib in project root (where pom.xml is placed)

2. Add next structure to pom.xml

<repositories>
    < repository>
         < id > lib < /id>
        < name > lib < /name>
         < releases>
            < enabled > true < /enabled >
             < checksumPolicy > ignore < /checksumPolicy>
         < /releases>
         < snapshots>
             < enabled > false < /enabled>
         < /snapshots >
         < url > file://${project.basedir}/lib < /url>
     < /repository>
  < /repositories>



3. Then install necessary jar (log4j-1.2.1234.jar) to local maven repo:

mvn install:install-file -Dfile=log4j-1.2.1234.jar -DgroupId=myrepo -DartifactId=log4j -Dversion=1.2.1234 -Dpackaging=jar

4. Then go to $user_home/.m2/repository/myrepo/log4j/1.2.1234/ and copy all it contents to {$project root}/lib/myrepo/log4j/1.2.1234/

5. Add new dependency jar to project:


          < dependency >
             < groupId > myrepo < /groupId >
             < artifactId > log4j < /artifactId>
            < version > 1.2.1234 < /version>
         < /dependency >


That's all.


PS. Every time you compile this project on new machine jar's will be added to local maven repo of this new machine

воскресенье, 8 июля 2012 г.

OrientDB - create new table (class or object)


First way



1. To create new object or class simple call:
orientdb>  create class person

2. Then we need to define what properties of object person we need to store
create property person.firstname STRING
create property person.lastname STRING
create property person.middlename STRING
create property person.age INTEGER
create property person.birthdate DATE
create property person.country STRING
create property person.city STRING
create property person.address STRING
create property person.email STRING
create property person.phone STRING
create property person.ssn STRING

3. Then if we need that some field of object (class) must be unique then we define index
orientdb> create index person.ssn UNIQUE

 or

orientdb>CREATE INDEX persons ON person (ssn, email, pnone) UNIQUE

Second way


1. To dynamically create new object it is possible to point out property names and values directly

orientdb> create class group
orientdb> insert into group (name, description) values ('employee','Internal personnel')

orientdb> browse class group

---+---------+--------------------+--------------------
  #| RID     |name                |description
---+---------+--------------------+--------------------
  0|     #9:0|employee            |Internal personnel
---+---------+--------------------+--------------------

2. To make name of group unique we must define property name and index
orientdb> create property group.name STRING
orientdb> create index group.name UNIQUE