Wednesday, October 8, 2014

Django using Python3.3 on Debian wheezy - how to

Debian 7 comes with python 2.7.3, and python 3.2.3

To use python2.7.3, we use the command "python" and to use python3.2.3 we use "python3"

The goal is we want to use python3.3.x. Why? you asked. That's a very good question!
The reason is because I want to use MySQL as the database and MySQL Connector Python 2.0.1 only supports Debian 6. 

I have to use the platform independent version of MySQL Connector Python instead of the Debian version.

So, first I have to install Python3.3 from source and this page shows me how.

I am going to tell you how anyway.

sudo apt-get install build-essential
sudo apt-get install libsqlite3-dev
sudo apt-get install sqlite3
sudo apt-get install bzip2 libbz2-dev

Cool! then I download and compile Python3.3

cd /home/me/downloads
wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
tar xJf ./Python-3.3.5.tar.xz
cd Python-3.3.5
./configure --prefix=/opt/python3.3
make && sudo make install

I prefer to use alias for Python3.3 and I called it "py"

echo 'alias py="/opt/python3.3/bin/python3.3"' >> .bashrc

That's it! I now have Python3.3 and the next step is to install Django 1.7. But before we do that, we must first install "distribute" and here how I did it. "Distribute" can be found on this page

cd /home/me/downloads
wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip#md5=c6c59594a7b180af57af8a0cc0cf5b4a
unzip distribute-0.7.3.zip
cd distribute-0.7.3
py setup.py install

Now we have distribute package which is what we need to install Django 1.7. Without this package, it will throw an ImportError: "No module name setuptools"
Get the latest release of Django 1.7 here

cd /home/me/downloads
wget https://www.djangoproject.com/download/1.7/tarball/
tar -zxvf Django-1.7.tar.gz
cd Django-1.7
py setup.py install

Great! I now have Django 1.7 installed. NOTE: when using django-admin.py, you must call it using "py" instead of just "django-admin.py" as mentioned in the Django tutorial.
Find out where "django-admin.py" was installed here:

locate django-admin.py
/usr/local/bin/django-admin.py

Last step is to install MySQL Connector Python, well, because I want to use MySQL. That's the reason why this post is created.
Download MySQL Connector Python here

cd /home/me/downloads
wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.0.1.tar.gz
tar -zxvf mysql-connector-python-2.0.1.tar.gz
cd mysql-connector-python-2.0.1
py setup.py install

Now you can start a new project by calling

py /usr/local/bin/django-admin.py startproject mysite

To use MySQL Connector Python, edit your settings.py as below

DATABASES = {
    'default': {
        'ENGINE'  : 'mysql.connector.django',
        'NAME'    : 'mysite',
        'USER'    : 'root',
        'PASSWORD': 'IShallNotUseRoot',
        'HOST'    : '127.0.0.1',
        'PORT'    : '3306'
    }
}

REMEMBER: Use "py" (in my case) for all the call, such as py manage.py runserver.
Hope this helps you!

Monday, May 27, 2013

How to generate existing entity from existing databases - Symfony, Doctrine

To generate an entity, yes, an entity from a table in an existing database (in YAML):

1. Create a mapping file.

$ app/console doctrine:mapping:convert yml 
./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm 
--from-database --force --filter=TableName --em=defaultEntityManager

2. Import annotation.
$ app/console doctrine:mapping:import BundleName annotation 
--filter=TableName --em=defaultEntityManager
3. Generate the entity.
$ app/console doctrine:generate:entitie Vendor/BundleName/Entity/EntityName 

Saturday, May 25, 2013

Uncaught TypeError: Object #<Object> has no method 'easeInOutCirc'

This error typically appears when you use Primefaces 3.5. 

I found the answer to this error : http://forum.primefaces.org/viewtopic.php?f=3&t=28427

Basically, just need to add somewhere in your .xhtml file a dummy dialog.

You can add this to your master template file, so that all your other pages will automatically include this dummy dialog. Hope this helps.

Glassfish: Exception while preparing the app : Invalid resource : __pm

I thought I'd like to share this information to anyone who might be having issue with deploying a WAR application on Glassfish Server.

