<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>treibsand.com &#187; Coding</title>
	<atom:link href="http://www.treibsand.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.treibsand.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 12:46:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Ruby Entwicklung mit RVM</title>
		<link>http://www.treibsand.com/2011/03/21/ruby-entwicklung-mit-rvm/</link>
		<comments>http://www.treibsand.com/2011/03/21/ruby-entwicklung-mit-rvm/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 12:23:31 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RVM]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=631</guid>
		<description><![CDATA[Die Entwicklung mit Ruby, vor allem mit Ruby on Rails, ist wirklich traumhaft. Webprojekte können mit Ruby on Rails relativ schnell umgesetzt werden. Das einzige was wirklich traurig ist, ist das Handling der benötigten Gems. Im Vergleich zu Python und Django werden sehr viele Gems benötigt. Das erinnert etwas an das grausame CPAN von Perl, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.treibsand.com/wp-content/uploads/2011/03/RubyLogo.png" rel="lightbox[631]"><img src="http://www.treibsand.com/wp-content/uploads/2011/03/RubyLogo.png" alt="" title="RubyLogo" width="145" height="163" class="alignleft size-full wp-image-632" /></a> Die Entwicklung mit Ruby, vor allem mit Ruby on Rails, ist wirklich traumhaft. Webprojekte können mit Ruby on Rails relativ schnell umgesetzt werden. Das einzige was wirklich traurig ist, ist das Handling der benötigten Gems. Im Vergleich zu Python und Django werden sehr viele Gems benötigt. Das erinnert etwas an das grausame CPAN von Perl, wo einige Perl Module eine Unzahl von Abhängigkeiten haben, so dass schnell 100 Module installiert sind.</p>
<p>Ein ähnliches Problem kann mit Ruby aufkommen. Sobald sich mehrere Projekte angehäuft haben, werden u.U. verschiede Ruby bzw. Rails Versionen, wenn nicht sogar jRuby benötigt. Sind alle Gems direkt im System installiert, kann das ganze schon ziemlich unübersichtlich werden. </p>
<p>Genau dieses Problem löst <a href="http://rvm.beginrescueend.com/">RVM</a>, hierbei handelt es sich um ein Tool, mit welchem sich unterschiedliche Ruby Versionen bzw. Gems verwalten lassen. Alles wird hier direkt in das Home Verzeichnis des Benutzers installiert. Sobald RVM in die lokale .bashrc eingebunden ist, kann per Kommando die Ruby Installation gewechselt werden. </p>
<p><span id="more-631"></span></p>
<p>Die Installation von RVM ist mehr als einfach. Sofern Git installiert ist, kann direkt die letzte Version aus Git installiert werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-head <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Eine Installation über Tarball ist auch möglich:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-latest <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Für die dauerhafte Aktivierung von RVM, muss die lokale <em>.bashrc</em> bzw. <em>.profile</em> Datei angepasst werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.rvm/scripts/rvm&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> . <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/.rvm/scripts/rvm&quot;</span>  <span style="color: #666666; font-style: italic;"># This loads RVM into a shell session.</span></pre></div></div>

<p>Mit dem Kommando</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm</pre></div></div>

<p>kann die RVM Installtion initial eingelesen werden, ohne dass ein neuer Login notwendig ist. Jetzt sollte das Kommando</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">type</span> rvm <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-1</span></pre></div></div>

<p>die Ausgabe</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm is a <span style="color: #000000; font-weight: bold;">function</span></pre></div></div>

<p>bringen. Dann ist RVM volständig installiert.</p>
<p>Als nächstes brauchen wir eine Ruby Installation. Um zu sehen, welche alle verfügbar sind, reicht das Kommando</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rvm list known</pre></div></div>

<p>Wenn wir z.B. Ruby 1.8.7 installieren wollen, können wir das wie folgt machen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rvm  <span style="color: #c20cb9; font-weight: bold;">install</span> ruby-1.8.7
Installing Ruby from <span style="color: #7a0874; font-weight: bold;">source</span> to: ...
&nbsp;
$ ruby <span style="color: #660033;">-v</span>
ruby 1.8.7 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2011</span>-02-<span style="color: #000000;">18</span> patchlevel <span style="color: #000000;">334</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin10.6.0<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Damit unser Environment auch das neu installierte Ruby benutzt, und nicht u.U. ein im System installiertes, können wir mit RVM die Ruby Installation wechseln</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rvm  ruby-1.8.7
Switching to ruby 1.8.7 <span style="color: #000000;">334</span> ...</pre></div></div>

<p>Auch das Kommando <em>gem</em> wird jetzt aus der RVM Installation verwendet, sodass alle Gems in das Home Verzeichnis installiert werden.</p>
<p>Nun zu der wirklich interessanten Funktion von RVM, den Gemsets. Nehmen wir an, es gibt ein Verzeichnis <em>projects</em>, in welchem ein Rails 2 Projekt (<em>project_a</em>) ist und ein Rails 3 Projekt (<em>project_b</em>). Um für <em>project_a</em> nun die Entwicklungsumgebung zu installieren, legen wir hierfür direkt im Projektverzeichnis eine <em>.rvmrc</em> an.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'rvm 1.8.7@rails2 --create'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> .rvmrc</pre></div></div>

<p>Durch den Inhalt der <em>.rvmrc</em> weiss nun RVM, dass es, sobald man in dieses Verzeichnis wechselt, Ruby 1.8.7 mit dem Gemset <em>rails2</em> verwenden soll. Noch haben wir allerdings keine Gems in dem Gemset. Um zum Gemset zu wechseln reicht</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rvm 1.8.7<span style="color: #000000; font-weight: bold;">@</span>rails2</pre></div></div>

<p>und Rails 2.3.8 kann einfach mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails <span style="color: #660033;">-v</span> 2.3.8</pre></div></div>

<p>instaliert werden.</p>
<p>Für unser Rails 3 Projekt machen wir das gleiche</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'rvm 1.8.7@rails2 --create'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> .rvmrc
$ rvm 1.8.7<span style="color: #000000; font-weight: bold;">@</span>rails3
$ gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</pre></div></div>

<p>Für unsere Projekte sind nun verschiedene Rails Versionen hinterlegt und man muss nur in das entsprechende Projekt Verzeichnis wechseln, damit die korrekte Version für das Projekt verwendet wird <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2011/03/21/ruby-entwicklung-mit-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>has_many :through mit Checkboxen</title>
		<link>http://www.treibsand.com/2010/11/03/has_many-through-mit-checkboxen/</link>
		<comments>http://www.treibsand.com/2010/11/03/has_many-through-mit-checkboxen/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 16:04:34 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=543</guid>
		<description><![CDATA[Nehmen wir an, wir haben eine Rails Applikation mit einer Many-to-Many Beziehung, bei welcher die Verknüpfungen über Checkboxen und nicht über Multiselect Listen oder ähnliches verwirklicht werden sollen. Die Umsetzung ist gar nicht mal so aufwändig&#8230;;-) Als Beispiel könnte man die Bestellung einer Pizza nehmen. Ein Kunde will eine Pizza über ein Formular bestellen. Im [...]]]></description>
			<content:encoded><![CDATA[<p><img class="linked-to-original" src="http://www.treibsand.com/wp-content/uploads/2010/06/rails-thumb.png" height="111" align="right" width="87" style=" display: inline; float: left; margin: 0 10px 10px 0;" />Nehmen wir an, wir haben eine Rails Applikation mit einer Many-to-Many Beziehung, bei welcher die Verknüpfungen über Checkboxen und nicht über Multiselect Listen oder ähnliches verwirklicht werden sollen. Die Umsetzung ist gar nicht mal so aufwändig&#8230;;-)</p>
<p>Als Beispiel könnte man die Bestellung einer Pizza nehmen. Ein Kunde will eine Pizza über ein Formular bestellen. Im Formular werden alle verfügbaren Beläge in einer Liste mit jeweils eine Checkbox dargestellt, so dass der Kunde einfach per Klick auf die Checkboxen die gewünschte Kombination auswählen kann.</p>
<p><span id="more-543"></span></p>
<p>Die Models würden dann wie folgt aussehen:</p>
<p><strong>app/models/pizza.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Pizza <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>, <span style="color:#ff3333; font-weight:bold;">:dependent</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:destroy</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:toppings</span>, <span style="color:#ff3333; font-weight:bold;">:through</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>app/models/topping.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Topping <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>, <span style="color:#ff3333; font-weight:bold;">:dependent</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:destroy</span> 
  has_many <span style="color:#ff3333; font-weight:bold;">:pizzas</span>, <span style="color:#ff3333; font-weight:bold;">:trhough</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:pizza_toppings</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>app/models/pizza_topping.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PizzaTopping <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:Topping</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:Pizza</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Nachdem die Beziehungen definiert sind können wir ohnen großen Aufwand die Beläge den Pizzen zuordnen:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> form_for <span style="color:#0066ff; font-weight:bold;">@pizza</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span> Topping.<span style="color:#9900CC;">all</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>topping<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    &lt;div&gt;
      <span style="color:#006600; font-weight:bold;">&lt;%</span>= check_box_tag <span style="color:#ff3333; font-weight:bold;">:topping_ids</span>, topping.<span style="color:#9900CC;">id</span>, <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'pizza[topping_ids][]'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
      <span style="color:#006600; font-weight:bold;">&lt;%</span>= label_tag <span style="color:#ff3333; font-weight:bold;">:topping_ids</span>, topping.<span style="color:#9900CC;">name</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    &lt;/div&gt;
  <span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= submit_tag <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Wenn das Formular abgeschickt wird, dann wird jeder ausgewählter Belag durch PizzaToppings mit der Pizza verknüpft. Sobald allerdings in einem gespeicherten Datensatz einmal alle Checkboxen abgewählt werden, dann wird das nicht an den Controller geposted. Dies kann man aber leicht im Controller fixen:</p>
<p><strong>app/controllers/pizza_controller.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@pizza</span>.<span style="color:#9900CC;">attributes</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">'topping_ids'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:pizza</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/11/03/has_many-through-mit-checkboxen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kleine C-Übung</title>
		<link>http://www.treibsand.com/2010/07/02/kleine-c-ubung/</link>
		<comments>http://www.treibsand.com/2010/07/02/kleine-c-ubung/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 08:50:06 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=520</guid>
		<description><![CDATA[Heute hat mir ein Kollege einen kleinen C Quelltext geschickt und mich gebeten, das Ergebnis mal nachzuvollziehen, ohne dabei das Programm zu kompilieren. Ich muss sagen, beim ersten Anlauf hatte ich nicht alle Werte der Variablen richtig. Es gibt doch einige Fallstricke Aber versucht es mal selber! Was kommt raus? Und bitte nicht kompilieren&#8230; #include [...]]]></description>
			<content:encoded><![CDATA[<p>Heute hat mir ein Kollege einen kleinen C Quelltext geschickt und mich gebeten, das Ergebnis mal nachzuvollziehen, ohne dabei das Programm zu kompilieren. Ich muss sagen, beim ersten Anlauf hatte ich nicht alle Werte der Variablen richtig. Es gibt doch einige Fallstricke <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span id="more-520"></span></p>
<p>Aber versucht es mal selber! Was kommt raus? Und bitte <b>nicht</b> kompilieren&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> func <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> c <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> a <span style="color: #339933;">+</span> b <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>c <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> a <span style="color: #339933;">=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">,</span> b <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> c <span style="color: #339933;">=</span> func<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	a <span style="color: #339933;">*=</span> a<span style="color: #339933;">++;</span>
	b <span style="color: #339933;">*=</span> <span style="color: #339933;">++</span>b<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d %d %d %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> func<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/07/02/kleine-c-ubung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Konfigurationsdatei für Rails Anwendungen</title>
		<link>http://www.treibsand.com/2010/06/17/konfigurationsdatei-fur-rails-anwendungen/</link>
		<comments>http://www.treibsand.com/2010/06/17/konfigurationsdatei-fur-rails-anwendungen/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 11:49:14 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/2010/06/17/konfigurationsdatei-fur-rails-anwendungen/</guid>
		<description><![CDATA[Oft kommt es vor, dass man für eine Rails Anwendung neben der Datenbank noch eine benutzerdefinierte Konfigurationsdatei braucht. Allerdings ist es auch nicht wirklich lesbar bzw. schön alles in die environment.rb zu schreiben. Als gute Lösung, ohne zusätzliches Plugin könnte man eine eigene config.yml im config Ordner erstellen defaults: &#38;defaults webservice_url: http://my.webservi.ce/rpc &#160; development: &#60;&#60;: [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.treibsand.com/wp-content/uploads/2010/06/rails-full.png" class="image-link" rel="lightbox[513]"><img class="linked-to-original" src="http://www.treibsand.com/wp-content/uploads/2010/06/rails-thumb.png" height="111" align="right" width="87" style=" display: inline; float: left; margin: 0 10px 10px 0;" /></a>Oft kommt es vor, dass man für eine Rails Anwendung neben der Datenbank noch eine benutzerdefinierte Konfigurationsdatei braucht. Allerdings ist es auch nicht wirklich lesbar bzw. schön alles in die <strong>environment.rb</strong> zu schreiben.</p>
<p><span id="more-513"></span></p>
<p>Als gute Lösung, ohne zusätzliches Plugin könnte man eine eigene <strong>config.yml</strong> im <strong>config</strong> Ordner erstellen</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">defaults: <span style="color:#006600; font-weight:bold;">&amp;</span>defaults
  webservice_url: http:<span style="color:#006600; font-weight:bold;">//</span>my.<span style="color:#9900CC;">webservi</span>.<span style="color:#9900CC;">ce</span><span style="color:#006600; font-weight:bold;">/</span>rpc
&nbsp;
development:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>defaults
&nbsp;
test:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>defaults
&nbsp;
production:
  <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>: <span style="color:#006600; font-weight:bold;">*</span>defaults</pre></div></div>

<p>Die Datei muss dann nur noch geladen werden. Dies kann man in <strong>config/</strong><strong>initializers </strong> mit einem eigenen initializer machen</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">APP_CONFIG = <span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#9900CC;">load_file</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/config/config.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ENV<span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Danach können die eingestellten Werte in der Rails Applikation einfach mit</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">webservice_url = APP_CONFIG<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'webservice_url'</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>abgefragt werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/06/17/konfigurationsdatei-fur-rails-anwendungen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveLdap sucht subschemaSubentry</title>
		<link>http://www.treibsand.com/2010/06/16/activeldap-sucht-subschemasubentry/</link>
		<comments>http://www.treibsand.com/2010/06/16/activeldap-sucht-subschemasubentry/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 12:13:21 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=488</guid>
		<description><![CDATA[Heute bin ich über ein interessantes Problem mit OpenLDAP und ActiveLdap für Ruby gestolpert. ActiveLdap wollte mir einfach keine Ergebnisse liefern, obwohl die Abfragen gestimmt haben&#8230; Es kam immer zu folgendem Fehler&#8230; ActiveLdap::LdapError::NoSuchObject&#40;No such object&#41;: filter &#40;objectClass=subschema&#41;: attributes: &#91;&#34;objectClasses&#34;, &#34;attributeTypes&#34;, &#34;matchingRules&#34;, &#34;matchingRuleUse&#34;, &#34;dITStructureRules&#34;, &#34;dITContentRules&#34;, &#34;nameForms&#34;, &#34;ldapSyntaxes&#34;&#93; ActiveLdap hat eine zusätzliche Abfrage gemacht, und sich immer [...]]]></description>
			<content:encoded><![CDATA[<p>Heute bin ich über ein interessantes Problem mit OpenLDAP und ActiveLdap für Ruby gestolpert. ActiveLdap wollte mir einfach keine Ergebnisse liefern, obwohl die Abfragen gestimmt haben&#8230;</p>
<p><span id="more-488"></span></p>
<p>Es kam immer zu folgendem Fehler&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActiveLdap::LdapError::NoSuchObject</span><span style="color:#006600; font-weight:bold;">&#40;</span>No such object<span style="color:#006600; font-weight:bold;">&#41;</span>: filter 
<span style="color:#006600; font-weight:bold;">&#40;</span>objectClass=subschema<span style="color:#006600; font-weight:bold;">&#41;</span>: attributes: <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;objectClasses&quot;</span>, <span style="color:#996600;">&quot;attributeTypes&quot;</span>, <span style="color:#996600;">&quot;matchingRules&quot;</span>,
<span style="color:#996600;">&quot;matchingRuleUse&quot;</span>, <span style="color:#996600;">&quot;dITStructureRules&quot;</span>, <span style="color:#996600;">&quot;dITContentRules&quot;</span>, <span style="color:#996600;">&quot;nameForms&quot;</span>,
<span style="color:#996600;">&quot;ldapSyntaxes&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>ActiveLdap hat eine zusätzliche Abfrage gemacht, und sich immer als anonymous beim LDAP Server angemeldet. Sobald man sehr restriktive ACLs auf dem LDAP Server hat, begegnet man diesem Problem sehr früh. Sobald also die ACL keine anonymen Verbindungen zulässt fliegt ActiveLdap auf die Nase.</p>
<p>Wenn folgende ACLs eingetragen werden</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">access to dn.base=<span style="color: #ff0000;">&quot;&quot;</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span>
access to dn.base=<span style="color: #ff0000;">&quot;cn=Subschema&quot;</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span></pre></div></div>

<p>dann funktioniert es auch&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/06/16/activeldap-sucht-subschemasubentry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails mit existierender Datenbank verwenden</title>
		<link>http://www.treibsand.com/2010/06/16/rails-mit-existierender-datenbank-verwenden/</link>
		<comments>http://www.treibsand.com/2010/06/16/rails-mit-existierender-datenbank-verwenden/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 12:11:17 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=497</guid>
		<description><![CDATA[Man stelle sich mal vor, man muss eine Rails Anwendung anhand einer vorhandenen Datenbank mit ca. 100 Tabellen erstellen. Das könnte ganz schön aufwendig werden, für jede Tabelle ein Model zu erstellen. Aber zum Glück gibt es mit Rails auch eine einfachere Methode&#8230; Mit dem Gem magic\_model\_generator ist das überhaupt kein Problem. Zuerst müssen wir [...]]]></description>
			<content:encoded><![CDATA[<p>Man stelle sich mal vor, man muss eine Rails Anwendung anhand einer vorhandenen Datenbank mit ca. 100 Tabellen erstellen. Das könnte ganz schön aufwendig werden, für jede Tabelle ein Model zu erstellen. Aber zum Glück gibt es mit Rails auch eine einfachere Methode&#8230;</p>
<p><span id="more-497"></span></p>
<p>Mit dem Gem <b>magic\_model\_generator</b> ist das überhaupt kein Problem. Zuerst müssen wir uns erst mal das Gem installieren:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> magic_model_generator</pre></div></div>

<p>Als nächstes sollte die Datenbank Konfiguration der Rails Anwendung auf die bestehende Datenbank geändert werden. Danach brauchen wir noch eine aktuelle<br />
<b>schema.rb</b> Datei. Diese kann mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rake db:schema:dump</pre></div></div>

<p>schnell erzeugt werden. Und am Ende können die Models mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>script<span style="color: #000000; font-weight: bold;">/</span>generate magic_model</pre></div></div>

<p>generiert werden. Momentan ist es aber leider noch nicht möglich, bereits vorhandene Models zu mergen, diese können nur überschrieben bzw. ignoriert werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2010/06/16/rails-mit-existierender-datenbank-verwenden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse Anwendungen als Windows Service</title>
		<link>http://www.treibsand.com/2009/06/29/eclipse-anwendungen-als-windows-service/</link>
		<comments>http://www.treibsand.com/2009/06/29/eclipse-anwendungen-als-windows-service/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 10:43:09 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[RCP]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=349</guid>
		<description><![CDATA[RCP Anwendungen mit Eclipse bauen ist schön und gut. Manchmal braucht man aber wirklich einen Windows Service, da die Anwendung z.B. immer laufen muss und nur einen TrayIcon hat. Das ganze Unterfangen schien auf den ersten Blick gar nicht einfach. Zumal ich von Windows Interna, wie z.B. den Services keine Ahnung habe, da ich eigentlich [...]]]></description>
			<content:encoded><![CDATA[<p>RCP Anwendungen mit Eclipse bauen ist schön und gut. Manchmal braucht man aber wirklich einen Windows Service, da die Anwendung z.B. immer laufen muss und nur einen TrayIcon hat. Das ganze Unterfangen schien auf den ersten Blick gar nicht einfach. Zumal ich von Windows Interna, wie z.B. den Services keine Ahnung habe, da ich eigentlich aus der Unix Welt komme.<br />
<span id="more-349"></span><br />
Zum Glück habe ich ein Projekt, den <a href="http://wrapper.tanukisoftware.org/">Java Service Wrapper</a>, gefunden, mit welchem es trivial ist, eine vorhandene Java Anwendung als Service laufen zu lassen.</p>
<p>Die Konfiguration es relativ einfach, es muss nur eine Konfigurationsdatei angelegt werden und einige Bibliotheken bzw. Batch Dateien kopiert werden. Nach dem das ganze RCP Produkt exportiert wurde, müssen folgende Dateien aus der Wrapper Distribution kopiert werden.</p>
<p>* wrapper.dll und wrapper.jar, einfach in das Unterverzeichnis lib (muss neu angelegt werden) kopieren.</p>
<p>* wrapper.exe und die 2 Install- bzw. Uninstal Batch Skripte in den Hauptordner legen.</p>
<p>* wrapper.conf habe ich in den configuration Ordner gelegt.</p>
<p>Nachdem alle Dateien in dem entsprechendem Ort liegen, muss die Datei wrapper.conf angepasst werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">wrapper.java.command=java
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
&nbsp;
<span style="color: #666666; font-style: italic;"># Java Classpath (include wrapper.jar)  Add class path elements as</span>
<span style="color: #666666; font-style: italic;">#  needed starting from 1</span>
wrapper.java.classpath.1=lib<span style="color: #000000; font-weight: bold;">/</span>wrapper.jar
wrapper.java.classpath.2=plugins<span style="color: #000000; font-weight: bold;">/</span>org.eclipse.equinox.launcher_1.0.101.R34x_v20081125.jar
<span style="color: #666666; font-style: italic;"># Java Library Path (location of Wrapper.DLL or libwrapper.so)</span>
wrapper.java.library.path.1=lib
&nbsp;
wrapper.java.additional.1=
wrapper.app.parameter.1=org.eclipse.equinox.launcher.Main
wrapper.console.format=PM
wrapper.console.loglevel=INFO
wrapper.logfile=wrapper.log
wrapper.logfile.format=LPTM
wrapper.logfile.loglevel=INFO
wrapper.logfile.maxsize=<span style="color: #000000;">0</span>
wrapper.logfile.maxfiles=<span style="color: #000000;">0</span>
wrapper.syslog.loglevel=NONE
&nbsp;
wrapper.console.title=Meine Eclipse Anwendungen
&nbsp;
wrapper.ntservice.name=EclipseAnwendung
wrapper.ntservice.displayname=EclipseAnwendung
wrapper.ntservice.description=Test Eclipse Anwendung
wrapper.ntservice.dependency.1=
wrapper.ntservice.starttype=AUTO_START
wrapper.ntservice.interactive=<span style="color: #c20cb9; font-weight: bold;">true</span></pre></div></div>

<p>In der Konfiguration wird angegeben, dass die DLL und JAR Dateien in dem Unterordner lib befinden. Da es sich hierbei im eine Eclipse Anwendung handelt muss im Classpath org.eclipse.equinox.launcher eingetragen sein. Der wrapper.app.parameter.1 muss für Eclipse 3.4 auf org.eclipse.equinox.launcher.Main gesetzt werden. Sobald die Anwendung auf den Desktop zugreifen muss, um z.B. Fenster darzustellen, muss die Option wrapper.ntservice.interactive auf true gesetzt werden.</p>
<p>Der Wrapper erwartet eigentlich, dass die Konfiguration an einem anderen Ort liegt, als im Ordner coniguration, aber warum sollte man dafür einen neuen Ordner anlegen? Damit da wieder alles passt, müssen noch kurz die 2 Batch Skripte angepasst werden. In beiden Dateien wird der Pfad zur wrapper.conf gesetzt, dies muss wie folgt abgeändert werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">_WRAPPER_CONF</span>=<span style="color: #ff0000;">&quot;%_REALPATH%/configuration/wrapper.conf&quot;</span></pre></div></div>

<p>Sobald das alles erlegt ist, reicht ein Doppelklick auf das Install Batch Skript, und der Service wird eingetragen <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2009/06/29/eclipse-anwendungen-als-windows-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ärger mit Generic Views von Django</title>
		<link>http://www.treibsand.com/2009/03/09/arger-mit-generic-views-von-django/</link>
		<comments>http://www.treibsand.com/2009/03/09/arger-mit-generic-views-von-django/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 10:16:12 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Generic Views]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=285</guid>
		<description><![CDATA[Django ist ja eines der besten Frameworks für Python um schnell Webanwendungen zu realisieren. Allerdings ist es leider noch nicht so ausgereift wie z.B. Ruby on Rails. Die Generic Views von Django sind zwar sehr hilfreich, allerdings nicht ganz konsequent umgesetzt. So gibt es bei den Views create\_object, update\_object und delete\_object die Möglichkeit login\_required zu [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.djangoproject.com">Django</a> ist ja eines der besten Frameworks für Python um schnell Webanwendungen zu realisieren. Allerdings ist es leider noch nicht so ausgereift wie z.B. Ruby on Rails. Die Generic Views von Django sind zwar sehr hilfreich, allerdings nicht ganz konsequent umgesetzt.</p>
<p><span id="more-285"></span><br />
So gibt es bei den Views <b>create\_object</b>, <b>update\_object</b> und <b>delete\_object</b> die Möglichkeit <b>login\_required</b> zu übergeben, aber bei anderen Views wie z.B. <b>direct\_to\_template</b> nicht. Das ist ziemlich ärgerlich, da es hier genauso Sinn machen würde.</p>
<p>Allerdings gibt es einen kleinen Workaround&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">decorators</span> <span style="color: #ff7700;font-weight:bold;">import</span> login_required 
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">views</span>.<span style="color: black;">generic</span>.<span style="color: black;">simple</span> <span style="color: #ff7700;font-weight:bold;">import</span> direct_to_template
&nbsp;
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
	<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^meineurl/$'</span>,login_required<span style="color: black;">&#40;</span>direct_to_template<span style="color: black;">&#41;</span>,
		<span style="color: black;">&#123;</span><span style="color: #483d8b;">'template'</span>:<span style="color: #483d8b;">'welcome.html'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>,
...</pre></div></div>

<p>Dadurch erhält man das gleiche Ergebnis, wie wenn man <b>login\_required</b> als Argument dem View übergibt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2009/03/09/arger-mit-generic-views-von-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RCP Anwendungen aktualisieren</title>
		<link>http://www.treibsand.com/2009/02/02/rcp-anwendungen-aktualisieren/</link>
		<comments>http://www.treibsand.com/2009/02/02/rcp-anwendungen-aktualisieren/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 10:50:57 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[RCP]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=243</guid>
		<description><![CDATA[Immer wieder ärger ich mich über Eclipse RCP, dass so wenig dokumentiert ist. Es ist wirklich schwer für dieses Thema vernünftige Dokumentationen zu bekommen. Auch die am Markt erhältlichen Bücher lassen zu Wünschen übrig. Ich hab vor kurzem sehr lange nach einer Dokumentation gesucht, um RCP Anwendungen über eine Update-Site zu aktualisieren. Vorab, das Buch [...]]]></description>
			<content:encoded><![CDATA[<p>Immer wieder ärger ich mich über Eclipse RCP, dass so wenig dokumentiert ist. Es ist<br />
wirklich schwer für dieses Thema vernünftige Dokumentationen zu bekommen. Auch die<br />
am Markt erhältlichen Bücher lassen zu Wünschen übrig. Ich hab vor kurzem sehr lange<br />
nach einer Dokumentation gesucht, um RCP Anwendungen über eine Update-Site<br />
zu aktualisieren. </p>
<p><span id="more-243"></span></p>
<p>Vorab, das Buch &#8220;Rich-Client Entwicklung mit Eclipse 3.3&#8243; von Berthold Daum ist riesiger<br />
Mist und keinen Cent Wert. Der dort beschrieben Weg, um Anwendungen zu aktualisieren<br />
funktioniert nicht und ist nur sehr oberflächlich beschrieben.</p>
<p>Nachdem ich gesehen habe, dass Eclipse 3.4 einen neuen Update Mechanismus verwendet, p2,<br />
dachte ich mir, dann bauen wir den gleich ein. Aber auch hier ist wieder kaum eine<br />
anständige Dokumentation zu finden. Ok, die Plug-Ins lassen sich ja problemlos einbinden,<br />
allerdings muss die Anwendung noch in einen p2-Anwendungen umgewandelt werden, was irgendwie<br />
nicht funktioniert hat und ich entnervt aufgegeben habe&#8230;ich hab ja auch nicht ewig Zeit<br />
forensisch herauszufinden wie etwas funktioniert. Wenn mir jemand evtl. einen Hinweis<br />
geben kann, wie dass alles stressfrei funktioniert bin ich dankbar <img src='http://www.treibsand.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Am Ende habe ich doch den &#8220;alten&#8221; Update-Manager verwendet. Herausgekommen ist folgende<br />
Klasse. Möge sie anderen genervten Entwicklern helfen&#8230;;-)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">foo.bar</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.InvocationTargetException</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.MalformedURLException</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Iterator</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.runtime.CoreException</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.runtime.IProgressMonitor</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.core.runtime.NullProgressMonitor</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.action.IAction</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.jface.viewers.ISelection</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.SWT</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Display</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.swt.widgets.Shell</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.ui.IWorkbenchWindow</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.ui.IWorkbenchWindowActionDelegate</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.configuration.IConfiguredSite</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.configuration.ILocalSite</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.core.IFeature</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.core.IFeatureReference</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.core.ISite</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.core.SiteManager</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.core.VersionedIdentifier</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.operations.IInstallFeatureOperation</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.operations.IUnconfigFeatureOperation</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.operations.IUninstallFeatureOperation</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.eclipse.update.operations.OperationsManager</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UpdateAction <span style="color: #000000; font-weight: bold;">implements</span> IWorkbenchWindowActionDelegate <span style="color: #009900;">&#123;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Shell shell<span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> Display display<span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> IWorkbenchWindow window<span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> restart<span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> dispose<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			shell.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			display.<span style="color: #006633;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>IWorkbenchWindow window<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">window</span> <span style="color: #339933;">=</span> window<span style="color: #339933;">;</span> 
		shell <span style="color: #339933;">=</span> window.<span style="color: #006633;">getShell</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		display <span style="color: #339933;">=</span> shell.<span style="color: #006633;">getDisplay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span>IAction action<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>shell <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			display <span style="color: #339933;">=</span> Display.<span style="color: #006633;">getCurrent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			shell <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Shell<span style="color: #009900;">&#40;</span>display, SWT.<span style="color: #006633;">NONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> 
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Update running...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			IProgressMonitor monitor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NullProgressMonitor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
			ISite rs <span style="color: #339933;">=</span> SiteManager.<span style="color: #006633;">getSite</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span> 
				<span style="color: #0000ff;">&quot;http://localhost:8080/update&quot;</span><span style="color: #009900;">&#41;</span>, monitor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			IFeatureReference<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> frs <span style="color: #339933;">=</span> rs.<span style="color: #006633;">getFeatureReferences</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			ILocalSite ls <span style="color: #339933;">=</span> SiteManager.<span style="color: #006633;">getLocalSite</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			IConfiguredSite ics <span style="color: #339933;">=</span> ls.<span style="color: #006633;">getCurrentConfiguration</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
				.<span style="color: #006633;">getConfiguredSites</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
			IFeatureReference<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> lfrs <span style="color: #339933;">=</span> ics.<span style="color: #006633;">getConfiguredFeatures</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			List<span style="color: #339933;">&lt;</span>IInstallFeatureOperation<span style="color: #339933;">&gt;</span> installOps <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>IInstallFeatureOperation<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Method initialized, ServerCount: &quot;</span> <span style="color: #339933;">+</span> frs.<span style="color: #006633;">length</span>
					<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; LocalCount: &quot;</span> <span style="color: #339933;">+</span> lfrs.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> frs.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Found Feature on Server: &quot;</span>
						<span style="color: #339933;">+</span> frs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getVersionedIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> lfrs.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
					VersionedIdentifier frsVi <span style="color: #339933;">=</span> frs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getVersionedIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
					VersionedIdentifier lfrsVi <span style="color: #339933;">=</span> lfrs<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> .<span style="color: #006633;">getVersionedIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Local feature: &quot;</span> <span style="color: #339933;">+</span> lfrsVi.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>frsVi.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>lfrsVi.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
						<span style="color: #003399;">String</span> v <span style="color: #339933;">=</span> frsVi.<span style="color: #006633;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
						<span style="color: #003399;">String</span> lv <span style="color: #339933;">=</span> lfrsVi.<span style="color: #006633;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
						<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Checking feature: &quot;</span>
								<span style="color: #339933;">+</span> lfrsVi.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; Local: &quot;</span> <span style="color: #339933;">+</span> lv 
								<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; Server: &quot;</span> <span style="color: #339933;">+</span> v<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>frsVi.<span style="color: #006633;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">isGreaterThan</span><span style="color: #009900;">&#40;</span>lfrsVi.<span style="color: #006633;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
							<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>lfrsVi.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
									<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; needs to be updated&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
							installOps.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>OperationsManager 
									.<span style="color: #006633;">getOperationFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
									.<span style="color: #006633;">createInstallOperation</span><span style="color: #009900;">&#40;</span>ics, 
											frs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getFeature</span><span style="color: #009900;">&#40;</span>monitor<span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">null</span>, 
											<span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
						<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> 
							<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>lfrsVi.<span style="color: #006633;">getIdentifier</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
									<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; is up to date&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
						<span style="color: #009900;">&#125;</span> 
					<span style="color: #009900;">&#125;</span> 
				<span style="color: #009900;">&#125;</span> 
			<span style="color: #009900;">&#125;</span> 
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Feature verification completed.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>installOps.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Iterator</span> iter <span style="color: #339933;">=</span> installOps.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> iter.<span style="color: #006633;">hasNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
					IInstallFeatureOperation op <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>IInstallFeatureOperation<span style="color: #009900;">&#41;</span> iter.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Updating: &quot;</span> <span style="color: #339933;">+</span> op.<span style="color: #006633;">getFeature</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
						<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;, Size: &quot;</span> <span style="color: #339933;">+</span> op.<span style="color: #006633;">getFeature</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDownloadSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
						<span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;kb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
					<span style="color: #000066; font-weight: bold;">boolean</span> succes <span style="color: #339933;">=</span> op.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>monitor, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>succes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
						restart<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
&nbsp;
						<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Update succesfull&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
						uninstallFeature<span style="color: #009900;">&#40;</span>ics,op.<span style="color: #006633;">getOldFeature</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,monitor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
					<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> 
						<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Update failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span> 
				<span style="color: #009900;">&#125;</span> 
				ls.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;There are no new updates.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvocationTargetException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>CoreException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">MalformedURLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 	
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> uninstallFeature<span style="color: #009900;">&#40;</span>IConfiguredSite ics, IFeature oldFeature, IProgressMonitor monitor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Uninstall Feature: &quot;</span> <span style="color: #339933;">+</span> oldFeature.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span> 
			IUnconfigFeatureOperation uo <span style="color: #339933;">=</span> OperationsManager
				.<span style="color: #006633;">getOperationFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createUnconfigOperation</span><span style="color: #009900;">&#40;</span>ics, oldFeature<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
			<span style="color: #000066; font-weight: bold;">boolean</span> isUnconfiged<span style="color: #339933;">=</span>uo.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>monitor,<span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Unconfigured: &quot;</span> <span style="color: #339933;">+</span> isUnconfiged<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			IUninstallFeatureOperation uninsto<span style="color: #339933;">=</span>OperationsManager.<span style="color: #006633;">getOperationFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
				.<span style="color: #006633;">createUninstallOperation</span><span style="color: #009900;">&#40;</span>ics, oldFeature<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #000066; font-weight: bold;">boolean</span> isUnstalled<span style="color: #339933;">=</span>uninsto.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>monitor,<span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Uninstalled: &quot;</span> <span style="color: #339933;">+</span> isUnstalled<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> selectionChanged<span style="color: #009900;">&#40;</span>IAction action, ISelection selection<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isRestart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">return</span> restart<span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2009/02/02/rcp-anwendungen-aktualisieren/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Volltextsuche mit PostgreSQL</title>
		<link>http://www.treibsand.com/2009/01/26/volltextsuche-mit-postgresql/</link>
		<comments>http://www.treibsand.com/2009/01/26/volltextsuche-mit-postgresql/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 16:11:25 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tsearch2]]></category>
		<category><![CDATA[Volltextsuche]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/2009/01/26/volltextsuche-mit-postgresql/</guid>
		<description><![CDATA[Viele Programmierer waren schon frustriert, weil eine Volltextsuche benötigt wurde. Welche Engine ist die Beste? Warum braucht die Engine einen eigenen Dienst? Wieso brauch ich dafür eine zweite Datenbank? Seit PostgreSQL 8.3 ist tsearch2 direkt integriert. Bei tsearch2 handelt es sich um eine Volltextsuche, welche direkt in PostgreSQL angesprochen wird. Dadurch ist es möglich, die [...]]]></description>
			<content:encoded><![CDATA[<p>Viele Programmierer waren schon frustriert, weil eine<br />
Volltextsuche benötigt wurde. Welche Engine ist die Beste? Warum braucht die<br />
Engine einen eigenen Dienst? Wieso brauch ich dafür eine zweite Datenbank?</p>
<p><span id="more-236"></span><br />
Seit PostgreSQL 8.3 ist tsearch2 direkt integriert. Bei tsearch2 handelt<br />
es sich um eine Volltextsuche, welche direkt in PostgreSQL angesprochen wird.<br />
Dadurch ist es möglich, die Informationen für die Suche direkt in die Tabellen einzubetten.</p>
<p>Tsearch2 liefert einige neue Datentypen und Funktionen, mit welchen gearbeitet werden<br />
kann. Ein Datentyp ist z.B. tsvector, welchen man direkt testen kann&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Der erste String zum testen '</span>::tsvector;
               tsvector                
<span style="color: #808080; font-style: italic;">---------------------------------------</span>
 <span style="color: #ff0000;">'Der'</span> <span style="color: #ff0000;">'zum'</span> <span style="color: #ff0000;">'erste'</span> <span style="color: #ff0000;">'String'</span> <span style="color: #ff0000;">'testen'</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">ROW</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Als Ergebnis bekommen wir alle Wörter des Strings. Wörter, welche<br />
doppelt im Text stehen, werden nur einmal angezeigt, was durchaus auch<br />
Sinn macht.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Der erste String zum testen und testen '</span>::tsvector;
               tsvector                   
<span style="color: #808080; font-style: italic;">---------------------------------------------</span>
 <span style="color: #ff0000;">'Der'</span> <span style="color: #ff0000;">'und'</span> <span style="color: #ff0000;">'zum'</span> <span style="color: #ff0000;">'erste'</span> <span style="color: #ff0000;">'String'</span> <span style="color: #ff0000;">'testen'</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">ROW</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Um das ganze mal etwas praktischer anzugehen, legen wir uns als erstes<br />
eine Tabelle an, welche Texte enthalten soll:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> messages <span style="color: #66cc66;">&#40;</span>
	id int4<span style="color: #66cc66;">,</span>
	message text<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Und wir brauchen auch noch Inhalte&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> messages <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Dies ist eine Testnachricht'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> messages <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'2'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Dumdidum Nachricht'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> messages <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'3'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Ich bin ein Blindtext'</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Jetzt haben wir ein Paar Daten in der Tabelle, aber noch keine Möglichkeit<br />
einen Volltextindex zu speichern. Den Index können wir wie folgt anlegen:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> messages <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">COLUMN</span> idxFTI tsvector;</pre></div></div>

<p>Um das Feld die neue Spalte initial zu füllen sollte man wie folgt vorgehen:</p>
<ul>
<li>Tabelle updaten</li>
<li>vacuum full analyze ausführen</li>
<li>Index erstellen</li>
<li>nochmal vacuum full analyze ausführen</li>
</ul>
<p>Als erstes erzeugen wir den Volltextindex aus der Spalte message und<br />
führen ein Vacuum aus&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> messages <span style="color: #993333; font-weight: bold;">SET</span> idxFTI<span style="color: #66cc66;">=</span>to_tsvector<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'default'</span><span style="color: #66cc66;">,</span>message<span style="color: #66cc66;">&#41;</span>;
VACUUM <span style="color: #993333; font-weight: bold;">FULL</span> ANALYZE;</pre></div></div>

<p>Wenn z.B. mehrere Spalten in den Volltextindex aufgenommen werden sollen,<br />
dann könnte man es wie folgt machen&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">UPDATE</span> messages
  <span style="color: #993333; font-weight: bold;">SET</span> idxFTI<span style="color: #66cc66;">=</span>to_tsvector<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'default'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>message<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">||</span><span style="color: #ff0000;">' '</span><span style="color: #66cc66;">||</span> <span style="color: #993333; font-weight: bold;">COALESCE</span><span style="color: #66cc66;">&#40;</span>andereSpalte<span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
VACUUM <span style="color: #993333; font-weight: bold;">FULL</span> ANALYZE;</pre></div></div>

<p>Jetzt erzeugen wir einen normalen Index auf der Spalte idxFTI&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> idxFTI_idx <span style="color: #993333; font-weight: bold;">ON</span> messages <span style="color: #993333; font-weight: bold;">USING</span> gist<span style="color: #66cc66;">&#40;</span>idxFTI<span style="color: #66cc66;">&#41;</span>;
VACUUM <span style="color: #993333; font-weight: bold;">FULL</span> ANALYZE;</pre></div></div>

<p>Im Prinzip kann man schon jetzt per Volltext suchen. Eine Suche nach<br />
dem Wort &#8220;ein&#8221; liefert z.B.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span> message <span style="color: #993333; font-weight: bold;">FROM</span> messages <span style="color: #993333; font-weight: bold;">WHERE</span> idxfti @@ <span style="color: #ff0000;">'ein'</span>::tsquery;
    id <span style="color: #66cc66;">|</span>           message           
<span style="color: #808080; font-style: italic;">-------+-----------------------------</span>
     <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">|</span> Dies ist eine Testnachricht
     <span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">|</span> Ich bin ein Blindtext
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span> <span style="color: #993333; font-weight: bold;">ROWS</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Wie aber erzeugen wir den Inhalt von idxFTI, wenn ein neuer<br />
Datensatz eingetragen wird? Hier helfen Trigger und Stored Procedures&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">REPLACE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> vectorupdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> <span style="color: #993333; font-weight: bold;">AS</span> $vectorupdate$
<span style="color: #993333; font-weight: bold;">BEGIN</span>
  <span style="color: #993333; font-weight: bold;">UPDATE</span> messages
  <span style="color: #993333; font-weight: bold;">SET</span> idxFTI<span style="color: #66cc66;">=</span>to_tsvector<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'default'</span><span style="color: #66cc66;">,</span>message<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">WHERE</span> id<span style="color: #66cc66;">=</span><span style="color: #993333; font-weight: bold;">NEW</span><span style="color: #66cc66;">.</span>id;
&nbsp;
  <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">NEW</span>;
<span style="color: #993333; font-weight: bold;">END</span>;
$vectorupdate$ <span style="color: #993333; font-weight: bold;">LANGUAGE</span> plpgsql;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TRIGGER</span> tgr_vectorupdate AFTER <span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">OR</span> <span style="color: #993333; font-weight: bold;">UPDATE</span> <span style="color: #993333; font-weight: bold;">ON</span> messages
  <span style="color: #993333; font-weight: bold;">FOR</span> EACH <span style="color: #993333; font-weight: bold;">ROW</span> <span style="color: #993333; font-weight: bold;">EXECUTE</span> <span style="color: #993333; font-weight: bold;">PROCEDURE</span> vectorupdate<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Wenn jetzt ein neuer Datensatz eingetragen bzw. verändert wird, dann<br />
wir auch automatisch der Volltextindex aktualisiert.</p>
<p>Natürlich war dies nur ein kurzer Abriss von tsearch2, für den<br />
vollen Einblick muss ich auf die <a href="http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/"><br />
Dokumentation</a> verweisen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2009/01/26/volltextsuche-mit-postgresql/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

