PortaleOrdiniGruppo/PostIn/postin_countR.java
2025-03-24 15:28:26 +01:00

324 lines
12 KiB
Java
Raw Permalink Blame History

// * --- Area Manuale = BO - Header
// * --- Fine Area Manuale
public class postin_countR implements CallerWithObjs {
// gestori associati a particolari eventi ('Routine start')
public static volatile java.util.Map<String,java.util.List<com.zucchetti.sitepainter.EventHandler>> specificEventsHandlers;
// gestori associati a tutti gli eventi
public static volatile java.util.List<com.zucchetti.sitepainter.EventHandler> allEventsHandlers;
// indica se si sta gestendo un evento scatenato da questa routine per restituire il valore corretto di i_EntityName ed i_EntityType
static boolean m_bEventRunning;
public String m_cLastMsgError;
public boolean m_bError;
// Variabile di collegamento con il database: passata nel costruttore
public CPSql m_Sql;
// Variabile di contesto (variabili globali): passata nel costruttore
public CPContext m_Ctx;
// Variabile di caller (variabili di caller): passata nel costruttore
public CallerWithObjs m_Caller;
String m_cServer;
String m_cPhName;
CPPhTableWrInfo m_oWrInfo;
String m_cQuery;
String m_cQueryTable;
String m_cSql;
java.util.List<String> m_oParameters;
String m_cWhere;
int m_nUpdatedRows;
// Contiene il messaggio di errore dell'ultima select terminata a causa della caduta della connessione
String m_cConnectivityError;
public boolean reload;
public String message;
public String[] instances;
public Integer i;
public java.sql.Date date_today;
public java.util.Map<String, String> instance_count;
public String w_instance;
// * --- Area Manuale = BO - Properties
// * --- Fine Area Manuale
public postin_countR (CPContext p_ContextObject, Caller caller) {
if (caller == null)
m_Caller = CallerWithObjsImpl.EMPTY;
else if (caller instanceof CallerWithObjs)
m_Caller = (CallerWithObjs)caller;
else
m_Caller = new CallerWithObjsImpl(caller);
m_Ctx=p_ContextObject;
// Assegnazione della variabile di collegamento con il database
m_Sql=m_Ctx.GetSql();
/* Impostazione dell'ambiente globale: il businness object si collega
all'oggetto globale (unico per pi<70> istanze di una stessa applicazione)
per recuperare informazioni sul:
1) nome fisico della tabella di gestione;
2) nome fisico delle tabelle collegate nei link;
3) stringa di connessione.
L'azienda <20> contenuta nel global object.
*/
p_ContextObject = p_ContextObject.DisabledDataFilteringVersion();
CPSecurity.RoutineCallableByProgram("postin_count",m_Caller);
Blank();
}
public double GetNumber(String p_cVarName,String p_cType,int len,int dec) {
return 0;
}
public String GetString(String p_cVarName,String p_cType,int len,int dec) {
if (CPLib.eqr("m_cVQRList",p_cVarName)) {
return m_cVQRList;
} else if (CPLib.eqr("i_InvokedRoutines",p_cVarName)) {
return i_InvokedRoutines;
} else if (m_bEventRunning && CPLib.eqr("i_EntityName",p_cVarName)) {
return "postin_count";
} else if (m_bEventRunning && CPLib.eqr("i_EntityType",p_cVarName)) {
return "function";
}
if (CPLib.eqr("message",p_cVarName)) {
return message;
}
if (CPLib.eqr("instance",p_cVarName)) {
return w_instance;
}
return "";
}
public java.sql.Date GetDate(String p_cVarName,String p_cType,int len,int dec) {
if (CPLib.eqr("date_today",p_cVarName)) {
return date_today;
}
return CPLib.NullDate();
}
public java.sql.Timestamp GetDateTime(String p_cVarName,String p_cType,int len,int dec) {
return CPLib.NullDateTime();
}
public boolean GetLogic(String p_cVarName,String p_cType,int len,int dec) {
if (CPLib.eqr("reload",p_cVarName)) {
return reload;
}
return false;
}
public CPMemoryCursor GetMemoryCursor(String p_cVarName,String p_cType,int len,int dec) {
return null;
}
public CPMemoryCursorRow GetMemoryCursorRow(String p_cVarName,String p_cType,int len,int dec) {
return null;
}
public com.zucchetti.sitepainter.datatypes.CPJSONStruct GetJSON(String p_cVarName,String p_cType,int len,int dec) {
return com.zucchetti.sitepainter.datatypes.CPJSONStruct.EmptyStruct();
}
public void SetNumber(String p_cVarName,String p_cType,int len,int dec,double value) {
}
public void SetString(String p_cVarName,String p_cType,int len,int dec,String value) {
if (CPLib.eqr("message",p_cVarName)) {
message = value;
return;
}
if (CPLib.eqr("instance",p_cVarName)) {
w_instance = value;
return;
}
}
public void SetDate(String p_cVarName,String p_cType,int len,int dec,java.sql.Date value) {
if (CPLib.eqr("date_today",p_cVarName)) {
date_today = value;
return;
}
}
public void SetDateTime(String p_cVarName,String p_cType,int len,int dec,java.sql.Timestamp value) {
}
public void SetLogic(String p_cVarName,String p_cType,int len,int dec,boolean value) {
if (CPLib.eqr("reload",p_cVarName)) {
reload = value;
return;
}
}
public void SetMemoryCursorRow(String p_cVarName,String p_cType,int len,int dec,CPMemoryCursorRow value) {
}
public void SetMemoryCursor(String p_cVarName,String p_cType,int len,int dec,CPMemoryCursor value) {
}
public void SetJSON(String p_cVarName,String p_cType,int len,int dec,com.zucchetti.sitepainter.datatypes.CPJSONStruct value) {
}
public void CalledBatchEnd() {
}
void Page_1() throws Exception {
/* Espone agli utenti loggati il numero di postin, evita di lanciare la query in continuazione per non appesantire il sistema */
/* reload Bool */
/* message Memo */
synchronized(lastExec) {
reload = lastExec.get() + 60*1000 < System.currentTimeMillis();
//prevedo al massimo 10 minuti per eseguire Page_2
if (reload) lastExec.set( System.currentTimeMillis() + 10 * 60 * 1000);
}
/* If reload */
if (reload) {
/* Exec Page 2 */
Page_2();
} // End If
/* Evito dipendenza da Utilities usando direttamente m_Ctx */
/* message := values.get(m_Ctx.GetInstance()+'*'+Str(m_Ctx.UserCode())) */
message = values.get(m_Ctx.GetInstance()+"*"+CPLib.Str(m_Ctx.UserCode()));
/* If IsNull(message) */
if (CPLib.IsNull(message)) {
/* Return "0" */
throw new Stop("0");
} else { // Else
/* Return message */
throw new Stop(message);
} // End If
}
void Page_2() throws Exception {
CPResultSet Cursor_postin_check=null;
VQRHolder l_VQRHolder = null;
try {
/* instances Object(String[]) */
/* i Object(Integer) */
/* date_today Date */
/* instances := CPPooler.InstanceNames() */
instances = CPPooler.InstanceNames();
/* instance_count Object(java.util.Map<String, String>) */
instance_count = new java.util.HashMap<String, String>();
/* i := 0 */
i = 0;
/* date_today := Date() */
date_today = CPLib.Date();
/* w_instance Char(100) */
/* w_instance := m_Ctx.GetInstance() */
w_instance = m_Ctx.GetInstance();
/* While i < instances.length */
while (CPLib.lt(i,instances.length)) {
double nTry00000017status;
nTry00000017status = m_Sql.GetTransactionStatus();
String cTry00000017msg;
cTry00000017msg = m_Sql.TransactionErrorMessage();
try {
/* leggo dati istanza */
/* m_Ctx.SetInstance(instances[i]) */
m_Ctx.SetInstance(instances[i]);
// * --- Select from postin_check
if (Cursor_postin_check!=null)
Cursor_postin_check.Close();
Cursor_postin_check = new VQRHolder("postin_check",com.zucchetti.sitepainter.Library.getVQRReaderFactory(m_Ctx.GetInstance()),this,true).GetResultSet(m_Ctx);
while ( ! (Cursor_postin_check.Eof())) {
/* instance_count.put(instances[i]+'*'+Str(postin_check->usercode),LRTrim(Str(postin_check->n_postit,8,0))) */
instance_count.put(instances[i]+"*"+CPLib.Str(Cursor_postin_check.GetDouble("usercode")),CPLib.LRTrim(CPLib.Str(Cursor_postin_check.GetDouble("n_postit"),8,0)));
Cursor_postin_check.Next();
}
m_cConnectivityError = Cursor_postin_check.ErrorMessage();
Cursor_postin_check.Close();
// * --- End Select
} catch(Exception l_exeption) {
Stop.ReactToException(l_exeption);
} finally {
if (CPLib.eqr(m_Sql.GetTransactionStatus(),0) || CPLib.ne(nTry00000017status,0)) {
m_Sql.SetTransactionStatus(nTry00000017status,cTry00000017msg);
}
}
/* i := i+1 */
i = i+1;
} // End While
/* m_Ctx.SetInstance(w_instance) */
m_Ctx.SetInstance(w_instance);
/* lastExec.set(System.currentTimeMillis()) */
lastExec.set(System.currentTimeMillis());
values = java.util.Collections.synchronizedMap(instance_count);
} finally {
try {
if (Cursor_postin_check!=null)
Cursor_postin_check.Close();
} catch(Throwable dontCare) {
// Ogni chiusura del cursore viene racchiusa in una catch per evitare di perdere l'eccezione
// originata all'interno della try-finally della pagina della routine
}
}
}
void _init_() {
}
public String RunAsync() {
return CPAsyncRoutine.CreateAsyncAndStart(
new CPAsyncRoutine.AsyncRunnable() {
public void Compute(CPAsyncRoutine.AsyncResult p_oResult) {
try {
p_oResult.m_oResult=new Stop(Run());
} finally {
//evito di tenere nell'heap della virtual machine riferimenti non piu' usati
m_Caller = null;
m_Sql = null;
m_Ctx = null;
}
}
}
);
}
public String Run() {
String l_result;
l_result = "";
m_Ctx = m_Ctx.DisabledDataFilteringVersion();
m_Ctx.BeginMutationSection();
try {
try {
try {
try {
m_bEventRunning = true;
com.zucchetti.sitepainter.EventHandler.notifyEvent("Run start",this,m_Ctx,specificEventsHandlers,allEventsHandlers);
} finally {
m_bEventRunning = false;
}
Page_1();
} finally {
try {
m_bEventRunning = true;
com.zucchetti.sitepainter.EventHandler.notifyEvent(com.zucchetti.sitepainter.EventHandler.RUN_END,this,m_Ctx,specificEventsHandlers,allEventsHandlers);
} finally {
m_bEventRunning = false;
}
}
} catch(Stop stop_value) {
l_result = stop_value.GetString();
} catch(RoutineException l_transactionRaise) {
//non va segnalato come errore
} catch(Exception fault) {
l_result = "";
CPStdCounter.Error(fault);
CallerExImpl l_oTraceSink;
l_oTraceSink = new CallerExImpl(m_Caller,"");
if (l_oTraceSink.HasWorkingVar("m_cFaultTrace")) {
if ( ! (CPLib.IsAdministrator(m_Ctx)) && m_Ctx.HasAdministeredUsers()) {
l_oTraceSink.SetString("m_cFaultTrace","C",0,0,"MSG_ADMIN_REQUIRED");
} else {
l_oTraceSink.SetString("m_cFaultTrace","C",0,0,CPLib.DumpException(fault));
}
}
}
} finally {
m_Ctx.EnableDataFiltering();
m_Ctx.EndMutationSection();
}
return l_result;
}
public static postin_countR Make(CPContext p_Ctx, Caller p_Caller) {
return new postin_countR(p_Ctx, p_Caller);
}
public static postin_countR Make(CPContext p_Ctx) {
return new postin_countR(p_Ctx, CPSecurity.EXECUTE_ALL_ROUTINES);
}
public void Blank() {
reload = false;
message = "";
instances = null;
i = null;
date_today = CPLib.NullDate();
instance_count = null;
w_instance = CPLib.Space(100);
}
// * --- Area Manuale = BO - Methods
// * --- postin_count
static volatile java.util.concurrent.atomic.AtomicLong lastExec;
static volatile java.util.Map<String, String> values;
static {
lastExec = new java.util.concurrent.atomic.AtomicLong(System.currentTimeMillis() - 10 * 60 * 1000);
Make(new CPContext("",0,CPPooler.InstanceNames()[0])).Run();
}
// * --- Fine Area Manuale
// ENTITY_VQR: ,postin_check,
public static final String m_cVQRList = ",postin_check,";
// ENTITY_BATCHES: ,postin_count,
public static final String i_InvokedRoutines = ",postin_count,";
public static String[] m_cRunParameterNames={};
}