Showing posts with label Web.Developer. Show all posts
Showing posts with label Web.Developer. Show all posts

Friday, January 07, 2011

Wednesday, November 10, 2010

NHibernate works without mapping

ISQLQuery query = Session.CreateSQLQuery("SELECT p.*, c.* FROM Product p Left JOIN Product_CustomField c on p.ProductId=c.ProductId");
query.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(Product)));
IList resultList = query.List();

Notes:
Add CusTomField1..5 into Product Class,not need declared in .hbm.xml

Combine with ScalarFields
public class SqlRepository {
...
public IList ListEmployees() {
using (ISession session = _sessionBuilder.GetSession()) {
return session
.CreateSQLQuery(@"
SELECT No_ AS EmployeeNumber, [E-mail Login] AS Username
FROM Employees")
.AddScalar("EmployeeNumber", NHibernateUtil.String)
.AddScalar("Username", NHibernateUtil.String)
.SetResultTransformer(Transformers.AliasToBean())
.List();
}
}
}


Add nHibernate mapping at run time
ISessionFactory sf = new Configuration()
.AddFile("Product.hbm.xml")
.AddFile("Category.hbm.xml")



References:
[1] http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html
[2] Store procedure http://www.martinwilley.com/net/code/nhibernate/sql.html
[3] Reduced wiring code needed for native sql http://swik.net/Hibernate/Hibernate+GroupBlog/Hibernate+3.1:+Reduced+wiring+code+needed+for+native+sql
[4] AddJoin http://es.efreedom.com/Question/1-1132059/NHibernate-problema-de-AddEntity-y-AddJoin
[5] Native SQL http://knol.google.com/k/fabio-maulo/nhibernate-chapter-14-native-sql/1nr4enxv3dpeq/17#
[6]Fluent NHibernate http://wiki.fluentnhibernate.org/Auto_mapping
[7]Dynamically load .hbm.xml http://www.codeguru.com/forum/showthread.php?t=474322

Wednesday, November 03, 2010

Cubecart:: Deprecated: Function eregi() is deprecated in

The latest versions of PHP 5 have deprecated a few functions, for turn off those messages as seen in CubeCart.

Edit /includes/ini.inc.php
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED | E_USER_DEPRECATED));

Thursday, October 21, 2010

Postgres save images


CREATE TABLE images (name text, img bytea);



File file = new File("image.gif");
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = conn.prepareStatement("INSERT INTO images VALUES (?, ?)");
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, file.length());
ps.executeUpdate();
ps.close();
fis.close();


setBinaryStream(), transfers a set number of bytes from a stream.
setBytes(), use this method if the contents of the image was already in a byte[].

Retrieving image

PreparedStatement ps = conn.prepareStatement("SELECT img FROM images WHERE name=?");
ps.setString(1, "image.gif");
ResultSet rs = ps.executeQuery();
if(rs.next()) {
byte[] imgBytes = rs.getBytes(1);
}
rs.close();
}
ps.close();


You could have used a InputStream object instead.

Alternatively you could be storing a very large file and want to use the LargeObject API to store the file:


CREATE TABLE imagesLO (imgname text, imgOID OID);

To insert an image, you would use:



conn.setAutoCommit(false); // All LargeObject API calls must be within a transaction

LargeObjectManager lobj = ((org.postgresql.PGConnection)conn).getLargeObjectAPI();

//create a new large object
int oid = lobj.create(LargeObjectManager.READ | LargeObjectManager.WRITE);

//open the large object for write
LargeObject obj = lobj.open(oid, LargeObjectManager.WRITE);

// Now open the file
File file = new File("image.gif");
FileInputStream fis = new FileInputStream(file);

// copy the data from the file to the large object
byte buf[] = new byte[2048];
int s, tl = 0;
while ((s = fis.read(buf, 0, 2048)) > 0)
{
obj.write(buf, 0, s);
tl += s;
}

obj.close();

//Now insert the row into imagesLO
PreparedStatement ps = conn.prepareStatement("INSERT INTO imagesLO VALUES (?, ?)");
ps.setString(1, file.getName());
ps.setInt(2, oid);
ps.executeUpdate();
ps.close();
fis.close();

Retrieving the image from the Large Object:


conn.setAutoCommit(false);

// Get the Large Object Manager to perform operations with
LargeObjectManager lobj = ((org.postgresql.PGConnection)conn).getLargeObjectAPI();

PreparedStatement ps = con.prepareStatement("SELECT imgOID FROM imagesLO WHERE imgname=?");
ps.setString(1, "image.gif");
ResultSet rs = ps.executeQuery();
if (rs.next())
{
int oid = rs.getInt(1);//open the large object for reading
LargeObject obj = lobj.open(oid, LargeObjectManager.READ);

//read the data
byte buf[] = new byte[obj.size()];
obj.read(buf, 0, obj.size());
//do something with the data read here
obj.close();
}
rs.close();
}
ps.close();

JSP Pagination mySQL Postgres

Postgres
select * from ubigeos order by nombre limit 10 offset 0

mySql
select * from ubigeos order by nombre limit 0 , 10

References:
[1] http://www.easywayserver.com/blog/jsp-pagination/
[2] http://www.todoexpertos.com/categorias/tecnologia-e-internet/programacion/java/respuestas/889187/paginacion-con-jsp

Friday, October 08, 2010

Web Service tools for Social Networks

Engine for Java Web service
http://enunciate.codehaus.org/

Social Networks Api
hi5
http://api.hi5.com/
Facebook
http://developers.facebook.com/docs/reference/javascript/

Friday, September 17, 2010

Thursday, September 02, 2010

Flash tools freeware

Slides/Media Slide Show
http://www.flashxml.net/
mp3 player
http://www.colewebs.org/spip.php?article24

Flash Animations with XML
http://www.flashcomponents.net/components/free_flash_files.html

Friday, August 20, 2010

Cross-Domain & jsonp (java struts, php, asp.net mvc, otros )

Cross-Domain Proxy
En el caso de Ajax, por seguridad sĆ³lo se permite acceder al mismo dominio origen de la pĆ”gina web que realiza la peticiĆ³n. Si se necesita acceder a otros servicios localizados en otros dominios, se instala un Cross-Domain proxy en el dominio origen que recibe las peticiones ajax y las reenvia a los dominios externos.

Con jsonp es posible la llamada cross-domain, debido a que no es una llamada ajax sino una carga de un script js completo que lanza una funciĆ³n que definimos en la url y que actĆŗa como callback.

Mientras que por motivos de seguridad es lĆ³gico que Ajax no funcione en dominios distintos al que lanza la web; con esta tĆ©cnica JSON con Padding se genera un archivo JSON dinĆ”micamente dejandolo abierto en el script que lo crea. Una variable que podemos definir nosotros mismos en la url serĆ” colocada antes del objeto Json, asĆ­ al crear el script Json decidimos que variable "callback" usar.


Referencias

[1] jQuery y Strust
http://blog.pontt.com/json-con-java/generar-respuesta-en-java-struts-para-getjson-de-jquery/
[2] jQuery y php http://www.9lessons.info/2009/12/display-cross-domain-data-json-callback.html
[3] jQuery y Asp.Net Mvc (cross-domain JSON to ASP.NET MVC with jQuery)
http://www.integratedwebsystems.com/2010/07/cross-domain-jsonp-using-asp-net-mvc-and-jquery/
[4] cross-domain JSON to ASP.NET MVC with jQuery II
http://stackoverflow.com/questions/2022878/posting-cross-domain-json-to-asp-net-with-jquery
[5] Genericos(muy buenos)
http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
http://ox.no/posts/ajast-cross-domain-rest-calls-using-json-injection
[6] Json to JsonP (easy)
http://www.codeproject.com/KB/aspnet/JSONToJSONP.aspx
http://www.codedigest.com/Articles/jQuery/310_Calling_a_WebService_using_jQuery_in_ASPNet.aspx
[7] Cross-site data retrieval using JSONP http://www.stpe.se/2008/10/cross-site-data-retrieval-using-jsonp/

Running apps

Runtastic (I uninstalled because force to update your device - Internet connection problems) Runkeeper  (Currently testing) Runna (Complex,...