forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1243 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
b0b1dddad2
commit
ba968d203e
@ -0,0 +1,115 @@
|
||||
package siprp.update.updates;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.evolute.utils.Singleton;
|
||||
import com.evolute.utils.arrays.Virtual2DArray;
|
||||
import com.evolute.utils.db.DBManager;
|
||||
import com.evolute.utils.db.Executer;
|
||||
import com.evolute.utils.sql.Assignment;
|
||||
import com.evolute.utils.sql.BlobUpdate;
|
||||
import com.evolute.utils.sql.Field;
|
||||
import com.evolute.utils.sql.Insert;
|
||||
import com.evolute.utils.sql.Select2;
|
||||
import com.evolute.utils.sql.Update;
|
||||
|
||||
public class V11_9_To_V12_0 implements siprp.update.Update
|
||||
{
|
||||
|
||||
public V11_9_To_V12_0()
|
||||
{
|
||||
}
|
||||
|
||||
public String []listChanges()
|
||||
{
|
||||
return new String[]{
|
||||
"A actualizar informacao dos tecnicos de higiene e seguranca"
|
||||
};
|
||||
}
|
||||
|
||||
public double getStartVersion()
|
||||
{
|
||||
return 11.9;
|
||||
}
|
||||
|
||||
public double getEndVersion()
|
||||
{
|
||||
return 12.0;
|
||||
}
|
||||
|
||||
public void doUpdate() throws Exception
|
||||
{
|
||||
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||
Executer executer = dbm.getSharedExecuter();
|
||||
|
||||
String nomes[] = new String[]{
|
||||
"David Afonso",
|
||||
"B\u00e1rbara Gon\u00e7alves",
|
||||
"Ana Sofia Jorge"
|
||||
};
|
||||
Integer ids[] = new Integer[]{
|
||||
3,
|
||||
4,
|
||||
5
|
||||
};
|
||||
String caps[] = new String[]{
|
||||
"28291002EC3",
|
||||
"em emiss\u00e3o - A 100 60 1820 D",
|
||||
"17050910EC5" };
|
||||
String assinaturas[] = new String[]{
|
||||
null,
|
||||
"siprp/update/updates/V11_9_To_V11_10_Barbara_Goncalves.png",
|
||||
"siprp/update/updates/V11_9_To_V11_10_Ana_Sofia_Jorge.png" };
|
||||
|
||||
for( int n = 0; n < ids.length; n++ )
|
||||
{
|
||||
Vector<Assignment> assignments = new Vector<Assignment>();
|
||||
assignments.add( new Assignment( "cap", caps[ n ] ) );
|
||||
if( assinaturas[ n ] != null )
|
||||
{
|
||||
Integer assinaturaID = null;
|
||||
String assinatura = "Assinatura(" + nomes[ n ] + ")";
|
||||
BufferedImage assinaturaImage = ImageIO.read( getClass().getClassLoader().getResourceAsStream(
|
||||
assinaturas[ n ] ) );
|
||||
ByteArrayOutputStream assinaturaBytesStream = new ByteArrayOutputStream();
|
||||
ImageIO.write( assinaturaImage, "PNG", assinaturaBytesStream );
|
||||
if( assinaturaImage == null || assinaturaBytesStream.size() == 0 )
|
||||
{
|
||||
throw new Exception("Erro ao ler assinatura: " + assinatura );
|
||||
}
|
||||
Insert insertQuery = new Insert( "image", new Assignment[]{
|
||||
new Assignment(new Field("name"),assinatura)
|
||||
} );
|
||||
Virtual2DArray array = executer.executeQuery( insertQuery );
|
||||
Select2 selectQuery = new Select2(new String[]{"image"},null,null,new String[]{"id"},new Field("name").isEqual( assinatura ),null,null,null,null);
|
||||
array = executer.executeQuery( selectQuery );
|
||||
if( array.columnLength() == 1 )
|
||||
{
|
||||
assinaturaID = (Integer) array.get( 0, 0 );
|
||||
}
|
||||
if( assinaturaID == null )
|
||||
{
|
||||
throw new Exception("Erro ao inserir assinatura: " + assinatura );
|
||||
}
|
||||
BlobUpdate blobUpdate = new BlobUpdate("image","image_data",assinaturaBytesStream.toByteArray(),new Field("id").isEqual( assinaturaID ) );
|
||||
executer.executeQuery( blobUpdate );
|
||||
assignments.add( new Assignment( "assinatura", assinaturaID ) );
|
||||
}
|
||||
Update update =
|
||||
new Update( "marcacoes_tecnicos_hst",
|
||||
assignments.toArray( new Assignment[ assignments.size() ] ),
|
||||
new Field( "id" ).isEqual( ids[ n ] ) );
|
||||
executer.executeQuery( update );
|
||||
}
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return "v" + getStartVersion() + " para v" + getEndVersion();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue