com.mizar.faces.jpa.facade
Class FacesCollection

java.lang.Object
  extended by com.mizar.persistence.jpa.facade.JPAFacade
      extended by com.mizar.faces.jpa.facade.FacesCollection
Direct Known Subclasses:
BasemapSetCollection, TrinidadCollection

public class FacesCollection
extends JPAFacade


Field Summary
protected  RowInterface currentRow
           
protected  java.util.List<RowInterface> list
           
protected  RowInterface previousRow
           
protected  java.util.List<RowInterface> selectionList
           
 
Fields inherited from class com.mizar.persistence.jpa.facade.JPAFacade
em, emf, model, persistenceUnitName, schemaName, sequencesValidated, silent, verbose
 
Constructor Summary
FacesCollection()
           
FacesCollection(java.lang.String persistenceUnitName)
           
 
Method Summary
 void clearList()
           
 void closeEm()
           
 javax.persistence.Query createNamedQuery(java.lang.String name)
           
 javax.persistence.Query createNativeQuery(java.lang.String sqlString)
           
 javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
           
 javax.persistence.Query createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
           
 javax.persistence.Query createQuery(java.lang.String sqlString)
           
 boolean decrementPosition(int index)
           
 int decrementPosition(RowInterface row)
          This method will only work as expected if there is only one occurrence of row in list
 void downloadFile(javax.faces.event.ActionEvent ae)
          NOTE: must be called with partialSubmit="false" or will fail badly The method writes a file to the output stream
 void exportToExcel(javax.faces.event.ActionEvent ignored)
          NOTE: must be called with partialSubmit="false" or will fail badly The method converts the list to a spreadsheet and writes it to output stream
