Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Habib Zare
Is it possible to define new column type in service builder
February 27, 2013 2:21 AM
Answer

Habib Zare

Rank: Junior Member

Posts: 43

Join Date: October 28, 2012

Recent Posts

I want to define an entity like below:

<entity name="Book" local-service="true" remote-service="true">
<column name="bookId" type="long" primary="true" />

<column name="bookPrice" type="BigDecimal" />
</entity>

(my liferay is 6.0.6)

Is it possible to create new type like BigDecimal or other types in service builder?
vinod kumar
RE: Is it possible to define new column type in service builder
February 27, 2013 3:06 AM
Answer

vinod kumar

Rank: Junior Member

Posts: 47

Join Date: October 3, 2012

Recent Posts

hi habib
according to my knowledge
we can not create new type
the following types are avalilabe
1.String
2.Collection
3.boolean
4.Date
5.int
6.long
7.double
David H Nebinger
RE: Is it possible to define new column type in service builder
February 27, 2013 5:44 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 5749

Join Date: September 1, 2006

Recent Posts

As long as the type can be mapped to a JDBC type automatically, you should be able to. Sometimes you might find that you need to specify the full java class name.
Hitoshi Ozawa
RE: Is it possible to define new column type in service builder
February 27, 2013 6:49 AM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Is it possible to create new type like BigDecimal or other types in service builder?


No. There was a feature request from Yuan about this some years back but Liferay.com hasn't supported it.
You'll just have to save it as a String and do a covertion in your Java or follow instruction in the following blog:

http://www.liferay.com/web/jonas.yuan/blog/-/blogs/bringing-data-type-bigdecimal-into-service-builder
David H Nebinger
RE: Is it possible to define new column type in service builder
February 27, 2013 6:09 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 5749

Join Date: September 1, 2006

Recent Posts

Hitoshi could be right here... I've got my own SB hacked up to accept catalog/schema and I must have added the other types along the way...
Habib Zare
RE: Is it possible to define new column type in service builder
February 27, 2013 7:13 AM
Answer

Habib Zare

Rank: Junior Member

Posts: 43

Join Date: October 28, 2012

Recent Posts

Thank David.

There is column type "Date".this type mapped to database type in liferay core source.

I think it is possible to map custom type to database type.

(or There is no data type "long" in dbms like postgres but it mapped to type "bigint");

how can map custom type to database type?
Sandeep Nair
RE: Is it possible to define new column type in service builder
February 27, 2013 8:54 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1691

Join Date: November 5, 2008

Recent Posts

Hi,

If you see ServiceBuilder class you will see which all types are used. There is a method called getSQLType( pasted the snippet below), which shows what all types are there, and what is it mapped to as far as Db data types (generic) is concerned.
 1
 2public String getSqlType(String model, String field, String type) {
 3        if (type.equals("boolean") || type.equals("Boolean")) {
 4            return "BOOLEAN";
 5        }
 6        else if (type.equals("double") || type.equals("Double")) {
 7            return "DOUBLE";
 8        }
 9        else if (type.equals("float") || type.equals("Float")) {
10            return "FLOAT";
11        }
12        else if (type.equals("int") || type.equals("Integer")) {
13            return "INTEGER";
14        }
15        else if (type.equals("long") || type.equals("Long")) {
16            return "BIGINT";
17        }
18        else if (type.equals("short") || type.equals("Short")) {
19            return "INTEGER";
20        }
21        else if (type.equals("Blob")) {
22            return "BLOB";
23        }
24        else if (type.equals("Date")) {
25            return "TIMESTAMP";
26        }
27        else if (type.equals("String")) {
28            Map<String, String> hints = ModelHintsUtil.getHints(model, field);
29
30            if (hints != null) {
31                int maxLength = GetterUtil.getInteger(hints.get("max-length"));
32
33                if (maxLength == 2000000) {
34                    return "CLOB";
35                }
36            }
37
38            return "VARCHAR";
39        }
40        else {
41            return null;
42        }
43    }


Regards,
Sandeep
Habib Zare
RE: Is it possible to define new column type in service builder
February 27, 2013 9:33 AM
Answer

Habib Zare

Rank: Junior Member

Posts: 43

Join Date: October 28, 2012

Recent Posts

Thanks Sandeep Nair.
ali seifodini
RE: Is it possible to define new column type in service builder
February 28, 2013 12:30 AM
Answer

ali seifodini

Rank: New Member

Posts: 11

Join Date: March 3, 2011

Recent Posts

I want this too..
I should add new data type in service builder like point or other geometry data type?
How I do this?
This is important for me.. please help.
Habib Zare
RE: Is it possible to define new column type in service builder
March 5, 2013 12:58 AM
Answer

Habib Zare

Rank: Junior Member

Posts: 43

Join Date: October 28, 2012

Recent Posts

Sandeep Nair.

is it possible to develope ServiceBuilder class and add something like below:

 1public String getSqlType(String model, String field, String type) {
 2        if (type.equals("boolean") || type.equals("Boolean")) {
 3            return "BOOLEAN";
 4        }
 5        else if (type.equals("double") || type.equals("Double")) {
 6            return "DOUBLE";
 7        }
 8        else if (type.equals("Point") ) {
 9            return "Point";
10        }
11
12....
13
14    }
Sandeep Nair
RE: Is it possible to define new column type in service builder
March 5, 2013 5:09 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1691

Join Date: November 5, 2008

Recent Posts

Hi Habib,

I would not modify Servicebuilder code if I were you. This will not be as simple as adding another block of else if condition. The returned String literal from this method will be used somewhere else too.

Servicebuilder is just a code generation tool and not a persistence framework. My recommendation is if ServiceBuilder doesnt give you what you want, use something else that does.

Modifying servicebuilder like this will also have upgrade issues in future.

Regards,
Sandeep
Habib Zare
RE: Is it possible to define new column type in service builder
March 5, 2013 5:58 AM
Answer

Habib Zare

Rank: Junior Member

Posts: 43

Join Date: October 28, 2012

Recent Posts

Thanks Sandeep Nair.

I have to add my column manualy in database.then extend XXXXLocalServiceWrapper class.

in this way for example after i do XXXXLocalService.add(...) i have to query and update my column value like :

 1
 2
 3public WikiLocation AddLocation(double latitude,double longtitude) throws SystemException
 4    {
 5
 6            
 7        long locationId = CounterLocalServiceUtil.increment(Location.class.getName());
 8        Location loc = LocationLocalServiceUtil.createLocation(locationId );
 9        loc.set(...)
10        super.addLocation(loc);
11       
12        String sql="UPDATE mytable SET \"location\"=GeomFromText('POINT("+latitude+" "+ longtitude+")') "";
13        DataSource dataSource=LocationPersistence.getDataSource();
14        SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql, new int[0]);
15        sqlUpdate.update();
16        return loc;
17    }