»
S
I
D
E
B
A
R
«
IntelliJ IDEA 9 released
Dec 9th, 2009 by evereq

Hi! It’s good news today for a lot of java, ruby and groovy developers – new version “Maia” (officially v9) was just released by JetBrains with a lot of new features (including faster environment, extensive Java 6 support, build-in Google App Engine and Grails projects support etc) – feel read full “What’s new” list.

There exists also not so good news – this time for PHP developers – support of PHP was removed from release of free (”community”) version of IDEA, so developers can stick with other completely free IDEs this time :( – for example NetBeans comes to my mind this time… as alternative… but after Oracle buy Sun, I not sure it is right choice… but this is “idea” for another post…)

Actually personally I don’t understand why “Community” version does not support PHP, Javascript, Python or Ruby as this languages are used by a lot (if not most) of “open source” developers that for some reasons does not feet into JetBrains licensing of commercial version of IntelliJ IDEA for open source projects. I think “vice versa” if compare to JetBrains – Commercial version must have extended support for Java development, while Community edition must support MORE other open source frameworks / languages, like Ruby, Python or PHP etc. Sure it’s only my “personal” opinion, but I think most of developers will agree with me – people that use IDEA for Java development (usually in enterprises) can (and will!) simply BUY commercial licenses, while a lot of potential IntelliJ users actually want to use it for small open source projects in non-Java languages stack and want to get IDE for FREE!

But totally – all new features show that JetBrains go in right direction – support for most “progressive” and “latest” technologies in IDEA (even if it is available only commercially ;-) )

Keep it going, JetBrains! ;-)

Evejob Sprint #1 Views, Templates, Controllers Part #1: About MVC (Model-View-Controller) and MVT (Model-View-Template)
Nov 23rd, 2009 by evereq

Because Evejob Project developed in few frameworks, we need to make clear “terminology” differences used by different frameworks as well as different strategies to develop MVC applications using such frameworks.
Let’s start from MVC frameworks:
1) ASP.NET MVC as we see from name is “Model-View-Controller” framework (powered by .NET framework), so use actually concepts of “Models”, “Views” and “Controllers”. “Views” and “Controllers” concepts defined by framework itself (i.e. you need to inherit controllers from System.Web.Mvc.Controller class and inherit views from System.Web.Mvc.ViewPage to use build-in view engine). It is also possible in ASP.NET MVC to attach third-party View Engine (just google and you will found at least few). But “Models” concept in ASP.NET MVC is true “concept” – you don’t need to inherit from some base class or implement some interface to made a models in ASP.NET MVC! Instead framework provide you will full flexibility to create your own domain model and select any persistent framework if you need to persist your model entities. You can use for example Entity Framework, Linq to SQL, any other ORM or even POCO to implement your models!
2) Ruby On Rails is true “Model-View-Controller” framework and more so it uses “convention over configuration” principle. This mean that you actually have already defined conventions where to put your model entities, where to put controllers and where to put views (templates) and how to implement them (from what class you need to inherit etc). Sure while it is still possible to made some changes and even use another ORMs etc, build-in (OK, read instead “installed by default with Rails”) ActiveRecord ORM is enough for most cases (OK, at least in most simple cases ;-) ). The same things with templates (views) – you can use build in template engines (provided by ActiveView module) or add your own – at the time I write this exists not less then 20! different third-party template engines in addition to build-in (sure you can always build your own if need and made 21-th)!
3) Grails is really “Model-View-Controller” framework, was build with same principles like RoR, but because Grails work on top of Spring and Hibernate, developers initially get BEST build-in enterprise infrastructure from Java world! And sure in Grails infrastructure was extended so much (thanks to power of Groovy), that it looks like it most powerful MVC framework to the moment (this is just my personal opinion – I don’t want to start a war here :D )!

So frameworks listed above all follow MVC terminology where you actually create your own Models (Domain Models possible with Persistence), implement Controller (with actions) and create presentation using Views (that is actually powered by some build-in or custom template engine).

One framework – Django – that we use for Evejob project made use of a little different terminology (instead of MVC): Model-View-Template.
Model term is used for same purposes like Model in MVC – it is simply domain model (provided usually by build-in to Django ORM, but also possible to use your own ORM… just note that it require little more “tuning / hacking” than in other frameworks).
View in Django play the same role as Controller in MVC.
And “Template” term in MVT actually used instead of “View” from MVC (while Template terms actually also used in MVC in sense that view CAN be represented as result of Template rendering)
What I found from my experience that this difference in terminology does NOT make any actually impact on development process!
More so, actually most MVCs that available in the market used mostly in “MTC” mode – i.e. “Model-Template-Controller”.
What does it means? It means that Controllers actually render Templates in MOST of the cases! Sure in case if you use MVC framework to build for example Web Services, you will probably not render any Templates and your controllers (controllers in MVC or your Views in MVT) actually more likely will return JSON or XML directly (OK… XML it is possible also to build using Templates sometimes – look how it is done in Grails for example! But let’s think here that we want to return raw XML from Controller without any template engine). Sometimes you also can return JavaScript or any other format etc directly from Views in MVT or from Controllers in MVC.
What is good in MVT is “order” of letters that give better understanding for developers that first time here about this pattern – “Model” <-> “View” <-> “Template”. This way logical flow going – i.e. views are in the “middle” of this logical flow! (using this principle it was better initially probably call MVC as MCV, i.e. “Model” <-> “Controller” <-> “View” :D , so “Controllers” become in the middle, center of logic). It related only to logical structure, because in MVC pattern, Model accessible (and used) actually in both Controller and View, same like in MVT both Views and Templates share same Model! You can read a short overview of MVC at Wikipedia article for example if want little more information)
But as I tell before – main thing is “understanding” how pattern works, not how we call it! And “idea” of implementation of this patter in Django and other frameworks is exactly same even so name is not!

Evejob Development Environment Installation Part #8: Configuring applications to work with MySQL
Nov 2nd, 2009 by evereq

Django

We will need to use MySQL for Python project for connection from Django Python code to MySQL database. Because I (and hope you also) use Windows 7 64 bit with Python 64 bit, needs to found and install 64 bit version of such library. On original project site, for some reason I could not found (at least in the moment when I write post), so I get it from different site:  http://www.codegood.com/download/3/. Just download and install it (it will automatically found your Python installation if you follow all steps that I write in previous posts).

Let’s configure now, EvejobDJ project to use MySQL database.

First, needs to create “EvejobDJ” database schema using one of the administration tools, for example, described in Part #7 – just create it visually or issue following SQL command:

CREATE DATABASE EvejobDJ;

Open “settings.py” file in root folder of EvejobDJ project inside IntelliJ IDEA IDE and change database engine parameters to following:

DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'evejobdj'         # Or path to database file if using sqlite3.
DATABASE_USER = 'root'                # Not used with sqlite3.
DATABASE_PASSWORD = ''             # Not used with sqlite3.
DATABASE_HOST = ''                     # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''                     # Set to empty string for default. Not used with sqlite3.

Now it is time to test connection and create default tables in database (for authentication, sessions etc):

cd C:\Evejob\EvejobDJ
python manage.py syncdb

Hopefully you will get something like this in response:

EvejobDJDatabaseCreate

As you see you will need to create default “superuser” (I just put “admin” as his username and “info at evejob.com” as his email) because Django authentication app enabled by default.

Now you can check in MySQL database administration tool that you really create tables (screenshot from free MySQL Administrator that you probably install with MySQL GUI Tools):

MySQLEvejobDJDatabaseJustCreated

Ruby On Rails

To use MySQL in Ruby On Rails (RoR) we need to install MySQL Adapter, for example:

ruby -S gem install mysql

But here we get into trouble – binaries of this gem (mysql) does not work correctly on Windows 64 bit and on project site there is no version for 64 bit OS…
While on some “Unix” OS it is possible to fix this issue (for example build gem from source…), on Windows it is simply not possible…
Ah, OK, OK… it is possible, but just too complex / time consuming – don’t want to spend time on this NOW and leave this time to focus on coding of Evejob… maybe somebody or author of gem will fix this issue later!

