Foros de discusión
adding one column in xisting database
sasmita swain, modificado hace 11 años.
adding one column in xisting database
Regular Member Mensajes: 183 Fecha de incorporación: 24/02/12 Mensajes recientes
Hi
I want to add one more column in shopping category table..how to do by using expando
can you give example of this
Thanks
Sasmita
I want to add one more column in shopping category table..how to do by using expando
can you give example of this
Thanks
Sasmita
David H Nebinger, modificado hace 11 años.
RE: adding one column in xisting database
Liferay Legend Mensajes: 14917 Fecha de incorporación: 2/09/06 Mensajes recientes
Every entity has an expando bridge that you can use to access extra values.
Use the XxxLocalServiceUtil to retrieve the entity that you want to add an expando value to.
Once you have the entity, you can use:
This returns a Serializable instance which you can cast to your desired type.
To set the entity, you can use:
myValue must be serializable.
QED.
Use the XxxLocalServiceUtil to retrieve the entity that you want to add an expando value to.
Once you have the entity, you can use:
if (entity.getExpandoBridge().hasAttribute("MyAttribute")) {
entity.getExpandoBridge().getAttribute("MyAttribute");
}
This returns a Serializable instance which you can cast to your desired type.
To set the entity, you can use:
if (! entity.getExpandoBridge().hasAttribute("MyAttribute")) {
// add the entity definition with the type the value is.
entity.getExpandoBridge().addAttribute("MyAttribute", ExpandoColumnConstants.INTEGER);
}
// now set the value
entity.getExpandoBridge().setAttribute("MyAttribute", myValue);
myValue must be serializable.
QED.
sasmita swain, modificado hace 11 años.
RE: adding one column in xisting database
Regular Member Mensajes: 183 Fecha de incorporación: 24/02/12 Mensajes recientes
Thanks David
actually i create table like custom field in expando table and successfully adding column to expandocolumn table..
my code is:
public void init() throws PortletException {
ExpandoTable table = null;
long categoryId = Long.parseLong("10154");
try{
ExpandoTable existingTable=ExpandoTableLocalServiceUtil.getTable(45506);
/*table=ExpandoTableLocalServiceUtil.addDefaultTable(categoryId, ShoppingCategory.class.getName());*/
String tablename=existingTable.getName();
System.out.println("table name = " + tablename);
}catch (Exception e) {
e.printStackTrace();
}
ExpandoColumn column = null;
ExpandoRow row=null;
/*long tableId = table.getTableId();
System.out.println("tableId ="+tableId);
*/
try {
column = ExpandoColumnLocalServiceUtil.addColumn(10904, "decription1", ExpandoColumnConstants.STRING);
row=ExpandoRowLocalServiceUtil.addExpandoRow(row);
}
catch(DuplicateColumnNameException dcne) {
// Get the ExpandoColumn ("comments-astronauts")
try {
column = ExpandoColumnLocalServiceUtil.getColumn(10904, "decription1");
row=ExpandoRowLocalServiceUtil.getRow(11002);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.init();
in jsp i hav 2 text fields.. i want to insert values in to expandovalues table..
Thanks
Sasmita
}
actually i create table like custom field in expando table and successfully adding column to expandocolumn table..
my code is:
public void init() throws PortletException {
ExpandoTable table = null;
long categoryId = Long.parseLong("10154");
try{
ExpandoTable existingTable=ExpandoTableLocalServiceUtil.getTable(45506);
/*table=ExpandoTableLocalServiceUtil.addDefaultTable(categoryId, ShoppingCategory.class.getName());*/
String tablename=existingTable.getName();
System.out.println("table name = " + tablename);
}catch (Exception e) {
e.printStackTrace();
}
ExpandoColumn column = null;
ExpandoRow row=null;
/*long tableId = table.getTableId();
System.out.println("tableId ="+tableId);
*/
try {
column = ExpandoColumnLocalServiceUtil.addColumn(10904, "decription1", ExpandoColumnConstants.STRING);
row=ExpandoRowLocalServiceUtil.addExpandoRow(row);
}
catch(DuplicateColumnNameException dcne) {
// Get the ExpandoColumn ("comments-astronauts")
try {
column = ExpandoColumnLocalServiceUtil.getColumn(10904, "decription1");
row=ExpandoRowLocalServiceUtil.getRow(11002);
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.init();
in jsp i hav 2 text fields.. i want to insert values in to expandovalues table..
Thanks
Sasmita
}
Siby Mathew, modificado hace 11 años.
RE: adding one column in xisting database
Expert Mensajes: 268 Fecha de incorporación: 4/03/11 Mensajes recientes
Hi Sasmita,
David's code is also internally using the same API's that you are using.
You can use his code snippet as its simpler and more readable.
Also In my opinion, in your code, you should try to fetch the values first ...and then on the exception block, try to add new if not present.
Thanks,
Siby
David's code is also internally using the same API's that you are using.
You can use his code snippet as its simpler and more readable.
Also In my opinion, in your code, you should try to fetch the values first ...and then on the exception block, try to add new if not present.
Thanks,
Siby