tag:blogger.com,1999:blog-28513466457163166692024-03-14T06:46:45.990-07:00Programmer's ChroniclesKirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.comBlogger36125tag:blogger.com,1999:blog-2851346645716316669.post-39394399115893964782012-02-20T02:49:00.001-08:002012-02-20T02:53:43.854-08:00Hibernate Proxy<div dir="ltr" style="text-align: left;" trbidi="on">
Есть много нюансов с прокси объектами. Кроме того что они протухают, их equals метод может удивить, т.к. отличается от equals клёвого объекта. Так, он по умолчанию сравнивает все поля клёвого объекта, что может привести к лэйзиинициалиэйшн и тп.<br />
<br />
Вот тут в тему, рядом.<br />
<a href="http://blog.xebia.com/2008/03/08/advanced-hibernate-proxy-pitfalls/">http://blog.xebia.com/2008/03/08/advanced-hibernate-proxy-pitfalls/</a>
<br />
<br />
P.S. Hibernate.initialize(..) инициализирует сам прокси, но не меняет его equals, так же как не инициализирует его lazy поля.</div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-88579709310891504222011-10-09T13:36:00.000-07:002011-10-09T13:36:31.308-07:00Motorola DEFY Fuck/Flashing<div dir="ltr" style="text-align: left;" trbidi="on">
Изначально в телефоне была прошивка ANDROID 2.1(BLUR)<br />
Которая как то работала, правда после 2-3 дней работы начинала здорово подтормаживать - переставали нормально работать самые нужные телефонные функции, так например при входящем звонке нажатие на кнопку ответа подвисало секунд на 20, а за это время звонок успевали уже сбросить. Установка всячиских приблуд(типа систем тюнеров и таск мэнеджеров), удаление виджетов и хард ресеты ситуацию не исправили. Прошивка на 2.2(BLUR) только усугубила ситуацию. Стали жёстко тормозить Google Maps и вообще вес интерфейс.<br />
В итоге решил попробовать перепрошиться с 2.2 на 2.3. Поскольку официальных прошивок не было, да и MOTOBLUR был первым кандидатом на роль источника тормозов, начал исследования любительских прошивок. После изучения возможных вариантов выбрал<br />
<a href="http://www.wuala.com/Bell071/Motorola/%D0%9F%D1%80%D0%BE%D1%88%D0%B8%D0%B2%D0%BA%D0%B8/Defy/MIUI%20%D0%BE%D1%82%20Kojan/1.10.7(8)/%D0%9D%D0%B0%20%D0%BE%D1%81%D0%BD%D0%BE%D0%B2%D0%B5%20miuiandroid.com/evolution_umts_jordan_1.10.8_0032Prototype_1110090120_deodexed.zip/">MIUI от Kojan 1.10.7(8)</a>. Перебрал разные варианты софта в итоге нашёл более менее правильное(простое) решение.<br />
<br />
<b>1. Установка root</b><br />
<span class="Apple-style-span" style="background-color: #fbf8f4; color: #111111;"><span class="Apple-style-span" style="font-family: inherit;"><span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Использовал утилиту </span><strong style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">SuperOneClick</span>.</strong></span></span><br />
<span class="Apple-style-span" style="color: #111111;">Качаем её с родного сайта </span><a href="ftp://shortfuse.org/SuperOneClick/Packages/">ftp://shortfuse.org/SuperOneClick/Packages/</a><br />
И читаем <a href="http://4pda.ru/forum/index.php?showtopic=200800&st=220">http://4pda.ru/forum/index.php?showtopic=200800&st=220</a><br />
<a href="http://forum.xda-developers.com/showthread.php?t=803682">http://forum.xda-developers.com/showthread.php?t=803682</a><br />
<span class="Apple-style-span" style="font-family: inherit;">Перед установкой необходимо поставить </span><br />
<span class="Apple-style-span" style="background-color: #fafcfe; line-height: 19px;"><span class="Apple-style-span" style="font-family: inherit;">NET.Framework, JDK 1.6 , Android SDK</span></span><br />
<br />
<b>2. Установка загрузчика</b><br />
Скачиваем <span class="Apple-style-span" style="background-color: #fbf8f4; color: #111111;"><strong style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><a href="https://market.android.com/details?id=com.pedronveloso.sndinitdefy">2ndInit </a></strong><span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">через AndroidMarket.</span></span></span><br />
<span class="Apple-style-span" style="background-color: #fbf8f4; color: #111111;"><span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;"><a href="http://forum.xda-developers.com/showthread.php?t=1032212">http://forum.xda-developers.com/showthread.php?t=1032212</a></span></span></span><br />
<span class="Apple-style-span" style="background-color: #fbf8f4; color: #111111;"><span style="background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><a href="http://www.appbrain.com/app/defy-2ndinit/com.pedronveloso.sndinitdefy">http://www.appbrain.com/app/defy-2ndinit/com.pedronveloso.sndinitdefy</a></span></span><br />
<span class="Apple-style-span" style="color: #111111;">Запускаем его как обычную программу и инсталируем последнюю версию. </span><br />
<span class="Apple-style-span" style="color: #111111;">В 2ndInit встроен </span><span class="Apple-style-span" style="background-color: white; font-family: 'Arial Narrow'; line-height: 19px;"><b>ClockworkMod Recovery</b></span><span class="Apple-style-span" style="background-color: white; font-family: 'Arial Narrow'; line-height: 19px;">, который используется для бэкапов и перепрошивки.</span><br />
<span class="Apple-style-span" style="color: #111111;"><br /></span><br />
<b>3. Бэкап</b><br />
Делается после перезагрузки телефона в меню 2ndInit<span class="Apple-style-span" style="background-color: white;">.</span><br />
<br />
<b>4. Перепрошивка</b><br />
Делается через меню 2ndInit<br />
Про разные прошивки можно почитать тут<br />
<a href="http://4pda.ru/forum/index.php?showtopic=239103&st=560#entry8883267">http://4pda.ru/forum/index.php?showtopic=239103&st=560#entry8883267</a><br />
Выбрал эту<br />
<a href="http://www.wuala.com/Bell071/Motorola/%D0%9F%D1%80%D0%BE%D1%88%D0%B8%D0%B2%D0%BA%D0%B8/Defy/MIUI%20%D0%BE%D1%82%20Kojan/1.10.7(8)/%D0%9D%D0%B0%20%D0%BE%D1%81%D0%BD%D0%BE%D0%B2%D0%B5%20miuiandroid.com/evolution_umts_jordan_1.10.8_0032Prototype_1110090120_deodexed.zip/">MIUI от Kojan 1.10.7(8)</a>.</div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-66678648813750271382011-08-26T03:18:00.000-07:002011-08-26T03:20:01.631-07:00Java Polymorphism issue<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<br />
<pre style="color: black; font-family: monospace; font-style: normal; font-weight: normal;"><span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> XXX {
<span style="color: olive; font-style: normal; font-weight: normal;">@Test</span>
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> test() {
B b = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> B();
b.doY();
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">class</span> A {
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> doY() {
XProcedure.<span style="color: black; font-style: italic; font-weight: normal;">doX</span>(<span style="color: navy; font-style: normal; font-weight: bold;">this</span>);
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">class</span> B <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> A {
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> doY() {
<span style="color: navy; font-style: normal; font-weight: bold;">super</span>.doY();
XProcedure.<span style="color: black; font-style: italic; font-weight: normal;">doX</span>(<span style="color: navy; font-style: normal; font-weight: bold;">this</span>);
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">class</span> XProcedure {
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> doX(A <span style="color: grey; font-style: normal; font-weight: normal;">a</span>) {
System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"</span><span style="color: green; font-style: normal; font-weight: bold;">AAAA</span><span style="color: green; font-style: normal; font-weight: bold;">!"</span>);
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> doX(B <span style="color: grey; font-style: normal; font-weight: normal;">b</span>) {
System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"</span><span style="color: green; font-style: normal; font-weight: bold;">BBBB</span><span style="color: green; font-style: normal; font-weight: bold;">!"</span>);
}
}
</pre>
<br />
What is output =) ?<br />
<br />
<br />
Answer:<br />
<span class="Apple-style-span" style="color: white;">AAAA!</span><br />
<span class="Apple-style-span" style="color: white;">BBBB!</span><br />
<br />
<br />
<br />
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<br />
<div>
<br /></div>
</div>
Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-30258995865202477562011-08-10T05:49:00.000-07:002011-11-06T23:50:07.241-08:00SOAPFaultException на платформах .NET и Java, опыт работы с JAX-WS<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">На днях поимел опыт работы с вебсервисами из коробки-моробки JAX-WS.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>1</b>. Все исключения выбрасываемые эндпоинтом нужно делать кастомными и аннотировать</span><br />
<pre style="color: green; font-family: monospace; font-style: normal; font-weight: bold;"><span style="color: olive; font-style: normal; font-weight: normal;">@WebFault</span><span style="color: black; font-style: normal; font-weight: normal;">(name = </span>"CRUDSoapException"<span style="color: black; font-style: normal; font-weight: normal;">, targetNamespace = </span>"<span style="color: green; font-style: normal; font-weight: bold;">wsdl</span>.xxx"<span style="color: black; font-style: normal; font-weight: normal;">)</span></pre>
<pre style="font-family: monospace; font-style: normal;">см. <a href="http://io.typepad.com/eben_hewitt_on_java/2009/07/using-soap-faults-and-exceptions-in-java-jaxws-web-services.html">блог Eben Hewitt</a> </pre>
<pre style="font-family: monospace; font-style: normal;"></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Иначе на клиента вываливается SOAPFaultException с кускокм строкового говна, который как бы описывает иксэпшн.</span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">
</span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>2</b>. Все исключения <span class="Apple-style-span" style="white-space: normal;"> выбрасываемые эндпоинтом</span> приходят на платформу .NET в виде строкового</span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> говна </span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">(обёрнутого в </span>SOAPFaultException<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">) в не зависимости от способа объявления на эндпоинте.</span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">
</span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>3</b>.JAX-B может зажевать исключения возникающие при сериализации, и чтобы таки их увидеть нужно включить такой параметр в запуск программы <b> -Djavax.net.debug=all</b></span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">
</span></pre>
<pre style="font-style: normal;"><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>4</b>. JAX-B не умеет сериализовать прокси объекты Hibernate (да и вообще - наверное любые сгенерённые прокси). Бороть так <a href="http://stackoverflow.com/questions/2216547/converting-hibernate-proxy-to-real-object">converting-hibernate-proxy-to-real-object</a></span></pre>
<pre style="font-style: normal;"><b style="font-family: Times, 'Times New Roman', serif;">5</b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">. </span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">JAX-B не умеет сериализовать интерфейсы. Если есть необходимость использовать интерфейс можно сделать абстрактный класс реализующий этот интерфейс и обвесить его </span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">JAX-B </span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">аннотациями(@XmlSeeAlso - с указанием классов). В дальнейшем в коде можно будет использовать этот интерфейс добавив для него частный </span><span class="Apple-style-span" style="background-color: #f3f3f3; color: #333333; font-family: 'Lucida Console', Monaco, 'DejaVu Sans Mono', monospace; font-size: 13px;">@XmlJavaTypeAdapter,</span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> который будет тупо преобразовывать абстрактный класс в интерфейс</span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">. </span></pre>
<br />
<div>
<br /></div>
<br />
<br /></div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-82121110442580693232011-03-20T02:49:00.000-07:002011-03-20T03:34:10.330-07:00Наибольшая общая подпоследовательность<div dir="ltr" style="text-align: left;" trbidi="on">
<!--StartFragment--><br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"><span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> SequenceTest {
<span style="color: grey; font-style: italic; font-weight: normal;">//0 1 2 3 4 5 6 7 8</span>
<span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">int</span>[] <span style="color: #660e7a; font-style: italic; font-weight: bold;">qwe</span> = {<span style="color: blue; font-style: normal; font-weight: normal;">1</span>, <span style="color: blue; font-style: normal; font-weight: normal;">4</span>, -<span style="color: blue; font-style: normal; font-weight: normal;">6</span>, <span style="color: blue; font-style: normal; font-weight: normal;">2</span>, -<span style="color: blue; font-style: normal; font-weight: normal;">1</span>, <span style="color: blue; font-style: normal; font-weight: normal;">5</span>, <span style="color: blue; font-style: normal; font-weight: normal;">2</span>, <span style="color: blue; font-style: normal; font-weight: normal;">0</span>, -<span style="color: blue; font-style: normal; font-weight: normal;">6</span>};
<span style="color: grey; font-style: italic; font-weight: normal;">//static int[] qwe = {1, 2, 3, 4, 5, 6, 7};</span>
<span style="color: olive; font-style: normal; font-weight: normal;">@Test</span>
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> test() {
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> maxSum = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> i1 = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> i2 = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> newSum = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> i1n = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> i2n = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">for</span> (<span style="color: navy; font-style: normal; font-weight: bold;">int</span> i = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>; i < <span style="color: #660e7a; font-style: italic; font-weight: bold;">qwe</span>.<span style="color: #660e7a; font-style: normal; font-weight: bold;">length</span>; i++) {
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> x = <span style="color: #660e7a; font-style: italic; font-weight: bold;">qwe</span>[i];
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (newSum == <span style="color: blue; font-style: normal; font-weight: normal;">0</span>) {
i1n = i;
}
i2n = i;
<span style="color: navy; font-style: normal; font-weight: bold;">int</span> current = newSum + x;
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (current > newSum) {<span style="color: grey; font-style: italic; font-weight: normal;">//</span><span style="color: grey; font-style: italic; font-weight: normal;">подпоследовательность</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">растёт</span>
newSum = current;
} <span style="color: navy; font-style: normal; font-weight: bold;">else</span> {<span style="color: grey; font-style: italic; font-weight: normal;">//</span><span style="color: grey; font-style: italic; font-weight: normal;">подпоследовательность</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">начала</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">уменьшаться</span>
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (newSum > maxSum) {<span style="color: grey; font-style: italic; font-weight: normal;">//</span><span style="color: grey; font-style: italic; font-weight: normal;">если</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">сумма</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">текущей</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">подпоследовательности</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">больше</span><span style="color: grey; font-style: italic; font-weight: normal;"> чем maxSum - </span><span style="color: grey; font-style: italic; font-weight: normal;">запомним</span><span style="color: grey; font-style: italic; font-weight: normal;"> её</span>
maxSum = newSum;
i1 = i1n;
i2 = i2n;
}
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (current <= <span style="color: blue; font-style: normal; font-weight: normal;">0</span>) {<span style="color: grey; font-style: italic; font-weight: normal;">//</span><span style="color: grey; font-style: italic; font-weight: normal;">если</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">подпоследовательность</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">меньше</span><span style="color: grey; font-style: italic; font-weight: normal;"> 0 она уже не </span><span style="color: grey; font-style: italic; font-weight: normal;">может</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">быть</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">полезной</span>
newSum = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
i1n = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
i2n = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
} <span style="color: navy; font-style: normal; font-weight: bold;">else</span> {<span style="color: grey; font-style: italic; font-weight: normal;">//</span><span style="color: grey; font-style: italic; font-weight: normal;">продолжаем</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">рассматривать</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">уменьшающуюся</span><span style="color: grey; font-style: italic; font-weight: normal;"> </span><span style="color: grey; font-style: italic; font-weight: normal;">последовательность</span>
newSum = current;
}
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (maxSum == <span style="color: blue; font-style: normal; font-weight: normal;">0</span> && newSum > <span style="color: blue; font-style: normal; font-weight: normal;">0</span>) {
maxSum = newSum;
i1 = i1n;
i2 = i2n;
}
System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(i1 + <span style="color: green; font-style: normal; font-weight: bold;">"-"</span> + i2 + <span style="color: green; font-style: normal; font-weight: bold;">" maxSum:"</span> + maxSum);
}
}
</pre>
<!--EndFragment--><br />
<div>
<br /></div>
</div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-25494661480375172732011-03-16T06:47:00.000-07:002011-03-20T02:45:34.790-07:00XStream vs Simple<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-family: inherit;">XStream быстрее чем Simple приблизительно в два раза. Тестил под Windows. Для теста были созданы сущности с дублирующими друг друга аннотациями для XStream и Simple.</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br /></span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br /></span><br />
<span class="Apple-style-span" style="font-family: inherit;">Класс тестика:</span><br />
<pre style="color: black; font-family: monospace; font-style: normal; font-weight: normal;"><span style="color: navy; font-style: normal; font-weight: bold;">package</span> ru.test.serialization;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> com.thoughtworks.xstream.XStream;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> com.thoughtworks.xstream.io.xml.*;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> <span style="color: olive; font-style: normal; font-weight: normal;">org.junit.Test</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> org.simpleframework.xml.convert.AnnotationStrategy;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> org.simpleframework.xml.core.Persister;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> org.simpleframework.xml.strategy.Strategy;
<span style="color: navy; font-style: normal; font-weight: bold;">import</span> java.io.StringWriter;
<span style="color: grey; font-style: italic; font-weight: normal;">/**</span>
<span style="color: grey; font-style: italic; font-weight: normal;"> * </span><span style="color: grey; font-style: italic; font-weight: bold;">@author</span><span style="color: grey; font-style: italic; font-weight: normal;"> k.burmistrov</span>
<span style="color: grey; font-style: italic; font-weight: normal;"> */</span>
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> SimpleVSXstream {
<span style="color: olive; font-style: normal; font-weight: normal;">@Test</span> <span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> test() {
XStream xStream = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> XStream(<span style="color: navy; font-style: normal; font-weight: bold;">new</span> DomDriver());
Persister serializer = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> Persister();
<span style="color: navy; font-style: normal; font-weight: bold;">long</span> <span style="color: black; font-style: normal; font-weight: normal;">smplstart</span>;
<span style="color: navy; font-style: normal; font-weight: bold;">long</span> <span style="color: black; font-style: normal; font-weight: normal;">smplexec</span>Time = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
Container container;
<span style="color: navy; font-style: normal; font-weight: bold;">long</span> <span style="color: black; font-style: normal; font-weight: normal;">xsstart</span>;</pre>
<pre style="color: black; font-family: monospace; font-style: normal; font-weight: normal;"> <span style="color: navy; font-style: normal; font-weight: bold;">long</span> <span style="color: black; font-style: normal; font-weight: normal;">xsexec</span>Time = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>;
String res = <span style="color: green; font-style: normal; font-weight: bold;">""</span>;</pre>
<pre style="color: black; font-family: monospace; font-style: normal; font-weight: normal;"> <span style="color: navy; font-style: normal; font-weight: bold;">for</span> (<span style="color: navy; font-style: normal; font-weight: bold;">int</span> i = <span style="color: blue; font-style: normal; font-weight: normal;">0</span>; i < <span style="color: blue; font-style: normal; font-weight: normal;">100</span>; i++) {
container = ContainerCreator.<span style="color: black; font-style: italic; font-weight: normal;">getContainer</span>();
xsstart = System.<span style="color: black; font-style: italic; font-weight: normal;">currentTimeMillis</span>();
res = xStream.toXML(container);
xsexecTime = xsexecTime + (System.<span style="color: black; font-style: italic; font-weight: normal;">currentTimeMillis</span>() - xsstart);
StringWriter writer = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> StringWriter();
<span style="color: navy; font-style: normal; font-weight: bold;">try</span> {
smplstart = System.<span style="color: black; font-style: italic; font-weight: normal;">currentTimeMillis</span>();
serializer.write(container,writer);
} <span style="color: navy; font-style: normal; font-weight: bold;">catch</span> (Exception e) {
smplstart = System.<span style="color: black; font-style: italic; font-weight: normal;">currentTimeMillis</span>();
e.printStackTrace();
}
res = writer.toString();
smplexecTime = smplexecTime + (System.<span style="color: black; font-style: italic; font-weight: normal;">currentTimeMillis</span>() - smplstart);
}
System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println( <span style="color: green; font-style: normal; font-weight: bold;">"</span><span style="color: green; font-style: normal; font-weight: bold;">XSTREAM</span><span style="color: green; font-style: normal; font-weight: bold;"> x 100 = "</span> + xsexecTime);
System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println( <span style="color: green; font-style: normal; font-weight: bold;">"SIMPLE x 100 = "</span> + smplexecTime);
System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"</span><span style="color: navy; font-style: normal; font-weight: bold;">\n</span><span style="color: green; font-style: normal; font-weight: bold;">"</span> + ContainerCreator.<span style="color: black; font-style: italic; font-weight: normal;">toDebugString</span>(res));
}
}</pre>
<span class="Apple-style-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: inherit;">Результирующий вывод:</span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span" style="white-space: pre;">XSTREAM x 100 = 138
SIMPLE x 100 = 213</span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span" style="white-space: pre;"><br /></span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span"></span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span"><span class="Apple-style-span" style="white-space: pre;"></span></span></span><br />
<span class="Apple-style-span"><span class="Apple-style-span"><CONTAINER PART="0"><br />
<BIG CODE="String code 50.35868861427403564" LOGIN="String login 50.7245088483040268" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
<BIG CODE="String code" LOGIN="String login" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 10.06973240045944129" LOGIN="String login 10.9788960825360289" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 20.627970543681521" LOGIN="String login 20.5815827829176397" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 30.9800044849451679" LOGIN="String login 30.5987182743788726" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 40.9685538564759587" LOGIN="String login 40.11954755881153056" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
</BIG><br />
<BIG CODE="String code 60.9978869534936364" LOGIN="String login 60.22744058846132909" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
<BIG CODE="String code" LOGIN="String login" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 10.06973240045944129" LOGIN="String login 10.9788960825360289" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 20.627970543681521" LOGIN="String login 20.5815827829176397" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 30.9800044849451679" LOGIN="String login 30.5987182743788726" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
<BIG CODE="String code 40.9685538564759587" LOGIN="String login 40.11954755881153056" SUBADDRESS="0"><br />
<PART PART="0" SERIAL="0"/><br />
</BIG><br />
</BIG><br />
</CONTAINER></span></span><br />
<br />
<div style="white-space: pre;">
<span class="Apple-style-span"><span class="Apple-style-span"><br /></span></span></div>
PS: значение атрибутов генериловалось для каждой итерации новое<br />
<div>
<span class="Apple-style-span" style="white-space: pre;"><span class="Apple-style-span" style="font-family: inherit;"><br /></span></span></div>
<pre style="color: black; font-style: normal; font-weight: normal;"><span class="Apple-style-span" style="font-family: inherit;">
</span></pre>
<pre style="color: black; font-style: normal; font-weight: normal;"><span class="Apple-style-span" style="font-family: inherit;">
</span></pre>
<pre style="color: black; font-style: normal; font-weight: normal;"><span class="Apple-style-span" style="font-family: inherit;">
</span></pre>
<pre style="color: black; font-style: normal; font-weight: normal;"><span class="Apple-style-span" style="font-family: inherit;">
</span></pre>
</div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-31788870024162630722011-02-08T09:12:00.000-08:002011-02-08T09:22:00.053-08:00SQL Поиск дырок<div dir="ltr" style="text-align: left;" trbidi="on">
Задача: в последовательности айдишников найти пропуски.<br />
<br />
<b>Пример 1: Дырка в одну цифру. </b><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAxQvyzIPA4xb8nFwGpqQfZ9rdHAoWCK7_n6QbNvfRtcTV8fPIUXWYiTtxikbk6O59o2K_zgs3no0_SLj_kmfK3aF4ASZH6z-UobLAayxQLRtRVLs6tcUK1Nv_WV2gPtCEcgjrOSAKTxad/s1600/1.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAxQvyzIPA4xb8nFwGpqQfZ9rdHAoWCK7_n6QbNvfRtcTV8fPIUXWYiTtxikbk6O59o2K_zgs3no0_SLj_kmfK3aF4ASZH6z-UobLAayxQLRtRVLs6tcUK1Nv_WV2gPtCEcgjrOSAKTxad/s1600/1.jpg" /></a><br />
В таблице "_IDCHECK" нужно<br />
<b>Найти 6.</b><br />
<br />
Наверное проще всего это сделать при помощи left outer join.<br />
Джоиним таблицу саму с собой со сдвигом на 1.<br />
Чтобы понять как это работает сначала посмотрим результаты такого запроса<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRaFsELRmFAu2SRGZlIsMwPKTTNAO-7YUQV1uCkZhf-vpkBhS4O7STO1GdDi3YbkFmtWQQoV_fw_Ez-Ov63PgT1opz37gfPSAzfFMiH2xdeCxwbemtDSPmE1tjYdSgo58ldPbKvSVN1vFx/s1600/1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRaFsELRmFAu2SRGZlIsMwPKTTNAO-7YUQV1uCkZhf-vpkBhS4O7STO1GdDi3YbkFmtWQQoV_fw_Ez-Ov63PgT1opz37gfPSAzfFMiH2xdeCxwbemtDSPmE1tjYdSgo58ldPbKvSVN1vFx/s1600/1.jpg" /></a><br />
<br />
select a.id, b.id<br />
from "_IDCHECK" as a<br />
left outer join "_IDCHECK" as b on (a.id+1) = (b.id)<br />
<br />
<br />
<br />
Осталось выбрать столбцы где b.id == null<br />
<br />
<br />
select a.id+1<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidteo_3dhNC0oQrBtuqgTLfKQl0GbZ0Vkm1UATJS8V8bmXVyPtuA_XcZu5-eMmy1TNCXmXtPRwGic5STltp7FF4BCQ7uTgs3PlUEVODyif4Zs9-bi67eQD-ejI-iRIhTk1rohqD7u1Bmlf/s1600/1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidteo_3dhNC0oQrBtuqgTLfKQl0GbZ0Vkm1UATJS8V8bmXVyPtuA_XcZu5-eMmy1TNCXmXtPRwGic5STltp7FF4BCQ7uTgs3PlUEVODyif4Zs9-bi67eQD-ejI-iRIhTk1rohqD7u1Bmlf/s1600/1.jpg" /></a>from "_IDCHECK" as a<br />
left outer join "_IDCHECK" as b on (a.id+1) = (b.id)<br />
where b.id is null<br />
<br />
И убрать последнее значение<br />
<br />
<br />
select a.id+1<br />
from "_IDCHECK" as a<br />
left outer join "_IDCHECK" as b on (a.id+1) = (b.id)<br />
where b.id is null and a.id<(select max(id) from "_IDCHECK" )<br />
<br />
ЗЫ: тоже самое можно написать через select<br />
<br />
<br />
select a.id+1 from "_IDCHECK" as a<br />
where not exists(select * from "_IDCHECK" as b where b.id=a.id+1)<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-53486858452529903292010-11-26T15:12:00.000-08:002010-11-27T05:31:23.317-08:00NEUROMANCER переводы на русский<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Русский(Б.Кадников, О.Колесников) - <a href="http://lib.ru/GIBSON/gibso01.txt">http://lib.ru/GIBSON/gibso01.txt</a></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Русский(М. Пчелинцев и Е. Летов)<a href="http://lib.rus.ec/b/160980">http://lib.rus.ec/b/160980</a></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Английский - <a href="http://project.cyberpunk.ru/lib/neuromancer/">http://project.cyberpunk.ru/lib/neuromancer/</a></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Однажды пришли Б.Кадников, О.Колесников(далее <b>БКОК</b>) и перевели Neuromancer.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Сначала они перевели название. Нейромантик. Забавно звучит. Тобишь, есть Нейромант, а это - рассказ про его маленького сына - Нейромантика. Хорошо что не перевели как Нерво-Сочинитель. Вообще в русском переводе самое оторванное название было бы - мозгопар. Спустя пару лет после <b>БКОК </b>пришли М. Пчелинцев и Е. Летов(<b>МПЕЛ</b>), и тоже перевелии. Название перевели нормально, а в остальном также. Но перевод <b>МПЕЛ </b>мне как то приятнее читать, и тупят они меньше, хотя точность перевода местами оставляет желать лучшего. Ну, перейдём к тексту - вот несколько какашечек с перевой же странички.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<u><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> <b>1. БКОК Не понял юмор, </b><i><span class="Apple-style-span" style="font-style: normal;"><b>МПЕЛ молодец </b></span></i></span></u><br />
<b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Eng</span></b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">. `It's not like I'm using,' Case heard someone say, as he</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">shouldered his way through the crowd around the door of the</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Chat. `It's like my body's developed this massive drug deficiency.'</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> <b>БКОК</b>. Проталкиваясь через толпу перед дверями "Чата", Кейс услышал, как</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">кто-то сказал:</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> - Не то чтобы мне все это нравилось. <i>Просто мой организм уже привык к</i></span><br />
<i><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">тому, что я в него вкачиваю.</span></i><br />
<i><span class="Apple-style-span" style="font-style: normal;"><b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">МПЕЛ. </span></b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">— Разве же я употребляю? — услышал Кейс, продираясь сквозь толпу к «Тацу». — </span></span><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Просто у моего организма острая алкогольно–наркотическая недостаточность.</span></i><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<b><u><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">2.БКОК придумал слово, МПЕЛ его переписал </span></u></b><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> <b>Eng</b>. Sprawl (the urban area formed by the expansion of a town or city into surrounding countryside</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">)</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> <b>БКОК</b>. Мурашовник</span><br />
<i><span class="Apple-style-span" style="font-style: normal;"><b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> МПЕЛ. </span></b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Муравейник</span></span></i><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> <b>Правильный</b>. Окраины, Пригород. Можнно назвать Бутово(в оригинали это окраины Бостона, так что первая буква хоть правильная)(<a href="http://en.wikipedia.org/wiki/The_Sprawl">http://en.wikipedia.org/wiki/The_Sprawl</a>).</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><a href="http://en.wikipedia.org/wiki/The_Sprawl"></a></span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<b><u><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">3.БКОК упускает детали и путает значения прилагательных, МПЕЛ упускает нюансы словоблудия оригинала</span></u></b><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> <b>Eng</b>. Case found a place at the bar, between the <i>unlikely </i>tan on one of Lonny Zone's whores and the crisp <i>naval </i>uniform of a tall African whose cheekbones were ridged with precise rows of tribal scars</span><br />
<b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">БКОК</span></b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">. Кейс разыскал себе место за стойкой, между</span><br />
<i><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">неприглядным </span></i><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">загаром одной из шлюх Лонни Зона и чистенькой униформой</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">высокого африканца, чьи щеки украшали ровные ряды ритуальных шрамов.</span><br />
<i><span class="Apple-style-span" style="font-style: normal;"><b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">МПЕЛ.</span></b></span></i><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Тот нашел себе место у стойки между <i>невероятно </i>загорелой шлюхой из команды Лонни Зоуна и высоким африканцем в отглаженной морской форме с аккуратными рядами племенных шрамов на щеках.</span><br />
<b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Правильный</span></b><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">. Кейс разыскал себе место за стойкой, между</span><br />
<i><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">неестественным </span></i><span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">загаром одной из шлюх Лонни Зона и отглаженной <i>морской </i>униформой</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">высокого африканца, чьи щеки украшали ровные ряды ритуальных шрамов.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><br /></span><br />
<br />
<div style="font-weight: bold; text-decoration: underline;">
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">4.БКОК пытается переводить ближе к тексту. МПЕЛ пейсатель сам</span></div>
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>Eng</b>.`Isn't you either, sister. So you vanish, okay? Zone, he's</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">a close personal friend of mine.'</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> She looked Case in the eye and made the softest possible</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">spitting sound, her lips barely moving. But she left.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>БКОК</b>. - К тебе это тоже относится, сестренка. Линяй отсюда, ага? Зон - один</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">из моих друзей.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"> Девушка посмотрела Кейсу в глаза и изобразила плевок, но тем и</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">ограничилась. Затем молча встала и отошла.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>МПЕЛ</b>.— И у тебя, цыпа, тоже не выйдет. И вообще, вали–ка ты отсюда. Мистер Зоун — мой лучший друг.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;">Девица в упор взглянула на Кейса и беззвучно ощерилась. Но все–таки ушла.</span><br />
<span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"><b>Правильный</b>. И у тебя тоже сестричка, так что исчезни, ладно? Мистер Зоун — мой хороший друг. Шлюшка посмотрела Кейсу в глаза и тихо сплюнула, её губы дрогнули. Но она ушла.</span><br />
<br />
<pre></pre>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-14785248271687368602010-10-02T14:29:00.000-07:002010-10-14T07:05:50.121-07:00SCJP/OCPJP(Oracle Certified Professional Java Programmer)СОРС<br />
<a href="http://in.sun.com/training/catalog/courses/CX-310-065.xml">http://in.sun.com/training/catalog/courses/CX-310-065.xml</a><br />
<br />
<br />
БРИФ<br />
1)<a href="http://www.rsdn.ru/article/java/scjp_article.xml">http://www.rsdn.ru/article/java/scjp_article.xml</a> Вспомнить то что не знал.<br />
Полезность 5 из 5.<br />
3)<span class="Apple-style-span" style="font-family: Arial, sans-serif; white-space: nowrap;"></span><br />
<h1 class="title" dir="ltr" style="display: inline; margin-left: 2px;">
<span class="Apple-style-span" style="font-size: medium;"><span class="Apple-style-span" style="font-weight: normal;"><a href="http://books.google.ru/books?id=Eh5NcvegzMkC&lpg=PP1&ots=ESQ7ACWXPq&dq=Kathy%20Sierra%20%20Bert%20Bates%20scjp&pg=PR35#v=onepage&q&f=false">SCJP Sun Certified Programmer for Java 6 Study Guide</a></span></span></h1>
<span class="addmd" style="margin-left: 2px;">Авторы: Kathy Sierra,Bert Bates. </span>Самая клёвая книжка про scjp.<br />
Полезность 5 из 5.<br />
2) <a href="http://topcode.ru/scjp/">http://topcode.ru/scjp/</a> Вспомнить то что не знал.<br />
Полезность 4 из 5.<br />
<br />
<br />
ХАЛЯВА<br />
<br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
1)<a href="http://www.javachamp.com/">http://www.javachamp.com</a> Много вопросов. Все не сосчитать!</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
Полезность 5 из 5.</div>
<br />
2)<a href="http://www.whizlabs.com/scjp/scjp.html">http://www.whizlabs.com/scjp/scjp.html</a> 14 вопросов c объяснениями. Нужна регистрация.<br />
Полезность 4 из 5.<br />
3)<a href="http://www.quizful.net/test">http://www.quizful.net/test</a> Нужна регистрация + нужно заработать балы(чтобы пройти scjp) вкладом в развитие сайта(например статью написать) . В основном материал по java 1.4. Если нету лишних часов - лучше не заморачиваться.<br />
Полезность 3 из 5.<br />
4)<a href="http://www.ucertify.com/">http://www.ucertify.com</a> 15 вопросов. Нужно устанавливать вражеский ехе. Вопросы содержат некорректные имена, местами перепутаны ответы.<br />
Полезность 3 из 5.<br />
<br />
<br />
РАЗНОЕ<br />
<br />
IO/NIO<br />
<a href="http://www.java-tips.org/java-se-tips/java.util/scanning-text-with-java.util.scanner-3.html">java.util.Scanner</a><br />
<a href="http://stackoverflow.com/questions/93423/java-reading-an-ascii-file-with-filechannel-and-bytearrays">FileChannel</a><br />
<a href="http://stackoverflow.com/questions/696626/java-filereader-encoding-issue">FileReader</a><br />
<br />
ЗЫ.<br />
Экзамен не включает вопросы про побитовые операции/сдвиги и тп.<br />
<br />
<br />
<br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-29163885089643228712010-09-29T01:06:00.000-07:002010-09-29T11:22:15.960-07:00BufferedImage getType() returns 0<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">0 это BufferedImage.TYPE_CUSTOM. С таким типом ряд операций(ресайз/скэйл и тп) с изображением сделать проблематично - все попытки закончатся </span><br />
<pre><span class="Apple-style-span" style="font-family: inherit;">- java.lang.IllegalArgumentException: Unknown image type 0</span></pre>
<pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Фигня возникла при работе с PNG, причём для одинаковых файлов на разных java машинах возвращался разный тип(TYPE_3BYTE_BGR(5) на </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">jdk 1.6.0_19 </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">и TYPE_CUSTOM(0) на </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">jdk 1.6.0_13</span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"> ) .</span></pre>
<pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">Для получения </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; white-space: normal;">BufferedImage </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">использовался </span></pre>
<pre><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;">
<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"><span style="color: maroon; font-style: normal; font-weight: normal;"> </span>ImageIO.<span style="color: black; font-style: italic; font-weight: normal;">read</span>(<span style="color: navy; font-style: normal; font-weight: bold;">new</span> File(configuration.getPath()))
</pre>
</span></pre>
<div>
Нашёл следующее лекарство - определять тип картинки ручками. Лекарство видимо будет помогать только при некоторых случаях. Тип определяется так:<br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"></span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"></span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"></span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"></span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"></span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"><pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"><span style="color: #660e7a; font-style: normal; font-weight: bold;">bufferedImage</span>.getColorModel().hasAlpha() ? BufferedImage.<span style="color: #660e7a; font-style: italic; font-weight: bold;">TYPE_4BYTE_ABGR</span> : BufferedImage.<span style="color: #660e7a; font-style: italic; font-weight: bold;">TYPE_3BYTE_BGR</span>;
</pre>
Лекарство нашёл тут:<br />
<br />
<br />
<br />
<div>
<a href="http://forums.sun.com/thread.jspa?threadID=5424043">http://forums.sun.com/thread.jspa?threadID=5424043</a><br />
<a href="http://forums.java.net/jive/thread.jspa?threadID=57575&tstart=79">http://forums.java.net/jive/thread.jspa?threadID=57575&tstart=79</a></div>
</span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal;"><br /></span></div>
<pre></pre>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-74932544913308915672010-08-31T00:01:00.000-07:002010-09-29T00:22:10.173-07:00Двойной диспатч как средство борьбы с неопределённостью типов при компиляции-----------------------------------------------------<br />
...Ласковое дуновение ветра коснулось выдубленной солнцем и непогодой красной кожи седого индейца. Он поморщился, как будто почувствовал в воздухе что-то неприятное, и вытянув губы в трубочку начал что то насвистывать себе под нос. Белый человек сидящий напротив него поднял глаза от костра, упёрся взглядом в грубую тунику седого и задумчиво сказал<br />
- Ты прав Бычий Хуй. Есть что то в двойном диспатче.<br />
Бычий Хуй ничего не ответил. Смотря на пламя костра и продолжая насвистывать странную мелодию он полез за трубкой...<br />
------------------------------------------------------<br />
<br />
Двойной диспатч можно любить или не любить. Но ввиду особенностей работы c Java, есть несколько ситуаций, когда без него просто не обойтись. Например когда класс, параметризующий вызов метода, неизвестен при компиляции.<br />
<br />
Пример:<br />
<br />
<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"><span style="color: maroon; font-style: normal; font-weight: normal;"> </span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span><span style="color: navy; font-style: normal; font-weight: bold;">import</span> <span style="color: olive; font-style: normal; font-weight: normal;">org.junit.Test</span>;
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span><span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> TestABC {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> A {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> B <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> A {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> C <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> A {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> print(ABC abc) {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print(<span style="color: navy; font-style: normal; font-weight: bold;">this</span>);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> ABC {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> print(A <span style="color: grey; font-style: normal; font-weight: normal;">a</span>) {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"a"</span>);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }<span style="color: maroon; font-style: normal; font-weight: normal;"> </span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> print(B <span style="color: grey; font-style: normal; font-weight: normal;">b</span>) {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"b"</span>);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> print(C <span style="color: grey; font-style: normal; font-weight: normal;">c</span>) {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"c"</span>);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="background-color: #f6ebbc; color: olive; font-style: normal; font-weight: normal;">@Test</span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> test() {
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> ABC abc = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> ABC();
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> A a = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> A();
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> B b = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> B();
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> C c = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> C();
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: grey; font-style: italic; font-weight: normal;">//----------------------</span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"-----------------------"</span>);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print(a);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print(b);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print(c);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: grey; font-style: italic; font-weight: normal;">//-----------------------</span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"-----------------------"</span>);
<span class="Apple-style-span" style="color: grey; font-style: italic;">//будет вызван только метод void print(A a) </span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print(a);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print((A) b);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> abc.print((A) c);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> <span style="color: grey; font-style: italic; font-weight: normal;">//-----------------------</span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> System.<span style="color: #660e7a; font-style: italic; font-weight: bold;">out</span>.println(<span style="color: green; font-style: normal; font-weight: bold;">"-----------------------"</span>);
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> ((A)c).print(abc);<span class="Apple-style-span" style="color: grey; font-style: italic;">//вот он красавец - двойной диспатч</span>
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span> }
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span>}
<span style="color: maroon; font-style: normal; font-weight: normal;"> </span>
</pre>
<br />
<div>
Вывод:<br />
<br />
<br />
-----------------------<br />
a<br />
b<br />
c<br />
-----------------------<br />
a<br />
a<br />
a<br />
-----------------------<br />
c<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-39715316726454575642010-08-02T08:01:00.000-07:002010-08-09T01:19:44.666-07:00Хроники поджаривающегося москвича<div style="text-align: justify;">
27 июля. В ашане смели всё что крутится и дует. Даже обогреватели. </div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
28 июля. Мотоцикл админа в течение дня плавно погружался подножкой в асфальт... Чтобы</div>
<div style="text-align: justify;">
избежать окончательного всасывания тс, весом админа единым, в качестве подставки в</div>
<div style="text-align: justify;">
асфальт был погружён старый винт.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
29 июля. Спать под мокрой простынёй не вариант. Высыхает. Пододеяльник держится дольше.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
1 августа. В ночь с пятницы на субботу было зарегистрировано N^3 очагов возгарания. С чего </div>
<div style="text-align: justify;">
бы это?</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
2 августа. Хорошо дымит! Курильщики в шоколаде. АдОптированный к дыму организм </div>
<div style="text-align: justify;">
успешно справляется с детским дымом торфяников. А ещё говорят курить вредно.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
3 августа. Днём в метро просто замечательно. Прохладно и дымом не пахнет. Прохладно </div>
<div style="text-align: justify;">
конечно относительно. И дымом тоже не пахнет относительно. А ещё относительно </div>
<div style="text-align: justify;">
много свободных мест - относительно много граждан предпочитают стоять, потому что </div>
<div style="text-align: justify;">
так относительно лучше обдувает. Всё относительно.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
4 августа. Яндекс пожары показывают только один пожар близь Москвы. Врут.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
5 августа. Гугл читает мысли. Так сильно и далеко мне хотелось быть от этого сайлентхила что </div>
<div style="text-align: justify;">
утром гугл мапс спозиционировал меня в районе Красного Села под Питером.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
6 августа. Знакомая из Анголы сказала, что у них так жарко не бывает.<br />
<br /></div>
<div style="text-align: justify;">
9.августа. На выходные ездили с корешами на шашлыки. В Питер. Просто ехали пока не кончился дым. А<br />
там уже и до финского залива всего ничего осталось. В Питере не забыл заехать в торговый <br />
центр и купить респираторов мешок.</div>
<div style="text-align: justify;">
</div>
<br />
<br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-90929727873196923452010-06-29T23:58:00.000-07:002010-07-01T01:22:26.023-07:00Hibernate and primitive type values Примитивные примитивы слишком примитивны для хибернэйта. Парадигму мозгоёбства можно описать следующей фразой одного эксперта:Hibernate doesn't care about values, just mappings(<a href="https://forum.hibernate.org/viewtopic.php?t=949814">https://forum.hibernate.org/viewtopic.php?t=949814</a>).Сказал в 2004 году - как отрезал. Ничего пока принципиально не поменялось. Геморой проистекает из того, что хибернэйт по-умолчнию вместо примитивных типов пишет в базу null. А потом приводит этот null к примитивам(например int). Так что вылетающие из недр хибернэйта<br />
<span style="color: red;">org.springframework.orm.hibernate3.HibernateSystemException: Null value was assigned to a property of primitive type setter of MovableObject.movingStatus; nested exception is org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of MovableObject.movingStatus </span><br />
-"это нормально".<br />
<br />
Вообще хибернэйт не обладает magic свойствами, всё что он гарантирует в плане метаданных-<br />
а)При начале работы с чистой бд все мапинги хибернэйта будут промаплены<br />
б)При изменениее мапинга старые данные не будут утеряны<br />
<br />
А это означает что изменение мапинга столбцов, таблиц и тп, на уже существующую бд через хибернэйт - будут "как то" применены. "Как-то" - по факту это добавление новых столбцов в таблицу, и сохранение метаданных старых.<br />
<br />
<b>Лечение. </b><br />
<br />
1) 100% лечение. Переписывем все геттеры. вместо примитивных типов используем врапперы (Integer) и делаем их проверку на null<br />
<br />
<span class="Apple-style-span" style="color: blue;"> @Column(name = "OBJECTSTATUS") </span><br />
<span class="Apple-style-span" style="color: blue;"> private Integer objectStatus ;</span><br />
<span class="Apple-style-span" style="color: blue;"><br /></span><br />
<span class="Apple-style-span" style="color: blue;"> public int getObjectStatus() {</span><br />
<span class="Apple-style-span" style="color: blue;"> if (objectStatus == null) {</span><br />
<span class="Apple-style-span" style="color: blue;"> objectStatus = 0;</span><br />
<span class="Apple-style-span" style="color: blue;"> }</span><br />
<span class="Apple-style-span" style="color: blue;"> return objectStatus;</span><br />
<span class="Apple-style-span" style="color: blue;"> }</span><br />
<br />
2) <span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: blue;">@Column(name = "OBJECTSTATUS", nullable = false)</span></span><br />
Лечение работает при вставках новых объектов с незаданными полями, имеет ряд противопоказаний. При добавлении мапинга нового столбца лечение не сработает. Также оно вероятно не сработает если изменить мапинг уже существующей колонки(c firebird 2.1.3+hibernate 3.5.1 не сработает точно).<br />
<br />
Так же присутствует полный просос при работе с наследованием по @DiscriminatorValue - поля которые казалось бы не используются в объектной модели, очень даже используются в таблицах и как результат - ошибки хибернэйта при попытках кастовать нулл к примитивам.<br />
<br />
3)<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: blue;">@Column(name = "OBJECTSTATUS")</span></span><br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="color: blue;"> private int objectStatus = 0;</span></span></div>
Лечение работает при вставках новых объектов с незаданными полями <br />
<br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br /></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
Самым правильным наверное будет делать так:</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br /></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> @Column(name = "OBJECTSTATUS")</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> private Integer objectStatus=0;</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"><br /></span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> public int getObjectStatus() {</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> if (objectStatus == null) {</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> objectStatus = 0;</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> }</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> return objectStatus;</span></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="color: blue;"> }</span></div>
<br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
-при вставках строк гарантируем что будет выставлен везде 0</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
-при вставке столбца гарантируем что не возникнет ошибки и через геттер всегда получим дефолтное значение</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br /></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br /></div>
<br />
PS.<br />
1)прокачать знания про то как
<a href="http://docs.jboss.org/hibernate/validator/4.0.1/reference/en/html/validator-checkconstraints.html#validator-checkconstraints-orm-hibernateevent">6.2.1. Hibernate event-based validation</a>
2)@NotFound(action=NotFoundAction.IGNORE) - это для объектовKirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-76625131074042655512010-06-21T06:03:00.000-07:002010-06-21T07:59:11.638-07:00String.format depends on locality...Неожиданно. Сужает область применения String.format до вывода в консоль.
<pre style="color:rgb(0,0,0);font-weight:normal;font-style:normal;font-family:monospace;">
<span style="color:rgb(0,0,128);font-weight:bold;font-style:normal;">public</span> <span style="color:rgb(0,0,128);font-weight:bold;font-style:normal;">class</span> xxx {
<span style="color:rgb(128,128,0);font-weight:normal;font-style:normal;">@Test</span>
<span style="color:rgb(0,0,128);font-weight:bold;font-style:normal;">public</span> <span style="color:rgb(0,0,128);font-weight:bold;font-style:normal;">void</span> xxxx() {
<span style="color:rgb(0,0,128);font-weight:bold;font-style:normal;">double</span> xxx = <span style="color:rgb(0,0,255);font-weight:normal;font-style:normal;">123.5657</span>;
System.<span style="color:rgb(102,14,122);font-weight:bold;font-style:italic;">out</span>.println(Double.<span style="color:rgb(0,0,0);font-weight:normal;font-style:italic;">toString</span>(xxx));
<span style="color:rgb(128,128,128);font-weight:normal;font-style:italic;">//123.5657</span>
System.<span style="color:rgb(102,14,122);font-weight:bold;font-style:italic;">out</span>.println(String.<span style="color:rgb(0,0,0);font-weight:normal;font-style:italic;">format</span>(<span style="color:rgb(0,128,0);font-weight:bold;font-style:normal;">"%.2f"</span>, xxx));<span style="color:rgb(128,128,128);font-weight:normal;font-style:italic;">//работет прально если Formatter formatter = new Formatter(sb, Locale.US)</span>
<span style="color:rgb(128,128,128);font-weight:normal;font-style:italic;">//123,57</span>
System.<span style="color:rgb(102,14,122);font-weight:bold;font-style:italic;">out</span>.println((<span style="color:rgb(0,0,128);font-weight:bold;font-style:normal;">new</span> BigDecimal(xxx)).setScale(<span style="color:rgb(0,0,255);font-weight:normal;font-style:normal;">2</span>, BigDecimal.<span style="color:rgb(102,14,122);font-weight:bold;font-style:italic;">ROUND_HALF_UP</span>).toPlainString());
<span style="color:rgb(128,128,128);font-weight:normal;font-style:italic;">//123.57</span>
String.<span style="color:rgb(0,0,0);font-weight:normal;font-style:italic;">format</span>(<span style="color:rgb(0,128,0);font-weight:bold;font-style:normal;">"%.2f"</span>, xxx).<span style="color:rgb(0,0,0);background-color:rgb(246,235,188);font-weight:normal;font-style:normal;">replaceAll</span>(<span style="color:rgb(0,128,0);font-weight:bold;font-style:normal;">"</span><span style="color:rgb(0,128,0);background-color:rgb(237,252,237);font-weight:bold;font-style:normal;">,</span><span style="color:rgb(0,128,0);font-weight:bold;font-style:normal;">"</span>, <span style="color:rgb(0,128,0);font-weight:bold;font-style:normal;">"."</span>);
<span style="color:rgb(128,128,128);font-weight:normal;font-style:italic;">//123.57</span>
}
}
</pre>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com2tag:blogger.com,1999:blog-2851346645716316669.post-207903482079706442010-05-19T05:52:00.000-07:002010-05-21T13:55:23.132-07:00Hibernate+Collections+N*Thread = ConcurrentModificationExceptionПри сохранении ентитей, содержащих коллекции из нескольких трэдов, возможно ConcurrentModificationException. Вне зависимости от секций синхронизации(с.с.), присутствующих внутри транзакции( типа TransactionTemplate tt = new TransactionTemplate(entityManager.getTransactionManager());), итерации по колециям выполняются вне с.с. при сохранении в базу. Чтобы гарантировать отсутствие ConcurrentModificationException необходимо включить в секцию синхронизации всю транзакцию.Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-90375172743328375822010-04-20T04:27:00.000-07:002010-04-20T04:50:53.453-07:00Unexpected Log from org.apache.commons.httpclient.WireВ commons-httpclient-3.1 славный парень Oleg Kalnichevski нахуячил в классе org.apache.commons.httpclient.Wire :<br />
<br />
<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> Wire <span style="color: #660e7a; font-style: italic; font-weight: bold;">HEADER_WIRE</span> = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> Wire(LogFactory.<span style="color: black; font-style: italic; font-weight: normal;">getLog</span>(<span style="color: green; font-style: normal; font-weight: bold;">"httpclient.wire.header"</span>));
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> Wire <span style="color: #660e7a; font-style: italic; font-weight: bold;">CONTENT_WIRE</span> = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> Wire(LogFactory.<span style="color: black; font-style: italic; font-weight: normal;">getLog</span>(<span style="color: green; font-style: normal; font-weight: bold;">"httpclient.wire.content"</span>));
</pre>
<br />
<div>
<br /></div>
<div>
Соответсвенно даже если в log4j.properties прописано что то типа </div>
<div>
log4j.logger.org=WARN</div>
<div>
сраный лог из httpclient продолжает валиться.</div>
<div>
засим в log4j.properties надо добавить что то вроде</div>
<div>
log4j.logger.httpclient=ERROR.<br />
<br />
Что интересно, на <a href="http://hc.apache.org/httpclient-3.x/logging.html">http://hc.apache.org/httpclient-3.x/logging.html</a> в примере логирования присутствуют указания на эту хрень...</div>
<div>
<br /></div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-84398158390526472542010-04-15T01:47:00.000-07:002010-04-15T07:10:36.569-07:00org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544336. deadlock update conflicts with concurrent updateЭта хрень возникает из за того что два потока пытаются одновременно изменить поля одной и той же ентити. Вот что пишут про это<br />
<a href="http://www.firebirdfaq.org/faq151/">http://www.firebirdfaq.org/faq151/</a> ,<br />
<a href="http://edn.embarcadero.com/article/30213">http://edn.embarcadero.com/article/30213</a>.<br />
<br />
В целом есть два способа это побороть<br />
<br />
<b>1)В коде добавить синхронизацию</b><br />
<br />
<b>2)Разобраться с изоляцией транзакций.</b><br />
<b><span class="Apple-style-span" style="font-size: small;"><i>Подробнее:</i></span></b><br />
<a href="http://ru.wikipedia.org/wiki/%D0%A3%D1%80%D0%BE%D0%B2%D0%BD%D0%B8_%D0%B8%D0%B7%D0%BE%D0%BB%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D0%B8_%D1%82%D1%80%D0%B0%D0%BD%D0%B7%D0%B0%D0%BA%D1%86%D0%B8%D0%B9"><span class="Apple-style-span" style="font-size: small;"><i>http://ru.wikipedia.org/wiki/Уровни_изолированности_транзакций</i></span></a><br />
<span class="Apple-style-span" style="font-size: small;"><i>для хибернэйта они задаются параметром hibernate.connection.isolation в пропертях,</i></span><br />
<span class="Apple-style-span" style="font-size: small;"><i>значения описаны в java.sql.Connection:</i></span><br />
<b><span class="Apple-style-span" style="font-size: small;"><i>Наверняка:</i></span></b><br />
<span class="Apple-style-span" style="font-size: small;"><i> для hibernate, в пропертях прописать: hibernate.connection.isolation=</i></span><span class="Apple-style-span" style="color: #333333; font-family: Georgia, serif; line-height: 20px;"><span class="Apple-style-span" style="font-size: small;"><i>8</i></span></span><br />
<br />
<b>Выдержки из java.sql.Connection:</b><br />
<br />
/**<br />
* A constant indicating that transactions are not supported.<br />
*/<br />
int TRANSACTION_NONE<span class="Apple-tab-span" style="white-space: pre;"> </span> = 0;<br />
<br />
/**<br />
* A constant indicating that<br />
* dirty reads, non-repeatable reads and phantom reads can occur.<br />
* This level allows a row changed by one transaction to be read<br />
* by another transaction before any changes in that row have been<br />
* committed (a "dirty read"). If any of the changes are rolled back,<br />
* the second transaction will have retrieved an invalid row.<br />
*/<br />
int TRANSACTION_READ_UNCOMMITTED = 1;<br />
<br />
/**<br />
* A constant indicating that<br />
* dirty reads are prevented; non-repeatable reads and phantom<br />
* reads can occur. This level only prohibits a transaction<br />
* from reading a row with uncommitted changes in it.<br />
*/<br />
int TRANSACTION_READ_COMMITTED = 2;<br />
<br />
/**<br />
* A constant indicating that<br />
* dirty reads and non-repeatable reads are prevented; phantom<br />
* reads can occur. This level prohibits a transaction from<br />
* reading a row with uncommitted changes in it, and it also<br />
* prohibits the situation where one transaction reads a row,<br />
* a second transaction alters the row, and the first transaction<br />
* rereads the row, getting different values the second time<br />
* (a "non-repeatable read").<br />
*/<br />
int TRANSACTION_REPEATABLE_READ = 4;<br />
<br />
/**<br />
* A constant indicating that<br />
* dirty reads, non-repeatable reads and phantom reads are prevented.<br />
* This level includes the prohibitions in<br />
* <code>TRANSACTION_REPEATABLE_READ</code> and further prohibits the<br />
* situation where one transaction reads all rows that satisfy<br />
* a <code>WHERE</code> condition, a second transaction inserts a row that<br />
* satisfies that <code>WHERE</code> condition, and the first transaction<br />
* rereads for the same condition, retrieving the additional<br />
* "phantom" row in the second read.<br />
*/<br />
int TRANSACTION_SERIALIZABLE = 8;Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-48940440299081683302010-03-25T00:18:00.000-07:002010-03-25T12:56:04.857-07:00Recursive generic<br />
Увидел нечто подобное у своего коллеги =)<br />
<br />
<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"><span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> X {
<span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> A<T <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> A<T>> {
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> T createObejct() {
<span style="color: navy; font-style: normal; font-weight: bold;">return</span> <span style="color: navy; font-style: normal; font-weight: bold;">null</span>;
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> B <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> A<B> {
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> B createObejct() {
<span style="color: navy; font-style: normal; font-weight: bold;">return</span> <span style="color: navy; font-style: normal; font-weight: bold;">null</span>;
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> main(String[] args) {
<span style="color: navy; font-style: normal; font-weight: bold;">new</span> B().createObejct();
}
}
</pre>
<br />
<div>
<br /></div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-68089832684323136472010-03-11T06:40:00.000-08:002010-03-25T12:56:36.991-07:00Unexpected generics behaviour<b>If someone knows what the fuck please suggest!</b><br />
<br />
<br />
<br />
<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"><span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> Test {
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">interface</span> EntityObject {
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">interface</span> SomeInterface {
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> BasicEntity <span style="color: navy; font-style: normal; font-weight: bold;">implements</span> EntityObject {
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">interface</span> BuisnessObject<E <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> EntityObject> {
E getEntity();
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">interface</span> ComplexObject1<<span style="color: grey; font-style: normal; font-weight: normal;">V</span> <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> SomeInterface> <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> BuisnessObject<BasicEntity> {
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">interface</span> ComplexObject2 <span style="color: navy; font-style: normal; font-weight: bold;">extends</span> BuisnessObject<BasicEntity> {
}
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">void</span> test(){
ComplexObject1 complexObject1 = <span style="color: navy; font-style: normal; font-weight: bold;">null</span>;
ComplexObject2 complexObject2 = <span style="color: navy; font-style: normal; font-weight: bold;">null</span>;
EntityObject <span style="color: grey; font-style: normal; font-weight: normal;">entityObject1</span> = <span style="background-color: #f6ebbc; color: black; font-style: normal; font-weight: normal;">complexObject1.getEntity()</span>;
<span style="color: grey; font-style: italic; font-weight: normal;">//BasicEntity entityObject1 = complexObject1.getEntity(); </span><span style="color: red; font-style: italic; font-weight: bold;">wtf incompatible types!!!!</span>
BasicEntity <span style="color: grey; font-style: normal; font-weight: normal;">basicEntity</span> = <span style="background-color: #f6ebbc; color: black; font-style: normal; font-weight: normal;">complexObject2.getEntity()</span>;
}
}
</pre>
<br />
<div>
<br /></div>
<br />
<br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com5tag:blogger.com,1999:blog-2851346645716316669.post-1123991490510684212010-02-17T03:07:00.000-08:002010-02-17T03:07:18.297-08:00HibernateOptimisticLockingFailureExceptionПри попытке сделать hibernateTemplate.saveOrUpdate(entity) вывалился такой иксэпшн:<br />
<br />
<br />
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1<br />
<div>
<br /></div>
<div>
Иксэпшн вываливается потому что у entity был id!=null и в базе не было entity с такой id. Фактически хибернэйт при сохранении entity вместо insert пытался сделать update. </div>
<div>
<br /></div>
<div>
Решил проблему вызов save вместо saveOrUpdate.</div>
<div>
<br /></div>
<div>
Помогла</div>
<div>
<a href="http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-12069.html">http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-12069.html</a></div>
<div>
<br /></div>Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-7438747682983954452010-02-02T23:10:00.000-08:002010-02-02T23:14:28.773-08:00Тануки: комплимент с дерьмомЕсть такая сеть ресторанов -ТАНУКИ. И вот однажды я с другом зашёл перекусить в ресторанчик на Генерала Белова(вспоминается история про бар кручёная сиська). В ресторане было полно свободных мест и мы выбрали замечательное место в курящем зале. Приветливая официантка-таджичка расторопно принесла меню и заказ был сделан. Принесли его довольно быстро, и трапеза началась. Закончив с едой я решил отведать чаю КОМПЛИМЕНТ. Этот чай разливается бесплатно всем посетителям тануки, основной его ингридиент судя по вкусу - каргадэ.<br />
Есть у меня такая особенность - не люблю когда в чае сверху плавают чаинки - поэтому когда я пью чай в котором сверху плавают чаинки я на них укоризненно смотрю. Вот и в этот раз. Но в чае плавало нечто, что сразу идентифицировать я не смог. Это нечто было овальной формы, коричневого цвета, где то 4 мм в ширину и около сантиметра в длину. Достав это из чая я подверг найденный артефакт пристальному изучению и выяснил что это кал или очень отожравшейся мыши или средней такой крысы. Я позвал мэнэджера и попросил её объяснить что это такое. Увидев экскременты мэнеджер(миловидная белая девушка) не растерялась и заявила что это такие ягоды,но в принесённых ей позже образцах чая таких ягод больше не попалось(видимо все съели - очень вкусные, правда попробовать эту ягоду мэнэджер отказалась). После этого была выдвинута версия два - это сорт другого чая, который туда случайно попал. Я отщепнул кусочек дерьма и передал его мэнеджеру чтобы она нашла мне такой же чай - больше я этот кусочек не видел, что впрочем меня не особо расстраивает, а вернувшаяся белая девушка мэнеджер заявила что она ничего не искала и не собиралась(куда она ходила с калом в кармене не ясно). Спустя какое то время мэнеджер призвала себе на помощь ещё одного белого человека - мусина в самом расцвете сил. Чертовски логичный. На мой вопрос: "А что вы будете делать если в чае который вам принесли вы обнаружите дерьмо?" он ответил "Я закажу ещё чая". Короче он почти убедил меня что это не дерьмо а чай ферментированный видимо самим тануки, привезённым из японии.<br />
<br />
Выводы:<br />
1)Дерьмо всплывает<br />
2)Не ходите в тануки. Там дерьмо в еде.Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com1tag:blogger.com,1999:blog-2851346645716316669.post-68766960545197106462010-01-23T07:59:00.000-08:002010-01-24T02:34:37.611-08:00How to set Spring bean propertiesКазалось бы тривиальная задача. Но вот возникла проблема - а именно вопрос: Как передать в качестве параметров одного бина - параметры другого. Задача возникла исходя из желания конфигурировать <b>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</b>(умеет врапить проперти из всяких файлов типа config.properties в переменные <span style="font-weight: bold;">applicationContext.xml<span style="font-weight: normal;">) не из <b>applicationContext.xml</b>, а из командной строки при запуске приложения.</span></span><br />
<br />
<a name='more'></a><br />
<br />
Вот первозданный вид<br />
<span style="font-family: monospace; font-size: small;"><span style="font-size: 12px; line-height: 15px; white-space: pre-wrap;"><span style="background-color: white;"><span style="color: white;">Version:0.9 StartHTML:00000000108 EndHTML:00000003623 StartFragment:00000000108 EndFragment:00000003623</span></span>
</span></span><br />
<span style="font-family: monospace; font-size: small;"></span><br />
<span style="font-family: monospace; font-size: small;"><pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"Server.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span><span style="color: black; font-style: normal; font-weight: bold;">></span>
</pre>
</span><br />
<br />
1)Идея поменять параметры бина в коде оказалась провальной - спринг читает сразу весь <span style="font-weight: bold;">applicationContext.xml</span>, что приводит к невозможности проинициализировать только один бин дручками до того как вычитать всё, следующий код вылетает с ошибкой<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> ClassPathXmlApplicationContext classPathXmlApplicationContext = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> ClassPathXmlApplicationContext(<span style="color: navy; font-style: normal; font-weight: bold;">new</span> String[]{<span style="color: #660e7a; font-style: normal; font-weight: bold;">applicationContextName</span>},<span style="color: navy; font-style: normal; font-weight: bold;">false</span>);
<span style="color: navy; font-style: normal; font-weight: bold;">final</span> Object <span style="color: grey; font-style: normal; font-weight: normal;">placeholderConfigurer</span> = classPathXmlApplicationContext.getBean(<span style="color: green; font-style: normal; font-weight: bold;">"placeholderConfigurer"</span>);
classPathXmlApplicationContext.refresh();
</pre>
до вызова refresh().<br />
<br />
2)Использовать <b>org.springframework.beans.factory.config.PropertyPathFactoryBean</b><br />
<b><br /></b><br />
<b><span style="background-color: white;"><span style="color: white;">Version:0.9
StartHTML:00000000108 EndHTML:00000006014 StartFragment:00000000108 EndFragment:00000006014
</span></span></b><br />
<b></b><br />
<b><pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties"</span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"</span><span style="background-color: #f6ebbc; color: green; font-style: normal; font-weight: bold;">serverProperties.properties</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"</span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPathFactoryBean"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">ref=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
</pre>
</b><br />
<br />
С утилитными схемами:<span style="color: white;">Version:0.9
StartHTML:00000000108
EndHTML:00000000509
StartFragment:00000000108
EndFragment:00000000509</span><br />
<pre style="border: thin solid; font-family: monospace; padding: 5px;"><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">xmlns:util=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"http://www.springframework.org/schema/util"</span>
</pre>
<span style="color: white;">Version:0.9
StartHTML:00000000108
EndHTML:00000000574
StartFragment:00000000108
EndFragment:00000000574
</span><br />
<pre style="border: thin solid; font-family: monospace; padding: 5px;"><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">xsi:schemaLocation=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd</span>
</pre>
<br />
можно написать это так<br />
<span style="background-color: white;"><span style="color: white;">Version:0.9
StartHTML:00000000108
EndHTML:00000005762
StartFragment:00000000108
EndFragment:00000005762
</span></span><br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties"</span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">util:property-path</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">path=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">ref=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
</pre>
<br />
<br />
3) Использовать <b>org.springframework.beans.factory.config.FieldRetrievingFactoryBean</b><br />
<b><span style="background-color: white;"><span style="color: white;">Version:0.9
StartHTML:00000000108 EndHTML:00000004810 StartFragment:00000000108 EndFragment:00000004810
</span></span></b><br />
<b></b><br />
<b><pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties.properties"</span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.FieldRetrievingFactoryBean"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">ref=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span><span style="color: black; font-style: normal; font-weight: bold;">></span>
</pre>
</b><br />
<br />
или так<br />
<span style="color: white;">Version:0.9
StartHTML:00000000108 EndHTML:00000006125 StartFragment:00000000108 EndFragment:00000006125
</span><br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties"</span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.FieldRetrievingFactoryBean"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"staticField"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">ref=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
</pre>
<br />
<br />
С утилитными схемами:<span style="color: white;">V</span><br />
<span style="color: white;"><br /></span><br />
<span style="color: white;">Version:0.9
StartHTML:00000000108 EndHTML:00000004549 StartFragment:00000000108 EndFragment:00000004549
</span><br />
<span style="color: white;"></span><br />
<span style="color: white;"><pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">util:constant</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">static-field=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">ref=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"</span><span style="background-color: #efefef; color: red; font-style: normal; font-weight: bold;">ru.intelcom.server.ServerProperties.properties</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
</pre>
</span><br />
<span style="color: white;"><br /></span><br />
<span style="color: white;">и</span>или так<br />
<br />
<span style="color: white;">Version:0.9
StartHTML:00000000108 EndHTML:00000004898 StartFragment:00000000108 EndFragment:00000004898
</span><br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">util:constant</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">id=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"serverProperties"</span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">static-field=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ru.intelcom.server.ServerProperties.properties"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">class=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"location"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">ref=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">serverProperties</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"><</span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">property</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">name=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"ignoreUnresolvablePlaceholders"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"> </span><span style="background-color: #efefef; color: blue; font-style: normal; font-weight: bold;">value=</span><span style="background-color: #efefef; color: green; font-style: normal; font-weight: bold;">"true"</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">/></span>
<span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;"></span><span style="background-color: #efefef; color: navy; font-style: normal; font-weight: bold;">bean</span><span style="background-color: #efefef; color: black; font-style: normal; font-weight: normal;">></span>
</pre>
<br />
<br />
узнал всё тут:<br />
<a href="http://static.springsource.org/spring/docs/2.0.x/reference/xsd-config.html">http://static.springsource.org/spring/docs/2.0.x/reference/xsd-config.html</a><br />
<a href="http://springindepth.com/book/in-depth-ioc-constructor-setter-injection.html">http://springindepth.com/book/in-depth-ioc-constructor-setter-injection.html</a><br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com1tag:blogger.com,1999:blog-2851346645716316669.post-20000160785021811822009-12-18T00:21:00.000-08:002009-12-19T04:14:46.420-08:00ProcessBuilder java.io.IOException: Cannot run program : CreateProcess error=123<span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial; font-size: 13px; white-space: pre;">ProcessBuilder мутный. Он непонимает команду одной строчкой.</span><br />
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><br /></span></span><br />
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span><br />
<span style="font-family: Arial; font-size: small;">Такую строчку он не поймёт - <span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">CreateProcess error=123</span>
</span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"></span><br />
<span style="font-family: Arial; font-size: small;"><pre style="border: thin solid; color: green; font-family: monospace; font-style: normal; font-weight: bold; padding: 5px;"><span style="color: black; font-style: normal; font-weight: normal;"> String </span><span style="color: #660e7a; font-style: normal; font-weight: bold;">debugCmd</span><span style="color: black; font-style: normal; font-weight: normal;"> = </span>"C:<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>development<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>Java<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>jdk1.6.0_12<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>bin<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>java -cp C:<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>work<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>trunk<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>Server<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>lib<span style="color: navy; font-style: normal; font-weight: bold;">\\xxx</span>.jar; xxx.Test"<span style="color: black; font-style: normal; font-weight: normal;">;</span>
</pre>
<br />
а такую совсем не поймёт - <span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">CreateProcess error=2</span><br />
<br />
<br />
<div>
<pre style="border-bottom-style: solid; border-bottom-width: thin; border-color: initial; border-left-style: solid; border-left-width: thin; border-right-style: solid; border-right-width: thin; border-top-style: solid; border-top-width: thin; color: green; font-family: monospace; font-style: normal; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;"><span style="color: black; font-style: normal; font-weight: normal;">String </span><span style="color: #660e7a; font-style: normal; font-weight: bold;">debugCmd</span><span style="color: black; font-style: normal; font-weight: normal;"> = </span>"java -cp C:<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>work<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>trunk<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>Server<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>lib<span style="color: navy; font-style: normal; font-weight: bold;">\\xxx</span>.jar; xxx.Test"<span style="color: black; font-style: normal; font-weight: normal;">;</span></pre>
<br />
а так поймёт!<br />
<pre style="border: thin solid; color: green; font-family: monospace; font-style: normal; font-weight: bold; padding: 5px;"><span style="color: black; font-style: normal; font-weight: normal;">String[] </span><span style="color: #660e7a; font-style: normal; font-weight: bold;">debugCmd</span><span style="color: black; font-style: normal; font-weight: normal;"> = </span><span style="color: navy; font-style: normal; font-weight: bold;">new</span><span style="color: black; font-style: normal; font-weight: normal;"> String[]{</span>
<span style="color: black; font-style: normal; font-weight: normal;"> </span>"java"<span style="color: black; font-style: normal; font-weight: normal;">, </span>"-cp"<span style="color: black; font-style: normal; font-weight: normal;">, </span>"C:<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>work<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>trunk<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>Server<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>lib<span style="color: navy; font-style: normal; font-weight: bold;">\\</span>xxx.jar;"<span style="color: black; font-style: normal; font-weight: normal;">, </span>"xxx.Test"
<span style="color: black; font-style: normal; font-weight: normal;"> };</span>
</pre>
<br />
<div>
<br />
</div>
и поехали<br />
<pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;">ProcessBuilder processBuilder = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> ProcessBuilder(<span style="color: #660e7a; font-style: normal; font-weight: bold;">debugCmd</span>);
processBuilder.directory(<span style="color: navy; font-style: normal; font-weight: bold;">new</span> File(home));
processBuilder.redirectErrorStream(<span style="color: navy; font-style: normal; font-weight: bold;">true</span>);
Process process = processBuilder.start();
</pre>
<br />
<div>
<br />
</div>
узнал тут :<br />
<a href="http://forums.sun.com/thread.jspa?threadID=5396595&messageID=10761026">http://forums.sun.com/thread.jspa?threadID=5396595&messageID=10761026</a><br />
</div>
</span><br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com1tag:blogger.com,1999:blog-2851346645716316669.post-5121309697994446652009-12-16T03:21:00.000-08:002009-12-16T05:56:53.048-08:00Генератор classpathРекурсивный генератор <span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial; font-size: 13px; white-space: pre;">classpath<span style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; font-family: 'Times New Roman'; font-size: medium; white-space: normal;">. Всасывает только jar.</span></span><br />
<span class="Apple-style-span" style="font-size: large;"></span><br />
<a name='more'></a><br /><br />
<span style="font-family: monospace;"><span style="white-space: pre;"><span style="font-family: 'Times New Roman';"><span style="white-space: normal;"></span></span></span></span><br />
<span style="font-family: monospace;"><span style="font-family: 'Times New Roman';"><br />
</span></span><br />
<span style="font-family: monospace;"><span style="font-family: 'Times New Roman';"></span></span><br />
<span style="font-family: monospace;"><span style="font-family: 'Times New Roman';"><pre style="border: thin solid; color: black; font-family: monospace; font-style: normal; font-weight: normal; padding: 5px;"> <span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> StringBuilder fileToClasspath(File file){
StringBuilder clathPath = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> StringBuilder();
List<File> files = <span style="color: black; font-style: italic; font-weight: normal;">listJars</span>(file);
<span style="color: navy; font-style: normal; font-weight: bold;">for</span> (File jar : files) {
clathPath.append(jar.getAbsolutePath());
clathPath.append(<span style="color: green; font-style: normal; font-weight: bold;">";"</span>);
}
<span style="color: navy; font-style: normal; font-weight: bold;">return</span> clathPath;
}
<span style="color: navy; font-style: normal; font-weight: bold;">private</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> List<File> listJars(File root) {
File[] childs = root.listFiles();
List<File> files = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> LinkedList<File>();
<span style="color: navy; font-style: normal; font-weight: bold;">for</span> (File child : childs) {
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (<span style="color: #660e7a; font-style: italic; font-weight: bold;">jarFilter</span>.accept(root, child.getName())) {
files.add(child);
}
<span style="color: navy; font-style: normal; font-weight: bold;">if</span> (child.isDirectory()) {
files.addAll(<span style="color: black; font-style: italic; font-weight: normal;">listJars</span>(child));
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">return</span> files;
}
<span style="color: navy; font-style: normal; font-weight: bold;">private</span> <span style="color: navy; font-style: normal; font-weight: bold;">static</span> <span style="color: navy; font-style: normal; font-weight: bold;">class</span> JarFilter <span style="color: navy; font-style: normal; font-weight: bold;">implements</span> FilenameFilter {
<span style="color: olive; font-style: normal; font-weight: normal;">@Override</span>
<span style="color: navy; font-style: normal; font-weight: bold;">public</span> <span style="color: navy; font-style: normal; font-weight: bold;">boolean</span> accept(File dir, String name) {
<span style="background-color: #f6ebbc; color: navy; font-style: normal; font-weight: bold;">if</span> (name.endsWith(<span style="color: green; font-style: normal; font-weight: bold;">".jar"</span>)) {
<span style="color: navy; font-style: normal; font-weight: bold;">return</span> <span style="color: navy; font-style: normal; font-weight: bold;">true</span>;
}
<span style="color: navy; font-style: normal; font-weight: bold;">return</span> <span style="color: navy; font-style: normal; font-weight: bold;">false</span>;
}
}
<span style="color: navy; font-style: normal; font-weight: bold;">static</span> JarFilter <span style="color: #660e7a; font-style: italic; font-weight: bold;">jarFilter</span> = <span style="color: navy; font-style: normal; font-weight: bold;">new</span> JarFilter();
</pre>
<br />
<br />
<br />
<div>
<br />
</div>
</span></span><br />
<pre style="color: black; font-family: monospace; font-style: normal; font-weight: normal;"></pre>
<br />
<div>
<br />
</div>
<br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0tag:blogger.com,1999:blog-2851346645716316669.post-16225780262254709362009-12-05T11:24:00.000-08:002009-12-05T11:29:27.713-08:00Hibernate - merge update refresh<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"> Пусть в абсолютно сферическом хибернейте на абсолютно перпендикулярной базе есть ентитя, и у неё есть два интовых поля a и b. </span><br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br /></div>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><a name='more'></a></span><span style="font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Arial, Helvetica, sans-serif;"><i>...А ещё есть две открытые сессии(Session I и Session II) из которых ведётся работа с бд. В каждой из сессий открыт один и тот же объект Ж типа ентитя с полями a и b. Посмотрим, что Же произойдёт с полямиЖ при вызове методов </i></span><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; white-space: pre;"><span style="font-family: Arial, Helvetica, sans-serif;"><i>merge update refresh некоторого HibernateTemplate с Ж в качестве параметра.</i></span></span><br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; white-space: pre;"><span style="font-family: Arial, Helvetica, sans-serif;"><i>(рассматриваем конечный результат, который обязательно появится в базе после успешного завершения всех транзакций)</i></span></span><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjf9cVF3xCJ-Kr5JRu2ZzySa5pFCQGYy-0Bj-Qn65sHh8jXoLU7CWnZzsZUA8SDP1jECn0Sd_1MEw4qQRV5C6XiaD21Y4Gdbj3tEMk8F6DghncquxbmjmYEtGRxhdlWxFQDjz54ot9pvR2/s1600-h/a.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjf9cVF3xCJ-Kr5JRu2ZzySa5pFCQGYy-0Bj-Qn65sHh8jXoLU7CWnZzsZUA8SDP1jECn0Sd_1MEw4qQRV5C6XiaD21Y4Gdbj3tEMk8F6DghncquxbmjmYEtGRxhdlWxFQDjz54ot9pvR2/s640/a.jpg" /></a><br /></div>
<br />Kirhttp://www.blogger.com/profile/01179746921950113016noreply@blogger.com0