Tremend Tech Blog

"Software is a great combination between artistry and engineering. When you finally get done and get to appreciate what you have done it is like a part of yourself that you've put together." (Bill Gates)

Looking for software experts?

Need an expert advice on software development? Need consulting work done in time and at high standards? Tremend has the right solution for you.

We can provide expertise in:
  • high traffic and complex content website infrastructures
  • website development-advanced web programming with PHP, .NET, Java, Flash/Flex, Ajax

Our friends

Solution to a problem with VMware Server 1.0.1 on Linux kernel 2.6.19-1.2288.fc5 - ‘CHECKSUM_HW’ undeclared (first use in this function)

February 28th, 2007 by spostelnicu

Solution to the following problem with VMware Server 1.0.1 on Linux kernel 2.6.19-1.2288.fc5 : ‘CHECKSUM_HW’ undeclared (first use in this function)

I use VMware Server 1.0.1 on Linux (Fedora Core 5) and I recently updated the kernel to 2.6.19-1.2288.fc5 - the reason of the update is that my older kernel version did not have drivers for my onboard soundcard :)

After the update, I discovered that I had to reconfigure vmware by running the command

/usr/bin/vmware-config.pl

That was ok, as this is required with each kernel update (vmware is configured to a particular kernel version).

When running vmware-config.pl, I got the following message (normal again):

None of the pre-built vmmon modules for VMware Server is suitable for your

running kernel. Do you want this program to try to build the vmmon module for

your system (you need to have a C compiler installed on your system)? [yes]

The next step is:

What is the location of the directory of C header files that match your running kernel? [/lib/modules/2.6.19-1.2288.fc5/build/include]

Note that for this you need to download the sources for your kernel version. For me this was as easy as running “Add/Remove Software” and selecting kernel-devel-2.6.19-1.2288.fc5 from the list of packages.

After skipping the networking setup (as it was already setup by me some time ago), I got the following error:

….. /tmp/vmware-config2/vmnet-only/userif.c : ‘CHECKSUM_HW’ undeclared (first use in this function)

After searching the net a little, I found out this:

From kernel 2.6.19, the CHECKSUM_HW value has long been used in thenetworking subsystem to support hardware checksumming. That value hasbeen replaced with CHECKSUM_PARTIAL (intended for outgoing packetswhere the job must be completed by the hardware) and CHECKSUM_COMPLETE(for incoming packets which have been completely checksummed by the hardware).

For more see http://lwn.net/Articles/200304/

So the solution to my problem was to locate the files where this values were used and replace CHECKSUM_HW with CHECKSUM_PARTIAL and linux/config.h to linux/autoconf.h

I found that the files were in /usr/lib/vmware/modules/source, inside the tar archive vmnet.tar

I unpacked the archive, replaced CHECKSUM_HW to CHECKSUM_PARTIAL in the files

bridge.c and userif.c, replaced linux/config.h to linux/autoconf.h in the file procfs.c, and then repacked the archive back to vmnet.tar (after renaming the old one to vmnet.tar.orig, just for backup)

Then I re-run vmware-config.pl and it worked fine.

Share/Save

Posted in General | 1 Comment »

Hibernate Annotations 3.2.1 - Lucene sort

February 28th, 2007 by Ioan Cocan

Keeping database and Lucene index in sync is easily done using the new Lucene-Hibernate integration.

Just place the default org.hibernate.search.event.FullTextIndexEventListener on Hibernate’s lifecycle methods, configure the Lucene annotations in classes you want to search and you’re ready to go. For custom operations such as persisting custom classes you can write bridges where you can create custom fields in index.

Save/update/deletes of your hibernate objects will propagate in Lucene index. A full reindex can be implemented as well using a custom the new FullTextSession class.

Everything is great on the keeping in sync part, but how about doing actual searches?

The intent was to wrap actual Lucene queries and have them transformed into Hibernate queries, empowering the API user with all the API Hibernate provides for query manipulation (eg. pagination). Problem is getting a hold of the actual Lucene index is no longer possible. All that nicely created and maintained in sync index cannot be used with real Lucene queries, using Lucene API to extract the information.

