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

📄 lockmanagerejb.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    /**     * Unlock all records using sessoin id from logon session     * @param ls logon session     */    public void unlock( LogonSession ls ) {        // Initialization        SqlWrapper sqlW = getSqlWrapper();        // Build SQL to delete lock.        StringBuffer sql = new StringBuffer( "DELETE FROM QX_LOCK WHERE SESSION_ID = ?" );        // Execute SQL.        Connection con = null;        PreparedStatement ps = null;        try {            con = sqlW.doConnection();            ps = sqlW.doPreparedStatement( con, sql.toString() );            ps.setString( 1, ls.getSessionID() );            sqlW.executeUpdate( ps );        } catch( SQLException ex ) {            throwException( "Cannot unlock record(s). Status code: " +                            ex.getErrorCode() + ".", ex );        } finally {            sqlW.closeConnection( con, ps );        }    }    /**     * Update locks time     * @param eqlRes EQLERes response     * @param ls logon session     */    public void ping( EQLERes eqlRes, LogonSession ls ) {        /** @todo implement it */    }    // ----------------------------------------------------- private methods    //    // Build select conditions.    //    private String getSelectCondition( List<LockStructure> lockStructList ) {        StringBuffer sql = new StringBuffer();        for( int i = 0; i < lockStructList.size(); i++ ) {            LockStructure lockStruct = lockStructList.get( i );            String recordId1 = lockStruct.recordIds.get( 0 );            String recordId2 = lockStruct.recordIds.get( 1 );            String recordId3 = lockStruct.recordIds.get( 2 );            String recordId4 = lockStruct.recordIds.get( 3 );            if( i > 0 ) {                sql.append( " OR " );            }            sql.append( "(" );            sql.append( "TABLE_NAME = '" ).append( lockStruct.tableName ).append( "'" );            sql.append( " AND " );            sql.append( "RECORD_ID = '" ).append( recordId1 ).append( "'" );            if( !recordId2.equals( NULL_VALUE ) ) {                sql.append( " AND " );                sql.append( "RECORD_ID2 = '" ).append( recordId2 ).append( "'" );            }            if( !recordId3.equals( NULL_VALUE ) ) {                sql.append( " AND " );                sql.append( "RECORD_ID3 = '" ).append( recordId3 ).append( "'" );            }            if( !recordId4.equals( NULL_VALUE ) ) {                sql.append( " AND " );                sql.append( "RECORD_ID4 = '" ).append( recordId4 ).append( "'" );            }            sql.append( ")" );        }        return sql.toString();    }    //    // Build EQLLockException object by LockLocal    //    private EQLLockException buildLockException( LogonSession ls, LockStructure lockStruct ) {        // get user parameters        String loginName = null;        String userType = null;        User user = null;        if( lockStruct.user != null ) {            try {                user = AccessRightsManager.getUser(lockStruct.user);            } catch( NoSuchUserException ex ) {                WARN( "User for lock not found: " + ex.getMessage() );            }        }        if( user != null ) {            loginName = user.getLoginName();            userType = String.valueOf(user.getAuthenticationType());        }        // get focus parameters        String focusName = null;        if( lockStruct.focus != null ) {            CaptionManagerLocal local = getCaptionManagerLocal();            focusName = local.getFocusCaption( ls.getUser().getLangID(),                                               lockStruct.focus );        }        // create exception        EQLLockException ex =            new EQLLockException( loginName,                                  userType,                                  focusName,                                  lockStruct.focusInstance );        return ex;    }    // --------------------------------------------------------------- private static methods    //    // Get list of LockStructure objects for entire EQLRes    //    private static List<LockStructure> buildLockStructures( LogonSession ls, EQLERes eqlRes, EQLResRecord record ) {        return buildLockStructures( ls, eqlRes, record, null, null );    }    private static List<LockStructure> buildLockStructures( LogonSession ls, EQLERes eqlRes ) {        return buildLockStructures( ls, eqlRes, null );    }    //    // Get list of LockStructure objects for entire EQLRes    //    private static List<LockStructure> buildLockStructures( LogonSession ls,                                             EQLERes eqlRes,                                             EQLResRecord record,                                             String focusId,                                             Long focusInstance ) {        List<LockStructure> ret = new ArrayList<LockStructure>();        buildLockStructures( ls, eqlRes, record, focusId, focusInstance, ret );        return ret;    }    //    // Get list of LockStructure objects for entire EQLRes (special method)    //    private static void buildLockStructures( LogonSession ls,                                             EQLERes eqlRes,                                             EQLResRecord record,                                             String focusId,                                             Long focusInstance,                                             List<LockStructure> ret ) {        // Build LockStructure object in cycle        int records = 0;        EQLResRecord[] recordsArray;        if( record == null ) {            records = eqlRes.size();            recordsArray = ( EQLResRecord[] ) eqlRes.getRecords().toArray( new EQLResRecord[0] );        } else {            records = 1;            recordsArray = new EQLResRecord[] {record};        }        for( int i = 0; i < records; i++ ) {            EQLResRecord eqlResRecord = recordsArray[i];            if( eqlResRecord.isNew() ) {                // Don't lock new record.                continue;            }            if( eqlResRecord.doDelete() ) {                // Don't lock record for deletion.                continue;            }            LockStructure lockStruct =                LockStructure.build( eqlRes,                                     eqlResRecord,                                     ls,                                     focusId,                                     focusInstance );            ret.add( lockStruct );            // Build LockStructure for datasets in cycle            int datasets = eqlResRecord.getDResSize();            for( int j = 0; j < datasets; j++ ) {                EQLDRes dRes = eqlResRecord.getDRes( j );                buildLockStructures( ls, dRes, null, focusId, focusInstance, ret );            }        }    }    // --------------------------------------------------------------- inner class    private static class LockStructure {        private Long pkey;        private String tableName;        private List<String> recordIds = new ArrayList<String>( 4 );        private String session;        private String focus;        private Long focusInstance;        private Long user;        private Integer userType;        private Date created;        // Constructor.        public LockStructure( String tableName,                              List<String> recordIds,                              String session,                              String focus,                              Long focusInstance,                              Long user,                              Integer userType ) {            this.tableName = tableName;            this.recordIds = recordIds;            this.session = session;            this.focus = focus;            this.focusInstance = focusInstance;            this.user = user;            this.userType = userType;        }        //        // LockStructure builder        //        static LockStructure build( ResultSet rs )            throws SQLException {            String tableName = rs.getString( "TABLE_NAME" );            List<String> recordIds = new ArrayList<String>();            recordIds.add( rs.getString( "RECORD_ID" ) );            recordIds.add( rs.getString( "RECORD_ID2" ) );            recordIds.add( rs.getString( "RECORD_ID3" ) );            recordIds.add( rs.getString( "RECORD_ID4" ) );            String session = rs.getString( "SESSION_ID" );            String focus = rs.getString( "FOCUS_ID" );            Long focusInstance = null;            long l = rs.getLong( "FOCUS_INSTANCE" );            if( !rs.wasNull() ) {                focusInstance = l;            }            Long user = null;            l = rs.getLong( "USER_ID" );            if( !rs.wasNull() ) {                user = l;            }            Integer userType = null;            int i = rs.getInt( "USER_TYPE_ID" );            if( !rs.wasNull() ) {                userType = i;            }            LockStructure lockStruct =                new LockStructure( tableName,                                   recordIds,                                   session,                                   focus,                                   focusInstance,                                   user,                                   userType );            lockStruct.pkey = rs.getLong("PKEY");            lockStruct.created = rs.getTimestamp( "CREATED" );            return lockStruct;        }        //        // LockStructure builder        //        static LockStructure build( EQLERes eqlRes,                                    EQLResRecord eqlResRecord,                                    LogonSession ls,                                    String focus,                                    Long focusInstance ) {            LockStructure lockStruct =                new LockStructure( getBaseEntity( eqlRes ).getDbobject(),                                   getRecordIds( eqlResRecord ),                                   ls.getSessionID(),                                   focus,                                   focusInstance,                                   ls.getUser().getUserID(),                                   ls.getUser().getAuthenticationType());            return lockStruct;        }        //        // Checks if lock own        //        public boolean isOwn( LogonSession ls, String __focus, Long __focusInstance ) {            boolean isOwnLock =                ( ( this.session != null && this.session.equals( ls.getSessionID() ) ) ||                  ( this.session == null && ls.getSessionID() == null ) ) &&                ( ( __focus == null ) || ( this.focus != null && this.focus.equals( __focus ) ) ) &&                ( ( __focusInstance == null ) || ( this.focusInstance != null && this.focusInstance.equals( __focusInstance ) ) );            return isOwnLock;        }        //        // Equals method.        //        public boolean equals( Object o ) {            if( o == null || ! ( o instanceof LockStructure ) ) {                return false;            }            LockStructure lockStruct = ( LockStructure ) o;            return                ( lockStruct.tableName.equals( tableName ) ) &&                ( lockStruct.recordIds.equals( recordIds ) );        }        //        // Hash code method.        //        public int hashCode() {            return tableName.hashCode() | recordIds.hashCode();        }        //        // To string method.        //        public String toString() {            return                " pkey = " + pkey +                ", tableName = " + tableName +                ", recordIds = " + recordIds +                ", session = " + session +                ", focus = " + focus +                ", focusInstance = " + focusInstance +                ", user = " + user +                ", userType = " + userType +                ", created = " + created;        }        //        // Get base entity from EQL response        //        private static Entity getBaseEntity( EQLERes eqlRes ) {            Entity baseEntity = eqlRes.getEntity();            if( baseEntity == null ) {                throw new IllegalStateException( "Base entity not found" );            }            return baseEntity;        }        //        // Build array of 4 elements of record ids        //        private static List<String> getRecordIds( EQLResRecord eqlResRecord ) {            List<String> pkeyList = new ArrayList<String>();            int pkeys = 0;            for( int i = 0; i < eqlResRecord.size(); i++ ) {                EQLResCell eqlResCell = eqlResRecord.getResCell( i );                Efield field = eqlResCell.getReqField().getField();                if(field.getPkey()) {                    String value = eqlResCell.getEQLObject().toString();                    pkeyList.add( pkeys, value == null ? NULL_VALUE : value );                    pkeys++;                }            }            for( int i = pkeys; i < 4; i++ ) {                pkeyList.add( i, NULL_VALUE );            }            return pkeyList;        }    } // -- end inner class}

⌨️ 快捷键说明

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