working on it ...

Filters

Explore Public Snippets

Sort by

Found 11k snippets matching: join

    public by fadzly  445751  70  5  0

    Magento - custom table join product eav table in a grid

    protected function _prepareCollection()
        {
    		//to join normal attributes; but not sku, type_id and others (see catalog_product_entity database table)
    		$productAttributesArray = array('product_name' => 'name', 'product_seller' => 'seller', 'product_supplier' => 'supplier');
    		$poTempModel = Mage::getModel('mymodule/modelone')->load($this->getRequest()->getParam('id'),'actual_id');
    		$collection = Mage::getModel('mymodule/modeltwo')->getCollection()->addFieldToFilter('parent_id',$poTempModel->getId());
    		foreach ($productAttributesArray as $alias => $attributeCode)
    		{
        		$tableAlias = $attributeCode . '_table';
        		$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
    			//Add eav attribute value
        		$collection->getSelect()
    							->joinLeft(
    								array($tableAlias => $attribute->getBackendTable()),
    								"main_table.product_id = $tableAlias.entity_id AND $tableAlias.attribute_id={$attribute->getId()}",
    								array($alias => 'value')
    							);
        	}
    		//to join entity attributes such sku, type_id
    		$collection->join(
                'catalog/product',
                'product_id = `catalog/product`.entity_id',//note the ` . DO NOT USE '
                array('sku' => 'sku')
            );
    		$this->setCollection($collection);
    		return parent::_prepareCollection();
        }
    	
    	protected function _prepareColumns()
    	{
    		$this->addColumn('position', array(
    			'header'=> 'Position',
    			'width' => '50px',
    			'type'  => 'number',
    			'index'=>'position',
    			'sortable' => false
    		));
    		$this->addColumn('product_name', array(
    			'header'=> 'Name',
    			'type'  => 'text',
    			'index'=>'product_name',
    			'sortable' => false
    		));
    		$this->addColumn('sku', array(
    			'header'=> 'SKU',
    			'type'  => 'text',
    			'index'=>'sku',
    			'sortable' => false
    		));
    		$this->addColumn('poitemtemp_id', array(
    			'header'=> 'Action',
    			'align'	=> 'center',
    			'type'  => 'number',
    			'index'=>'poitemtemp_id',
    			'renderer' 	=> 'mymodule/adminhtml_editpo_elements_edit_gridscontainer_currentitemsrender',
    			'sortable' => false
    		));
    		return parent::_prepareColumns();
    	}            

    public by cghersi  179395  5  7  0

    Apache Cayenne: how to select with Joins

    This is how to create simple queries that use JOIN among several tables. Such tables must be modelled as related in Cayenne modeler. In the example, we have 4 classes in JOIN chain. We want to retrieve all the objects of the 4th class that match the join with the object of the first class with the given id.
    ObjectContext context = getMyContext();
    int id = ...; //the pk of the FirstClass table
    FirstClass n = Cayenne.objectForPK(context, FirstClass.class, id);
    Expression qualifier = ExpressionFactory.matchExp(FourthClass.THIRD_CLASS_PROPERTY + "." + 
    					ThirdClass.SECOND_CLASS_PROPERTY + "." + SecondClass.FIRST_CLASS_PROPERTY, n);
    SelectQuery select = new SelectQuery(FourthClass.class, qualifier);
    List<FourthClass> result = context.performQuery(select);

    public by maindog  15982  1493  8  17

    javascript cheat for A Dark Room v1.3

    (can be used on chrome using the javascript console) After you get a hut and someone joins your village (not the builder) this code will provide you with a lot of wood, allowing you to build more huts, traps and other buildings once you have the resources. (does not purchase the buildings and for the mines you still have to find them on the map)
    /**
     * Module that registers the outdoors functionality
     */
    var Outside = {
    	name: "Outside",
    	
    	_GATHER_DELAY: 60,
    	_TRAPS_DELAY: 90,
    	_POP_DELAY: [0.5, 3],
    	
    	_INCOME: {
    		'gatherer': {
    			delay: 1,
    			stores: {
    				'wood': 10000
    			}
    		},
    		'hunter': {
    			delay: 1,
    			stores: {
    				'fur': 10000,
    				'meat': 10000,
    				'alien alloy': 10000,
    				'medicine': 10000
    			}
    		},
    		'trapper': {
    			delay: 1,
    			stores: {
    				'meat': 10000,
    				'bait': 10000,
    				'teeth': 10000,
    				'scales': 10000
    			}
    		},
    		'tanner': {
    			delay: 1,
    			stores: {
    				'fur': 100000,
    				'leather': 100000
    			}
    		},
    		'charcutier': {
    			delay: 1,
    			stores: {
    				'meat': 100000,
    				'wood': 100000,
    				'cured meat': 100000
    			}
    		},
    		'iron miner': {
    			delay: 1,
    			stores: {
    				'cured meat': 100000,
    				'iron': 100000
    			}
    		},
    		'coal miner': {
    			delay: 1,
    			stores: {
    				'cured meat': 100000,
    				'coal': 100000
    			}
    		},
    		'sulphur miner': {
    			delay: 1,
    			stores: {
    				'cured meat': 100000,
    				'sulphur': 100000
    			}
    		},
    		'steelworker': {
    			delay: 1,
    			stores: {
    				'iron': 100000,
    				'coal': 100000,
    				'steel': 100000
    			}
    		},
    		'armourer': {
    			delay: 1,
    			stores: {
    				'steel': 100000,
    				'sulphur': 10000,
    				'bullets': 100000
    			}
    		}
    	},
    	
    	TrapDrops: [
    		{
    			rollUnder: 0.5,
    			name: 'fur',
    			message: 'scraps of fur'
    		},
    		{
    			rollUnder: 0.75,
    			name: 'meat',
    			message: 'bits of meat'
    		},
    		{
    			rollUnder: 0.85,
    			name: 'scales',
    			message: 'strange scales'
    		},
    		{
    			rollUnder: 0.93,
    			name: 'teeth',
    			message: 'scattered teeth'
    		},
    		{
    			rollUnder: 0.995,
    			name: 'cloth',
    			message: 'tattered cloth'
    		},
    		{
    			rollUnder: 1.0,
    			name: 'charm',
    			message: 'a crudely made charm'
    		}
    	],
    	
    	init: function(options) {
    		this.options = $.extend(
    			this.options,
    			options
    		);
    		
    		if(Engine._debug) {
    			this._GATHER_DELAY = 0;
    			this._TRAPS_DELAY = 0;
    		}
    		
    		// Create the outside tab
    		this.tab = Header.addLocation("A Silent Forest", "outside", Outside);
    		
    		// Create the Outside panel
    		this.panel = $('<div>').attr('id', "outsidePanel")
    			.addClass('location')
    			.appendTo('div#locationSlider');
    		
    		//subscribe to stateUpdates
    		$.Dispatch('stateUpdate').subscribe(Outside.handleStateUpdates);
    		
    		if(typeof $SM.get('features.location.outside') == 'undefined') {
    			$SM.set('features.location.outside', true);
    			if(!$SM.get('game.buildings')) $SM.set('game.buildings', {});
    			if(!$SM.get('game.population')) $SM.set('game.population', 0);
    			if(!$SM.get('game.workers')) $SM.set('game.workers', {});
    		}
    		
    		this.updateVillage();
    		Outside.updateWorkersView();
    		
    		Engine.updateSlider();
    		
    		// Create the gather button
    		new Button.Button({
    			id: 'gatherButton',
    			text: "gather wood",
    			click: Outside.gatherWood,
    			cooldown: Outside._GATHER_DELAY,
    			width: '80px'
    		}).appendTo('div#outsidePanel');
    	},
    	
    	getMaxPopulation: function() {
    		return $SM.get('game.buildings["hut"]', true) * 4;
    	},
    	
    	increasePopulation: function() {
    		var space = Outside.getMaxPopulation() - $SM.get('game.population');
    		if(space > 0) {
    			var num = Math.floor(Math.random()*(space/2) + space/2);
    			if(num == 0) num = 1;
    			if(num == 1) {
    				Notifications.notify(null, 'a stranger arrives in the night');
    			} else if(num < 5) {
    				Notifications.notify(null, 'a weathered family takes up in one of the huts.');
    			} else if(num < 10) {
    				Notifications.notify(null, 'a small group arrives, all dust and bones.');
    			} else if(num < 30) {
    				Notifications.notify(null, 'a convoy lurches in, equal parts worry and hope.');
    			} else {
    				Notifications.notify(null, "the town's booming. word does get around.");
    			}
    			Engine.log('population increased by ' + num);
    			$SM.add('game.population', num);
    		}
    		Outside.schedulePopIncrease();
    	},
    	
    	killVillagers: function(num) {
    		$SM.add('game.population', num * -1);
    		if($SM.get('game.population') < 0) {
    			$SM.set('game.population', 0);
    		}
    		var remaining = Outside.getNumGatherers();
    		if(remaining < 0) {
    			var gap = -remaining;
    			for(var k in $SM.get('game.workers')) {
    				var num = $SM.get('game.workers["'+k+'"]');
    				if(num < gap) {
    					gap -= num;
    					$SM.set('game.workers["'+k+'"]', 0);
    				} else {
    					$SM.add('game.workers["'+k+'"]', gap * -1);
    					break;
    				}
    			}
    		}
    	},
    	
    	schedulePopIncrease: function() {
    		var nextIncrease = Math.floor(Math.random()*(Outside._POP_DELAY[1] - Outside._POP_DELAY[0])) + Outside._POP_DELAY[0];
        	Engine.log('next population increase scheduled in ' + nextIncrease + ' minutes');
        	Outside._popTimeout = setTimeout(Outside.increasePopulation, nextIncrease * 60 * 1000);
    	},
    	
    	updateWorkersView: function() {
    		var workers = $('div#workers');
    
    		// If our population is 0 and we don't already have a workers view,
    		// there's nothing to do here.
    		if(!workers.length && $SM.get('game.population') == 0) return;
    
    		var needsAppend = false;
    		if(workers.length == 0) {
    			needsAppend = true;
    			workers = $('<div>').attr('id', 'workers').css('opacity', 0);
    		}
    		
    		var numGatherers = $SM.get('game.population');
    		var gatherer = $('div#workers_row_gatherer', workers);
    		
    		for(var k in $SM.get('game.workers')) {
    			var workerCount = $SM.get('game.workers["'+k+'"]');
    			var row = $('div#workers_row_' + k.replace(' ', '-'), workers);
    			if(row.length == 0) {
    				row = Outside.makeWorkerRow(k, workerCount);
    				
    				var curPrev = null;
    				workers.children().each(function(i) {
    					var child = $(this);
    					var cName = child.attr('id').substring(12).replace('-', ' ');
    					if(cName != 'gatherer') {
    						if(cName < k && (curPrev == null || cName > curPrev)) {
    							curPrev = cName;
    						}
    					}
    				});
    				if(curPrev == null && gatherer.length == 0) {
    					row.prependTo(workers);
    				} 
    				else if(curPrev == null)
    				{
    					row.insertAfter(gatherer);
    				} 
    				else 
    				{
    					row.insertAfter(workers.find('#workers_row_' + curPrev.replace(' ', '-')));
    				}
    				
    			} else {
    				$('div#' + row.attr('id') + ' > div.row_val > span', workers).text(workerCount);
    			}
    			numGatherers -= workerCount;
    			if(workerCount == 0) {
    				$('.dnBtn', row).addClass('disabled');
    				$('.dnManyBtn', row).addClass('disabled');
    			} else {
    				$('.dnBtn', row).removeClass('disabled');
    				$('.dnManyBtn', row).removeClass('disabled');
    			}
    		}
    		
    		if(gatherer.length == 0) {
    			gatherer = Outside.makeWorkerRow('gatherer', numGatherers);
    			gatherer.prependTo(workers);
    		} else {
    			$('div#workers_row_gatherer > div.row_val > span', workers).text(numGatherers);
    		}
    		
    		if(numGatherers == 0) {
    			$('.upBtn', '#workers').addClass('disabled');
    			$('.upManyBtn', '#workers').addClass('disabled');
    		} else {
    			$('.upBtn', '#workers').removeClass('disabled');
    			$('.upManyBtn', '#workers').removeClass('disabled');
    		}
    		
    		
    		if(needsAppend && workers.children().length > 0) {
    			workers.appendTo('#outsidePanel').animate({opacity:1}, 300, 'linear');
    		}
    	},
    	
    	getNumGatherers: function() {
    		var num = $SM.get('game.population'); 
    		for(var k in $SM.get('game.workers')) {
    			num -= $SM.get('game.workers["'+k+'"]');
    		}
    		return num;
    	},
    	
    	makeWorkerRow: function(name, num) {
    		var row = $('<div>')
    			.attr('id', 'workers_row_' + name.replace(' ','-'))
    			.addClass('workerRow');
    		$('<div>').addClass('row_key').text(name).appendTo(row);
    		var val = $('<div>').addClass('row_val').appendTo(row);
    		
    		$('<span>').text(num).appendTo(val);
    		
    		if(name != 'gatherer') {
    		  $('<div>').addClass('upManyBtn').appendTo(val).click([10], Outside.increaseWorker);
    			$('<div>').addClass('upBtn').appendTo(val).click([1], Outside.increaseWorker);
    			$('<div>').addClass('dnBtn').appendTo(val).click([1], Outside.decreaseWorker);
    			$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Outside.decreaseWorker);
    		}
    		
    		$('<div>').addClass('clear').appendTo(row);
    		
    		var tooltip = $('<div>').addClass('tooltip bottom right').appendTo(row);
    		var income = Outside._INCOME[name];
    		for(var s in income.stores) {
    			var r = $('<div>').addClass('storeRow');
    			$('<div>').addClass('row_key').text(s).appendTo(r);
    			$('<div>').addClass('row_val').text(Engine.getIncomeMsg(income.stores[s], income.delay)).appendTo(r);
    			r.appendTo(tooltip);
    		}
    		
    		return row;
    	},
    	
    	increaseWorker: function(btn) {
    		var worker = $(this).closest('.workerRow').children('.row_key').text();
    		if(Outside.getNumGatherers() > 0) {
    		  var increaseAmt = Math.min(Outside.getNumGatherers(), btn.data);
    			Engine.log('increasing ' + worker + ' by ' + increaseAmt);
    			$SM.add('game.workers["'+worker+'"]', increaseAmt);
    		}
    	},
    	
    	decreaseWorker: function(btn) {
    		var worker = $(this).closest('.workerRow').children('.row_key').text();
    		if($SM.get('game.workers["'+worker+'"]') > 0) {
    		  var decreaseAmt = Math.min($SM.get('game.workers["'+worker+'"]') || 0, btn.data);
    			Engine.log('decreasing ' + worker + ' by ' + decreaseAmt);
    			$SM.add('game.workers["'+worker+'"]', decreaseAmt * -1);
    		}
    	},
    	
    	updateVillageRow: function(name, num, village) {
    		var id = 'building_row_' + name.replace(' ', '-');
    		var row = $('div#' + id, village);
    		if(row.length == 0 && num > 0) {
    			row = $('<div>').attr('id', id).addClass('storeRow');
    			$('<div>').addClass('row_key').text(name).appendTo(row);
    			$('<div>').addClass('row_val').text(num).appendTo(row);
    			$('<div>').addClass('clear').appendTo(row);
    			var curPrev = null;
    			village.children().each(function(i) {
    				var child = $(this);
    				if(child.attr('id') != 'population') {
    					var cName = child.attr('id').substring(13).replace('-', ' ');
    					if(cName < name && (curPrev == null || cName > curPrev)) {
    						curPrev = cName;
    					}
    				}
    			});
    			if(curPrev == null) {
    				row.prependTo(village);
    			} else {
    				row.insertAfter('#building_row_' + curPrev.replace(' ', '-'));
    			}
    		} else if(num > 0) {
    			$('div#' + row.attr('id') + ' > div.row_val', village).text(num);
    		} else if(num == 0) {
    			row.remove();
    		}
    	},
    	
    	updateVillage: function(ignoreStores) {
    		var village = $('div#village');
    		var population = $('div#population');
    		var needsAppend = false;
    		if(village.length == 0) {
    			needsAppend = true;
    			village = $('<div>').attr('id', 'village').css('opacity', 0);
    			population = $('<div>').attr('id', 'population').appendTo(village);
    		}
    		
    		for(var k in $SM.get('game.buildings')) {
    			if(k == 'trap') {
    				var numTraps = $SM.get('game.buildings["'+k+'"]');
    				var numBait = $SM.get('stores.bait', true);
    				var traps = numTraps - numBait;
    				traps = traps < 0 ? 0 : traps;
    				Outside.updateVillageRow(k, traps, village);
    				Outside.updateVillageRow('baited trap', numBait > numTraps ? numTraps : numBait, village);
    			} else {
    				if(Outside.checkWorker(k)) {
    					Outside.updateWorkersView();
    				}
    				Outside.updateVillageRow(k, $SM.get('game.buildings["'+k+'"]'), village);
    			}
    		}
    		
    		population.text('pop ' + $SM.get('game.population') + '/' + this.getMaxPopulation());
    		
    		var hasPeeps;
    		if($SM.get('game.buildings["hut"]', true) == 0) {
    			hasPeeps = false;
    			village.addClass('noHuts');
    		} else {
    			hasPeeps = true;
    			village.removeClass('noHuts');
    		}
    		
    		if(needsAppend && village.children().length > 1) {
    			village.appendTo('#outsidePanel');
    			village.animate({opacity:1}, 300, 'linear');
    		}
    		
    		if(hasPeeps && typeof Outside._popTimeout == 'undefined') {
    			Outside.schedulePopIncrease();
    		}
    		
    		this.setTitle();
    
    		if(!ignoreStores && Engine.activeModule === Outside && village.children().length > 1) {
    			$('#storesContainer').css({top: village.height() + 26 + 'px'});
    		}
    	},
    	
    	checkWorker: function(name) {
    		var jobMap = {
    			'lodge': ['hunter', 'trapper'],
    			'tannery': ['tanner'],
    			'smokehouse': ['charcutier'],
    			'iron mine': ['iron miner'],
    			'coal mine': ['coal miner'],
    			'sulphur mine': ['sulphur miner'],
    			'steelworks': ['steelworker'],
    			'armoury' : ['armourer']
    		};
    		
    		var jobs = jobMap[name];
    		var added = false;
    		if(typeof jobs == 'object') {
    			for(var i = 0, len = jobs.length; i < len; i++) {
    				var job = jobs[i];
    				if(typeof $SM.get('game.buildings["'+name+'"]') == 'number' && 
    						typeof $SM.get('game.workers["'+job+'"]') != 'number') {
    					Engine.log('adding ' + job + ' to the workers list');
    					$SM.set('game.workers["'+job+'"]', 0);
    					added = true;
    				}
    			}
    		}
    		return added;
    	},
    	
    	updateVillageIncome: function() {		
    		for(var worker in Outside._INCOME) {
    			var income = Outside._INCOME[worker];
    			var num = worker == 'gatherer' ? Outside.getNumGatherers() : $SM.get('game.workers["'+worker+'"]');
    			if(typeof num == 'number') {
    				var stores = {};
    				if(num < 0) num = 0;
    				var tooltip = $('.tooltip', 'div#workers_row_' + worker.replace(' ', '-'));
    				tooltip.empty();
    				var needsUpdate = false;
    				var curIncome = $SM.getIncome(worker);
    				for(var store in income.stores) {
    					stores[store] = income.stores[store] * num;
    					if(curIncome[store] != stores[store]) needsUpdate = true;
    					var row = $('<div>').addClass('storeRow');
    					$('<div>').addClass('row_key').text(store).appendTo(row);
    					$('<div>').addClass('row_val').text(Engine.getIncomeMsg(stores[store], income.delay)).appendTo(row);
    					row.appendTo(tooltip);
    				}
    				if(needsUpdate) {
    					$SM.setIncome(worker, {
    						delay: income.delay,
    						stores: stores
    					});
    				}
    			}
    		}
    		Room.updateIncomeView();
    	},
    	
    	updateTrapButton: function() {
    		var btn = $('div#trapsButton');
    		if($SM.get('game.buildings["trap"]', true) > 0) {
    			if(btn.length == 0) {
    				new Button.Button({
    					id: 'trapsButton',
    					text: "check traps",
    					click: Outside.checkTraps,
    					cooldown: Outside._TRAPS_DELAY,
    					width: '80px'
    				}).appendTo('div#outsidePanel');
    			} else {
    				Button.setDisabled(btn, false);
    			}
    		} else {
    			if(btn.length > 0) {
    				Button.setDisabled(btn, true);
    			}
    		}
    	},
    	
    	setTitle: function() {
    		var numHuts = $SM.get('game.buildings["hut"]', true);
    		var title;
    		if(numHuts == 0) {
    			title = "A Silent Forest";
    		} else if(numHuts == 1) {
    			title = "A Lonely Hut";
    		} else if(numHuts <= 4) {
    			title = "A Tiny Village";
    		} else if(numHuts <= 8) {
    			title = "A Modest Village";
    		} else if(numHuts <= 14) {
    			title = "A Large Village";
    		} else {
    			title = "A Raucous Village";
    		}
    		
    		if(Engine.activeModule == this) {
    			document.title = title;
    		}
    		$('#location_outside').text(title);
    	},
    	
    	onArrival: function(transition_diff) {
    		Outside.setTitle();
    		if(!$SM.get('game.outside.seenForest')) {
    			Notifications.notify(Outside, "the sky is grey and the wind blows relentlessly");
    			$SM.set('game.outside.seenForest', true);
    		}
    		Outside.updateTrapButton();
    		Outside.updateVillage(true);
    
    		Engine.moveStoresView($('#village'), transition_diff);
    	},
    	
    	gatherWood: function() {
    		Notifications.notify(Outside, "dry brush and dead branches litter the forest floor");
    		var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10;
    		$SM.add('stores.wood', gatherAmt);
    	},
    	
    	checkTraps: function() {
    		var drops = {};
    		var msg = [];
    		var numTraps = $SM.get('game.buildings["trap"]', true);
    		var numBait = $SM.get('stores.bait', true);
    		var numDrops = numTraps + (numBait < numTraps ? numBait : numTraps);
    		for(var i = 0; i < numDrops; i++) {
    			var roll = Math.random();
    			for(var j in Outside.TrapDrops) {
    				var drop = Outside.TrapDrops[j];
    				if(roll < drop.rollUnder) {
    					var num = drops[drop.name];
    					if(typeof num == 'undefined') {
    						num = 0;
    						msg.push(drop.message);
    					}
    					drops[drop.name] = num + 1;
    					break;
    				}
    			}
    		}
    		var s = 'the traps contain ';
    		for(var i = 0, len = msg.length; i < len; i++) {
    			if(len > 1 && i > 0 && i < len - 1) {
    				s += ", ";
    			} else if(len > 1 && i == len - 1) {
    				s += " and ";
    			}
    			s += msg[i];
    		}
    		
    		var baitUsed = numBait < numTraps ? numBait : numTraps;
    		drops['bait'] = -baitUsed;
    		
    		Notifications.notify(Outside, s);
    		$SM.addM('stores', drops);
    	},
    	
    	handleStateUpdates: function(e){
    		if(e.category == 'stores'){
    			Outside.updateVillage();
    		} else if(e.stateName.indexOf('game.workers') == 0
    		          || e.stateName.indexOf('game.population') == 0){
    			Outside.updateVillage();
    			Outside.updateWorkersView();
    			Outside.updateVillageIncome();
    		};
    	}
    };

    public by p.kontalis  2080  0  5  0

    SQL Join with Static Columns

    Identifies the origin of each row after the join of two tables.
    DROP TABLE IF EXISTS signed_A;
    DROP TABLE IF EXISTS signed_B;
    CREATE TEMPORARY TABLE signed_A AS (SELECT 'TableA' AS STATUS, A.col1, A.col2 FROM A);
    CREATE TEMPORARY TABLE signed_B AS (SELECT 'TableB' AS STATUS, hostings.col3 FROM B);
    SELECT * FROM A LEFT JOIN B ON A.col2=B.col3;

    public by AnghelLeonard  1484  0  5  0

    EntityManager joining a JTA transaction

    EntityManager joining a JTA transaction
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo_PU");
    EntityManager em = emf.createEntityManager();
    
    // specific to JBossStandAloneJtaPlatform
    javax.transaction.TransactionManager tx = 
                    com.arjuna.ats.jta.TransactionManager.transactionManager();        
    // or
    javax.transaction.UserTransaction tx_ = 
                    com.arjuna.ats.jta.UserTransaction.userTransaction();
    
    try {
        tx.begin();
        em.joinTransaction();
        em.persist(transientInstance);
        tx.commit();
        ...

    public by sjschmalfeld  11546  7  4  0

    Join Two Datatables

    also deals with duplicate field names
    DataTable targetTable = dataTable1.Clone();
    var dt2Columns = dataTable2.Columns.OfType<DataColumn>().Select(dc => 
    new DataColumn(dc.ColumnName, dc.DataType, dc.Expression, dc.ColumnMapping));
    var dt2FinalColumns=from dc in dt2Columns.AsEnumerable()
                        where targetTable.Columns.Contains(dc.ColumnName) == false
                        select dc;
    targetTable.Columns.AddRange(dt2FinalColumns.ToArray());
    var rowData =from row1 in dataTable1.AsEnumerable()
                 join row2 in dataTable2.AsEnumerable()
                 on row1.Field<int>("ID") equals row2.Field<int>("ID")
                 select row1.ItemArray.Concat(row2.ItemArray.Where(r2=> row1.ItemArray.Contains(r2)==false)).ToArray();
    foreach (object[] values in rowData)
    targetTable.Rows.Add(values);                                                

    public by lbottaro  3227  0  6  0

    Python join list element

    This script joins element in a list
    result = []
    [ result.extend(el) for el in x] 
    
    for el in result:
      print el

    public by fadzly  2678  74  6  0

    Magento Join Derived Table and EAV

    protected function _prepareCollection()
    	{
    		$paymentTbl = Mage::getSingleton('core/resource')->getTableName('sales/order_payment');
    		$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'cost');
    		$attributeTable = $attribute->getBackend()->getTable();
    		$deliveryTable = Mage::getSingleton('core/resource')->getTableName('plansetter/deliveryorderitem');
    		$orderTable = Mage::getSingleton('core/resource')->getTableName('sales/order');
    		$collection = Mage::getModel('sales/order_item')->getCollection()->filterByParent();
    		$collection->getSelect()
    					->join(
    							array('ordertbl' => $orderTable),
    							"main_table.order_id=ordertbl.entity_id"
    						)
    					->joinLeft(
    							array('paymenttbl'=>$paymentTbl),
    							'main_table.order_id = paymenttbl.parent_id',
    							array
    							(
    								'*',
    							)
    					)
    					/*
    					->joinLeft(
    						array('productentitydectbl' => $attributeTable),
    						'main_table.product_id = productentitydectbl.entity_id'
    					)
    					*/
    					/*
    					->where('productentitydectbl.attribute_id='.$attribute->getAttributeId())
    					*/
    					->joinLeft(
    						array('productentitydectbl' => new Zend_Db_Expr("(SELECT * FROM ".$attributeTable." WHERE ".$attributeTable.".attribute_id = ".$attribute->getAttributeId().")")),
    						'main_table.product_id = productentitydectbl.entity_id'
    					)
    					->joinLeft(
    						array('delivery_table' => $deliveryTable),
    						"main_table.item_id = delivery_table.order_item_id"
    					)
    					->columns('(qty_ordered - qty_refunded) AS net_qty_ordered')
    					->columns('IF(ISNULL(productentitydectbl.value),0,1)AS cost_updated');
    		$this->setCollection($collection);
    		//$collection->printLogQuery(true);
    		//die();
    		parent::_prepareCollection();
    		return $this;
    	}

    public by mporru  2191  1  4  0

    Join a string array in java

    If we join an array like this ["a", "b", "c"] with the separator ": ", we have as a result: "a: b :c"
    public static String join(String[] s, String delimiter) {
    	if ((s == null) || (s.length==0))
    		return "";
    	
    	StringBuilder builder = new StringBuilder();
    	for (int i=0; i<s.length; i++) {
    		builder.append(s[i]);
    		if (i>= s.length-1) {
    			break;                  
    		}
    		builder.append(delimiter);
    	}
    	return builder.toString();
    }

    public by rafacoding  1425  0  5  0

    Select de una join de tablas en MySQL

    select its_artist.name ,count(*) 
    from its_artist join its_song on its_artist.id= its_song.artist 
    GROUP BY its_artist.name 
    HAVING count(*)>100
    • Public Snippets
    • Channels Snippets