⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachmentmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    /**     * Deletes all the temporary attachements spawned by the same process.     *     * @param processID process ID     * @param ls LogonSession object     */    public void deleteTempAttachments( LogonSession ls, long processID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        // Delete the temp attachments.        try {            List hnds = AttachmentTempObjectHandler.selectByProcessID( jeoManager, ls, processID );            if( hnds != null ) {                DEBUG( "Found " + hnds.size() + " temp attachments..." );                for( int i = 0; i < hnds.size(); i++ ) {                    JEObjectHandler hnd = ( JEObjectHandler ) hnds.get( i );                    hnd.remove();                    hnd.commit();                }            }        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Process temp attachment deleted (process ID = " + processID + ") at " + time + " ms." );        }    }    // ========================================== Regular attachments management    /**     * Makes a new regular attachment from the temporary one.     * The temporary attachment is deleted after use.     *     * @param ls LogonSession object     * @param tempAttachID temporary attachment ID     * @return ID new attachment ID     */    public long addAttachment( LogonSession ls, long tempAttachID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        long attachID = EMPTY_NUMBER;        try {            // Get the temp attachement.            JEObjectHandler tmpHnd = AttachmentTempObjectHandler.selectByPkey( jeoManager, ls, tempAttachID );            if( tmpHnd == null ) {                WARN( "Can't get temporary attachment by ID = " + tempAttachID );                return attachID;            }            AttachmentTempObject tmpObj = ( AttachmentTempObject ) tmpHnd.getJEObject();            // Create a new regular attachement.            JEObjectHandler attHnd = jeoManager.create( ls, AttachmentObjectHandler.class );            AttachmentObject attObj = ( AttachmentObject ) attHnd.getJEObject();            attObj.setProcess_id( tmpObj.getProcess_id() );            attObj.setFilename( tmpObj.getFilename() );            attObj.setFiletype( tmpObj.getFiletype() );            attObj.setFileext( tmpObj.getFileext() );            attObj.setCreated( tmpObj.getCreated() );            attObj.setData( tmpObj.getData() );            attObj.setUser_id( tmpObj.getUser_id() );            attHnd.commit();            attachID = attObj.getAttachment_id().longValue();            // Delete the temp attachment used.            tmpHnd.remove();            tmpHnd.commit();        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Attachment added (ID = " + attachID + ") at " + time + " ms." );        }        return attachID;    }    /**     * Makes new regular attachments from all temporary ones spawned by     * the same process. The temporary attachments are deleted after use.     *     * @param ls LogonSession object     * @param processID process ID to filter temporary attachments     * @return new attachments IDs array (might be empty)     */    public HashMap addAttachments( LogonSession ls, long processID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        long[] attachIDs = EMPTY_ID_ARRAY;        HashMap resultList = new HashMap();        try {            // Get the temp attachements by the process ID.            List tmpHnds = AttachmentTempObjectHandler.selectByProcessID( jeoManager, ls, processID );            if( tmpHnds == null || tmpHnds.isEmpty() ) {                WARN( "No temporary attachments found for process ID = " + processID );                return resultList;            }            int size = tmpHnds.size();            DEBUG( "Found " + size + " temp attachments..." );            attachIDs = new long[size];            for( int i = 0; i < size; i++ ) {                // Get the next temp attachement.                AttachmentTempObjectHandler tmpHnd = ( AttachmentTempObjectHandler ) tmpHnds.get( i );                AttachmentTempObject tmpObj = ( AttachmentTempObject ) tmpHnd.getJEObject();                // Create a new attachement from the temp one.                JEObjectHandler attHnd = jeoManager.create( ls, AttachmentObjectHandler.class );                AttachmentObject attObj = ( AttachmentObject ) attHnd.getJEObject();                attObj.setProcess_id( tmpObj.getProcess_id() );                attObj.setFilename( tmpObj.getFilename() );                attObj.setFiletype( tmpObj.getFiletype() );                attObj.setFileext( tmpObj.getFileext() );                attObj.setCreated( tmpObj.getCreated() );                attObj.setData( tmpObj.getData() );                attObj.setUser_id( tmpObj.getUser_id() );                attHnd.commit();                attachIDs[i] = attObj.getAttachment_id().longValue();                resultList.put(attObj.getAttachment_id(), tmpObj.getFilename());            } // for( int i = 0; i < size; i++ )        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Process attachment added (process ID = " + processID + ") at " + time + " ms." );        }        return resultList;    } // addAttachments( LogonSession, long ) : HashMap    /**     * Gets the attachement by its ID.     *     * @param ls LogonSession object     * @param attachID attachment ID     * @return attachment value object, or <b>null</b> if not found     */    public AttachmentObject getAttachment( LogonSession ls, long attachID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        // Get the attachment.        AttachmentObject obj = null;        try {            JEObjectHandler hnd = AttachmentObjectHandler.selectByPkey( jeoManager, ls, attachID );            if( hnd != null ) {                obj = ( AttachmentObject ) hnd.getJEObject();            } else {                INFO( "No attachments found for ID = " + attachID );                return obj;            }        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Got attachment (ID = " + attachID + ") at " + time + " ms." );        }        return obj;    }    /**     * Gets the attachement by the Process Id and file name.     *     * @param ls LogonSession object     * @param processID process ID     * @param fileName attachment file name     * @return attachment value object, or <b>null</b> if not found     */    public AttachmentObject getAttachment( LogonSession ls, long processID, String fileName ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        // Get the attachment.        AttachmentObject obj = null;        try {            JEObjectHandler hnd = AttachmentObjectHandler.selectByProcessFName( jeoManager, ls, processID, fileName );            if( hnd != null ) {                obj = ( AttachmentObject ) hnd.getJEObject();            } else {                INFO( "No attachments found for ProcessID = " + processID +                        " and file name = " + fileName);                return obj;            }        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Got attachment (ProcessID = " + processID + " and File Name = " + fileName + ") at " + time + " ms." );        }        return obj;    }    /**     * Gets all the attachements spawned by the same process.     *     * @param processID process ID     * @param ls LogonSession object     * @return array of attachment value objects (might be empty)     */    public AttachmentObject[] getAttachments( LogonSession ls, long processID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        // Get attachments.        ArrayList list = new ArrayList();        try {            List hnds = AttachmentObjectHandler.selectByProcessID( jeoManager, ls, processID );            if( hnds != null ) {                for( int i = 0; i < hnds.size(); i++ ) {                    AttachmentObjectHandler hnd = ( AttachmentObjectHandler ) hnds.get( i );                    AttachmentObject obj = ( AttachmentObject ) hnd.getJEObject();                    DEBUG( "Got attachment '" + obj.getFilename() + "'" );                    list.add( obj );                }            }        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Got attachments by the process (process ID = " + processID + ") at " + time + " ms." );        }        return( list.size() == 0 )            ? EMPTY_ATTACH_ARRAY            : ( AttachmentObject[] ) list.toArray( new AttachmentObject[0] );    }    /**     * Deletes the attachement.     *     * @param attachID attachment ID     * @param ls LogonSession object     */    public void deleteAttachment( LogonSession ls, long attachID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        // Delete the temp attachment.        try {            JEObjectHandler hnd = AttachmentObjectHandler.selectByPkey( jeoManager, ls, attachID );            if( hnd != null ) {                hnd.remove();                hnd.commit();            }        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Attachment deleted (ID = " + attachID + ") at " + time + " ms." );        }    }    /**     * Deletes all attachements spawned by the same process.     * @param processID process ID     * @param ls LogonSession object     */    public void deleteAttachments( LogonSession ls, long processID ) {        // Initialization.        long time = System.currentTimeMillis();        JEOManagerLocal jeoManager = getJEOManager();        // Delete the attachments.        try {            List hnds = AttachmentObjectHandler.selectByProcessID( jeoManager, ls, processID );            if( hnds != null ) {                DEBUG( "Found " + hnds.size() + " attachments..." );                for( int i = 0; i < hnds.size(); i++ ) {                    JEObjectHandler hnd = ( JEObjectHandler ) hnds.get( i );                    hnd.remove();                    hnd.commit();                }            }        } catch( EQLException ex ) {            throwException( ex );        }        // Ok.        if( getLogger().isInfoEnabled() ) {            time = System.currentTimeMillis() - time;            INFO( "Process attachment deleted (process ID = " + processID + ") at " + time + " ms." );        }    }    // ========================================================= Private methods    // Gets file extension.    private String getFileExt( String fileName, String fileType ) {        /** @todo detect file extension by the file type */        String fileExt = null;        int pos = fileName.lastIndexOf( "." );        if( pos >= 0 && pos < ( fileName.length() - 1 ) ) {            fileExt = fileName.substring( pos + 1 ).toLowerCase();            if( fileExt.length() > EXT_LENGTH ) {                fileExt = null;            }        }        return fileExt;    }    // Gets the JEO Manager EJB local interface.    private JEOManagerLocal getJEOManager() {        return( JEOManagerLocal ) getLocalObject( JNDINames.JEOManager, JEOManagerLocalHome.class );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -