Jerry Jacob's Blog

Own ID Column for the Model in the Play! Framework

Posted in Java/ J2EE, Play Framework by jerlinworld on January 11, 2012

When you create Model entities in the Play! Framework, Play will provide a default id column.  If you need to use your own id column — say if you are given a database schema to work with — then you should extend a different Play class called GenericModel instead of Model class.  In addition to providing an @Id annotation, it also provides @GeneratedValue annotation. Here is its usage both with  Oracle and MySql.
MySql

@Entity
public class Tutorial extends GenericModel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long tutorial_id;

Oracle

@Id
@GeneratedValue(strategy=SEQUENCE, generator="videoIdSeq")
@SequenceGenerator(name="videoId", sequenceName="video_id_seq", allocationSize=1)
@Column(name="video_id")
protected Long videoId;

Create zip files in Java

Posted in Java/ J2EE by jerlinworld on January 11, 2012

The output of the below Java program will be the creation of a zip file inside c:/ with the name test.zip
Taken from http://extreme-java.com



package com.example;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
 
/** This class is a Java tutorial for creating zip file
 * 
 * @author Extreme Java
 */
public class Test{
 
	/** The method creates zip file and also creates an entry inside it
	 * 
	 * @param args is the command line arguments
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException  {
		//create a file output stream
		FileOutputStream zipFOS = new FileOutputStream("c://test.zip");
 
		//create a zip output stream from the file output stream created above.
		//zip output stream decorates file output stream
		ZipOutputStream zipoutStream = new ZipOutputStream(zipFOS);
 
		//creates an zip entry. You can create as many entries as you wish
		//Each entry represent a file with in the zip archive
		ZipEntry zipEntry = new ZipEntry("source1");
 
		//put the zip entry create above into the zip file
		zipoutStream.putNextEntry(zipEntry);
 
		//write some text into the zip entry created above.
		//Whatever is written will be added to last added zip entry
		zipoutStream.write(1);
 
		//close the zip entry.
		zipoutStream.closeEntry();
 
		//Finish the creation of zip file.
		zipoutStream.finish();
 
		//close the file output stream
		zipFOS.close();
 
		//close the zip output stream
		zipoutStream.close();
	}
}