Search Results

Search found 2601 results on 105 pages for 'condition'.

Page 7/105 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Get records based on child condition

    - by Shawn Mclean
    In LINQ To Entities: How do I get the records (including both child and parent) based on a condition of the child in a one to many. My structure is set up as follows: GetResources() - returns a list of Resources. GetResources().ResourceNames - this is the child, which is an entity collection. GetResources().ResourceNames - a property of one record of this child is Name. I'd like to construct something like this: return (from p in repository.GetResources() where p.ResourceNames.Exist(r => r.Name.Contains(text, StringComparison.CurrentCultureIgnoreCase)) select p).ToList(); but of course, Exist doesn't exist. thanks.

    Read the article

  • improve my python program to fetch the desire rows by using if condition

    - by user2560507
    unique.txt file contains: 2 columns with columns separated by tab. total.txt file contains: 3 columns each column separated by tab. I take each row from unique.txt file and find that in total.txt file. If present then extract entire row from total.txt and save it in new output file. ###Total.txt column a column b column c interaction1 mitochondria_205000_225000 mitochondria_195000_215000 interaction2 mitochondria_345000_365000 mitochondria_335000_355000 interaction3 mitochondria_345000_365000 mitochondria_5000_25000 interaction4 chloroplast_115000_128207 chloroplast_35000_55000 interaction5 chloroplast_115000_128207 chloroplast_15000_35000 interaction15 2_10515000_10535000 2_10505000_10525000 ###Unique.txt column a column b mitochondria_205000_225000 mitochondria_195000_215000 mitochondria_345000_365000 mitochondria_335000_355000 mitochondria_345000_365000 mitochondria_5000_25000 chloroplast_115000_128207 chloroplast_35000_55000 chloroplast_115000_128207 chloroplast_15000_35000 mitochondria_185000_205000 mitochondria_25000_45000 2_16595000_16615000 2_16585000_16605000 4_2785000_2805000 4_2775000_2795000 4_11395000_11415000 4_11385000_11405000 4_2875000_2895000 4_2865000_2885000 4_13745000_13765000 4_13735000_13755000 My program: file=open('total.txt') file2 = open('unique.txt') all_content=file.readlines() all_content2=file2.readlines() store_id_lines = [] ff = open('match.dat', 'w') for i in range(len(all_content)): line=all_content[i].split('\t') seq=line[1]+'\t'+line[2] for j in range(len(all_content2)): if all_content2[j]==seq: ff.write(seq) break Problem: but istide of giving desire output (values of those 1st column that fulfile the if condition). i nead somthing like if jth of unique.txt == ith of total.txt then write ith row of total.txt into new file.

    Read the article

  • HTML tag closes when inside a condition

    - by Malharhak
    I'm having a little problem with jade. Here is the following code : each user in users - if (user.valid == 1) tr(style="color:green;") - else tr(style="color:red;") td = user.mail td = user.lastIp td = user.token td = user.valid My problem is that the tds are created only in the else case. if the if (user.valid == 1) is true, then it creates an empty tr. Is there a way I can create my tr with this condition, and then only fill them ? Thanks :)

    Read the article

  • int and float increment condition in for loop [on hold]

    - by Mazaya Jamil
    I am doing a program that involves integer and float number.Let say I want to calculate atx={1,1/2,2,3,4} and want to use for-loop. But I know the condition of increment for(x=1;x<=4;x++) as x++=x+1. I want to find the iteration at x={1,2,3,4} and at x={1/2}. But I do not have idea how to modify the for-loop statement; either to make the increment of 0.5 or 1. But if I set 0.5, I will get the answers for 5/2 and 7/2 instead.

    Read the article

  • Constant embedded for loop condition optimization in C++ with gcc

    - by solinent
    Will a compiler optimize tihs: bool someCondition = someVeryTimeConsumingTask(/* ... */); for (int i=0; i<HUGE_INNER_LOOP; ++i) { if (someCondition) doCondition(i); else bacon(i); } into: bool someCondition = someVeryTimeConsumingTask(/* ... */); if (someCondition) for (int i=0; i<HUGE_INNER_LOOP; ++i) doCondition(i); else for (int i=0; i<HUGE_INNER_LOOP; ++i) bacon(i); someCondition is trivially constant within the for loop. This may seem obvious and that I should do this myself, but if you have more than one condition then you are dealing with permuatations of for loops, so the code would get quite a bit longer. I am deciding on whether to do it (I am already optimizing) or whether it will be a waste of my time.

    Read the article

  • If and only if condition SQL -- SQL server 2008

    - by user494901
    I'm writing a SQL statement to select a user on a table if that user does not exist on another table, then I want to pull in all their data from another table then I'll be outputting all that in Coldfusion. How do I do this? I have tried, my atempt is below: pro_profile == All employees mod_userStatus == All Professional Staff members I am doing the not exists to remove professional stuff to just get our student staff. mod_StudentCertifications is a listing of the certifications they (students) hold. If we do an AND statement between the where statements it returns no users, or only users that meet both conditions, if we do an OR it will return users with only 1 condition. I need it first Match the not exists then proceed to the exists statement. Is that do able? Here's my Statement: SELECT profileID, firstName, lastName FROM pro_Profile WHERE not exists ( SELECT profileID FROM mod_userStatus WHERE mod_userStatus.profileID = pro_Profile.profileID ) OR exists ( SELECT cprAdultExp, cprInfantChildExp, cprFPRExp, aedExp, firstAidExp, emtExp, waterSafetyInstructionExp, bloodPathogensExp, oxygenAdminExp, lifegaurdingExp, wildernessResponderExp, notes FROM mod_StudentCertifications WHERE mod_StudentCertifications.profileID = pro_Profile.profileID );

    Read the article

  • Performing multiple operations if condition is satisfied in ternary operator in linq

    - by user1575914
    I am a beginner in LINQ.I want to perform some conditional operation lik follows, (from emp in Employees let DOB=emp.BirthDate.GetValueOrDefault() let year=DOB.Year let month=DOB.Month let EmpAgeInYearsToday=DateTime.Now.Year-year let EmpAgeInMonthToday=DateTime.Now.Month-month let temp_year=(EmpAgeInYearsToday-1) let ExactNoOfMonths_temp=EmpAgeInMonthToday<0?temp_year:EmpAgeInMonthToday let ExactNoOfMonths=EmpAgeInMonthToday<0?EmpAgeInMonthToday+12&temp_year:EmpAgeInMonthToday select new{emp.EmployeeID,DOB, EmployeeAgeToday=EmpAgeInYearsToday+" Years "+ExactNoOfMonths+" Months ").Dump(); Here, let ExactNoOfMonths=EmpAgeInMonthToday<0?EmpAgeInMonthToday+12&temp_year:EmpAgeInMonthToday This part is not working. How to achieve this? How to perform multiple operations when the condition is satisfied?

    Read the article

  • pass parameter from controller to models condition

    - by Alex
    I'm trying to bind a param to a join via a named scope., but I'm getting an error. What is the correct way to do that? has_one :has_voted, :class_name => 'Vote', :conditions => ['ip = :userIp'] # named scopes scope :with_vote, lambda {|ip| { :include => [:has_voted], # like this ?? :conditions => [:has_voted => {:conditions => {:userIp => ip}} ] }} Idea.with_vote(request.ip).all I believe I need the condition definition in the model for it to appear in the ON clause of a JOIN, rather then in the WHERE one. Edit I'm trying to get the following query select Ideas.*, Votes.* from Ideas left outer join Votes on Votes.Idea_id = Idea.id AND Votes.ip = {request.ip}

    Read the article

  • Placing the where condition

    - by user182944
    I came up with the below query: SELECT ROOMNO,BUILDINGNO FROM MRM_ROOM_DETAILS WHERE ROOMID IN ( SELECT distinct roomid FROM MRM_BOOKING_DETAILS WHERE (CHECKIN NOT BETWEEN '2012-04-13 09:50:00' AND '2012-04-13 10:20:00') AND (CHECKOUT NOT BETWEEN '2012-04-13 09:50:00' AND '2012-04-13 10:20:00')) AND CAPACITY > 15 AND PROJECTIONSTATUS = 'NO'; I need to place this query in the method SQLiteDatabase.query() and fetch the rows accordingly. I am not able to understand how to place this big where condition (which contains a sub-query as well) in place of the "String selection" i.e. 3rd parameter of the method. Shall i simple write the entire where part(including the sub-query) as a string in the 3rd parameter or else there is some other better way for doing the same? Please suggest me the best way to do the same. Regards,

    Read the article

  • trigger execution against condition satisfaction

    - by maheshasoni
    I have created this trigger which should give a error, whenever the value of new rctmemenrolno of table-receipts1 is matched with the memenrolno of table- memmast, but it is giving error in both condition(it is matched or not matched). kindly help me. CREATE OR REPLACE TRIGGER HDD_CABLE.trg_rctenrolno before insert ON HDD_CABLE.RECEIPTS1 for each row declare v_enrolno varchar2(9); cursor c1 is select memenrolno from memmast; begin open c1; fetch c1 into v_enrolno; LOOP If :new.rctmemenrolno<>v_enrolno then raise_application_error(-20186,'PLEASE ENTER CORRECT ENROLLMENT NO'); close c1; end if; END LOOP; end;

    Read the article

  • trigger execution against condition satisfaction

    - by maheshasoni
    I have created this trigger which should give a error, whenever the value of new rctmemenrolno of table-receipts1 is matched with the memenrolno of table- memmast, but it is giving error in both condition(it is matched or not matched). kindly help me. CREATE OR REPLACE TRIGGER HDD_CABLE.trg_rctenrolno before insert ON HDD_CABLE.RECEIPTS1 for each row declare v_enrolno varchar2(9); cursor c1 is select memenrolno from memmast; begin open c1; fetch c1 into v_enrolno; LOOP If :new.rctmemenrolno<>v_enrolno then raise_application_error(-20186,'PLEASE ENTER CORRECT ENROLLMENT NO'); close c1; end if; END LOOP; end;

    Read the article

  • "And" condition in C#/LINQ Query

    - by user1213055
    partial void PrintDocLetter1_CanExecute(ref bool result) { if (this.PatientsMasterItem.DoctorsMasterItem != null) { var Doctor = PatientsMasterItem.DoctorsMasterItem; var PatientList = Doctor.PatientsMasterItem; var Letters = PatientsMasterItem.LettersSentItem; if ((PatientList.Count() > 1) && (Letters.Any(i => i.LetterType == "DoctorLetter1"))) { result = false; } else { result = true; } } } I think something is wrong with my second condition. I'm trying to find two things. 1) Doctors with more than 1 patient. 2) Among those patients whether a lettertype called "DoctorLetter1" has been sent or not. The above code is working good for that particular record but not working other patients with same doctors where patient1 has already been sent with DoctorLetter1.

    Read the article

  • jQuery if condition text contains

    - by olo
    I wrote a simple if condition, but not quite working. if text is 123 change to hi, if text is 456 change it to hi2 Could someone please give me a hand. <h1>123</h1> <h1>456</h1> <h1>789</h1>? $(document).ready(function() { var changeText1 = '123'; var changeText2 = '456'; var text = $(h1).text(); if (text == changeText) { $(this).text('hi'); } else if (text == changeText2 ) { $(this).text('hi2'); } }); ? http://jsfiddle.net/8P2ma/

    Read the article

  • What is Registry Condition?

    - by serhio
    I have a setup project and I add some registry keys. Say I have a key ..\MyApplication\ServerIp key. When installing the second time I'd like that the ancient value will not be overridden. 1) What kind of "Condition" should I set in the setup properties of ServerIp registry key. 2) Is it possible to recuperate the ancient value from registry and display it in the "ServerIp" textBox in the installer dialog box? In this case the override could be unconditional.

    Read the article

  • Firefox running infinitely even after condition met in jquery function

    - by Kyle
    The following function is called with setTimeout(function () { get_progress(fileID,fileName)},8000); upon a form submit. The purpose of the function is to get read_file.php to read a txt file that stores the file upload status from a form (in percentage). Upon reaching 80%, my Firefox seems to run infinitely even when HEAD returns an error. Am I have too many recursions or have I used a wrong condition that's causing get_progress to run repeatedly even when filename does not exist in the folder ? function get_progress( fileID, filename) { $.ajax({ url: filename, type: 'HEAD', success: function() { $.ajax({ type: 'POST', url: 'read_file.php', data: 'filename=' +filename, success: function(html) { document.getElementById(fileID).innerHTML = html + ' <img src="images/loading.gif" />' setInterval(function() {get_progress(fileID,filename)},4000); } }); } });}

    Read the article

  • Insert a row and avoiding race condition (PHP/MySQL)

    - by justkevin
    I'm working on a multiplayer game which has a lobby-like area where players select "sectors" to enter. The lobby gateway is powered by PHP, while actual gameplay is handled by one or more Java servers. The datastore is MySQL. The happy path: A player chooses a sector and tells the lobby he'd like to enter. The lobby checks whether this is okay, including checking whether there are too many players in the sector (compares the entry count in sector assignments for that sector against the sector's max_players value). The player is added to the sector_assignments table pairing him with the sector. The player client receives a passkey that will let him connect to the appropriate game server. The race condition: If two players request access to the same sector at close to same time, I can envision a case where they are both added because there was one space free when their check was started and max players gets exceeded. Is the best solution LOCK TABLE on sector_assignments? Is there another option?

    Read the article

  • Can't figure out where race condition is occuring

    - by Nik
    I'm using Valgrind --tool=drd to check my application that uses Boost::thread. Basically, the application populates a set of "Book" values with "Kehai" values based on inputs through a socket connection. On a seperate thread, a user can connect and get the books send to them. Its fairly simple, so i figured using a boost::mutex::scoped_lock on the location that serializes the book and the location that clears out the book data should be suffice to prevent any race conditions. Here is the code: void Book::clear() { boost::mutex::scoped_lock lock(dataMutex); for(int i =NUM_KEHAI-1; i >= 0; --i) { bid[i].clear(); ask[i].clear(); } } int Book::copyChangedKehaiToString(char* dst) const { boost::mutex::scoped_lock lock(dataMutex); sprintf(dst, "%-4s%-13s",market.c_str(),meigara.c_str()); int loc = 17; for(int i = 0; i < Book::NUM_KEHAI; ++i) { if(ask[i].changed > 0) { sprintf(dst+loc,"A%i%-21s%-21s%-21s%-8s%-4s",i,ask[i].price.c_str(),ask[i].volume.c_str(),ask[i].number.c_str(),ask[i].postTime.c_str(),ask[i].status.c_str()); loc += 77; } } for(int i = 0; i < Book::NUM_KEHAI; ++i) { if(bid[i].changed > 0) { sprintf(dst+loc,"B%i%-21s%-21s%-21s%-8s%-4s",i,bid[i].price.c_str(),bid[i].volume.c_str(),bid[i].number.c_str(),bid[i].postTime.c_str(),bid[i].status.c_str()); loc += 77; } } return loc; } The clear() function and the copyChangedKehaiToString() function are called in the datagetting thread and data sending thread,respectively. Also, as a note, the class Book: struct Book { private: Book(const Book&); Book& operator=(const Book&); public: static const int NUM_KEHAI=10; struct Kehai; friend struct Book::Kehai; struct Kehai { private: Kehai& operator=(const Kehai&); public: std::string price; std::string volume; std::string number; std::string postTime; std::string status; int changed; Kehai(); void copyFrom(const Kehai& other); Kehai(const Kehai& other); inline void clear() { price.assign(""); volume.assign(""); number.assign(""); postTime.assign(""); status.assign(""); changed = -1; } }; std::vector<Kehai> bid; std::vector<Kehai> ask; tm recTime; mutable boost::mutex dataMutex; Book(); void clear(); int copyChangedKehaiToString(char * dst) const; }; When using valgrind --tool=drd, i get race condition errors such as the one below: ==26330== Conflicting store by thread 1 at 0x0658fbb0 size 4 ==26330== at 0x653AE68: std::string::_M_mutate(unsigned int, unsigned int, unsigned int) (in /usr/lib/libstdc++.so.6.0.8) ==26330== by 0x653AFC9: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.8) ==26330== by 0x653B064: std::string::assign(char const*, unsigned int) (in /usr/lib/libstdc++.so.6.0.8) ==26330== by 0x653B134: std::string::assign(char const*) (in /usr/lib/libstdc++.so.6.0.8) ==26330== by 0x8055D64: Book::Kehai::clear() (Book.h:50) ==26330== by 0x8094A29: Book::clear() (Book.cpp:78) ==26330== by 0x808537E: RealKernel::start() (RealKernel.cpp:86) ==26330== by 0x804D15A: main (main.cpp:164) ==26330== Allocation context: BSS section of /usr/lib/libstdc++.so.6.0.8 ==26330== Other segment start (thread 2) ==26330== at 0x400BB59: pthread_mutex_unlock (drd_pthread_intercepts.c:633) ==26330== by 0xC59565: pthread_mutex_unlock (in /lib/libc-2.5.so) ==26330== by 0x805477C: boost::mutex::unlock() (mutex.hpp:56) ==26330== by 0x80547C9: boost::unique_lock<boost::mutex>::~unique_lock() (locks.hpp:340) ==26330== by 0x80949BA: Book::copyChangedKehaiToString(char*) const (Book.cpp:134) ==26330== by 0x80937EE: BookSerializer::serializeBook(Book const&, std::string const&) (BookSerializer.cpp:41) ==26330== by 0x8092D05: BookSnapshotManager::getSnaphotDataList() (BookSnapshotManager.cpp:72) ==26330== by 0x8088179: SnapshotServer::getDataList() (SnapshotServer.cpp:246) ==26330== by 0x808870F: SnapshotServer::run() (SnapshotServer.cpp:183) ==26330== by 0x808BAF5: boost::_mfi::mf0<void, RealThread>::operator()(RealThread*) const (mem_fn_template.hpp:49) ==26330== by 0x808BB4D: void boost::_bi::list1<boost::_bi::value<RealThread*> >::operator()<boost::_mfi::mf0<void, RealThread>, boost::_bi::list0>(boost::_bi::type<void>, boost::_mfi::mf0<void, RealThread>&, boost::_bi::list0&, int) (bind.hpp:253) ==26330== by 0x808BB90: boost::_bi::bind_t<void, boost::_mfi::mf0<void, RealThread>, boost::_bi::list1<boost::_bi::value<RealThread*> > >::operator()() (bind_template.hpp:20) ==26330== Other segment end (thread 2) ==26330== at 0x400B62A: pthread_mutex_lock (drd_pthread_intercepts.c:580) ==26330== by 0xC59535: pthread_mutex_lock (in /lib/libc-2.5.so) ==26330== by 0x80546B8: boost::mutex::lock() (mutex.hpp:51) ==26330== by 0x805473B: boost::unique_lock<boost::mutex>::lock() (locks.hpp:349) ==26330== by 0x8054769: boost::unique_lock<boost::mutex>::unique_lock(boost::mutex&) (locks.hpp:227) ==26330== by 0x8094711: Book::copyChangedKehaiToString(char*) const (Book.cpp:113) ==26330== by 0x80937EE: BookSerializer::serializeBook(Book const&, std::string const&) (BookSerializer.cpp:41) ==26330== by 0x808870F: SnapshotServer::run() (SnapshotServer.cpp:183) ==26330== by 0x808BAF5: boost::_mfi::mf0<void, RealThread>::operator()(RealThread*) const (mem_fn_template.hpp:49) ==26330== by 0x808BB4D: void boost::_bi::list1<boost::_bi::value<RealThread*> >::operator()<boost::_mfi::mf0<void, RealThread>, boost::_bi::list0>(boost::_bi::type<void>, boost::_mfi::mf0<void, RealThread>&, boost::_bi::list0&, int) (bind.hpp:253) For the life of me, i can't figure out where the race condition is. As far as I can tell, clearing the kehai is done only after having taken the mutex, and the same holds true with copying it to a string. Does anyone have any ideas what could be causing this, or where I should look? Thank you kindly.

    Read the article

  • STLport crash (race condition, Darwin only?)

    - by Jonas Byström
    When I run STLport on Darwin I get a strange crash. (Haven't seen it anywhere else than on Mac, but exactly same thing crash on both i686 and PowerPC.) This is what it looks like in gdb: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000 [Switching to process 21097] 0x000000010120f47c in stlp_std::__node_alloc_impl::_M_allocate () It may be some setting in STLport, I noticed that Mac.h and MacOSX.h seemed far behind on features. I also know that it it must be some type of race condition, since it doesn't occur just by calling this method (implicity called). The crash happens mainly when I push the system, running 10 simultaneous threads that do a lot of string handling. Other theories I come up with have to do with compiler flags (configure script) and g++ 4.2 bugs (seems like 4.4.3 isn't on Mac yet with Objective-C support, which I need to link with). HELP!!! :) Edit: I run unit tests, which do all sorts of things. This problem arise when I start 10 threads that push the system; and it always comes down to std::string::append which eventually boils down to _M_allocate. Since I can't even get a descent dump of the code that's causing the problem, I figure I'm doing something bad. Could it be so since it's trying to execute at instruction pointer 0x000...000? Are dynlibs built as DLLs in Windows with a jump table? Could it perhaps be that such a jump table has been overwritten for some reason? That would probably explain this behavior. (The code is huge, if I run out of other ideas, I'll post a minimum crashing sample here.)

    Read the article

  • getting incorrect error even if the condition is fulfilled

    - by Tapan Desai
    I am trying to show the message based on the text shown on webpage after a particular action. If the webpage contains text MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY, I want to print Message sent successfully on the screen otherwise MESSAGE SENDING FAILED. Everything is working fine but for one thing. PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(sendConnection.getOutputStream()), true); printWriter.print(sendContent); printWriter.flush(); printWriter.close(); //Reading the returned web page to analyse whether the operation was sucessfull BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(sendConnection.getInputStream())); StringBuilder SendResult = new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { SendResult.append(line); } if (SendResult.toString().contains("MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY")) { System.out.println("Message sent to " + phoneNumber + " successfully."); } else { System.err.println("Message could not send to " + phoneNumber + ". Also check login credentials"); } bufferedReader.close(); The problem is that even if the webpage contains the text MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY, the condition always goes into ELSE part and show MESSAGE SENDING FAILED but thats not true because the message has been sent and i see the MESSAGE HAS BEEN SUBMITTED SUCCESSFULLY on the webpage. Can anyone tell me where am i going wrong?

    Read the article

  • html body inside if condition

    - by gautam
    Hi, i have two different bodies for different conditions. can i do like this.... <% if(yes) %> <body onload="JavaScript:timedRefresh(120000);"> <% } else { %> <body> <% } %> Please help me... Thanks in advance.. I want to compare my title in if condition how can i do??? currently i am doing like this: <head> <title> <tiles:getAsString name="title"/> </title> </head> <% if(%><tiles:getAsString name="title"/><%.equals("Trade Confirmation Analysis Screen")) %> <body onload="JavaScript:timedRefresh(120000);"> <%else { %> <body> <% } %> Its giving me error..Unable to compile class for JSP:

    Read the article

  • Protecting critical sections based on a condition in C#

    - by NAADEV
    Hello, I'm dealing with a courious scenario. I'm using EntityFramework to save (insert/update) into a SQL database in a multithreaded environment. The problem is i need to access database to see whether a register with a particular key has been already created in order to set a field value (executing) or it's new to set a different value (pending). Those registers are identified by a unique guid. I've solved this problem by setting a lock since i do know entity will not be present in any other process, in other words, i will not have same guid in different processes and it seems to be working fine. It looks something like that: static readonly object LockableObject = new object(); static void SaveElement(Entity e) { lock(LockableObject) { Entity e2 = Repository.FindByKey(e); if (e2 != null) { Repository.Insert(e2); } else { Repository.Update(e2); } } } But this implies when i have a huge ammount of requests to be saved, they will be queued. I wonder if there is something like that (please, take it just as an idea): static void SaveElement(Entity e) { (using ThisWouldBeAClassToProtectBasedOnACondition protector = new ThisWouldBeAClassToProtectBasedOnACondition(e => e.UniqueId) { Entity e2 = Repository.FindByKey(e); if (e2 != null) { Repository.Insert(e2); } else { Repository.Update(e2); } } } The idea would be having a kind of protection that protected based on a condition so each entity e would have its own lock based on e.UniqueId property. Any idea?

    Read the article

  • PHP & WP: Render Certain Markup Based on True False Condition

    - by rob
    So, I'm working on a site where on the top of certain pages I'd like to display a static graphic and on some pages I would like to display an scrolling banner. So far I set up the condition as follows: <?php $regBanner = true; $regBannerURL = get_bloginfo('stylesheet_directory'); //grabbing WP site URL ?> and in my markup: <div id="banner"> <?php if ($regBanner) { echo "<img src='" . $regBannerURL . "/style/images/main_site/home_page/mock_banner.jpg' />"; } else { echo 'Slider!'; } ?> </div><!-- end banner --> In my else statement, where I'm echoing 'Slider!' I would like to output the markup for my slider: <div id="slider"> <img src="<?php bloginfo('stylesheet_directory') ?>/style/images/main_site/banners/services_banners/1.jpg" alt="" /> <img src="<?php bloginfo('stylesheet_directory') ?>/style/images/main_site/banners/services_banners/2.jpg" alt="" /> <img src="<?php bloginfo('stylesheet_directory') ?>/style/images/main_site/banners/services_banners/3.jpg" alt="" /> ............. </div> My question is how can I throw the div and all those images into my else echo statement? I'm having trouble escaping the quotes and my slider markup isn't rendering.

    Read the article

  • Drools - Doing Complex Stuff inside a Rule Condition or Consequence

    - by mfcabrera
    Hello, In my company we are planning to use Drools a BRE for couple of projects. Now we trying to define some best-practices. My question is what should be and shouldn't be done inside a Rule Condition/Consequence. Given that we can write Java directly or call methods (for example From a Global object in the Working Memory). Example. Given a Rule that evaluates a generic Object (e.g. Person) have property set to true. Now, that specific propertie can only be defined for that Object going to the database and fetching that info. So we have two ways of implementing that: Alternative A: Go to the database and fetch the object property (true/false, a code) Insert the Object in the working memory Evaluate the rule Alternative B: Insert a Global Object that has a method that connects to the database and check for the property for the given object. Insert the Object to eval in Working Memory In the rule, call the Global Object and perform the access to the database Which of those is considered better? I really like A, but sometimes B is more straightforward, however what would happen if something like a Exception from the Database is raised? I have seen the alternative B implemented in the Drools 5.0 Book from Packt Publishing,however they are doing a mocking and they don't talk about the actual implications of going to the database at all. Thank you,

    Read the article

  • SQL Server race condition issue with range lock

    - by Freek
    I'm implementing a queue in SQL Server (please no discussions about this) and am running into a race condition issue. The T-SQL of interest is the following: set transaction isolation level serializable begin tran declare @RecordId int declare @CurrentTS datetime2 set @CurrentTS=CURRENT_TIMESTAMP select top 1 @RecordId=Id from QueuedImportJobs with (updlock) where Status=@Status and (LeaseTimeout is null or @CurrentTS>LeaseTimeout) order by Id asc if @@ROWCOUNT> 0 begin update QueuedImportJobs set LeaseTimeout = DATEADD(mi,5,@CurrentTS), LeaseTicket=newid() where Id=@RecordId select * from QueuedImportJobs where Id = @RecordId end commit tran RecordId is the PK and there is also an index on Status,LeaseTimeout. What I'm basically doing is select a record of which the lease happens to be expired, while simultaneously updating the lease time with 5 minutes and setting a new lease ticket. So the problem is that I'm getting deadlocks when I run this code in parallel using a couple of threads. I've debugged it up to the point where I found out that the update statement sometimes gets executing twice for the same record. Now, I was under the impression that the with (updlock) should prevent this (it also happens with xlock btw, not with tablockx). So it actually look like there is a RangeS-U and a RangeX-X lock on the same range of records, which ought to be impossible. So what am I missing? I'm thinking it might have something to do with the top 1 clause or that SQL Server does not know that where Id=@RecordId is actually in the locked range? Deadlock graph: Table schema (simplified):

    Read the article

  • Controlling race condition at startup.

    - by Will Hartung
    I have some code that I want to have some one time initialisation performed. But this code doesn't have a definite lifecycle, so my logic can be potentially invoked by multiple threads before my initialisation is done. So, I want to basically ensure that my logic code "waits" until initialisation is done. This is my first cut. public class MyClass { private static final AtomicBoolean initialised = new AtomicBoolean(false); public void initialise() { synchronized(initialised) { initStuff(); initialised.getAndSet(true); initialised.notifyAll(); } } public void doStuff() { synchronized(initialised) { if (!initialised.get()) { try { initialised.wait(); } catch (InterruptedException ex) { throw new RuntimeException("Uh oh!", ex); } } } doOtherStuff(); } } I basically want to make sure this is going to do what I think it's going to do -- block doStuff until the initialised is true, and that I'm not missing a race condition where doStuff might get stuck on a Object.wait() that will never arrive. Edit: I have no control over the threads. And I want to be able to control when all of the initialisation is done, which is why doStuff() can't call initialise(). I used an AtomicBoolean as it was a combination of a value holder, and an object I could synchronize. I could have also simply had a "public static final Object lock = new Object();" and a simple boolean flag. AtomicBoolean conveniently gave me both. A Boolean can not be modified. The CountDownLatch is exactly what I was looking for. I also considered using a Sempahore with 0 permits. But the CountDownLatch is perfect for just this task.

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >