Merge pull request #1769 from hector-cortez/BUG-11510
BUG 11510 Números de casos duplicados SOLVED
This commit is contained in:
@@ -347,6 +347,7 @@ class Application extends BaseApplication
|
||||
*/
|
||||
public function create($sProUid, $sUsrUid)
|
||||
{
|
||||
require_once ("classes/model/Sequences.php");
|
||||
$con = Propel::getConnection('workflow');
|
||||
|
||||
try {
|
||||
@@ -371,16 +372,14 @@ class Application extends BaseApplication
|
||||
$c = new Criteria();
|
||||
$c->clearSelectColumns();
|
||||
|
||||
$c->addSelectColumn('MAX(' . ApplicationPeer::APP_NUMBER . ')'); //the appnumber is based in all processes
|
||||
//active, not only in the specified
|
||||
//process guid
|
||||
$oSequences = new Sequences();
|
||||
$oSequences->lockSequenceTable();
|
||||
|
||||
$result = ApplicationPeer::doSelectRS($c);
|
||||
$result->next();
|
||||
$row = $result->getRow();
|
||||
$maxNumber = $oSequences->getSequeceNumber("APP_NUMBER");
|
||||
|
||||
$maxNumber = $row[0] + 1;
|
||||
$this->setAppNumber($maxNumber);
|
||||
$oSequences->changeSequence('APP_NUMBER', $maxNumber);
|
||||
$oSequences->unlockSequenceTable();
|
||||
|
||||
if ($this->validate()) {
|
||||
$con->begin();
|
||||
|
||||
241
workflow/engine/classes/model/Sequences.php
Normal file
241
workflow/engine/classes/model/Sequences.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
require_once 'classes/model/om/BaseSequences.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'SEQUENCES' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class Sequences extends BaseSequences {
|
||||
|
||||
/**
|
||||
* Create Sequences Table
|
||||
*
|
||||
* @param type $aData
|
||||
* @return type
|
||||
* @throws type
|
||||
*
|
||||
*/
|
||||
public function create($aData)
|
||||
{
|
||||
$con = Propel::getConnection( SequencesPeer::DATABASE_NAME );
|
||||
try {
|
||||
$this->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
|
||||
if ($this->validate()) {
|
||||
$result = $this->save();
|
||||
} else {
|
||||
$e = new Exception( "Failed Validation in class " . get_class( $this ) . "." );
|
||||
$e->aValidationFailures = $this->getValidationFailures();
|
||||
throw ($e);
|
||||
}
|
||||
$con->commit();
|
||||
return $result;
|
||||
} catch(Exception $e) {
|
||||
$con->rollback();
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Sequence with native query
|
||||
*
|
||||
* @param type $seqName
|
||||
* @param type $seqValue
|
||||
* @return type
|
||||
*
|
||||
*/
|
||||
public function changeSequence($seqName, $seqValue)
|
||||
{
|
||||
try {
|
||||
$con = Propel::getConnection('workflow');
|
||||
if ($this->nameExists($seqName)) {
|
||||
$sql = "UPDATE SEQUENCES SET SEQ_VALUE = $seqValue WHERE SEQ_NAME = '$seqName' ";
|
||||
} else {
|
||||
$sql = "INSERT INTO SEQUENCES (`SEQ_NAME`,`SEQ_VALUE`) VALUES ('$seqName', $seqValue) ";
|
||||
}
|
||||
$stmt = $con->createStatement();
|
||||
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
||||
return $rs;
|
||||
} catch(Exception $e) {
|
||||
// throw ($e);
|
||||
throw new Exception( G::LoadTranslation('ID_ERROR_CHANGE_SEQUENCE_NUMBER'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock Sequence Table
|
||||
*
|
||||
* @return type
|
||||
*
|
||||
*/
|
||||
public function lockSequenceTable()
|
||||
{
|
||||
try {
|
||||
$con = Propel::getConnection('workflow');
|
||||
$sql = "LOCK TABLES SEQUENCES WRITE, APPLICATION READ ";
|
||||
|
||||
$stmt = $con->createStatement();
|
||||
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
||||
return $rs;
|
||||
} catch(Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock Sequence Table
|
||||
*
|
||||
* @return type
|
||||
*
|
||||
*/
|
||||
public function unlockSequenceTable()
|
||||
{
|
||||
try {
|
||||
$con = Propel::getConnection('workflow');
|
||||
$sql = "UNLOCK TABLES ";
|
||||
$stmt = $con->createStatement();
|
||||
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
||||
return $rs;
|
||||
} catch(Exeption $e) {
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Name Exists
|
||||
*
|
||||
* @param type $seqName
|
||||
* @return boolean
|
||||
*
|
||||
*/
|
||||
public function nameExists($seqName)
|
||||
{
|
||||
try {
|
||||
$oRow = SequencesPeer::retrieveByPK( $seqName );
|
||||
if (! is_null( $oRow )) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Sequences
|
||||
*
|
||||
* @param type $seqName
|
||||
* @return type
|
||||
* @throws type
|
||||
*
|
||||
*/
|
||||
public function load($seqName)
|
||||
{
|
||||
try {
|
||||
$oRow = SequencesPeer::retrieveByPK( $seqName );
|
||||
if (! is_null( $oRow )) {
|
||||
$aFields = $oRow->toArray( BasePeer::TYPE_FIELDNAME );
|
||||
$this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
|
||||
$this->setNew( false );
|
||||
return $aFields;
|
||||
} else {
|
||||
throw (new Exception( "The row '" . $seqName . "' in table SEQUENCES doesn't exist!" ));
|
||||
}
|
||||
} catch (Exception $oError) {
|
||||
throw ($oError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Sequences
|
||||
*
|
||||
* @param type $fields
|
||||
* @return type
|
||||
* @throws type
|
||||
*/
|
||||
public function update($fields)
|
||||
{
|
||||
$con = Propel::getConnection( SequencesPeer::DATABASE_NAME );
|
||||
try {
|
||||
$con->begin();
|
||||
$this->load( $fields['SEC_NAME'] );
|
||||
$this->fromArray( $fields, BasePeer::TYPE_FIELDNAME );
|
||||
if ($this->validate()) {
|
||||
$result = $this->save();
|
||||
$con->commit();
|
||||
return $result;
|
||||
} else {
|
||||
$con->rollback();
|
||||
throw (new Exception( "Failed Validation in class " . get_class( $this ) . "." ));
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$con->rollback();
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Sequences
|
||||
*
|
||||
* @param type $seqName
|
||||
* @return type
|
||||
* @throws type
|
||||
*
|
||||
*/
|
||||
public function remove($seqName)
|
||||
{
|
||||
$con = Propel::getConnection( SequencesPeer::DATABASE_NAME );
|
||||
try {
|
||||
$con->begin();
|
||||
$this->setSecName( $seqName );
|
||||
$result = $this->delete();
|
||||
$con->commit();
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
$con->rollback();
|
||||
throw ($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new sequece number
|
||||
*
|
||||
* @param type $seqName
|
||||
* @return type
|
||||
* @throws type
|
||||
*/
|
||||
public function getSequeceNumber($seqName)
|
||||
{
|
||||
$c = new Criteria();
|
||||
$c->clearSelectColumns();
|
||||
try {
|
||||
|
||||
if ($this->nameExists("APP_NUMBER") ) {
|
||||
$aSequence = $this->load($seqName);
|
||||
$nSeqValue = ($aSequence['SEQ_VALUE'] + 1);
|
||||
} else {
|
||||
$c->addSelectColumn('MAX(' . ApplicationPeer::APP_NUMBER . ')'); //the appnumber is based in all processes
|
||||
//active, not only in the specified
|
||||
//process guid
|
||||
$result = ApplicationPeer::doSelectRS($c);
|
||||
$result->next();
|
||||
$row = $result->getRow();
|
||||
$nSeqValue = $row[0] + 1;
|
||||
}
|
||||
|
||||
return $nSeqValue;
|
||||
} catch (Exception $e) {
|
||||
throw ($e);
|
||||
}
|
||||
|
||||
}
|
||||
} // Sequences
|
||||
23
workflow/engine/classes/model/SequencesPeer.php
Normal file
23
workflow/engine/classes/model/SequencesPeer.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
// include base peer class
|
||||
require_once 'classes/model/om/BaseSequencesPeer.php';
|
||||
|
||||
// include object class
|
||||
include_once 'classes/model/Sequences.php';
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for performing query and update operations on the 'SEQUENCES' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package classes.model
|
||||
*/
|
||||
class SequencesPeer extends BaseSequencesPeer {
|
||||
|
||||
} // SequencesPeer
|
||||
74
workflow/engine/classes/model/map/SequencesMapBuilder.php
Normal file
74
workflow/engine/classes/model/map/SequencesMapBuilder.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
require_once 'propel/map/MapBuilder.php';
|
||||
include_once 'creole/CreoleTypes.php';
|
||||
|
||||
|
||||
/**
|
||||
* This class adds structure of 'SEQUENCES' table to 'workflow' DatabaseMap object.
|
||||
*
|
||||
*
|
||||
*
|
||||
* These statically-built map classes are used by Propel to do runtime db structure discovery.
|
||||
* For example, the createSelectSql() method checks the type of a given column used in an
|
||||
* ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY case-insensitive
|
||||
* (i.e. if it's a text column type).
|
||||
*
|
||||
* @package workflow.classes.model.map
|
||||
*/
|
||||
class SequencesMapBuilder
|
||||
{
|
||||
|
||||
/**
|
||||
* The (dot-path) name of this class
|
||||
*/
|
||||
const CLASS_NAME = 'classes.model.map.SequencesMapBuilder';
|
||||
|
||||
/**
|
||||
* The database map.
|
||||
*/
|
||||
private $dbMap;
|
||||
|
||||
/**
|
||||
* Tells us if this DatabaseMapBuilder is built so that we
|
||||
* don't have to re-build it every time.
|
||||
*
|
||||
* @return boolean true if this DatabaseMapBuilder is built, false otherwise.
|
||||
*/
|
||||
public function isBuilt()
|
||||
{
|
||||
return ($this->dbMap !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databasemap this map builder built.
|
||||
*
|
||||
* @return the databasemap
|
||||
*/
|
||||
public function getDatabaseMap()
|
||||
{
|
||||
return $this->dbMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* The doBuild() method builds the DatabaseMap
|
||||
*
|
||||
* @return void
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function doBuild()
|
||||
{
|
||||
$this->dbMap = Propel::getDatabaseMap('workflow');
|
||||
|
||||
$tMap = $this->dbMap->addTable('SEQUENCES');
|
||||
$tMap->setPhpName('Sequences');
|
||||
|
||||
$tMap->setUseIdGenerator(false);
|
||||
|
||||
$tMap->addPrimaryKey('SEQ_NAME', 'SeqName', 'string', CreoleTypes::VARCHAR, true, 50);
|
||||
|
||||
$tMap->addColumn('SEQ_VALUE', 'SeqValue', 'int', CreoleTypes::INTEGER, true, null);
|
||||
|
||||
} // doBuild()
|
||||
|
||||
} // SequencesMapBuilder
|
||||
568
workflow/engine/classes/model/om/BaseSequences.php
Normal file
568
workflow/engine/classes/model/om/BaseSequences.php
Normal file
File diff suppressed because it is too large
Load Diff
572
workflow/engine/classes/model/om/BaseSequencesPeer.php
Normal file
572
workflow/engine/classes/model/om/BaseSequencesPeer.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -2973,4 +2973,28 @@
|
||||
<column name="APP_CHANGE_TRACE" type="VARCHAR" size="500" required="true" />
|
||||
<column name="APP_UPDATED" type="TINYINT" required="true" default="1"/>
|
||||
</table>
|
||||
<table name="SEQUENCES">
|
||||
<vendor type="mysql">
|
||||
<parameter name="Name" value="SEQUENCES"/>
|
||||
<parameter name="Engine" value="InnoDB"/>
|
||||
<parameter name="Version" value="10"/>
|
||||
<parameter name="Row_format" value="Dynamic"/>
|
||||
<parameter name="Rows" value="2"/>
|
||||
<parameter name="Avg_row_length" value="128"/>
|
||||
<parameter name="Data_length" value="6768"/>
|
||||
<parameter name="Max_data_length" value="281474976710655"/>
|
||||
<parameter name="Index_length" value="5120"/>
|
||||
<parameter name="Data_free" value="0"/>
|
||||
<parameter name="Auto_increment" value=""/>
|
||||
<parameter name="Create_time" value="2013-05-17 11:21:20"/>
|
||||
<parameter name="Update_time" value="2013-05-17 11:48:16"/>
|
||||
<parameter name="Check_time" value=""/>
|
||||
<parameter name="Collation" value="utf8_general_ci"/>
|
||||
<parameter name="Checksum" value=""/>
|
||||
<parameter name="Create_options" value=""/>
|
||||
<parameter name="Comment" value="Sequences, Controls the numerical sequence of a table"/>
|
||||
</vendor>
|
||||
<column name="SEQ_NAME" type="VARCHAR" size="50" required="true" primaryKey="true" default=""/>
|
||||
<column name="SEQ_VALUE" type="INTEGER" required="true" default="0"/>
|
||||
</table>
|
||||
</database>
|
||||
|
||||
@@ -1442,5 +1442,18 @@ CREATE TABLE `APP_SOLR_QUEUE`
|
||||
`APP_UPDATED` TINYINT default 1 NOT NULL,
|
||||
PRIMARY KEY (`APP_UID`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='APP_SOLR_QUEUE';
|
||||
#-----------------------------------------------------------------------------
|
||||
#-- SEQUENCES
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS `SEQUENCES`;
|
||||
|
||||
|
||||
CREATE TABLE `SEQUENCES`
|
||||
(
|
||||
`SEQ_NAME` VARCHAR(50) default '' NOT NULL,
|
||||
`SEQ_VALUE` INTEGER default 0 NOT NULL,
|
||||
PRIMARY KEY (`SEQ_NAME`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Sequences, Controls the numerical sequence of a table';
|
||||
# This restores the fkey checks, after having unset them earlier
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
Reference in New Issue
Block a user