Fórumok

Is it possible to define new column type in service builder

thumbnail
habib zare, módosítva 11 év-val korábban

Is it possible to define new column type in service builder

Junior Member Bejegyzések: 58 Csatlakozás dátuma: 2012.10.28. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Junior Member Bejegyzések: 64 Csatlakozás dátuma: 2012.10.04. Legújabb bejegyzések
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
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Liferay Legend Bejegyzések: 14918 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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.
thumbnail
Hitoshi Ozawa, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
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
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Liferay Legend Bejegyzések: 14918 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
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...
thumbnail
habib zare, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Junior Member Bejegyzések: 58 Csatlakozás dátuma: 2012.10.28. Legújabb bejegyzések
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?
thumbnail
Sandeep Nair, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Liferay Legend Bejegyzések: 1744 Csatlakozás dátuma: 2008.11.06. Legújabb bejegyzések
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.

public String getSqlType(String model, String field, String type) {
		if (type.equals("boolean") || type.equals("Boolean")) {
			return "BOOLEAN";
		}
		else if (type.equals("double") || type.equals("Double")) {
			return "DOUBLE";
		}
		else if (type.equals("float") || type.equals("Float")) {
			return "FLOAT";
		}
		else if (type.equals("int") || type.equals("Integer")) {
			return "INTEGER";
		}
		else if (type.equals("long") || type.equals("Long")) {
			return "BIGINT";
		}
		else if (type.equals("short") || type.equals("Short")) {
			return "INTEGER";
		}
		else if (type.equals("Blob")) {
			return "BLOB";
		}
		else if (type.equals("Date")) {
			return "TIMESTAMP";
		}
		else if (type.equals("String")) {
			Map<string, string> hints = ModelHintsUtil.getHints(model, field);

			if (hints != null) {
				int maxLength = GetterUtil.getInteger(hints.get("max-length"));

				if (maxLength == 2000000) {
					return "CLOB";
				}
			}

			return "VARCHAR";
		}
		else {
			return null;
		}
	}</string,>


Regards,
Sandeep
thumbnail
habib zare, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Junior Member Bejegyzések: 58 Csatlakozás dátuma: 2012.10.28. Legújabb bejegyzések
Thanks Sandeep Nair.
thumbnail
ali seifodini, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

New Member Bejegyzések: 11 Csatlakozás dátuma: 2011.03.03. Legújabb bejegyzések
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.
thumbnail
Habib Zare, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Junior Member Bejegyzések: 58 Csatlakozás dátuma: 2012.10.28. Legújabb bejegyzések
Sandeep Nair.

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

public String getSqlType(String model, String field, String type) {
        if (type.equals("boolean") || type.equals("Boolean")) {
            return "BOOLEAN";
        }
        else if (type.equals("double") || type.equals("Double")) {
            return "DOUBLE";
        }
        else if (type.equals("Point") ) {
            return "Point";
        }

....

    }
thumbnail
Sandeep Nair, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Liferay Legend Bejegyzések: 1744 Csatlakozás dátuma: 2008.11.06. Legújabb bejegyzések
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
thumbnail
Habib Zare, módosítva 11 év-val korábban

RE: Is it possible to define new column type in service builder

Junior Member Bejegyzések: 58 Csatlakozás dátuma: 2012.10.28. Legújabb bejegyzések
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 :



public WikiLocation AddLocation(double latitude,double longtitude) throws SystemException 
	{

			
		long locationId = CounterLocalServiceUtil.increment(Location.class.getName());
		Location loc = LocationLocalServiceUtil.createLocation(locationId );
		loc.set(...)
		super.addLocation(loc);
		
		String sql="UPDATE mytable SET \"location\"=GeomFromText('POINT("+latitude+" "+ longtitude+")') "";
		DataSource dataSource=LocationPersistence.getDataSource();
		SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql, new int[0]);
		sqlUpdate.update();
		return loc;
	}