掲示板

How to avoid creating table in the database during service deploy in DXP?

thumbnail
6年前 に Abhishek Jain によって更新されました。

How to avoid creating table in the database during service deploy in DXP?

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
I don't want to create a table during service deployment. Can I do that in Liferay DXP? If yes, can anyone provide me the steps on how to do the same? Please help..thanks in advance
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
The table must exist for the service to be useful. If you don't want the table, don't deploy the service.







Come meet me at the 2017 LSNA!
thumbnail
6年前 に Abhishek Jain によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
Thanks for your reply David..but my need is to deploy the service to use its methods. Is fake entity concept there in liferay DXP? If yes what configuration I need to do to make it work..
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
The fake entity concept means that you're building an empty entity, with no properties. This will not create a table in the database, just make the service available.

An alternative to the original words of your question is to run Liferay with a database account that just doesn't have any CREATE TABLE permissions. This works even when you have an entity that has a table, but you'll need to create the table manually this way.
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Olaf Kock:
The fake entity concept means that you're building an empty entity, with no properties. This will not create a table in the database, just make the service available.


No, the "fake entity" concept is based on using a non-existent DB to create an entity which is not backed by the database.

Check out my blog, https://web.liferay.com/web/user.26526/blog/-/blogs/fake-servicebuilder-entities, for details how to define a null database. This process still works in Liferay 7 CE / Liferay DXP.








Come meet me at the 2017 LSNA!
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
.. but as someone pointed out recently (Christoph I think it was?), one of the beauties of the new OSGI world is that you don't have to use that fake entities approach anymore. In fact, I am pretty sure that the six part series that you (David) did to introduce development in 7 showed how to define your own API/Service without using service builder.

So if the goal is to use the old approach just to get a service/api pattern in place, the good news is that you don't have to do that anymore. Trying following the series that David did, but adjust for your business problem: https://web.liferay.com/web/user.26526/blog/-/blogs/liferay-7-development-part-1
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Right, Andrew, fake entities aren't the only way going forward in OSGi.

However, it may still be the easiest way to get remote services, either json and/or soap, with all of the service builder generated goodness. I mean, a service.xml file, a custom datasource and one "gradlew buildService" and you're ready to start dropping in methods. IMHO that kind of convenience is hard to beat.

But it certainly not the only way in the OSGi realm...







Come meet me at the 2017 LSNA!
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
Excellent point -- there is something nice about "clicking that one button" and then being able to use the Liferay.Service in your JS, or having the SOAP services available. I guess I'm just eager to try other patterns as well, including the new REST options that come with 7. Personally, I've always been an advocate for SB but I am also looking forward to still being able to deliver proper quality solutions when I lose the SB arguments with clients emoticon
thumbnail
6年前 に Christoph Rabel によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
Service Builder was a necessity in 6.2, since it was the only way to create services. But it was a workaround and a hack to use fake entities.

In Liferay 7 I prefer to write SomeService Interface, SomeServiceImpl and write an activator.
That's all the code I need to start:


public interface SomeService {
	public void doSomething();
}

public class SomeServiceImpl implements SomeService {
	public void doSomething() {...}
}

public class SomeServiceActivator implements BundleActivator {
	@Override
	public void start(BundleContext bundleContext) throws Exception {
		Registry registry = RegistryUtil.getRegistry();
		_serviceRegistration = registry.registerService(SomeService.class, new SomeServiceImpl());
	}

	@Override
	public void stop(BundleContext bundleContext) throws Exception {
		if (_serviceRegistration != null) {
			_serviceRegistration.unregister();
			_serviceRegistration = null;
		}
	}
private ServiceRegistration<someservice> _serviceRegistration = null;
}
</someservice>


And if I need it as a rest service I can add the JSONWebService annotation and *magic* it is even added to /api/jsonws. IMHO it doesn't get any simpler than that. (Actually I prefer to not use JSONWebservice but jax-rs, but it would be possible)
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Yep, we have lots more options now.

I don't know there's a hard and fast rule for which one to pick, and they all have their strengths and weaknesses.









Come meet me at the 2017 LSNA!
thumbnail
6年前 に Jack Bakker によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
David H Nebinger:
Yep, we have lots more options now.
I don't know there's a hard and fast rule for which one to pick, and they all have their strengths and weaknesses.


I have a v6.2 need for an entity XYZ which is to have attributes from multiple other entities (X,Y,Z). I then need to provide, via remote and local services: a list of such XYZs. For v6.2 I am looking at a fake entity and as I do, I wonder on how best to plan for continue to supporting this XYZ need on upgrade to v7(DXP).

Any advice ? Go with a fake entity for now and then later on rewrite for DXP: refactor into non-hack OSGi approaches ? or...
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Fake entities still work in DXP, Jack, and I'd argue that they still have a place.

I mean, ServiceBuilder will still generate a slew of code for your local and remote services based off of the entities. You still get automagic JSON and SOAP web service support, etc.

If you still have those requirements, then a Fake Entity will still help you get there.

If that's way more than you need, though, you might go to clean JSON or even REST support available in LR7CE/DXP.







Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
6年前 に Jack Bakker によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
I like your argument David. Thanks
thumbnail
6年前 に Abhishek Jain によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
Christoph Rabel:


And if I need it as a rest service I can add the JSONWebService annotation and *magic* it is even added to /api/jsonws. IMHO it doesn't get any simpler than that. (Actually I prefer to not use JSONWebservice but jax-rs, but it would be possible)


I tried using @JSONWebService to the Service interface but it is not added to /api/jsonws. Can u tell me why?
thumbnail
6年前 に Christoph Rabel によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX (回答)

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
Yes, you need to register it in an activator. The annotations alone were not sufficient for me.


@AccessControlled
@JSONWebService
@OSGiBeanProperties(property = {
"json.web.service.context.name=dccs", "json.web.service.context.path=dccs"}, service = MyJSONService.class)
public class MyJSONService {
// Your methods here
}

@Override
	public void start(BundleContext bundleContext) throws Exception {
		Dictionary<string, object> properties = new Hashtable&lt;&gt;();

		properties.put("json.web.service.context.name", "dccs");
		properties.put("json.web.service.context.path", "dccs");

		_osgiRegistration = bundleContext.registerService(
					Object.class, new MyJSONService(), properties);
	}

	@Override
	public void stop(BundleContext bundleContext) throws Exception {
		if (_osgiRegistration != null) {
			_osgiRegistration.unregister();
			_osgiRegistration = null;
		}
	}	
		
	private org.osgi.framework.ServiceRegistration<object> _osgiRegistration = null;
</object></string,>
thumbnail
6年前 に Abhishek Jain によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
Thanks Christoph, it worked..
thumbnail
6年前 に Christoph Rabel によって更新されました。

RE: How to avoid creating table in the database during service deploy in DX

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
May I ask, what you actually want to accomplish?
Please give us more context

e.g. something like:

- I already have tables and I don't want service builder to "mess" with them
- I just need a webservice, I don't need any database at all
- ?