<T> T
find(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
           
 RowInterface getBean(javax.faces.component.UIComponent uic)
          This method requires that the component have an <f:attribute name='pkey' value='something'>.
 java.lang.Class getBeanClass()
           
 GenericBean getBeanFromRow(RowInterface row)
           
 java.util.List<GenericBean> getBeanList()
           
protected  java.lang.String getClassNameRoot()
           
 RowMutable getCurrentMutableRow()
          This is a variation on getCurrentRow() that returns a RowMutable but only if the Collection RowClass implements RowMutable
 RowInterface getCurrentRow()
           
 javax.persistence.EntityManager getEm()
           
 int getEmScope()
          Do not change default of EmScope.SESSION
 java.lang.String getExportName()
           
 oracle.spatial.geometry.JGeometry getGeom(RowInterface thisRow)
           
 java.util.List<RowInterface> getList()
           
 int getListSize()
           
 java.lang.String getManagedBeanName()
           
 long getMaxDownloadSize()
           
 int getMaxResults()
           
<T> T
getReference(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
           
 java.util.List getResultList()
           
 java.lang.Class getRowClass()
          Returns the rowClass as previously set or as infered from the name of the implementing TableClass.
 java.lang.reflect.Constructor getRowConstructor()
           
 RowInterface getRowSQL(java.lang.String sql, java.lang.Class resultClass)
          The method does a Query.setMaxResults(1) to ensure that only one row is returned.
 java.util.List<RowInterface> getSelectionList()
           
 java.lang.Object getSingleResult()
           
 javax.persistence.Query getTrackedQuery()
           
 boolean getTruncatedList()
           
 java.lang.Object getValue(java.lang.String property)
           
 boolean incrementPosition(int index)
           
 int incrementPosition(RowInterface row)
          This method will only work as expected if there is only one occurrence of row in list
 boolean isDefaultRowConstructor()
           
 java.lang.Boolean isFileDownloadable(java.lang.String fileName)
           
 boolean isListDirty()
           
 boolean isSelectionListDirty()
           
protected  void maxResultsOff()
           
protected  void maxResultsOff(int newMax)
           
protected  int maxResultsOn()
           
 RowInterface newRow()
          This method is called indirectly by SessionConstants.getEmf() as per a RowFactory so that GenericBeans are wrapped in their associated RowInterface classes.
 RowInterface newRow(java.lang.Object bean)
          Currently this only supports creating a new RowInterface instance from an Entity bean that is a direct superclass of the RowInterface, thus RowInterfaces cannot be extended.
 RowInterface refresh(RowInterface row)
           
 RowInterface refreshBean(RowInterface row)
          Refreshs a row from the database
 RowInterface resetCurrentRow()
           
 java.util.List<RowInterface> selectRows(javax.persistence.Query query, java.util.Map<java.lang.String,java.lang.Object> parameters)
           
 java.util.List<RowInterface> selectRows(javax.persistence.Query query, java.lang.Object[] parameters)
           
 java.util.List<RowInterface> selectRowsExpression(org.eclipse.persistence.expressions.Expression expression, java.lang.String orderBy)
           
 java.util.List<RowInterface> selectRowsExpression(org.eclipse.persistence.expressions.Expression expression, java.lang.String orderBy, java.lang.Class resultClass)
           
 java.util.List<RowInterface> selectRowsJPQL(java.lang.String jpql)
          Never pass unsanitized jpql to this method.
 java.util.List<RowInterface> selectRowsJPQL(java.lang.String jpql, java.util.Map<java.lang.String,java.lang.Object> parameters)
           
 java.util.List<RowInterface> selectRowsJPQL(java.lang.String property, java.lang.Object value)
           
 java.util.List<RowInterface> selectRowsJPQL(java.lang.String jpql, java.lang.Object[] parameters)
           
 java.util.List<RowInterface> selectRowsSQL(java.lang.String sql)
          Never pass unsanitized sql to this method.
 java.util.List<RowInterface> selectRowsSQL(java.lang.String sql, java.lang.Class resultClass)
          Never pass unsanitized sql to this method.
 java.util.List<RowInterface> selectRowsSQL(java.lang.String sql, java.lang.Class resultClass, java.util.Map<java.lang.String,java.lang.Object> parameters)
           
 java.util.List<RowInterface> selectRowsSQL(java.lang.String sql, java.lang.Class resultClass, java.lang.Object[] parameters)
           
 java.util.List<RowInterface> selectRowsSQL(java.lang.String sql, java.util.Map<java.lang.String,java.lang.Object> parameters)
           
 java.util.List<RowInterface> selectRowsSQL(java.lang.String sql, java.lang.Object[] parameters)
           
 void setBeanClass(java.lang.Class beanClass)
           
 void setCurrentRow(javax.faces.event.ActionEvent ae)
           
 void setCurrentRow(org.apache.myfaces.trinidad.event.LaunchEvent le)
           
 void setCurrentRow(RowInterface row)
           
 void setCurrentRow(javax.faces.component.UIComponent uic)
          The method looks at the uic for an attribute with a name of 'pkey' and uses that to find the current instance of that bean.
 void setDefaultRowConstructor(boolean defaultRowConstuctor)
           
 void setEmScope(int emScope)
           
 void setExportName(java.lang.String exportName)
           
 void setList(GenericBean bean)
           
 void setList(java.util.List<RowInterface> newList)
           
 void setList(RowInterface bean)
           
 void setListDirty(boolean dirtyList)
           
 void setManagedBeanName(java.lang.String managedBeanName)
           
 void setMaxDownloadSize(long maxDownloadSize)
           
 void setMaxResults(int maxResults)
           
protected  void setRowClass(java.lang.Class rowClass)
          If any implementing table class supports a row class with a name that is not the same (except for Row and Table) then this method should be called in its constructor.
 void setRowConstructor(java.lang.reflect.Constructor rowConstructor)
           
 void setSelectionList(java.util.List<RowInterface> selectionList)
           
 void setSelectionListDirty(boolean selectionListDirty)
           
 void setTrackedQuery(javax.persistence.Query trackedQuery)
           
 
Methods inherited from class com.mizar.persistence.jpa.facade.JPAFacade
closeEm, closeEmf, executeDDL, executeNativeUpdate, executeNativeUpdate, executeUpdate, getClosableConnectionAccessor, getConnection, getConnection, getEm, getEmf, getEmf, getLogger, getPassword, getPassword, getPersistenceUnitName, getSchemaName, getSequencesValidated, getSid, getSilent, getTableName, getToleratedErrorCodes, getUrl, getUser, getVerbose, mergeBean, persist, persistBean, printAnyBean, queryTester, queryTester, refreshBean, remove, removeBean, removeBean, setEmf, setPersistenceUnitName, setSilent, setToleratedErrorCodes, setVerbose, validateSequences
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

protected java.util.List<RowInterface> list

selectionList

protected java.util.List<RowInterface> selectionList

currentRow

protected RowInterface currentRow

previousRow

protected RowInterface previousRow
Constructor Detail

FacesCollection

public FacesCollection()

FacesCollection

public FacesCollection(java.lang.String persistenceUnitName)
Method Detail

setSelectionList

public void setSelectionList(java.util.List<RowInterface> selectionList)

getSelectionList

public java.util.List<RowInterface> getSelectionList()

getList

public java.util.List<RowInterface> getList()

getListSize

public final int getListSize()

getTruncatedList

public boolean getTruncatedList()

clearList

public void clearList()

decrementPosition

public int decrementPosition(RowInterface row)
This method will only work as expected if there is only one occurrence of row in list

Parameters:
row - an object that is assumed to exist in list
Returns:
the new index in list of row

incrementPosition

public int incrementPosition(RowInterface row)
This method will only work as expected if there is only one occurrence of row in list

Parameters:
row - an object that is assumed to exist in list
Returns:
the new index in list of row

decrementPosition

public boolean decrementPosition(int index)

incrementPosition

public boolean incrementPosition(int index)

setListDirty

public void setListDirty(boolean dirtyList)

isListDirty

public boolean isListDirty()

setSelectionListDirty

public void setSelectionListDirty(boolean selectionListDirty)

isSelectionListDirty

public boolean isSelectionListDirty()

newRow

public RowInterface newRow(java.lang.Object bean)
Currently this only supports creating a new RowInterface instance from an Entity bean that is a direct superclass of the RowInterface, thus RowInterfaces cannot be extended. This should be corrected.

Parameters:
bean -
Returns:

setMaxDownloadSize

public void setMaxDownloadSize(long maxDownloadSize)

getMaxDownloadSize

public long getMaxDownloadSize()

maxResultsOff

protected void maxResultsOff(int newMax)

maxResultsOff

protected void maxResultsOff()

maxResultsOn

protected int maxResultsOn()

setRowClass

protected final void setRowClass(java.lang.Class rowClass)
If any implementing table class supports a row class with a name that is not the same (except for Row and Table) then this method should be called in its constructor. If SomeTable manages SomeRow classes then this does not need to be called as getRowClass will infer it.

Parameters:
rowClass -
See Also:
getRowClass()

getRowClass

public final java.lang.Class getRowClass()
Returns the rowClass as previously set or as infered from the name of the implementing TableClass.

Example:

If the table class name is com.mizar.components.SomeTable the returned class will be com.mizar.components.SomeRow If the implementing Table class manages Rows with a different name, then the caller must explicitly setRowClass(SomeRow.class)

Returns:
the Row class that this Table class manages collections of

setList

public void setList(RowInterface bean)

setList

public void setList(GenericBean bean)

setList

public void setList(java.util.List<RowInterface> newList)

setMaxResults

public void setMaxResults(int maxResults)

getMaxResults

public int getMaxResults()

getBeanList

public java.util.List<GenericBean> getBeanList()

setCurrentRow

public void setCurrentRow(javax.faces.component.UIComponent uic)
The method looks at the uic for an attribute with a name of 'pkey' and uses that to find the current instance of that bean.

Parameters:
uic -

setCurrentRow

public void setCurrentRow(javax.faces.event.ActionEvent ae)
Parameters:
ae - an ActionEvent
See Also:
setCurrentRow(UIComponent)

setCurrentRow

public void setCurrentRow(org.apache.myfaces.trinidad.event.LaunchEvent le)
Parameters:
le - a launchEvent
See Also:
setCurrentRow(UIComponent)

setCurrentRow

public void setCurrentRow(RowInterface row)

getCurrentRow

public RowInterface getCurrentRow()

resetCurrentRow

public RowInterface resetCurrentRow()

getCurrentMutableRow

public RowMutable getCurrentMutableRow()
This is a variation on getCurrentRow() that returns a RowMutable but only if the Collection RowClass implements RowMutable

Returns:
the currentRow if the rowClass implements RowMutable otherwise it returns null

getGeom

public oracle.spatial.geometry.JGeometry getGeom(RowInterface thisRow)

getBean

public RowInterface getBean(javax.faces.component.UIComponent uic)
This method requires that the component have an <f:attribute name='pkey' value='something'>. It makes a fair attempt to convert the primary key value passed to the correct object name required for the EntityManger.find(Class,Object) call but this has not been exhaustively tested.

Parameters:
uic -
Returns:

getBeanFromRow

public GenericBean getBeanFromRow(RowInterface row)

getClassNameRoot

protected final java.lang.String getClassNameRoot()
Returns:
the root name of this class, formed by stripping off the leading "Table" from the simple name.

getBeanClass

public final java.lang.Class getBeanClass()
Returns:
the superclass of getRowClass()
See Also:
getRowClass()

getValue

public java.lang.Object getValue(java.lang.String property)
Parameters:
property -
Returns:
the value of the property
See Also:
ReflectUtils.getValue(java.lang.Object, java.lang.String)

selectRows

public java.util.List<RowInterface> selectRows(javax.persistence.Query query,
                                               java.util.Map<java.lang.String,java.lang.Object> parameters)

selectRows

public java.util.List<RowInterface> selectRows(javax.persistence.Query query,
                                               java.lang.Object[] parameters)

selectRowsJPQL

public java.util.List<RowInterface> selectRowsJPQL(java.lang.String jpql,
                                                   java.util.Map<java.lang.String,java.lang.Object> parameters)

selectRowsJPQL

public java.util.List<RowInterface> selectRowsJPQL(java.lang.String jpql,
                                                   java.lang.Object[] parameters)

selectRowsJPQL

public java.util.List<RowInterface> selectRowsJPQL(java.lang.String property,
                                                   java.lang.Object value)
Parameters:
property - a valid property of beanClass. If null or empty then results will not be ordered.
value - a valid value of the correct type for beanClass.property. May contain wild card characters.
Returns:
a list of all the instances of beanClass matching the property value ordered by the property.

selectRowsJPQL

public java.util.List<RowInterface> selectRowsJPQL(java.lang.String jpql)

Never pass unsanitized jpql to this method.

The results are limited to {@link #getMaxResults the value of the maxResults property.

Parameters:
jpql - a JPQL query
Returns:
the results of the query

selectRowsSQL

public java.util.List<RowInterface> selectRowsSQL(java.lang.String sql,
                                                  java.lang.Class resultClass,
                                                  java.util.Map<java.lang.String,java.lang.Object> parameters)

selectRowsSQL

public java.util.List<RowInterface> selectRowsSQL(java.lang.String sql,
                                                  java.lang.Class resultClass,
                                                  java.lang.Object[] parameters)

selectRowsSQL

public java.util.List<RowInterface> selectRowsSQL(java.lang.String sql,
                                                  java.lang.Class resultClass)

Never pass unsanitized sql to this method.

The results are limited to {@link #getMaxResults the value of the maxResults property.

Parameters:
sql - an SQL query
resultClass - the GenericBean class to return
Returns:
the results of the query.

selectRowsSQL

public java.util.List<RowInterface> selectRowsSQL(java.lang.String sql,
                                                  java.util.Map<java.lang.String,java.lang.Object> parameters)

selectRowsSQL

public java.util.List<RowInterface> selectRowsSQL(java.lang.String sql,
                                                  java.lang.Object[] parameters)

selectRowsSQL

public java.util.List<RowInterface> selectRowsSQL(java.lang.String sql)

Never pass unsanitized sql to this method.

The results are limited to #getMaxResults the value of the maxResults property. The method finds rows using {@link #getBeanClass beanClass}.

Parameters:
sql - an SQL query
Returns:
the results of the query.

selectRowsExpression

public java.util.List<RowInterface> selectRowsExpression(org.eclipse.persistence.expressions.Expression expression,
                                                         java.lang.String orderBy,
                                                         java.lang.Class resultClass)
Parameters:
expression -
orderBy -
resultClass -
Returns:

selectRowsExpression

public java.util.List<RowInterface> selectRowsExpression(org.eclipse.persistence.expressions.Expression expression,
                                                         java.lang.String orderBy)
Parameters:
expression -
orderBy -
Returns:
See Also:
Expression

getRowSQL

public RowInterface getRowSQL(java.lang.String sql,
                              java.lang.Class resultClass)
The method does a Query.setMaxResults(1) to ensure that only one row is returned. It is the responsibility of the caller to ensure that the SQL should only return one row.

Parameters:
sql - an SQL query
resultClass - the GenericBean class to return
Returns:
a single RowInterface

setBeanClass

public void setBeanClass(java.lang.Class beanClass)

setManagedBeanName

public void setManagedBeanName(java.lang.String managedBeanName)

getManagedBeanName

public java.lang.String getManagedBeanName()

setExportName

public void setExportName(java.lang.String exportName)

getExportName

public java.lang.String getExportName()

setRowConstructor

public void setRowConstructor(java.lang.reflect.Constructor rowConstructor)

getRowConstructor

public java.lang.reflect.Constructor getRowConstructor()

setDefaultRowConstructor

public void setDefaultRowConstructor(boolean defaultRowConstuctor)

isDefaultRowConstructor

public boolean isDefaultRowConstructor()

newRow

public RowInterface newRow()
This method is called indirectly by SessionConstants.getEmf() as per a RowFactory so that GenericBeans are wrapped in their associated RowInterface classes. This provides the ability to associate Faces methods with the GenericBeans while isolating the GenericBeans from the presentation layer.

Returns:
a RowInteface wrapper for a GenericBean
See Also:
SessionConstants.getBeanTableMap(), SessionConstants.getEmf(), RowFactory

setEmScope

public void setEmScope(int emScope)

getEmScope

public int getEmScope()

Do not change default of EmScope.SESSION

The Scope of the entity manager might be EmScope.COLLECTION, EmScope.SESSION, or EmScope.APPLICATION

The concept of an EmScope.APPLICATION is conceived of, but not implemented, because of the fear that the application scope would either

  1. result in a very large cache requirement, or
  2. cause the cache to be blown out by many uses attempting to cache entity beans.
Of course, this might all be foolishness and an APPLICATION scoped entity manager might be a fine idea, but we're not ready to test it yet.

Returns:
the default scope of the entity manager

refresh

public RowInterface refresh(RowInterface row)

refreshBean

public RowInterface refreshBean(RowInterface row)
Refreshs a row from the database

Parameters:
row -

getEm

public javax.persistence.EntityManager getEm()
Overrides:
getEm in class JPAFacade
Returns:

closeEm

public void closeEm()
Overrides:
closeEm in class JPAFacade

exportToExcel

public void exportToExcel(javax.faces.event.ActionEvent ignored)
NOTE: must be called with partialSubmit="false" or will fail badly The method converts the list to a spreadsheet and writes it to output stream

Parameters:
ignored -
See Also:
FacesUtils.getExcelFromList(java.util.List), ServletUtils#sendOutputStream(ByteArrayOutputStream,String)

isFileDownloadable

public java.lang.Boolean isFileDownloadable(java.lang.String fileName)

downloadFile

public void downloadFile(javax.faces.event.ActionEvent ae)
NOTE: must be called with partialSubmit="false" or will fail badly The method writes a file to the output stream

Parameters:
ae -
See Also:
FacesUtils.getExcelFromList(java.util.List), ServletUtils.sendFile(java.lang.String)

setTrackedQuery

public void setTrackedQuery(javax.persistence.Query trackedQuery)

getTrackedQuery

public javax.persistence.Query getTrackedQuery()

createNamedQuery

public javax.persistence.Query createNamedQuery(java.lang.String name)
Parameters:
name -
Returns:
See Also:
EntityManager.createNamedQuery(String)

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString)
Parameters:
sqlString -
Returns:
See Also:
EntityManager.createNativeQuery(String)

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString,
                                                 java.lang.Class resultClass)
Parameters:
sqlString -
resultClass -
Returns:
See Also:
EntityManager.createNativeQuery(String, Class)

createNativeQuery

public javax.persistence.Query createNativeQuery(java.lang.String sqlString,
                                                 java.lang.String resultSetMapping)
Parameters:
sqlString -
resultSetMapping -
Returns:
See Also:
EntityManager.createNativeQuery(String, String)

createQuery

public javax.persistence.Query createQuery(java.lang.String sqlString)
Parameters:
sqlString -
Returns:
See Also:
EntityManager.createQuery(String)

find

public <T> T find(java.lang.Class<T> entityClass,
                  java.lang.Object primaryKey)
Type Parameters:
T -
Parameters:
entityClass -
primaryKey -
Returns:
See Also:
EntityManager.find(java.lang.Class, java.lang.Object)

getReference

public <T> T getReference(java.lang.Class<T> entityClass,
                          java.lang.Object primaryKey)
Type Parameters:
T -
Parameters:
entityClass -
primaryKey -
Returns:
See Also:
EntityManager.getReference(java.lang.Class, java.lang.Object)

getResultList

public java.util.List getResultList()
Returns:
See Also:
Query.getResultList()

getSingleResult

public java.lang.Object getSingleResult()
Returns:
See Also:
Query.getSingleResult()