A simple problem was using Lucene to do a Sort for me, turns out that current API does not provide that. As I understand, 3.3.0 will allow direct access to Lucene Directory (see here). To get around that you can use something similar to SearchDAO.java using the same index access as Lucene-Hibernate integration is using.

Share/Save

Posted in Java, General | 3 Comments »

Dojo DND - how to cancel drag and drop in dojo

February 27th, 2007 by Marius Hanganu

How can one cancel the drag and drop operation in dojo, based on conditions specific to the application? I’ve seen this question asked several times and few if none answers, so I thought I might post my solution here.
The basic idea is to connect to the accepts event from a dojo.dnd.DropTarget using the around advice which lets you control the output of the accepts method (more details here).

Here’s a code snippet:

dojo.event.connect(”around”, myDropTarget, “accepts”, “acceptsDrop”);

Inside your acceptsDrop function you can cancel the DND operation using your own custom conditions:

function acceptsDrop(invocation) {

    var dragObjects = invocation.args[0];

    for (var x = 0; x < dragObjects.length; x++) {

        // if some condition related to dragObjects is true

       if(dragObjects[x].domNode.getAttribute(”someAttribute”) == “someValue”) {

          // returning false will result in cancelling the drag and drop

         return false;

        }

    }

    // returning true will allow the drag and drop operation to continue

    return true;

}

Enjoy

Share/Save

Posted in HTML, Javascript | No Comments »

Serializable java objects in MySQL

February 15th, 2007 by Sebastian Mitroi

How to save a complex java object in a MySQL table

If you want to save complex java objects to MySQL you can serialize and save them as BLOB in a MySQL table.

For example you have an object “complexObject” from class “ComplexObject” and you want to save it in database.

The ComplexObject class must implements Serializable interface and you can serialize the objects like this:

ByteArrayOutputStream baos;

ObjectOutputStream out;

baos = new ByteArrayOutputStream();

try {

out = new ObjectOutputStream(baos);

out.writeObject(complexObject);

out.close();

} catch (IOException e) {

e.printStackTrace();

}

byte[] byteObject = baos.toByteArray();

to deserialize the object :

ByteArrayInputStream bais;

ObjectInputStream in;

try {

bais = new ByteArrayInputStream(byteObject);

in = new ObjectInputStream(bais);

complexObject = (ComplexObject) in.readObject();

in.close();

} catch (IOException ex) {

ex.printStackTrace();

} catch (ClassNotFoundException ex) {

ex.printStackTrace();

}

The MySQL table looks like this:

CREATE TABLE myTable(



complexObject BLOB,…

);

If you use Hibernate and Annotation you declare the complexObject transient, and a byte[] byteObject that will be persisted:

@Entity

@Table(name = “myTable”)

SomeClass{

private byte[] byteObject;

private ComplexObject complexObject;



@Transient

public ComplexObject getComplexObject() {

return complexObject;

}

public void setComplexObject(ComplexObject complexObject) {

this.complexObject = complexObject;

ByteArrayOutputStream baos;

ObjectOutputStream out;

baos = new ByteArrayOutputStream();

try {

out = new ObjectOutputStream(baos);

out.writeObject(complexObject);

out.close();

} catch (IOException e) {

e.printStackTrace();

}

this.byteObject = baos.toByteArray();

}

@Column(columnDefinition = “blob”)

public byte[] getByteObject() {

return byteObject;

}

public void setByteObject(byte[] byteObject) {

ByteArrayInputStream bais;

ObjectInputStream in;

try {

bais = new ByteArrayInputStream(byteObject);

in = new ObjectInputStream(bais);

complexObject = (ComplexObject) in.readObject();

in.close();

} catch (IOException ex) {

ex.printStackTrace();

} catch (ClassNotFoundException ex) {

ex.printStackTrace();

}

this.byteObject= byteObject;

}

}

Attention the table column must be BLOB, not varchar.

Because the ComplexObject is transient it will not be save in database, but the byteObject will be save.


Share/Save

Posted in Java, General | 3 Comments »