Thursday, October 24, 2013
Starting Eclipse / Android Game Development - Day 1
Started by reading this next but skipped the Java Part 1 and went right to Part 2
http://www.kilobolt.com/game-development-tutorial.html
Downloaded Android for Eclipse Plugin and Android 2.1 for Eclipse.
Created a project and followed Part 2 of the above tutorial.
Sunday, October 20, 2013
Day #3 - Angular JS Customer App Part 1
Goal:
Develop a Customer Management Application using Angular JS, JQuery and CSS
Develop a Customer Management Application using Angular JS, JQuery and CSS
Friday, October 18, 2013
Day #2 - Basic Spring MVC Web App framework, Annotation driven, JAVA, XML
Description/Goal:
Create a basic Spring MVC Web Application that is Annotation driven that sets the framework to be used in future programs.
Roadblocks:
Create a basic Spring MVC Web Application that is Annotation driven that sets the framework to be used in future programs.
Roadblocks:
- Getting the Annotations picked up by the Eclipse Tomcat instance.
- Understanding how the @ResponseBody Annotation worked
- Getting JSON to be sent back to the browser, I was missing JSON Jackson Jar, downloading the 1.9 Jackson (ALL) from here resolved it.
Thursday, October 17, 2013
Day #1 - Pay per hour Counter in Javascript, JQuery
Program #1 - Pay Per Hour Counter
Description: Sort of like a stop watch, given an amount per hour, will start counting based on the time, how much you're making at the moment until stopped. Will show the time elapsed and the amount accrued.
Platform: Javascript, JQuery
Link to Github project:
https://github.com/seanjgildea/PayCounter
Link to JSFiddle Demo:
http://jsfiddle.net/bishopknight/k86J8/3/
Amount/hr
Description: Sort of like a stop watch, given an amount per hour, will start counting based on the time, how much you're making at the moment until stopped. Will show the time elapsed and the amount accrued.
Platform: Javascript, JQuery
Link to Github project:
https://github.com/seanjgildea/PayCounter
Link to JSFiddle Demo:
http://jsfiddle.net/bishopknight/k86J8/3/
Pay Counter
Amount/hr
30 Programs in 30 Days
So a goal of mine since reading this incredible article about Jennifer Dewalt is to code 30 programs/projects in 30 days. Uploading everything to my github.com account with an accompanying blog post. Some of the larger projects will be done incrementally. Doing as much as I can each day and uploading that version of what I got done in an Agile ( albeit develop, test and release in a 1 day ) format. If I can reach 30, I'd like to continue and set a new stretch goal.
Project Outline / Goals:
1. Build a different program/project everyday for 30 consecutive days.
2. Every website must be accompanied by a blog post.
3. Any code I write must be made publicly available so that everyone can see it.
4. Projects can build upon others, but a working version must be released each day.
Benefits:
- Being able to develop whatever I want through directed self-study increases motivation
- Making and seeing incremental progress on projects
- Being accountable/visible to/for my code leads to proper practices like readability, comments, unit tests
- Improving and expanding a diverse set of programming skills
- Effects on Social Life
- Demands of a Full Time Software Engineering job can be draining
Thursday, September 12, 2013
JQuery notes
<style>
#abc {
display: none;
}
</style>
<script>
$(document).ready(function() {
$("#<portlet:namespace />def").change(function(){
var id = $(this).find("option:selected").attr("id");
switch (id){
case "area":
$("#abc").css({display: "block"});
break;
case "neu":
$("#eai").css('font-weight', 'bold');
break;
}
});
});
</script>
#abc {
display: none;
}
</style>
<script>
$(document).ready(function() {
$("#<portlet:namespace />def").change(function(){
var id = $(this).find("option:selected").attr("id");
switch (id){
case "area":
$("#abc").css({display: "block"});
break;
case "neu":
$("#eai").css('font-weight', 'bold');
break;
}
});
});
</script>
Thursday, August 8, 2013
Solved: Liferay Parent Child Nav elements highlighted
So some background.
I have 2 pages at the top horizontally aligned. When one of those is selected, I have 5 pages. Under one of those, the child pages were not showing my "selected" css classes. I wanted them to show up but nothing was working. So I did some basic print outs to the screen with the boolean values of isSelected and isChildSelected. From there I came up with the solution below.
Basically if isSelected() was false and isChildSelected() was true then display the css class "selected" element for the child menu element.
#if (!$nav_child.isSelected() && $nav_child.isChildSelected())
<li class="sub_menu">
<a class="selected" href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child_upper.toUpperCase()</a>
</li>
I have 2 pages at the top horizontally aligned. When one of those is selected, I have 5 pages. Under one of those, the child pages were not showing my "selected" css classes. I wanted them to show up but nothing was working. So I did some basic print outs to the screen with the boolean values of isSelected and isChildSelected. From there I came up with the solution below.
Basically if isSelected() was false and isChildSelected() was true then display the css class "selected" element for the child menu element.
#if (!$nav_child.isSelected() && $nav_child.isChildSelected())
<li class="sub_menu">
<a class="selected" href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child_upper.toUpperCase()</a>
</li>
Friday, August 2, 2013
twitter json api example with angular js
http://stackoverflow.com/questions/16195199/create-a-jsonp-api-in-angularjs-consume-with-jquery
http://angular-ui.github.io/ng-grid/
<!doctype html>
<!-- Create a basic module -->
<html lang="en" data-ng-app="jsonApp">
<head>
<title>Services Test</title>
<link href="css/site.css" rel="stylesheet" type="text/css">
</head>
<body >
{{ 1 + 2 }}
<div ng-controller="getJSON">
<a href="#" ng-click="getDetails()">View Details</a>
<ul>
<li ng-repeat=""></li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script>
var jsonApp = angular.module('app', [] );
jsonApp.controller('getJSON', function($scope) {
$scope.getDetails = function() {
$http.get(...).success(function(data){
$scope.story = data;
});
}
})
</script>
</body>
</html>
http://angular-ui.github.io/ng-grid/
<!doctype html>
<!-- Create a basic module -->
<html lang="en" data-ng-app="jsonApp">
<head>
<title>Services Test</title>
<link href="css/site.css" rel="stylesheet" type="text/css">
</head>
<body >
{{ 1 + 2 }}
<div ng-controller="getJSON">
<a href="#" ng-click="getDetails()">View Details</a>
<ul>
<li ng-repeat=""></li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script>
var jsonApp = angular.module('app', [] );
jsonApp.controller('getJSON', function($scope) {
$scope.getDetails = function() {
$http.get(...).success(function(data){
$scope.story = data;
});
}
})
</script>
</body>
</html>
Monday, July 29, 2013
Angular Fiddle #2
Inventory Cost analyzer
http://jsfiddle.net/bishopknight/56tjM/
Some interesting tags in this one:
ng-pattern
step
min
http://jsfiddle.net/bishopknight/56tjM/
Some interesting tags in this one:
ng-pattern
step
min
Goal for the week - 1 Angular JS fiddle per day
So I'm aiming to shoot for a goal this week. 1 Angular JS fiddle per day. Doesn't have to be anything that great. Something I can create within an hour or two.
Minor nuisances:
Good place to start is with a robust form using Angular JS controller and model elements
http://jsfiddle.net/bishopknight/ZreFq/
Minor nuisances:
- Must be "No Wrap - in <head>
- Angular JS 1.0.3 at least
Good place to start is with a robust form using Angular JS controller and model elements
http://jsfiddle.net/bishopknight/ZreFq/
Thursday, May 2, 2013
popup menu onclick javascript image
http://jsfiddle.net/bishopknight/S3jft/
$('#test').click(function() {
$('#Menu').show('slow');
});
#Menu
{
padding:0;
margin:0;
list-style-type:none;
font-size:13px;
color:#717171;
width:105px;
display: none;
border: 1px solid #333;
}
#Menu li
{
border-bottom:1px solid #eeeeee;
padding:7px 10px 7px 10px;
}
#Menu li:hover
{
color:White;
background-color:#ffcc00;
display: block;
}
#Menu a:link
{
color:#717171;
text-decoration:none;
display: block;
}
#Menu a:hover
{
color:White;
display: block;
}
<img id="test" onclick="test()" src="http://cdn-img.easyicon.net/png/126/12616.png" width="20px" height="20px" />
<div>
<ul id="Menu">
<li><a href="#">Add Above...</a></li>
<li><a href="#">Edit Inject...</a></li>
<li><a href="#">Delete Inject...</a></li>
<li><a href="#">Add Below...</a></li>
</ul>
</div>
Friday, April 12, 2013
AJAX in Liferay Portlets Example
A working example for Liferay Portal with AJAX using AUI
3 components here. init.jsp, view.jsp and the portlet, in this case I call it AjaxTestPortlet and it extends GenericPortlet. init.jsp contains the basic setup stuff like "page" and "taglib" imports for liferay jsps.
Here is the code for the view.jsp
And here is the code for the AjaxTestPortlet
3 components here. init.jsp, view.jsp and the portlet, in this case I call it AjaxTestPortlet and it extends GenericPortlet. init.jsp contains the basic setup stuff like "page" and "taglib" imports for liferay jsps.
Here is the code for the view.jsp
<%@ include file="init.jsp" %>
<portlet:resourceURL var="testLink" id="test22" />
<h1>Ajax Test</h1>
<div id="<portlet:namespace />testDiv">
<label for="<portlet:namespace />name">Enter Name</label>
<div>
<input id="<portlet:namespace />name" name="usernameField" type="text" maxlength="255" value=""/>
</div>
<label for="<portlet:namespace />age">Enter Age</label>
<div>
<input id="<portlet:namespace />age" name="incidentField" type="text" maxlength="255" value=""/>
</div>
</div>
<button onClick="javascript:<portlet:namespace />ajaxTest()">Test Ajax</button>
<script type="text/javascript">
function <portlet:namespace />ajaxTest()
{
var url = '<%= testLink.toString() %>';
AUI().use( function(A){
var name1 = document.getElementById("<portlet:namespace />name").value;
var age1 = document.getElementById("<portlet:namespace />age").value;
A.io.request(url, {
data: {
name: name1,
age: age1
},
dataType: 'json',
on: {
failure: function(){
},
success: function(event, id, obj)
{
console.log("Ajax Test worked!!!!" + name1 + " and " + age1);
alert("Ajax Test Worked!!!!!" + name1 + " and " + age1);
}
}
});
});
}
</script>
And here is the code for the AjaxTestPortlet
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AjaxTestPortlet extends GenericPortlet {
private static Log log = LogFactory.getLog(AjaxTestPortlet.class);
protected static String viewJSP = "";
public void init() throws PortletException {
viewJSP = getInitParameter("view-jsp");
}
public void processAction(ActionRequest aReq, ActionResponse aResp) throws IOException, PortletException {
}
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
include(viewJSP, renderRequest, renderResponse);
}
protected void include(String path, RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
.getRequestDispatcher(path);
if (portletRequestDispatcher == null) {
log.error(path + " is not a valid include!");
} else {
portletRequestDispatcher.include(renderRequest, renderResponse);
}
}
}
Thursday, April 4, 2013
Coding Theory and Philosophy
Coding Theory / Philosophy
http://www.inc.com/magazine/20110301/making-money-small-business-advice-from-jason-fried.htmlhttp://gillesleblanc.wordpress.com/2013/03/25/hire-talent-not-five-years-with-java/
http://blog.zackshapiro.com/want-to-learn-to-code-start-here
Computer Science Lectures for all levels
http://blog.idonethis.com/post/45912361388/busyness-not-virtue
http://1-3-5.com/
http://nathanmarz.com/blog/principles-of-software-engineering-part-1.html
Cool Applications
http://www.sqwiggle.com/
http://blog.streak.com/2013/04/search-find-in-pipeline-now-possible.html
Tuesday, April 2, 2013
HTML5 Summary
Playing with HTML5 Tags
small tag - Created April 2nd, 2013 by Sean GildeaFigure Tag
Captions for images
Content Editable
Try editing the text in the unordered list below- Break mechanical cab driver.
- Drive to abandoned factory
- Watch video of self
Email Inputs, Autofocus, Placeholders and Required
Try submitting anything but a validly formed email.HTML5 Local Storage
Go ahead and edit the text in the Unordered List and then refresh the browserHTML5 Form features
Try submitting anything but a validly formed email.Range Input
Javascript Reference
Javascript Reference
Upon button click, loading a new page in the same window ( try below )
<script type="text/javascript">
openWindow = function (url) {
document.location.assign(url);
}
</script>
<button class="blueX" onclick="javascript:openWindow('http://www.google.com')"><span class="button_text">Go To Google</span></button>
Function Expressions
var add = function add(a, b) {
return a + b;
}
Function Declarations
function foo() {
console.log("hello");
}
Callback Functions (jsfiddle)
var addNumbers = function (callback) {
var i = 5;
var num = callback(5);
alert("num = " + num);
}
var callback = function(num) {
return num * num;
}
addNumbers(callback);
Anonymous Callback Function ( using prior example )
addNumbers( function (num) {
return num * num;
});
test
Spring Project DD
Spring Project Design Document
- Online Movie Database
person ( id, first_name, middle_name, last_name, birthdate, bio )
person_roles( id, person_id, role_id
role( id, type, description )
photos ( title, person(s), date, description, credit, id )
film ( id, film_genre_id, director_id, writer_id,
film_genre ( id, type )
film_rating ( id, film_id, person_id )
Use Cases:
display a performer, their roles
Monday, March 25, 2013
Liferay Save File to Liferay CMS
Not the best method but it works:
public void saveFileToCMS(ActionRequest aReq, long groupId, String fileName, File filenameWithPath) {
try {
ServiceContext serviceContext = ServiceContextFactory.getInstance(
Group.class.getName(), aReq);
// prevents duplicate entries based on unique title name
Random rand = new Random();
Integer suffix = new Integer(rand.nextInt(10000));
// actual method which does inserting, poor liferay documentation on this
DLAppServiceUtil.addFileEntry(groupId, 0, fileName, "application/vnd.ms-excel",
fileName + suffix.toString(), "description goes here", "changelogname",
filenameWithPath, serviceContext);
log.info("Successfully added the new file");
} catch (PortalException pe) {
log.error("Portal Exception occurred while saving file to CMS");
pe.printStackTrace();
} catch (SystemException e) {
log.error("System Exception occurred while saving file to CMS");
e.printStackTrace();
}
}
public void saveFileToCMS(ActionRequest aReq, long groupId, String fileName, File filenameWithPath) {
try {
ServiceContext serviceContext = ServiceContextFactory.getInstance(
Group.class.getName(), aReq);
// prevents duplicate entries based on unique title name
Random rand = new Random();
Integer suffix = new Integer(rand.nextInt(10000));
// actual method which does inserting, poor liferay documentation on this
DLAppServiceUtil.addFileEntry(groupId, 0, fileName, "application/vnd.ms-excel",
fileName + suffix.toString(), "description goes here", "changelogname",
filenameWithPath, serviceContext);
log.info("Successfully added the new file");
} catch (PortalException pe) {
log.error("Portal Exception occurred while saving file to CMS");
pe.printStackTrace();
} catch (SystemException e) {
log.error("System Exception occurred while saving file to CMS");
e.printStackTrace();
}
}
Tuesday, March 19, 2013
Spring PetClinic sample setup and description
Examining the Spring Pet Clinic Project
- Forked the project on Github
- Downloaded the Spring Petclinic project via eGit plugin through my github fork
- Deleted project because it wasn't setup as a Maven project but directory was now there
- Re-Imported it as a maven project and then "shared the project" via eGit to my fork
- Project requires Tomcat, so I downloaded Apache Tomcat 7
- Started up Tomcat and verified localhost:8080 worked
- Also created Tomcat Server in Eclipse but not sure what it does yet
- CMD Prompt: Ran "mvn clean install" and it generated the war
- CMD Prompt: Ran "mvn deploy" and it didn't deploy... going to hand copy it over
- Found the default location of maven is ~/m2/
- Found out I can right-click on pom.xml > Run As... ( maven build )
- Copied the petclinic.war to the tomcat/webapps dir
- Restarted tomcat, verified project in webapps directory
- Went to localhost:8080 and logged into the manager gui with tomcat/s3cret
- Deployed project to http://localhost:8080/petclinic
- Read the project description at http://static.springsource.org/docs/petclinic.html
I have to say they did an excellent job describing the application structure - Learned more about what a use case is
- Had to setup the JDK in Eclipse due to error running mvn build
- Unresolved test failures upon mvn build ( inside eclipse )
- Reverted back to HSQL
- Opened CMD prompt, went to pom dir, ran mvn clean install, worked fine
- Reverted data-access.properties back to MYSQL
- What should I be focusing on.... Modifying the Spring code. ( yes, priority )
- Where are the main parts of the project? (
- How can I change the view?
- How is Spring Roo involved in the Framework?
- Does JPA add the annotations to the Entity POJOs?
- How do I collapse all the methods I'm viewing in Eclipse?
Sunday, March 17, 2013
Jboss jBPM first look
- Downloaded the jbpm-5.4.0.Final-installer-full.zip
- Extracted it to /hibernate folder
- Ran the build.xml scripts as referenced in the install.html for manual install
- Downloaded a 64 bit eclipse and dropped it into the extracted folder
- Went to Eclipse Marketplace and added this eclipse download site for DROOLS
http://download.jboss.org/drools/release/5.5.0.Final/org.drools.updatesite/ - Installed the DROOLS core, Guvnor, jBPM Core and jBPM Task updates.
- Went to File > New > Other > jBPM > jBPM project
- Configured a jBPM Runtime
Friday, March 15, 2013
Areas to focus learning next
- Expert Spring Knowledge ( 3/20 )
- Maven Experience ( 3/20 )
- JBoss jBPM
- JBoss ESB
- Continuous Integration Tools
- Oracle
- JUnit
- Medium Database Design
- Expert OO Design & Development
Monday, March 11, 2013
Liferay Service Builder Notes
- All you really write initially is a service.xml file with the table schemas.
- Then you right click the service.xml script > Liferay > Build Services
- When the server gets started, it updates the tables in the database automatically
- Service Builder can generate your queries for you using "Finder methods". These are declared inside the <entity> mapping of the service.xml. For example:
<finder name="Product" return-type="Collection">
<finder-column name="productId" />
</finder>
This line will generate a method which can be called via the ProductLocalServiceUtil class. It will take an ID and return a collection of product objects. - Once you've ran Service Builder and you want to start using the auto generated methods, you first have to implement the Impl class methods. So if your class name was product, that file is ProductLocalServiceImpl. Heres the thing though that they don't explain very well in the Liferay documentation though. You make your model method calls to the productPersistence object (where product is replaced by your class name) without initializing it. So for instance,
Product p = productPersistence.findByLatestProduct(true);
Also of note, those queries Service Builder generated for you are in the that object, as referenced by my example above.
Wednesday, March 6, 2013
Liferay Notes: windowState, sessionErrors
Liferay First Hand Notes:
windowState
When working on a portlet and creating a popup, in the there is a windowState variable which should be set. It basically tells the browser what parts of the screen to render on load. So for windowState, there is normal which includes everything, maximized which I'm not sure, and exclusive which shows only that JSP page.
sessionErrors
So there are 2 parts to sessionErrors:
First part: You must add something like this to the jsp
<liferay-ui:error key="excel-failure" message="File Extension Not Supported."/>
Second part: Wherever you call need to call the error in your java code, add something like this
SessionErrors.add(aReq, "excel-failure");
windowState
When working on a portlet and creating a popup, in the
Tuesday, February 19, 2013
Reading an XLS file with Java and Apache POI
A class I wrote that reads an excel XLS file and returns a Collection of some Object. The following jars maybe all be necessary:
---------------------------------------------------------------------------------------------------------------------------------------------------------
public static void buildProductList(List sheetData, List<Product> productList ) {
for (int i = 1; i < 5; i++) {
List list = (List) sheetData.get(i);
Product p = new Product();
Cell cell1 = (HSSFCell) list.get(0);
p.setProductId((long)cell1.getNumericCellValue());
Cell cell2 = (HSSFCell) list.get(1);
p.setCreatedOn(new Date());
// methods
Cell cell3 = (HSSFCell) list.get(2);
p.setDescription(cell3.getRichStringCellValue().getString());
injectList.add(inject);
}
}
- poi
- poi-ooxml
- xbean
- poi-ooxml-schemas
- dom4j
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class ExcelParser {
private static Log log = LogFactory.getLog(ExcelParser.class);
public static List<Product> parseSheet(File outputFilePath) {
List sheetData = new ArrayList();
FileInputStream file = null;
try {
// Create a FileInputStream that will be use to read the excel file.
file = new FileInputStream(outputFilePath);
// Create an excel workbook from the file system.
Workbook workbook = new HSSFWorkbook(file);
// Get the first sheet on the workbook.
Sheet sheet = workbook.getSheetAt(0);
// When we have a sheet object in hand we can iterator on each
// sheet's rows and on each row's cells. We store the data read
// on an ArrayList so that we can printed the content of the excel
// to the console.
Iterator rows = sheet.rowIterator();
while (rows.hasNext())
{
Row row = (HSSFRow) rows.next();
Iterator cells = row.cellIterator();
List data = new ArrayList();
while (cells.hasNext()) {
Cell cell = (HSSFCell) cells.next();
data.add(cell);
}
sheetData.add(data);
}
} catch (IOException e) {
e.printStackTrace();
}
return sheetData;
}
---------------------------------------------------------------------------------------------------------------------------------------------------------
public static void buildProductList(List sheetData, List<Product> productList ) {
for (int i = 1; i < 5; i++) {
List list = (List) sheetData.get(i);
Product p = new Product();
Cell cell1 = (HSSFCell) list.get(0);
p.setProductId((long)cell1.getNumericCellValue());
Cell cell2 = (HSSFCell) list.get(1);
p.setCreatedOn(new Date());
// methods
Cell cell3 = (HSSFCell) list.get(2);
p.setDescription(cell3.getRichStringCellValue().getString());
injectList.add(inject);
}
}
Monday, February 18, 2013
Maven Spring Hibernate MySQL Project
Goal: Create a Maven Spring Hibernate MySQL project with Git integration
http://www.mkyong.com/spring/maven-spring-hibernate-mysql-example/
- Ran this command in a dos prompt in the workspace folder:
mvn archetype:generate -DgroupId=com.exo.mass -DartifactId=MavenHibernateSpringMysql -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false - It creates a folder and the layout structure
- Next I ran this command
mvn eclipse:eclipse - Then imported as a Maven project into Eclipse
- Created the database with MySQL Workbench
Sunday, February 17, 2013
Hibernate Generic DAO Project
First of all, I wrote a successful HQL query earlier using this link
http://www.mkyong.com/hibernate/hibernate-query-examples-hql/
Anyways, I'm looking for a better way to use Hibernate without writing complex DAO's. I found a couple ways
http://blog.patouchas.net/technology/hibernate-dao-java-tutorial/
http://code.google.com/p/hibernate-generic-dao/
A bit later I finished that tutorial and also committed my project to git then pushed it to github.
http://www.mkyong.com/hibernate/hibernate-query-examples-hql/
Session session = HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery("from Actor where firstName = :firstName ");
query.setParameter("firstName", firstName);
List actors = query.list();
session.close();
return actors;
Anyways, I'm looking for a better way to use Hibernate without writing complex DAO's. I found a couple ways
http://blog.patouchas.net/technology/hibernate-dao-java-tutorial/
http://code.google.com/p/hibernate-generic-dao/
A bit later I finished that tutorial and also committed my project to git then pushed it to github.
Friday, February 15, 2013
Liferay Portal FileUpload Notes
First of all, I have one months experience using Liferay. I've created a custom theme and some simple portlets so far.
Now, I've been tasked with creating a Portlet to upload an Excel Document and display it in a Table Grid ( Liferay SearchContainer )
So far implementing the SearchContainer was pretty simple. There are tons of code you can copy and slap into your JSP to have it display. I created a POJO and then built a list in my portlet, then called the portlet method in the searchContainer results.
First major hurdle I've had is with understanding the ActionURL in Liferay Portal as it corresponds to JSP pages.
Now, I've been tasked with creating a Portlet to upload an Excel Document and display it in a Table Grid ( Liferay SearchContainer )
So far implementing the SearchContainer was pretty simple. There are tons of code you can copy and slap into your JSP to have it display. I created a POJO and then built a list in my portlet, then called the portlet method in the searchContainer results.
First major hurdle I've had is with understanding the ActionURL in Liferay Portal as it corresponds to JSP pages.
- If you define <portlet:actionURL var="someURL" ... You do not have to have a jsp:useBean in your code
Monday, February 11, 2013
Hib Eclipse Part 3 Notes
- In Eclipse, select Database Development. Right click Database Connections, New.
- Create a Java > Build Path > User Library
Get jars from hibernate/required folder - Download Hibernate Annotations GA
Add EJB3Persistence and Annotations jars to user library - Add 2 jars from /test dir
I didn't know:
- You don't need mapping files in the hibernate.cfg.xml if you're using annotations
- User Libraries simplify adding new projects
- The hibernate Dialect corresponds to a class type in the Hibernate distribution
- db-derby/bin/startNetworkServer
Saturday, February 9, 2013
Hibernate with Eclipse Plugin Part 2
Some notes on what caused me a hassle before I finally got Hibernate with Eclipse Plugin working finally.
If you're using PostGres, make sure you add the Driver Jar to the library as well and remove the MySQL driver.
I needed ALL of these jars. I had to download them individually. Why these aren't included in some package makes no sense to me honestly.
Hibernate ID generation
Use Longs, not Integers for ID auto incrementing
So did a totally from scratch 2nd example, I generated hibernate classes and hbm files from reverse engineering using this tutorial. http://www.wikihow.com/Generate-Hibernate-Pojo-Classes-from-DB-Tables
I still had JNDI setup errors, javax.naming.NoInitialContextException. I fixed it by
If you're using PostGres, make sure you add the Driver Jar to the library as well and remove the MySQL driver.
I needed ALL of these jars. I had to download them individually. Why these aren't included in some package makes no sense to me honestly.
Hibernate ID generation
Use Longs, not Integers for ID auto incrementing
So did a totally from scratch 2nd example, I generated hibernate classes and hbm files from reverse engineering using this tutorial. http://www.wikihow.com/Generate-Hibernate-Pojo-Classes-from-DB-Tables
I still had JNDI setup errors, javax.naming.NoInitialContextException. I fixed it by
Friday, February 8, 2013
Hibernate Tools plugin for Eclipse
Some steps of how I got Hibernate to run in Eclipse while using this tutorial
http://www.dzone.com/tutorials/java/hibernate/hibernate-example/hibernate-tools-1.html
Download the Hibernate Tools from
http://download.jboss.org/jbosstools/updates/stable/
Download the MySQL Jar to a folder on C:
Add to the CLASSPATH ( optional )
Create a Java Project
Create a Class
In Hibernate Perspective
New > hbm xml mapping file
New > hibernate.cfg.xml file
New > Console Configuration ( Drill down and find the MySQL jar and add it, its in a submenu )
Find the green run task on top bar > Hibernate Code Generation tool
Got a mapping exception, could not find *.hbm.xml file, went to project "Run as configurations", selected classpath and added the folder containing the hbm.xml to the path.
.HBM.XML MUST BE IN SAME FOLDER AS .JAVA !!!
Got an Error:
org.hibernate.MappingException: class ll.mit.edu.Person not found while looking for property: id
Fixed it by editing the src/ll/mit/edu/Person.hbm.xml file. This is what passed for me.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="ll.mit.edu"> <class name="ll.mit.edu.Person" table="Person"> <id name="id" column="id" type="java.lang.Integer" /> <property name="name" column="name" type="java.lang.String"/> <property name="surname" column="surname" type="java.lang.String" /> <property name="address" column="address" type="java.lang.String" /> </class></hibernate-mapping>
After that here is what my configuration looked like:
Project > New > Source Folder > select /src
Downloaded Hibernate from Sourceforge to C:\hibernate
In project java build path, added external jar, Hibernate3.jar to jar path
http://www.dzone.com/tutorials/java/hibernate/hibernate-example/hibernate-tools-1.html
Download the Hibernate Tools from
http://download.jboss.org/jbosstools/updates/stable/
Download the MySQL Jar to a folder on C:
Add to the CLASSPATH ( optional )
Create a Java Project
Create a Class
In Hibernate Perspective
New > hbm xml mapping file
New > hibernate.cfg.xml file
New > Console Configuration ( Drill down and find the MySQL jar and add it, its in a submenu )
Find the green run task on top bar > Hibernate Code Generation tool
Got a mapping exception, could not find *.hbm.xml file, went to project "Run as configurations", selected classpath and added the folder containing the hbm.xml to the path.
.HBM.XML MUST BE IN SAME FOLDER AS .JAVA !!!
Got an Error:
org.hibernate.MappingException: class ll.mit.edu.Person not found while looking for property: id
Fixed it by editing the src/ll/mit/edu/Person.hbm.xml file. This is what passed for me.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="ll.mit.edu"> <class name="ll.mit.edu.Person" table="Person"> <id name="id" column="id" type="java.lang.Integer" /> <property name="name" column="name" type="java.lang.String"/> <property name="surname" column="surname" type="java.lang.String" /> <property name="address" column="address" type="java.lang.String" /> </class></hibernate-mapping>
After that here is what my configuration looked like:
Project > New > Source Folder > select /src
Downloaded Hibernate from Sourceforge to C:\hibernate
In project java build path, added external jar, Hibernate3.jar to jar path
Wednesday, February 6, 2013
Java Checkstyle with Xalan Formatter
An ANT script I created to parse Java with Checkstyle and then parse it with Xalan formatting it into HTML
<project name="Checkstyle Code Review and Reports"
basedir="." default="runCodeReview" >
<property name="home.dir" location="/home/euish7v/ae23d" />
<property name="checkstyle.dir" location="${home.dir}/checkstyle-5.6/" />
<property name="xalan.dir" location="${home.dir}/Downloads/xalan-j_2_7_0" />
<target name="runCodeReview">
<taskdef resource="checkstyletask.properties"
classpath="${checkstyle.dir}/checkstyle-5.6-all.jar" />
<checkstyle config="${checkstyle.dir}/sun_checks.xml"
failOnViolation="false">
<fileset dir="src/main/java">
<include name="**/*.java"/>
</fileset>
<formatter type="xml" toFile="checkstyle-result.xml"/>
</checkstyle>
</target>
<target name="generateReport">
<xslt basedir="." destdir="${checkstyle.dir}/html"
style="${checkstyle.dir}/contrib/checkstyle-frames.xsl" >
<classpath>
<fileset dir="${xalan.dir}">
<include name="*.jar"/>
</fileset>
</classpath>
</xslt>
</target>
</project>
<project name="Checkstyle Code Review and Reports"
basedir="." default="runCodeReview" >
<property name="home.dir" location="/home/euish7v/ae23d" />
<property name="checkstyle.dir" location="${home.dir}/checkstyle-5.6/" />
<property name="xalan.dir" location="${home.dir}/Downloads/xalan-j_2_7_0" />
<target name="runCodeReview">
<taskdef resource="checkstyletask.properties"
classpath="${checkstyle.dir}/checkstyle-5.6-all.jar" />
<checkstyle config="${checkstyle.dir}/sun_checks.xml"
failOnViolation="false">
<fileset dir="src/main/java">
<include name="**/*.java"/>
</fileset>
<formatter type="xml" toFile="checkstyle-result.xml"/>
</checkstyle>
</target>
<target name="generateReport">
<xslt basedir="." destdir="${checkstyle.dir}/html"
style="${checkstyle.dir}/contrib/checkstyle-frames.xsl" >
<classpath>
<fileset dir="${xalan.dir}">
<include name="*.jar"/>
</fileset>
</classpath>
</xslt>
</target>
</project>
Unix, GIT and Maven Commands
Unix:
ps -ef | grep "liferay"
kill -9 18490
find . -name "liferay"
chmod -R a+rwx
vim .bashrc
CD to the WAR directory on your local machine, something like
~/liferay-6-ce-ga2/dist
LS to look at the files
scp SomePortlet.war 444.33.22.11:
In a new terminal tab
sudo cp SomePortlet.war /liferay/deploy
In a new terminal tab
cd /liferay/tomcat.../logs
tail -f catalina.out
GIT:
git status
git stash ( gets rid of adds/untracked files before you commit)
git commit -am "Comment goes here"
git checkout master
git pull origin master
git checkout develop
git push origin develop
git branch
git clean -f -d ( removes untracked files and directories from working copy )
git fetch
git remote prune origin
Maven
/usr/lib/mvn clean install (from projects pom.xml directory)
ps -ef | grep "liferay"
kill -9 18490
find . -name "liferay"
chmod -R a+rwx
vim .bashrc
CD to the WAR directory on your local machine, something like
~/liferay-6-ce-ga2/dist
LS to look at the files
scp SomePortlet.war 444.33.22.11:
In a new terminal tab
sudo cp SomePortlet.war /liferay/deploy
In a new terminal tab
cd /liferay/tomcat.../logs
tail -f catalina.out
GIT:
git status
git stash ( gets rid of adds/untracked files before you commit)
git commit -am "Comment goes here"
git checkout master
git pull origin master
git checkout develop
git push origin develop
git branch
git clean -f -d ( removes untracked files and directories from working copy )
git fetch
git remote prune origin
Maven
/usr/lib/mvn clean install (from projects pom.xml directory)
Generating Javadoc comments for projects
Generating Javadoc for existing Java Projects with JAutoDoc
- Install the eclipse plugin from http://jautodoc.sourceforge.net/
- Under Window > Preferences > Java > JAutodoc, remove the option for "Add ToDo", the rest is pretty good standard.
- At the project root create a build file xml
- Add this code:
<project name="ABC Project" basedir="." default="jautodoc">
<target name="jautodoc">
<jautodoc srcdir="src" includes="**/*.java"/>
</target>
</project> - Add to the ANT view and then "Run As...", Select JRE tab and then select "Run in the same JRE as the workspace"
- Run the ant script and then verify the code.
Subscribe to:
Posts (Atom)


