Tribune

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

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Habib Zare
Is it possible to define new column type in service builder
27 febbraio 2013 2.21
Risposta

Habib Zare

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 28 ottobre 2012

Messaggi recenti

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?
kumar E
RE: Is it possible to define new column type in service builder
27 febbraio 2013 3.06
Risposta

kumar E

Punteggio: Junior Member

Messaggi: 64

Data di Iscrizione: 3 ottobre 2012

Messaggi recenti

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
27 febbraio 2013 5.44
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11295

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
27 febbraio 2013 6.49
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7949

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

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
27 febbraio 2013 6.09
Risposta

David H Nebinger

Community Moderator

Punteggio: Liferay Legend

Messaggi: 11295

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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
27 febbraio 2013 7.13
Risposta

Habib Zare

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 28 ottobre 2012

Messaggi recenti

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
27 febbraio 2013 8.54
Risposta

Sandeep Nair

Punteggio: Liferay Legend

Messaggi: 1721

Data di Iscrizione: 5 novembre 2008

Messaggi recenti

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
27 febbraio 2013 9.33
Risposta

Habib Zare

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 28 ottobre 2012

Messaggi recenti

Thanks Sandeep Nair.
ali seifodini
RE: Is it possible to define new column type in service builder
28 febbraio 2013 0.30
Risposta

ali seifodini

Punteggio: New Member

Messaggi: 11

Data di Iscrizione: 3 marzo 2011

Messaggi recenti

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
5 marzo 2013 0.58
Risposta

Habib Zare

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 28 ottobre 2012

Messaggi recenti

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
5 marzo 2013 5.09
Risposta

Sandeep Nair

Punteggio: Liferay Legend

Messaggi: 1721

Data di Iscrizione: 5 novembre 2008

Messaggi recenti

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
5 marzo 2013 5.58
Risposta

Habib Zare

Punteggio: Junior Member

Messaggi: 58

Data di Iscrizione: 28 ottobre 2012

Messaggi recenti

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    }