My case is Glassfish 3.1.2 and the error is 
Error occurred during deployment: Exception while preparing the app : Invalid resource : jdbc/login__pm 
It's something to do with glassfish-resources.xml file. If you are deploying a WAR file, it must be a web application, and you need to have glassfish-resources.xml file in your WEB-INF folder.

For other applications, this will be in your META-INF folder.

My glassfish-resources.xml looks like this and this gives me the error  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
    <jdbc-connection-pool 
        allow-non-component-callers="false" associate-with-thread="false" 
        connection-creation-retry-attempts="0" 
        connection-creation-retry-interval-in-seconds="10" 
        connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" 
        connection-validation-method="auto-commit" 
        datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 
        fail-all-connections="false" idle-timeout-in-seconds="300" 
        is-connection-validation-required="false" 
        is-isolation-level-guaranteed="true" 
        lazy-connection-association="false" lazy-connection-enlistment="false" 
        match-connections="false" max-connection-usage-count="0" 
        max-pool-size="128" max-wait-time-in-millis="0" 
        name="java:app/LoginPool" non-transactional-connections="false" 
        pool-resize-quantity="5" 
        res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" 
        steady-pool-size="10" validate-atmost-once-period-in-seconds="0" 
        wrap-jdbc-objects="false">
        <property name="serverName" value="localhost"/>
        <property name="portNumber" value="3307"/>
        <property name="databaseName" value="clientdb_user"/>
        <property name="User" value="login1"/>
        <property name="Password" value="login1"/>
        <property name="URL" value="jdbc:mysql://localhost:3307/clientdb_user?zeroDateTimeBehavior=convertToNull"/>
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="create" value="true" />
        <property name="connectionAttributes" value=";create=true" />
    </jdbc-connection-pool>
    <jdbc-resource enabled="true" jndi-name="java:app/jdbc/login"
         object-type="user" pool-name="java:app/LoginPool"/>
</resources>

Wednesday, January 2, 2013

Multiple Modules EJB, JPA, JAR, WAR - Maven Netbeans

I hope this can be a useful post for those who are looking to do an EAR project, with multiple modules.
First stop, using Netbeans 7.2.1 create Maven Enterprise Application, and this will give you the EAR, EJB, and WAR project. You will have one parent project which consists only one pom.xml
  1. Create a new module, a JAR project, to contain all your POJO classes, supposedly your entity classes, java classes with @Entity annotation. Nothing else, only POJO classes. Note: don't forget to include these classes in your persistence.xml file, this is where you put the persistence.xml, not anywhere else.
  2. In your EJB projects, placed all your session beans, in NetBeans, normally this has suffix "Facade". This is where the EntityManager lives. Note: don't forget to include your database dependency jar, for MySQL is something like mysql-connector-java, there is one for PostgreSQL as well. Include JAR project as dependency here.
  3. In your WAR projects, all web application files, html, css, images, resources and etc. This is where your controller files (managed beans, converters, utils, and etc) live. Note: include JAR, and EJB projects as dependencies here.
  4. Finally, your EAR projects, which is supposed to package all three modules above.
    • Your glassfish-resources.xml should be here (if you want to use application scoped resources).
    • In your EAR pom.xml, package the JAR project into a folder called "lib" or whatever name you specify in the <defaultLibBundledir/>.
    • Use option <unpack>true</unpack>.
    • List all three modules above as dependency
  5. You should be good to go

Tuesday, September 11, 2012

Installing Ubuntu 12.04 TLS on HP 530

Simply follow the tutorial from Ubuntu site

After my installation I encountered a few glitches and issues:

  1. Can't boot into Ubuntu, I have to have my USB plugged in and boot from it
  2. Unable to set up my wireless network, the wireless button on HP530 not working
  3. Unable to find my graphics driver
For issue 1:
sudo grub-install /dev/sda  

Then I modify the /boot/grub/menu.lst and change somewhere in the line "quiet splash" to "nomodeset" 

For issue 2:
sudo rfkill unblock all  

For issue 3:
Can anyone help? I can't seem to find the correct driver.