Note: other available adapters for MySQL from Ruby seems also have same problems… at least by now.

So let’s just temporary switch to PostgreSQL for Ruby on Rails version of Evejob.

To setup PostgreSQL for EvejobRoR development it takes just few minutes:

  • Download and install latest PostgreSQL from http://www.enterprisedb.com/products/pgdownload.do#windows. Installation is trivial same like for MySQL (sure same – configuration is NOT trivial for production usage!). Make sure that you remember password that you put for “postgres” login role (default database user name).
  • Create “EvejobRoR_development” database in PgAdmin (this app comes with PostgreSQL… very similar to MySQL Administrator) and select “postgres” role as owner for this database.
  • Open EvejobRoR project in IntelliJ IDEA and copy file “config\database.yml” to “config\database_mysql.yml” (we will need it again when fix issue with MySQL + Ruby)
  • Edit file “config\database.yml” and enter here following information (make sure you put your password instead of my fake “admin”):
    development:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: EvejobRoR_development
      pool: 5
      username: postgres
      password: admin
      host: localhost
     
    test:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: EvejobRoR_test
      pool: 5
      username: postgres
      password: admin
      host: localhost
     
    production:
      adapter: postgresql
      encoding: utf8
      reconnect: false
      database: EvejobRoR_production
      pool: 5
      username: postgres
      password:  admin
      host: localhost
  • Execute following commands:
    ruby -S gem install postgres-pr

    This will install PostgreSQL adapter for Ruby (gem “postgres-pr” works on Windows x64)

    Now you can try to execute database “migration” that will hopefully create some stuff in development database:

    cd c:\Evejob\EvejobRoR
    c:\ruby\bin\rake db:migrate

    It will be to simple if this will work for you from first attempt! On my machine, I was need to made small “hack” to made this work, i.e. to add following code into new_rails_defaults.rb file in “config\initializers” folder and run db:migrate again:

    def PGconn.quote_ident(name)
        %("#{name}")
    end

    (look for more info about this “hack” here)

If you complete everything, you can check that db:migrate actually create one table (”schema_migrations”) in your development database:

pgAdmin_Shema_migrations_table

Grails

Let’s configure last version of Evejob which going to use MySQL database – EvejobGoG.

First, needs to create “evejobGoG_development”, “evejobGoG_test” and “evejobGoG_production” empty databases. You can do this trivial task using MySQL Administrator GUI Tool for example.

Next step is to let know Grails how to connect to just created MySQL databases. Because Grails runs on Groovy and Groovy itself runs in JVM we can use MySQL Connector/J from MySQL site: http://dev.mysql.com/downloads/connector/j/

Download “zip” file, unpack it to temporary folder and copy mysql-connector-java-x.x.xx-bin.jar file to the C:\evejob\EvejobGoG\lib folder.

Now open EvejobGoG project in IntelliJ IDEA and found DataSource.groovy file located in “EvejobGoG\Grails-app\conf” folder. Let’s change some settings in this file:

dataSource {
	pooled = true
	driverClassName = "com.mysql.jdbc.Driver" //"org.hsqldb.jdbcDriver"
	username = "root"
	password = ""
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
	development {
		dataSource {
			dbCreate = "update" // one of 'create', 'create-drop','update'
			url = "jdbc:mysql://localhost/evejobGoG_development" // "jdbc:hsqldb:mem:devDB"
		}
	}
	test {
		dataSource {
			dbCreate = "update"
			url = "jdbc:mysql://localhost/evejobGoG_test" // "jdbc:hsqldb:mem:testDb"
		}
	}
	production {
		dataSource {
			dbCreate = "update"
			url = "jdbc:mysql://localhost/evejobGoG_production" // "jdbc:hsqldb:file:prodDb;shutdown=true"
		}
	}
}

Now Grails know how to connect to MySQL. Unfortunately, there is no build-in database migrations functionality in Grails framework yet, so our next step is to install some plug-ins that can help us to maintain database schema versions and migrations. While exists few of such plug-ins, I think most “featured” is LiquiBase (but also you can take a look into “Autobase” if you prefer to dial with DSL instead of XML… just take a note that this plugin works only with Grails, while LiquiBase can be used with Ant, Maven, Spring etc or even independently as database change management solution)

