Archive for the ‘Coding’ Category

Open Source E/R Modeling von Oracle

Tuesday, July 7th, 2009

Ich weiss nich ob’s an dem positiven Einfluss der neuen Tochter Sun liegt, oder sich generell bei Oracle der Comunity Gedanke (und der sicherlich damit verbundene Marketing-Faktor durch einen naheliegenden Image Gewinn) ein wenig mehr breit gemacht hat, aber auf jeden Fall kommt da imemr mehr aus der Ecke.
Neuester OSS-Spross ist der SQL Developer Data Modeler mit dem sich ER-Diagramme erstellen und nach SQL/DDL Code exportieren lassen. Das ganze funktioniert laut eigener Angabe (man höre und staune) selbst mit den Konkurenzprodukten von MS und IBM.
Auch wenn ich noch keinen Blick riskiert habe kann ich an der Stelle nur schonmal sagen: Weiter so!

UPDATE: Das ganze ist natürlich nich wirklich Open Source, sondern unter der OTN erschienen… aber immerhin ;)

UPDATE: Tja, zu früh gelobt. Der “Download” ist zwar kostenlos aber die Benutzung anscheinend nicht.

Rapid Application Development von Oracle

Wednesday, May 13th, 2009

Einer der Gründe warum ich Symfony so gerne mag und in meiner täglichen Arbeit des öfteren als Projektbasis einsetze ist die unglaubliche Geschwindigkeit, mit der sich neue, datenzentrierte Anwendungen erstellen lassen. DBDesigner öffnen, modellieren, XML exportieren, konvertieren, per Konsole Model-Klassen und CRUD-Module erstellen – fertig.
Oracle hat nun unter dem Titel APEX ein auf die hauseigenen Datenbanksysteme zugeschnittenes Tool veröffentlicht, dass diesen von mir gewohnten Ablauf sogar noch beschleunigen könnte. Die in der Selbstbeschreibung als “rapid web application development tool for the Oracle database” bezeichnete Anwendung kommt als browserbasiertes Tool daher, mit dem sich, laut Eigenaussage, auch ohne enorme Programmierkenntnisse datenzentrierte Anwendungen erstellen lassen. Das schöne daran: Durch die direkte Anbindung an die Datenbank fällt der komplette Teil des Modelings weg.
Ob und wie das in der Praxis funktioniert werd ich mir selber mal anschauen müssen. Der Artikel auf heise Developer zu dem Thema klingt allerdings bereits recht vielversprechend.

UPDATE: Für diejenigen (mich), die keine Lust haben für eine Evaluation extra Oracle + APEX auf einem Testsystem aufzusetzen bietet Oracle unter http://apex.oracle.com/i/index.html einen kostenlosen SaaS-Dienst an. Habe mich grad mal angemeldet, mal schauen wie scharf beim Approval kontrolliert wird…

Symfony ezComponents Integration

Monday, August 27th, 2007

As the documentation on how to integrate and use ezComponents in Symfony is quite meager here’s a small example on that. Exemplarily I picked the Graph component for the demonstration. Further documentaion on that can be found here.
Asuming there is an already configured symfony project with one or more application and modules the first thing to do after downloading ezComponents is to prepare symfony for the usage and copy the ezComponent classes into the project folder (they can also be referenced as explained in symfony book chapter 17 but copying the files has some advantages. E.g. you don’t have to change the application’s settings.yml when swapping from Win to Linux).
Configuration is quite easy. Just copy the base folder of the ezComponent you want to use into your symfony lib folder. In our case the folders “Base”, “autoload” and “Graph” are needed. Afterwards you just have to activate the built-in bridge class in symfony. So search for the line autoloading_functions: in your settings.yml, uncomment it and add the following line:
- [sfEzComponentsBridge, autoload]
The whole block should look like that afterwards:

.settings:
.
.
.
  autoloading_functions:
    - [sfEzComponentsBridge, autoload]

After doing this we can instance the ez classes like every other custom class from the lib folder. Let’s assume you have a shop and want to illustrate how many items of each product are sold per day. The following code snippets demonstrate how to generate a simple line chart showing the amount of sold products broken down by product category for each day of the year. Please ignore the absurdity or the performance issues of this approach as it shall only demonstrate how the data passed to the graph class has to be formatted ;)
This is the actions.class.php of the module:

