mirror of https://github.com/apache/cloudstack.git
72 lines
2.2 KiB
Java
72 lines
2.2 KiB
Java
// Copyright 2012 Citrix Systems, Inc. Licensed under the
|
|
// Apache License, Version 2.0 (the "License"); you may not use this
|
|
// file except in compliance with the License. Citrix Systems, Inc.
|
|
// reserves all rights not expressly granted by the License.
|
|
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
// Automatically generated by addcopyright.py at 04/03/2012
|
|
package com.cloud.network.ovs.dao;
|
|
|
|
import javax.ejb.Local;
|
|
|
|
import com.cloud.utils.db.DB;
|
|
import com.cloud.utils.db.GenericDaoBase;
|
|
import com.cloud.utils.db.SearchBuilder;
|
|
import com.cloud.utils.db.SearchCriteria;
|
|
import com.cloud.utils.db.Transaction;
|
|
import com.cloud.utils.db.SearchCriteria.Op;
|
|
|
|
@Local(value = { OvsTunnelDao.class })
|
|
public class OvsTunnelDaoImpl extends GenericDaoBase<OvsTunnelVO, Long>
|
|
implements OvsTunnelDao {
|
|
|
|
protected final SearchBuilder<OvsTunnelVO> fromToSearch;
|
|
|
|
public OvsTunnelDaoImpl() {
|
|
fromToSearch = createSearchBuilder();
|
|
fromToSearch.and("from", fromToSearch.entity().getFrom(), Op.EQ);
|
|
fromToSearch.and("to", fromToSearch.entity().getTo(), Op.EQ);
|
|
fromToSearch.done();
|
|
}
|
|
|
|
@Override
|
|
public OvsTunnelVO lockByFromAndTo(long from, long to) {
|
|
SearchCriteria<OvsTunnelVO> sc = fromToSearch.create();
|
|
sc.setParameters("from", from);
|
|
sc.setParameters("to", to);
|
|
return lockOneRandomRow(sc, true);
|
|
}
|
|
|
|
@Override
|
|
@DB
|
|
public int askKey(long from, long to) {
|
|
int key = -1;
|
|
|
|
final Transaction txn = Transaction.currentTxn();
|
|
txn.start();
|
|
OvsTunnelVO t = lockByFromAndTo(from, to);
|
|
if (t != null) {
|
|
key = t.getKey();
|
|
t.setKey(key+1);
|
|
update(t.getId(), t);
|
|
}
|
|
|
|
txn.commit();
|
|
return key;
|
|
}
|
|
|
|
@Override
|
|
public OvsTunnelVO getByFromAndTo(long from, long to) {
|
|
SearchCriteria<OvsTunnelVO> sc = fromToSearch.create();
|
|
sc.setParameters("from", from);
|
|
sc.setParameters("to", to);
|
|
return findOneBy(sc);
|
|
}
|
|
|
|
}
|