forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1246 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
d4af2fc129
commit
26e6fbcd4e
@ -0,0 +1,105 @@
|
||||
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 V12_0_To_V12_1 implements siprp.update.Update
|
||||
{
|
||||
|
||||
public V12_0_To_V12_1()
|
||||
{
|
||||
}
|
||||
|
||||
public String []listChanges()
|
||||
{
|
||||
return new String[]{
|
||||
"A actualizar assinatura de B\u00e1rbara Gon\u00e7alves"
|
||||
};
|
||||
}
|
||||
|
||||
public double getStartVersion()
|
||||
{
|
||||
return 12.0;
|
||||
}
|
||||
|
||||
public double getEndVersion()
|
||||
{
|
||||
return 12.1;
|
||||
}
|
||||
|
||||
public void doUpdate() throws Exception
|
||||
{
|
||||
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||
Executer executer = dbm.getSharedExecuter();
|
||||
|
||||
String nomes[] = new String[]{
|
||||
"B\u00e1rbara Gon\u00e7alves",
|
||||
};
|
||||
Integer ids[] = new Integer[]{
|
||||
4,
|
||||
};
|
||||
String assinaturas[] = new String[]{
|
||||
"siprp/update/updates/V12_0_To_V12_1_Barbara_Goncalves.png"
|
||||
};
|
||||
|
||||
for( int n = 0; n < ids.length; n++ )
|
||||
{
|
||||
Vector<Assignment> assignments = new Vector<Assignment>();
|
||||
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