public function executeIndex()
{
.
.
.
(the days array could be generated with PEAR::Date)
  foreach ($days as $day) {
    $product_1[$day]++;
    $product_2[$day]++;
    $c = new Criteria();
    $c->add(SalesPeer::DAY,$day);
    $sales = SalesPeer::doSelect($c);
    foreach ($sales as $sale) {
      if($sales->getProductId() == '1') {
      $product_1[$day]++;
    } elseif($sales->getProductId() == '2') {
      $product_2[$day]++;
    }
  }

This results in an array with the days of the year as indexes and the sale count as value. Now we just have to pass those arrays to the Graph component:

$data = array('Product 1' => $product_1,'Product 2' => $product_2);
//init graph
$graph = new ezcGraphLineChart();
//set title of the chart
$graph->title = 'Sales';
//tell class to generate a jpg instead of svg
$graph->driver = new ezcGraphGdDriver();
$graph->options->font = 'fonts/tutorial_font.ttf';
$graph->driver->options->supersampling = 1;
$graph->driver->options->jpegQuality = 100;
$graph->driver->options->imageFormat = IMG_JPEG;
//assign previously generated arrays to class
foreach ( $data as $item => $count ) {
$graph->data[$item] = new ezcGraphArrayDataSet( $count );
}
//render image
$graph->render( 500, 300, 'images/charts/sales_chart.jpg' );
}

The ezComponents automatically know about the application paths so if you don’t pass any dir names (like “images/charts/”) the output would be saved to the “web” folder (same for the ttf file for the jpg generation). So all you have to do to display the generated chart on a page is the call of the “image_tag” helper:

< ?php echo image_tag('charts/sales_chart.jpg'); ?>

As you can see, quite simple and very comfortable. Have fun with it!

Javascript based table sort

Tuesday, June 19th, 2007

Yesterday I searched for a simple way to sort data sets fetched from a DB by column without querying the DB anytime the sort order changes. A Google search came up with a very nice Javascript at http://www.frequency-decoder.com/. Very sweet, very fast even for large result sets and most important very easy to integrate into a running application.
Check out the demo here or read the whole article.

Zend Framework All-In-One Getting Started Package

Saturday, December 2nd, 2006

I started a new PHP project today and as everytime I was pissed that setting up a proper project structure always takes so much time. So I thought it might be useful for some of you if I present my result right here. The following zip file contains a, for my purposes quite suitable all-in-one out-of-the-box eclipse project for a Windows development environment. I basically went through some Zend Developerzone tutorials and put it alltogether.
Let’s start with the general configuration. The code base can be used on any Windows system with WAMP installed but to get things started even faster I recommend to install the following two software packages first:

  1. PHP IDE from Zend (which is basically Eclipse with some neat little plugins for PHP development)
  2. XAMPP as WAMP package.

The whole paths in my scripts are customized for this configuration so as I said, for quick quickstart get those two first. XAMPP isn’t shipped with mod_rewrite enabled, so the first thing to do is to adjust the httpd.conf in “XAMPP_HOME\apache\conf”.
Next thing to do is to remove all files and subfolders in “XAMPP_HOME\htdocs” and to extract the zip from this page into that folder.
Afterwards change DocumentRoot and attribute from “XAMPP_HOME/htdocs” to “XAMPP_HOME/htdocs/www” and (re)start the server.
The provided zip file comes with the following features:

  • Zend Framework 0.2.0
  • Smarty Template Engine 2.6.16
  • Propel 1.2.0
  • Creole 1.1.0 (needed for Propel)
  • Phing 2.2.0 (needed for Propel)

The directory structure explained in detail:

  • app – this is where all MVC classes should go. The “views” folder conatins a example.tpl.html which is just a standard Smarty template. I prefer to name my tpl files with .html ending as they can be opened more easy and are recognised as HTML by Eclipse.
  • bin – this folder just contains the batch file for model generation
  • build – this is where all propel related files should go to. The files from the archive are simply copy & pasted from this tutorial. Generation of the sample model from that tutorial should work out-of-the-box (as long as you changed the path variables the right way).
  • cfg – Here goes the config.ini file used by Zend_Config and the autogenerated propel-config.php
  • lib – self-explanatory I guess. Be sure to add the path to /www/.htaccess if you add new libs here.
  • www – this is the document root for the apache server. Only content (images, CSS, JS, etc.) needed by clients should go here as it’s public.

As a special feature there is a generate-model.bat which can be used to automatically start the phing build process for propel ORM generation.
To get started with this base project structure there are some config lines which have to be overviewed:

  1. “set XAMPP_HOME=c:\Programme\xampp” in “bin/generate-model.bat”
  2. “smarty.template_dir= C:\Programme\xampp\htdocs\app\views” in “cfg/config.ini”
  3. Paths and DB config in “build/build.properties”

Sorry for not giving more details on how to use the code base, but it’s late, I’m tired and everything one needs to know is written on Zend Developerzone… ;)
I’m planing to integrate the LiveUser package aswell the next days, maybe I’ll give you an update. Feel free to comment, ask questions or indicate errors…
Oh, almost forgot HERE is the zip.

Zend Framework in subdirs

Wednesday, October 18th, 2006

It took me some time to find this out so maybe it’s useful for you aswell…
I went through the very good tutorial written by Chris Shiflett concerning Zend Framework and was confontend with a little problem. Everything worked fine except the redirection by the Controller objects, I always was redirected to the noRouteAction. The problem is that I installed the application in a vhost subdirectory (http://devserver/subdir/) and it kept redirecting me to the server root. To “fix” this issue one have to make use of the Zend_Controller_RewriteRouter class. The following code snippet shows the usage:

< ?php
include 'Zend.php';

Zend::loadClass('Zend_Controller_Front');
Zend::loadClass('Zend_Controller_RewriteRouter');

$controller = Zend_Controller_Front::getInstance();
$controller->setControllerDirectory(
'/path/to/controller_classes');

Zend::register('controller', $controller);
$router = new Zend_Controller_RewriteRouter();
$controller->setRouter($router);
$controller->dispatch();

?>

Zend Framework

Wednesday, October 18th, 2006

I dealt with PHP first time since ages the last days and did some evaluation work on frameworks. The most promising candidate for future projects is the Zend Framework of which a first stable release is expected during the next weeks.
Most important feature is a MVC implementaion which looks quite similar to Struts. Other neat little features include PDF creation, XMLRPC support, RSS feed handling and many more. The most exciting thing with Zend Framework is the very flexible and “non-invasive” integration opportunity. All features are based on a “can do” basis and it seems to be very easy to integrate 3rd party modules. E.g. integration of Smarty tpl engine and Propel O/R mapping is done in no time (Howtos can be found here and here). I can’t wait for the stable release to come and I’ll definitely give it a try for some upcoming projects. Looks like this could become a Spring for PHP…

Integrate PostgreSQL Data Source in Websphere Application Server

Thursday, October 12th, 2006

A quite unusual configuration but this short guidance might be useful for some persons (like me):

  1. Open Integrated Solution Console
  2. Navigate to “Resources -> JDBC -> JDBC Providers”
  3. Select the right scope for your application
  4. Click “New”
  5. Select “User-defined” from “Database Type” dropdown
  6. Insert “org.postgresql.ds.PGConnectionPoolDataSource” at “Implementation class name” field
  7. Provide a name and a descriotion of your choice and click “next”
  8. If you haven’t done so before download the JDBC Driver from http://jdbc.postgresql.org/download.html which suits your needs (should be JDBC3 driver for your DB version) and save it at some local library path (e.g. {WAS_HOME}/lib)
  9. Insert the path and jar file name in the next dialog, click “next” and “finish” afterwards
  10. Navigate to “Resources -> JDBC -> Data sources”
  11. Again select the right scope and click “new”
  12. Provide a Data source and a jndi name (e.g. jdbc/myPGdb)
  13. On step 2 dialog select your already created JDBC provider
  14. Just leave step 3 at default values and finish creation, that’s it!

Tested on Websphere Application Server 6.1

J2EE Development with Rational Application Developer

Friday, September 29th, 2006

As I have to develop a serious application during my thesis first time ever with Rational Application Developer I was seraching for a good introduction on how to use this mighty tool. I found it, who yould have thought, in an IBM redbook. “Rational Application Developer V6 Programming Guide” is an awesome entrance into the RAD world. Abutted on the classical SUN J2EE tutorial this book describes in detail how to realise a sample banking application with RAD and Websphere Application Server. It covers the realisation of JSP and Servlet-, JSF and SDO-, even Struts based Dynamic Web Application and the integration of EJB Business logic using integrated UML- and other Data modelling tools.
A must read for any person who thinks Eclipse is too much code work ;)

Java Instant Messenger

Friday, May 19th, 2006

After some time here’s another code example. I had to write a Java based Instant Messenger for university. The code demonstrates the usage of object serialisation mechanisms in Java and sending streams via TCP and UDP. Features included are Unicast based chatting, Multicast based Chatting and File Transfer via TCP. As it’s just a proof of concept there might be some minur issues when running it and as there was a deadline there are some “unaesthetic” code parts (don’t look at the GUI part, I had to adapt that from my professor ;) ) but the main concepts should be pointed out quite ok. Especially the file transfer via TCP migth be interesting because most of the tutorials one can find just handle Strings or something else.
The complete eclispe project can be found here.