To install LiquiBase do following (you can read more regarding Grails integration with LiquidBase here):

cd C:\evejob\EvejobGoG
grails install-plugin liquibase

Now check that you have following folder (that is empty by now):

C:\evejob\EvejobGoG\grails-app\migrations

If you don’t have folder yet, just create it before continue with migrations – this folder will be used to save migrations change log etc..

Now it’s time to generate change log and migrate database (that is empty for now) to initial version:

grails generate-changelog grails-app\migrations\changelog.xml
grails migrate

After first command (”generate-changelog”) LiquiBase will create initial version of database change log and save it to the “C:\evejob\EvejobGoG\grails-app\migrations\changelog.xml” file. It will looks something like following:

Second command (”grails migrate”) will actually made migration in database. In our case because our domain is empty, LiquiBase will just create changes maintenance tables: “databasechangelog” and “databasechangeloglock”. You can check now this using MySQL Administrator:

LiquiBaseInitialTables

If all steps above completed successfully you finish setup EvejobGoG Grails project to use MySQL Database and have ability to migrate databases!

Evejob Development Environment Installation Part #2: IntelliJ IDEA and Plugins Installation
Oct 21st, 2009 by evereq

Let’s start with installation and configuration of the IntelliJ IDEA IDE for RoR / GoG / Django and Google App Engine development.

At the time I write this article, version 8 is available and version 9 (Maia) only at pre-release stages… So we start development in version 8 (but with really huge interest we will wait for version 9!). Also please note that community version of IDE is lack some important functions, so we going to use commercial version (30 day trial will be enough to start)

So go to http://www.jetbrains.com/idea/, download and start installation of Windows version of IntelliJ IDEA. During installation you need to select the plugins to enable. Made following selection (I am going to use Git and Subversion version controls systems in Evejob project)

SelectVCS

On next screen, when IDEA will ask you about Web/JavaEE plugins I recommend to leave all options selected (unless you know that you not going to use some of Java technologies in near future) dues to the fact that when we move to Grails development, some of this plug ins will be in used.

On “Select Application Server Plugins” I also recommend to leave all options, as probably we will want to test hosting of application on as much Web Servers as possible (unless you know specific server requirements) – it is exactly way I am going to develop Evejob!

Same way, I recommend to leave all HTML / JavaScript development Plugins and Other Plugins selected (unless you know for sure which one you going to use and which one not… seems effort to enable them later can be more then performance issues in case if you just leave everything enabled, at least on latest hardware).

In case if you have only one developer machine, on next screen with “IDEA Server Account details” you can just select “Do not login”, press “Skip”

DontLogin

and move forward to the end of installation.

Finish!

But wait – it’s not all – we need also to install plugins for RoR, Django and even Google AppEngine (Grails support build in to IntelliJ IDEA 8)…

Let’s start:
- go to File / Settings
- in Settings window found at left list box “Plugins” item and select it.

- open tab Available

- wait few seconds, until get a list of all available plugins in JetBrains database.

- in search box, start typing “Python”.

- select “Python” plugin in filtered list

- right click and press “Download and Install” link

IntelliJPythonPlugin

Plugin will be downloaded and installed for you (usually takes few minutes)!

Now it is time to install same way “Ruby” and “Google App Engine” plugins…

After you install all 3 plugins, press “Apply” button and answer “Yes” to the question about restart IDEA to activate changes in plugins.

That’s it with IntelliJ IDEA installation!

Evejob Development Environment Installation Part #4: Groovy, Grails + AppEngine Installation
Oct 18th, 2009 by evereq

Grails Installation

To install Grails follow steps:

1) Download and install JDK from http://java.sun.com/javase/downloads. Make sure that you use following version

Java SE Development Kit (JDK)

JDK 6 Update X

Note: You don’t need Bundles packages. Also make sure that you download Windows x64 version of JDK, like on screenshot bellow:

