[weld-commits] Weld SVN: r5975 - in examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode: session and 1 other directory.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Tue Mar 2 09:16:10 EST 2010
Author: mgencur at redhat.com
Date: 2010-03-02 09:16:09 -0500 (Tue, 02 Mar 2010)
New Revision: 5975
Removed:
examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java
examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java
examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java
Log:
removed old files
Deleted: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java 2010-03-02 14:11:49 UTC (rev 5974)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/model/Code.java 2010-03-02 14:16:09 UTC (rev 5975)
@@ -1,136 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.model;
-
-import java.io.Serializable;
-import javax.persistence.*;
-import java.util.Date;
-
-/**
- * The persistent class for the code database table.
- *
- */
- at Entity
- at Table(name = "code")
-public class Code implements Serializable, Cloneable
-{
- private static final long serialVersionUID = 1L;
- private int id;
- private Date datetime;
- private String language;
- private String note;
- private String text;
- private String user;
- private String hash;
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "id")
- public int getId()
- {
- return id;
- }
-
- public void setId(int id)
- {
- this.id = id;
- }
-
- @Column(name = "hash")
- public String getHash()
- {
- return hash;
- }
-
- public void setHash(String hash)
- {
- this.hash = hash;
- }
-
- public Code()
- {
- this.language = "";
- this.note = "";
- this.text = "";
- this.user = "";
- this.hash = null;
- this.datetime = null;
- }
-
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name = "datetime")
- public Date getDatetime()
- {
- return this.datetime;
- }
-
- public void setDatetime(Date datetime)
- {
- this.datetime = datetime;
- }
-
- @Column(name = "language")
- public String getLanguage()
- {
- return this.language;
- }
-
- public void setLanguage(String language)
- {
- this.language = language;
- }
-
- @Lob()
- @Column(name = "note")
- public String getNote()
- {
- return this.note;
- }
-
- public void setNote(String note)
- {
- this.note = note;
- }
-
- @Lob()
- @Column(name = "text")
- public String getText()
- {
- return this.text;
- }
-
- public void setText(String text)
- {
- this.text = text;
- }
-
- @Column(name = "user")
- public String getUser()
- {
- return this.user;
- }
-
- public void setUser(String user)
- {
- this.user = user;
- }
-}
\ No newline at end of file
Deleted: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java 2010-03-02 14:11:49 UTC (rev 5974)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAO.java 2010-03-02 14:16:09 UTC (rev 5975)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.session;
-
-import javax.ejb.Local;
-import java.util.List;
-import org.jboss.weld.examples.pastecode.model.Code;
-
- at Local
-public interface CodeEAO
-{
- public String addCode(Code code, boolean secured);
-
- public Code getCode(String id);
-
- public List<Code> allCodes();
-
- public List<Code> recentCodes();
-
- public List<Code> searchCodes(Code code, int page, QueryInfo info);
-}
Deleted: examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java
===================================================================
--- examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java 2010-03-02 14:11:49 UTC (rev 5974)
+++ examples/trunk/jsf/pastecode/ejb/src/main/java/org/jboss/weld/examples/pastecode/session/CodeEAOBean.java 2010-03-02 14:16:09 UTC (rev 5975)
@@ -1,219 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.session;
-
-import java.security.NoSuchAlgorithmException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import javax.annotation.Resource;
-import javax.ejb.EJBContext;
-import javax.ejb.EJBException;
-import javax.ejb.Stateless;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.persistence.*;
-import org.jboss.weld.examples.pastecode.model.Code;
-import javax.inject.*;
-import java.util.*;
-
-/**
- * Session Bean implementation class CodeEAOBean
- */
- at Stateless
- at Named("codeEAOBean")
-public class CodeEAOBean implements CodeEAO
-{
-
- @PersistenceContext(unitName = "pastecodeDatabase")
- private EntityManager em;
-
- @Resource
- EJBContext ctx;
-
- @Inject
- private HashComputer hashComp;
-
- private int MAX_CODES = 7;
-
- private int PAGE_SIZE = 2;
-
- public CodeEAOBean()
- {
- }
-
- public String addCode(Code code, boolean secured)
- {
- String result;
- if (code.getDatetime() == null)
- {
- code.setDatetime(Calendar.getInstance().getTime());
- }
-
- if (code.getUser().trim().isEmpty())
- {
- code.setUser("Anonymous");
- }
-
- /* compute hash value and return it if secured flag has been set */
- if (secured)
- {
- try
- {
- String hashValue = hashComp.getHashValue(code);
- code.setHash(hashValue);
- result = hashValue;
- em.persist(code);
- }
- catch (NoSuchAlgorithmException e)
- {
- e.printStackTrace();
- return null;
- }
- }
- else
- {
- em.persist(code);
- result = new Integer(code.getId()).toString();
- }
-
- // System.out.println("Result: " + result);
-
- return result;
- }
-
- public Code getCode(String id)
- {
- boolean secured = true;
-
- try
- {
- Integer.parseInt(id);
- secured = false; /*
- * if it is possible to convert to number -> not
- * secured, otherwise -> secured
- */
- }
- catch (NumberFormatException e)
- {
- }
-
- if (secured)
- {
- Query q = em.createQuery("SELECT c FROM Code c WHERE hash = :hash");
- q.setParameter("hash", id);
- return (Code) q.getSingleResult();
- }
- else
- {
- Code c = em.find(Code.class, Integer.parseInt(id));
- /*
- * if somebody is trying to guess Id of secured code paste he cannot
- * pass
- */
- if (c.getHash() == null)
- {
- return c;
- }
- else
- {
- throw new EJBException("Access denied");
- }
- }
- }
-
- public List<Code> recentCodes()
- {
- Query q = em.createQuery("SELECT c FROM Code c WHERE hash=null ORDER BY datetime DESC ");
- q.setMaxResults(MAX_CODES);
- List<Code> codes = q.getResultList();
- return codes;
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public List<Code> allCodes()
- {
- Query q = em.createQuery("SELECT c FROM Code c WHERE hash=null ORDER BY datetime DESC ");
- List<Code> codes = q.getResultList();
- return codes;
- }
-
- /**
- * getting codes from database needs new transaction so that we can further
- * modify returned Codes without affecting database (when we call this
- * function from another session bean
- */
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public List<Code> searchCodes(Code code, int page, QueryInfo info)
- {
- StringBuilder sb = new StringBuilder();
-
- String delim = "";
- if (!code.getUser().trim().equals(""))
- {
- sb.append("c.user = \'" + code.getUser().trim().toLowerCase() + "\'");
- delim = " AND";
- }
- if (!code.getLanguage().trim().equals(""))
- {
- sb.append(delim).append(" c.language = \'" + code.getLanguage().trim().toLowerCase() + "\'");
- delim = " AND";
- }
- if (!code.getNote().trim().equals(""))
- {
- sb.append(delim).append(" c.note LIKE \'%" + code.getNote().trim().toLowerCase() + "%\'");
- delim = " AND";
- }
- if (!code.getText().trim().equals(""))
- {
- sb.append(delim).append(" c.text LIKE \'%" + code.getText().toLowerCase() + "%\'");
- delim = " AND";
- }
- if (code.getDatetime() != null)
- {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
- Date date2 = new Date();
- date2.setTime(code.getDatetime().getTime() + 24 * 60 * 60 * 1000); // +1
- // day
-
- String formattedDate1 = formatter.format(code.getDatetime());
- String formattedDate2 = formatter.format(date2);
-
- sb.append(delim).append(" c.datetime between \'" + formattedDate1 + "\' and \'" + formattedDate2 + "\'");
- delim = " AND";
- }
-
- if (sb.toString().length() == 0)
- sb.append("1 = \'1\'");
-
- Query q = em.createQuery("SELECT c FROM Code c WHERE hash=null AND " + sb.toString() + " ORDER BY datetime DESC");
- int allRecords = q.getResultList().size();
- q.setFirstResult(page * PAGE_SIZE);
- q.setMaxResults(PAGE_SIZE);
- List<Code> codes = q.getResultList();
-
- info.setPage(page);
- info.setRecordsCount(allRecords);
- info.setPagesCount(allRecords / PAGE_SIZE);
-
- return codes;
- }
-}
More information about the weld-commits
mailing list