java

Spring Transaction not rolling back

我与影子孤独终老i 提交于 2021-02-18 11:20:10
问题 I have something like this: @Service @Transactional public class ServiceA { @Autowired SomeDAO1 dao1; @Autowired ServiceB serviceB; public void methodServiceA() { serviceB.someMethodThatRunsInsertIntoDB(); dao1.anotherMethodThatRunsInsertIntoDB(); } } @Service @Transactional public class ServiceB { @Autowired Dao2 dao2; public void someMethodThatRunsInsertIntoDB() { dao2.insertXXX(); } } My problem is: if serviceB.someMethodThatRunsInsertIntoDB() executes sucessfully but dao1

EJB/JPA Transaction Boundaries

情到浓时终转凉″ 提交于 2021-02-18 11:17:10
问题 I was reading EJB Transaction boundary and Transaction boundary Lets concentrate on RequiresNew Attribute . Here is the modified diagram from the link So let say method-B is annotated with RequiredNew attribute . so according to theory when method-A calls method-B a new transaction will be start and the already started transaction will be suspended, and when method-B returns the new transaction will be committed. Now consider that in section S1 we create a jpa entity using entitymanager

Mockito: is it possible to combine mock with a method name to create a methodCall inside a when() call?

落爺英雄遲暮 提交于 2021-02-18 11:15:09
问题 my first question on StackOverflow. I'd like to be able to do something like: SomeClass mock = mock(SomeClass.class); String methodName = "someMethod"; OR Method method = ...someMethod... Both of these things (the mock and the method) would combine to do the following: when(mock.someMethod()).thenReturn(null); Of course, the 'null' value will be changed accordingly for my needs, but I am trying to determine two things: 1) Is it even possible to do something like this in Java? This = combining

Encrypt video on the fly from android camera

百般思念 提交于 2021-02-18 11:14:26
问题 I want to encrypt video on the fly that android camera captures. So I need to tell android MediaRecorder to write it video stream to my CipherOutputStream . The problem is MediaRecorder.setOutputFile() method accepts only FileDescriptor and there is no way to get encrypting file descriptor from CipherOutputStream. So my question is how can I either emulate FileDescriptor to receive data writes and do encryption manually or somehow convince MediaRecorder to stream video into CipherOutputStream

Android open browser from service avoiding multiple tabs

懵懂的女人 提交于 2021-02-18 11:03:25
问题 I am trying to open the browser window from my service with a link that opens in the current tab of the browser. when I use Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com")); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(intent); If the browser was opened and in the foreground before my service starts the intent and the browser opens the link in the same window/tab. If the Browser was minimized and the

How to stub private methods of class under test by Mockito

蓝咒 提交于 2021-02-18 11:01:07
问题 Say we have java class called SomeClass public class SomeClass { private boolean isMethod() { return false; } public void sendRequest(String json, String text) { int messageId; if (isMethod()) { messageId = getMessageId(json); sendMessage(messageId, text); } else { throw new IllegalArgumentException(); } } private void sendMessage(int messageId, String text) { } private int getMessageId(String text) { Pattern p = Pattern.compile("messageId=(\\d+)&"); Matcher m = p.matcher(text); if (m.find())

中介者模式

喜夏-厌秋 提交于 2021-02-18 10:50:45
1.1 中介者 1.1.1 定义 中介者模式 (Mediator Pattern) 也称为调解者模式或调停者模式,Mediator 本身就有调停者和调解者的意思。在日常生活中调停者或调解者这个角色我们见得比较多的是 ”和事佬“,也就是说调解两个有争端的人的角色。中介者模式包装了一系列对象相互作用的方式,使得这些对象不必相互明显作用,从而使他们可以松散偶合。当某些对象之间的作用发生改变时,不会立即影响其他的一些对象之间的作用,保证这些作用可以彼此独立变化。中介者模式将多对多的相互作用转化为一对多的相互作用,将对象的行为和协作抽象化,把对象在小尺度的行为上与其他对象的相互作用分开处理。 1.1.2 角色 UML Mediator: 抽象中介者角色,定义了同事对象到中介者对象的接口,一般以抽象类的方式实现。 ConcreteMediator: 具体中介者角色,继承于抽象中介者,实现了父类定义的方法,它从具体的同事对象接收消息,向具体同事对象发出命令。 Colleague: 抽象同事类角色,定义了中介者对象的接口,它只知道中介者而不知道其它的同事对象。 ConcreteColleagueA/B: 具体同事类角色,继承于抽象同事类,每个具体同事类都知道本身在小范围内的行为,而不知道它在大范围内的目的。 1.1.3 代码 public class Demo { public static

toArray with pre sized array

微笑、不失礼 提交于 2021-02-18 10:49:47
问题 when using ar.toArray(new String[ar.size()]) Android studio 3.2.1 warns about pre-sized array and recommends empty array : There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of

toArray with pre sized array

≡放荡痞女 提交于 2021-02-18 10:49:08
问题 when using ar.toArray(new String[ar.size()]) Android studio 3.2.1 warns about pre-sized array and recommends empty array : There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()])) or using an empty array (like c.toArray(new String[0]). In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of

In Java, what is the fastest way to get the system time?

放肆的年华 提交于 2021-02-18 10:46:41
问题 I'm developing a system that often use the system time because the Delayed interface. What is fastet way to get the time from system? Currently I'm using Calendar.getInstance().getTimeInMillis() every time I need to get the time, but I don't know if there is a faster way. 回答1: System.currentTimeMillis() "Returns the current time in milliseconds" . Use this to get the actual system time. System.nanoTime(). "The value returned represents nanoseconds since some fixed but arbitrary origin time"