JDKDownload

Let’s assume that you download and install JDK to following default location: C:\Program Files\Java\jdk1.6.0_16

2) Download latest stable Grails Binary ZIP Release from http://www.grails.org/Download, for example: grails-bin-1.1.1.zip. We not going to install Grails from sources (build it) due to the fact that Grails support “grails update” command, which can update your Grails version to latest one.

3) Extract Grails archive to the following folder: C:\Grails

4) Create JAVA_HOME environment variable that points to the path where you have installed JDK and create a GRAILS_HOME environment variable that points to the C:\Grails folder:

JAVA_HOME_variable GRAILS_HOME_variable

Note, make sure you enter your system path to JDK and JDK version that you install before.

5) Append %GRAILS_HOME%\bin to the PATH variable:

GrailsPath

6) Check that Grails installed successfully - just type “Grails” in command prompt and check that you get a help message like:

GrailsWelcome

OK, installation of Grails finishes here, let’s move to the next task…

EvejobGoG and EvejobGoGG projects configuration

So let’s start to create EvejobGoG project that is build on  Grails and EvejobGoGG also build on Grails but specially adjusted to be hosted by Google App Engine.

First Start IntelliJ IDEA, open “Create New Project”, select “Grails Application” and enter project files location as “C:\evejob\EvejobGoG”:

EvejobGoGCreate

Press Next and on Grails SDK window, press “New” to add new one and in “Select Path” window select “C:\Grails” folder (where you install Grails before):

GrailsSDKSelectionInIDEA

You will get something like this (your version of Grails can be different):

GrailsSDKSelectionFinished

Press “Next” and on next window (Select the desired technologies) leave all options unselected. After you press “Finish” you will get new Grails project opened in IDEA (if during this phrase IDEA will ask you about some updates in Grails Tool Window, press “y” to do so):

GrailsEvejobGoGProjectInIDEA

Now you can repeat same steps to create EvejobGoGG project that will use Google App Engine.

But first let’s install Google App Engine SDK for Java.

Go to the http://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Java and download Zip file that contains SDK (usually file have name like “appengine-java-sdk-1.2.6.zip”). Than create folder C:\Google\google_appengine_java_sdk and unzip archive content to this folder. That’s it – Google App Engine Java SDK installed.

Let’s setup environment variable which is used by Grails plugin to locate App Engine Java SDK – APPENGINE_HOME (in our system we install it to C:\Google\google_appengine_java_sdk folder):

APPENGINE_HOME_variable

Let’s reload IDEA so environment changes takes effect (we will use APPENGINE_HOME variable in a second).

Now let’s continue with IDEA and setup EvejobGoGG project same way like we create and setup EvejobGoG (all step exactly same like above).

IntelliJ Idea provide great support of Grails development build-in. For example it is very simple to install Grails Plug-ins directly from IDE (make sure that you select EvejobGoGG project in IDEA window):

GrailsPluginsInIDEA

Ones you open Grails plugins window, probably you will need to press “Reload Grails Plugin” button, to get a full list of available plugins:

GrailsPluginsReload

Type “app” in search box and select “app-engine” plugin (”Grails AppEngine plugin”). Check check box “Enable” and press “Apply Changes”. Than select latest release version of the plugin, for example:

GrailsAppEnginePluginVersion

OK, let’s back to plugin installation – press “OK” on plugin installation window and in Grails window you will probably get question “Do you want to use JPA or JDO for persistence”. Let’s for now just answer “jpa” and finish plugin installation.

Finished… Ah, ups… Let’s just check that project structure is OK – go to “File / Project Structure” window:

ProjectStructureCheck

Sometimes (looks like due to some bug in IDEA currently???) you will not get Project SDK configured:

ProjectSDKNotConfigured

If you in this situation (hopefully not, but just in case), press “New” button,  select “JSDK” in drop down and browse to your JDK path:

JDKPath

After, press “Apply” and you will add JDK to EvejobGoGG project.

Do the same check (and probably fix) for EvejobGoG project.

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2008–2009 EvereQ.com All rights reserved.