Category Archives: Uncategorized

A new beginning…

so its been a while, since i lastly added a new post to this blog… and actually i was supriced, that it was still there.

So its time to reactivate it. But it will be different… the main focus will still be the same… so only a notebook for things i run into, and want to document. own projects and inspiration. Mainly only for me…

so what is different? me 🙂

i dont work as a programmer anymore… so no work related coding stuff… so new stuff:
– i backed a 3d printer on kickstarter.
– i startet sewing.
– i like pinterest.
– i started backing again.

so thats it… we will see, if i stick in this plan 😛

Excel Worksheets

ok something completle different… vba… currently i am working in a small person related company, where they manage their clients in an Excel sheet. This actually is a good tool, but every person has his own sheet, where searching is horrible… so my goal is to write a small script, to generate an index page.

Sub SheetNames()

‘ Erster Eintrag auf Zeile
StartRow = 3

‘ Laufvariable mit der Postion zum einfüllen des aktuellen SheetNamens
Position = StartRow

For i = 1 To Sheets.Count

‘ Nur einfüllen, wenn der SheetName nicht dem Inhaltsverzeichnis entspricht

If Sheets(i).Name <> ActiveSheet.Name Then

‘Link erstellen
‘=HYPERLINK(“[Makro Tester.xlsm]’Tabelle1’!A1”; “Tabelle1”)
Worksheets(“Index”).Cells(Position, 1) = “=HYPERLINK(“”[” & ThisWorkbook.Name & “]'” & Sheets(i).Name & “‘!A1″”, “”” & Sheets(i).Name & “””)”

‘Position weiterzählen
Position = Position + 1
End If

Next i

‘ Leere Zeilen am Ende einfügen, um gegebenenfalls gelöschte Sheets aus dem Index zu löschen
For i = 1 To 5
Worksheets(“Index”).Cells(Position, 1) = “”

‘ Position weiterzählen
Position = Position + 1
Next i
End Sub

MAVEN_OPTS

how to set MAVEN_OPTS:

export MAVEN_OPTS=”-Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m”

wsdl sharing by pack/unpack artifact

The problem is simple… we have a service-contract maven project, which contains all the wsdls… this will be deployed on a seperate server… why not simply use the maven repo?

so there are actually two solutions… put wsdl artifact on maven or unpack the arifact. This blog entry handles only the unpacking…

The solution is to put all wsdls as jar to the maven repo. Get the artifact, unpack it and generate the server or client from the unpacked wsdls. This solution matches my problem at work and no really effort was needed… but the solution kinda sucks… later more… first the solution 😉

Create a jar and pack the wsdls with build-helper-maven-plugin:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main</directory>
<targetPath></targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

And then unpack it in the actual service with maven-dependency-plugin:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>ch.michio.test</groupId>
<artifactId>service-contracts</artifactId>
<version>1.0.0</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/service-contracts</outputDirectory>
<includes>**/*.xsd,**/*.wsdl</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Important it needs to be unpacked, before the generate-sources. Now it is in the target folder…

And finally generate it with cxf-codegen-plugin.

JSF AlertBox

So once again i m working on a frontend… my main goal was not to work on frontends again… not that i dont want to do these kind of work, but creating customer facing stuff is demanding (which is a good thing) and a pain, because of the Business… a good idea is death, when the Business thinks they have a good idea aswell… so frontend pixel moving is really not my enjoyable work… but as i said… im doing it again… 

this time with JSF (JavaServer Faces)… in general, i like JSF ans its concepts… but there are still some really confusing things, including communication frontend to backend. But this might be a ajax problem… 

and now to the topic related stuff. I needed to implement an AlertBox. We use PrimeFaces, therefore i tried to do it as a dialog. But dialogs cant be updated, so its inside an outputPanel… 

xhtml

<p:outputPanel id=”alertBoxPanel”>
  <p:dialog header=”#{alertBoxBean.header}” widgetVar=”alertBoxDialog” visible=”#{alertBoxBean.show}”>
    <h:form>
      <table cellpadding=”0″ cellspacing=”0″ border=”0″>
      <tr>
        <td align=”center”><h:outputText value=”#{alertBoxBean.text}” escape=”false” /></td>
       </tr>
      <tr>
        <td align=”center”><p:commandButton value=”Ok” oncomplete=”alertBoxDialog.hide();” actionListener=”#{alertBoxBean.handleClose}” /></td>
     </tr>
    </table>
  </h:form>
</p:dialog>
</p:outputPanel>

java

Mainly there is the bean and its handles.

timestamp with jpa

so i have my jpa project with some really nice DAOs and i was really happy… all unit tests are up and running and everything looked good… but it wasnt…

i store timestamp(6) in the oracle db and the mapping class looks good and correct:

@Column(name = “TIME_ADDED”)
@Temporal(TemporalType.DATE)
private Date timeAdded;

the @Temporal defines the mapping type… and actual DATE is really only the date… TIMESTAMP is the thing i wanted…

The @Temporal annotation denotes, whether annotated property should be mapped to java.sql.Date (holds only date part), java.sql.Time (holds only time part) or to java.sql.Timestamp (holds date and time also with fractions of second). It has nothing to do with generation of property value.
(http://stackoverflow.com/questions/2591570/hibernate-reverse-engineering-procedure-generated-temporaltemporaltype-timestam)

and btw. unit tests will not find these errors… due to jpa caching… 🙁

mule flow

needed to reconfigure our mule-config and i was really confused about the whole mule documentation… i really think its crap, but i figured it out 🙂

first a side note to the documentation: we use flows… and a co-worker told me, that flows are kinda new, so not everything might work… its kinda documented, but without any example… so hard to figure it out…

so what did i need? just a simple flow, which sends the result to the next flow… so simple outbound to inbound…

mule-config.xml
<flow name="fooWorklow">
<vm:inbound-endpoint ... />
  <component class="Foo" />
  <vm:outbound-endpoint path="myFooBar" exchange-pattern="one-way">
    <payload-type-filter expectedType="FoobarMessage" />
  </vm:outbound-endpoint>
</flow>

<flow name="barWorkflow">
  <vm:inbound-endpoint path="myFooBar" exchange-pattern="one-way" />
  <component class="Bar" />
</flow>

and some more… so the connection between these two workwlows is made by the path=”myFooBar”… in config… additionally the outbound payload-type-filter is a rooter, which defines, that only the class foobarMessage is allowed on this connection and only this class will be sent… other result will be burned (at the koax terminator)… so how do the classes look like?

Foo
public class Foo{
  public FoobarMessage inboundMethod(){
    ...
    return foobarMessage;
  }
}

Bar
public class Bar{
  public void process(FoobarMessage msg){
    ...
  }
}

and how does the message finds it method? Reflection… so just create one method with the message argument and voila… it finds it 🙂 pretty cool…

splunk

splunk… a tool, which gathers all the log entires of files, index them and present them in a really cool frontend…

really cool when using multiple servers, different application and actually the need, to read the logfiles… http://www.splunk.com/

weaving: spring and eclipselink

What is weaving?

Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime. (http://static.springsource.org/spring/docs/2.5.x/reference/aop.html)

So weaving is used to load objects and manipulate them… so… why? and why did this concern me?

ok in my project we use spring with eclipselink and the idea was to create the entities in spring and just @Autowire them for usage…  but it needed a InstumentalLoadTimeWeaver to do so… and this Weaver needs to run in a special java-agent (spring-agent)… which is really crap on a server… so it really concerned me!

Solution? EclipseLink allows the configuration weaving=false (link)… which just simply disables the dynamic weaving, so no weaver is used and no java-agent is used… hurray…

but… what are the side-effects?

… to weave all applicable class files at build time so that you can deliver pre-woven class files. Consider this option to weave all applicable class files at build time so that you can deliver prewoven class files. By doing so, you can improve application performance by eliminating the runtime weaving step required by dynamic weaving… (http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving)

so its this a solution? i think so 🙂

genericDAO

in my jpa project i needed DAOs… Data Access Objects… and the concept to implement those should be generic… initially this concept is confusing as hell… but after that its kinda cool 🙂

Each Entity needs an DAO and for every entity there are 6 object involved:

  • interfcae GenericDao<T, K>: the main Interface with the basic DAO functions (CRUD(create, read, update, delete))
  • class GenericDaoImpl<T, K>: implements the GenericDao interface.
  • interface <entity>Dao: interface of the entity DAO, implements the GenericDao<<entityType>, <entityPrimaryKeyType>>
  • class <entity>DaoImpl: implementation of the entity Dao. it is extended by the GenericDaoImpl
  • class <entity>: the entity class
  • class <entity>DaoTest: testing rocks 🙂

confused? ok heres the example: partly in pseudo code…

Basic things:
public interface GenericDao<T, K extends Serializable>{
T findById(K id, boolean lock);
List<T> findAll();
T save(T entity);
void delete(T entity);
}

public abstract class GenericDaoImpl<T, K extends Serializable> implements GenericDao<T, K>

public Person{
  int id;
  string name
}

Person Dao:
public interface PersionDao extends GenericDao<Persion, Integer>

public class PersonDaoImpl extends GenericDaoImpl<Person, Integer> implements PersionDao

And thats it… in the GenericDaoImpl are all the methods for all entites and in the PersonDaoImpl the persion stuff…