Friday, April 22, 2011

Netbeans API

Netbeans API
- tutorial - learning trail
- tried first example, didn't run until added more libraries
- do not see the System.out.println result

Tuesday, April 19, 2011

SVN Import

http://svnbook.red-bean.com/en/1.4/svn.tour.importing.html


svnadmin create /usr/local/svn/newrepos
$ svn import mytree file:///usr/local/svn/newrepos/some/project \
-m "Initial import"
Adding mytree/foo.c
Adding mytree/bar.c
Adding mytree/subdir
Adding mytree/subdir/quux.h

Committed revision 1.

---------------

So much better than the headache of figuring out CVS Root syntax

Monday, April 18, 2011

Hibernate Notes

Hibernate Notes
1. Develop a system that displays, allows add, delete, and modifications
New Project
2. Web Application,
3. select Hibernate and Java Faces frameworks,
4. choose correct database
hibernate configuration
1. open hibernate.cfg.xml
2. add,
a. driver_class,
b. url, jdbc:mysql://localhost:3306/databaseName
c. username,
d. password if not there
3. Optional Properties
a. Configuration properties
i. Show_sql – true
4. Miscellaneous properties
a. Current_session_context_class – thread
Package
Create filviewer package in Soruce Packages
HibernateUtil
i. Use File->Hibernate->New HIbernateUtil (or somewhere in there)
ii. Put in Source Packages in package filmviewer
Reverse Engineering
i. Go to default package
ii. Open up New file->Hibernate->Hibernate reverse engineering wizard
iii. Use src/java
iv. Add tables from database
Mapping POJO’s
i. Use File->Hibernate->Hibernate Mapping Files and POJO’s from Database
ii. Use
a. JDK5.1 language,
b. hibernate.cfg.xml ,
c. hibernate.reveng.xml,
d. domain Code,
e. Hibernate XML Mappings
Session Bean
i. Use File->JavaServer Faces->JSF Managed Bean
ii. Use either Request Scoped or Session Scoped as appropriate.
iii. Edit:
a. Import Org.hibernate.Session, Query, Transaction, java.util.*
b. Cache HibernateUtil.getSessionFactory().getCurrentSession() in an instance variable
c. Helper Methods
private Session getSession() {
return HibernateUtil.getSessionFactory().getCurrentSession();
}

private Transaction beginTransaction() {
return HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
}

private Transaction getTransaction() {
return HibernateUtil.getSessionFactory().getCurrentSession().getTransaction();
}
View
public List view() {
try {
beginTransaction();
Query query getSession().createQuery("from Film");
List< POJO > result = (List< POJO >) query.list();
getTransaction().commit();
return result;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Add
public void add(String title, String description) {
try {
beginTransaction();
POJO film = new POJO ();
film.setTitle(title);
film.setDescription(description);
getSession().save(film);
getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
}
}
Delete
public void delete(int id) {
try {
beginTransaction();
Film film = (Film)getSession().get(Film.class, id);
getSession().delete(film);
getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
}
}
Update

public void update(int id, String title, String description) {
try {
beginTransaction();
Film film = (Film)m_session.get(Film.class, id);
film.setTitle(title);
film.setDescription(description);
getSession().update(film);
getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
}
}


Running Methods/Accessing View
a. Edit Web Pages/index.xhtml
b. Add xmlns:f=http://java.sun.com/jsf/core
c.














Debugging
1. Helpful to run server from console using glassfish\bin\startserv so you can see stacktraces in terminal window.
Database
Example of how to create a table with autoincremented primary key
CREATE TABLE film (
filmId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) ,
description VARCHAR(1000)
);

What to plan before starting development on a project?

[someone asked this on Programmers.stackexchange.com - my response]

Most important thing to do: review the specs, interact with customer to get more refined specs.

The requirements are undoubtedly incomplete, vague, or incorrect. The biggest waste of time is doing the wrong thing. Customers are not professional software engineeers, and cannot be expected to be good at developing a good set of requirements.

So, you should review the specs, interview the customer and find out if this is what he/she really needs and wants, and can afford, etc.

Develop test/use cases and review with customer. If a requirement isn't testable, throw it out.

Develop the design and make sure if all the pieces function correctly that it would in theory do what you need.

Develop an architecture prototype that tests all of the technology to be used in every layer but ignore functionality. You are testing the architecture, not the functional specification. Having the wrong architecture will mean you have to rewrite everything, so getting the right architecture is important. Make sure it can meet your requiremenets for speed, efficiency, security, etc.

Tuesday, April 12, 2011

How to delete a windows service

1. Run Regedit or Regedt32

2. Find the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"

3. Look for the service there and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).

Saturday, April 9, 2011

Glassfish no free port available port value out of range

You may get this error when trying to start the Glassfish server. I believe this occurs because it's trying to use a port already in use.

My glassfish was set up with default ports 8080, and I had a Default Web Site and Team Foundation server running using port 8080. When I shut these off, this error disppeared.

When I have time I'll just change the ports.

Thursday, April 7, 2011

Kamikaze Java

Sun's Java initiative reminds me of the Kamikaze in WWII. A gutsy move against an overwhelmingly powerful enemy, but they had to know its close to the end when they're that desperate.

Monday, April 4, 2011

Zune - No installation Media

This fix worked for me

http://support.microsoft.com/kb/910336