📄 eqlmanagerejb.java
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.modules.eql.ejb;import com.queplix.core.error.ErrorHelper;import com.queplix.core.error.GenericSystemException;import com.queplix.core.integrator.security.LogonSession;import com.queplix.core.jxb.entity.Afterdelete;import com.queplix.core.jxb.entity.Afternew;import com.queplix.core.jxb.entity.Afterupdate;import com.queplix.core.jxb.entity.Beforedelete;import com.queplix.core.jxb.entity.Beforeupdate;import com.queplix.core.jxb.entity.Dataset;import com.queplix.core.jxb.entity.Delete;import com.queplix.core.jxb.entity.Efield;import com.queplix.core.jxb.entity.Entity;import com.queplix.core.jxb.entity.Fkeys;import com.queplix.core.jxb.entity.Update;import com.queplix.core.modules.config.utils.EntityHelper;import com.queplix.core.modules.eql.CompoundKey;import com.queplix.core.modules.eql.EQLDReq;import com.queplix.core.modules.eql.EQLDRes;import com.queplix.core.modules.eql.EQLEReq;import com.queplix.core.modules.eql.EQLERes;import com.queplix.core.modules.eql.EQLFactory;import com.queplix.core.modules.eql.EQLNullObject;import com.queplix.core.modules.eql.EQLObject;import com.queplix.core.modules.eql.EQLReq;import com.queplix.core.modules.eql.EQLReqDataset;import com.queplix.core.modules.eql.EQLReqField;import com.queplix.core.modules.eql.EQLReqMetaData;import com.queplix.core.modules.eql.EQLRes;import com.queplix.core.modules.eql.EQLResCell;import com.queplix.core.modules.eql.EQLResRecord;import com.queplix.core.modules.eql.EQLSession;import com.queplix.core.modules.eql.error.EQLConstraintViolationException;import com.queplix.core.modules.eql.error.EQLDeadlockException;import com.queplix.core.modules.eql.error.EQLDeleteConflictException;import com.queplix.core.modules.eql.error.EQLDuplicateKeyException;import com.queplix.core.modules.eql.error.EQLException;import com.queplix.core.modules.eql.error.EQLIndexConflictException;import com.queplix.core.modules.eql.error.EQLRemoveException;import com.queplix.core.modules.eql.error.EQLSystemException;import com.queplix.core.modules.eql.parser.EQLAgent;import com.queplix.core.modules.eql.parser.EQLAgentFactory;import com.queplix.core.modules.eql.parser.EQLIntPreparedStatement;import com.queplix.core.modules.eql.parser.EQLInterpreter;import com.queplix.core.modules.eql.update.EntityUpdate;import com.queplix.core.modules.eql.update.EntityUpdateFactory;import com.queplix.core.modules.eql.update.EntityUpdateObject;import com.queplix.core.modules.eql.utils.cache.EQLResCacheManager;import com.queplix.core.modules.eql.utils.cache.EQLResCacheObject;import com.queplix.core.utils.JNDINames;import com.queplix.core.utils.async.ASyncObject;import com.queplix.core.utils.async.ASyncRequest;import com.queplix.core.utils.async.JMSClient;import com.queplix.core.utils.sql.error.SQLDeadlockException;import com.queplix.core.utils.sql.error.SQLDeleteConflictException;import com.queplix.core.utils.sql.error.SQLDuplicateKeyException;import com.queplix.core.utils.sql.error.SQLIndexConflictException;import java.util.HashMap;/** * EQL Manager session EJB. * * @author Baranov Andrey [ALB] * @author [ONZ] Oleg N. Zhovtanyuk * @version $Revision: 1.1.1.1 $ $Date: 2005/09/12 15:30:23 $ */public class EQLManagerEJB extends AbstractEQLSupportedEJB { // =============================================================== Constants /** Updates status: Continue updates process */ private static final int CONTINUE = 0; /** Updates status: Skip updates process */ private static final int SKIP = 1; // ================================================================== Fields private AsyncClient asyncClient; // ========================================================== Public methods /** Initializes bean. */ public void ejbCreate() { INFO( "EQL Manager EJB created - " + hashCode() ); asyncClient = new AsyncClient(); } // -------------- // SELECT METHODS // -------------- /** * EQL <code>SELECT</code> query - selects a result set. * * @param ls user logon session * @param entity selected Entity object * @return EQLERes response object * @throws EQLException */ public EQLERes select( LogonSession ls, Entity entity ) throws EQLException { return select( ls, entity, null ); } /** * EQL <code>SELECT</code> query - selects a result set. * * @param ls user logon session * @param entity selected Entity object * @param meta EQl meta data * @return EQLERes response object * @throws EQLException */ public EQLERes select( LogonSession ls, Entity entity, EQLReqMetaData meta ) throws EQLException { return select( ls, entity, null, null, meta ); } /** * EQL <code>SELECT</code> query - selects a result set. * * @param ls user logon session * @param entity selected Entity object * @param pkeyEntity primary keys entity * @param compoundPkeys compound keys * @param meta EQL meta data * @return EQLERes response object * @throws EQLException */ public EQLERes select( LogonSession ls, Entity entity, Entity pkeyEntity, CompoundKey[] compoundPkeys, EQLReqMetaData meta ) throws EQLException { // Init. EQLRes res = null; EQLIntPreparedStatement ps = null; int psCount = 1; int compounds = ( compoundPkeys == null ) ? 0 : compoundPkeys.length; if( compounds == 0 ) { // Try find in cache. res = EQLResCacheManager.getInstance().findEQLResInCache( entity ); } if( res == null ) { // Build EQL request. String eqlQuery = "SELECT " + entity.getName() + ".*"; if( compounds > 0 ) { // Add constraints. ps = new EQLIntPreparedStatement(); eqlQuery += " WHERE "; for( int i = 0; i < compounds; i++ ) { CompoundKey compoundPkey = compoundPkeys[i]; int size = compoundPkey.size(); if( i > 0 ) { eqlQuery += " OR "; } eqlQuery += "("; int key_num = 0; for( int j = 0; j < pkeyEntity.getEfieldCount(); j++ ) { Efield field = pkeyEntity.getEfield( j ); if( !field.getPkey().booleanValue() ) { continue; } // Pimary key found... if( key_num >= size ) { break; } // .. add pkey in request if( key_num > 0 ) { eqlQuery += " AND "; } eqlQuery += field.getId() + " = ?"; ps.setObject( psCount++, EQLObject.getInstance( compoundPkey.getKey( key_num ) ) ); key_num++; } eqlQuery += ")"; } } // Do select. res = select( ls, eqlQuery, ps, meta ); } return( EQLERes ) res; } /** * EQL <code>SELECT</code> query - selects a result set. * * @param ls user logon session * @param eqlQuery EQL query * @return EQLRes response object * @throws EQLException */ public EQLRes select( LogonSession ls, String eqlQuery ) throws EQLException { return select( ls, eqlQuery, null ); } /** * EQL <code>SELECT</code> query - selects a result set. * * @param ls user logon session * @param eqlQuery EQL query * @param eqlPS EQLIntPreparedStatement object * @return EQLRes response object * @throws EQLException */ public EQLRes select( LogonSession ls, String eqlQuery, EQLIntPreparedStatement eqlPS ) throws EQLException { return select( ls, eqlQuery, eqlPS, null ); } /** * EQL <code>SELECT</code> query - selects a result set. * * @param ls user logon session * @param eqlQuery EQL query * @param eqlPS EQLIntPreparedStatement object * @param meta EQL meta data * @return EQLRes response object * @throws EQLException */ public EQLRes select( LogonSession ls, String eqlQuery, EQLIntPreparedStatement eqlPS, EQLReqMetaData meta ) throws EQLException { // Initialization long time = System.currentTimeMillis(); EQLSession eqlSession = getEQLSession( ls ); EQLRes res = null; try { res = doSelect( eqlSession, eqlQuery, eqlPS, meta ); } catch( EQLException ex ) { // Make explicit rollback on checked exception. setRollbackOnly(); throw ex; } catch( Throwable t ) { ErrorHelper.throwSystemException( t, this ); } // Ok.// INFO( "EQL SELECT completed. Time (ms) = " + ( System.currentTimeMillis() - time ) ); return res; } // ------------------ // SELECT NEW METHODS // ------------------ /** * EQL <code>SELECT NEW</code> query - selects a new entity field value. * * @param ls user logon session * @param field selected Efield object * @return EQLRes response object * @throws EQLException */ public EQLRes selectNew( LogonSession ls, Efield field ) throws EQLException { return __selectNew( getEQLSession( ls ), field ); } /** * EQL <code>SELECT NEW</code> query - selects a new entity fields values. * * @param ls user logon session * @param entity selected Entity object * @return EQLERes response object * @throws EQLException */ public EQLERes selectNew( LogonSession ls, Entity entity ) throws EQLException { // Initializarion. long time = System.currentTimeMillis(); EQLSession eqlSession = getEQLSession( ls ); EQLERes ret = new EQLERes( entity ); try { // Select new records. __selectNew( eqlSession, entity, ret ); } catch( EQLException ex ) { // Make explicit rollback on checked exception. setRollbackOnly(); throw ex; } catch( Throwable t ) { ErrorHelper.throwSystemException( t, this ); } // Ok.// INFO( "EQL SELECT NEW completed. Time (ms) = " + ( System.currentTimeMillis() - time ) ); return ret; } // ------------------- // SELECT COUNT METHOD // ------------------- /** * EQL <code>COUNT</code> query - counts records in database for * the given EQL response <code>res</code>. * * @param ls user logon session * @param res EQLERes object * @return count records in database * @throws EQLException */ public int selectCount( LogonSession ls, EQLRes res ) throws EQLException { return doCount( getEQLSession( ls ), res ); } // -------------- // UPDATE METHODS // -------------- /** * EQL <code>UPDATE</code> query - updates / inserts / deletes * database record(s). * * @param ls user logon session * @param res EQLERes object * @throws EQLException */ public void update( LogonSession ls, EQLERes res ) throws EQLException { update( ls, res, null ); } /** * EQL <code>UPDATE</code> query - updates / inserts / deletes * database record(s). * * @param ls user logon session * @param res EQLERes object * @param record EQLResRecord object * @throws EQLException */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -