📄 lockfeature.java
字号:
throw new WFSException("Could not aquire locks for:"
+ response.getFeaturesNotLocked());
}
//remove empty parts of the response object
if (response.getFeaturesLocked().getFeatureId().isEmpty()) {
response.setFeaturesLocked(null);
}
if (response.getFeaturesNotLocked().getFeatureId().isEmpty()) {
response.setFeaturesNotLocked(null);
}
return response;
} catch (WFSException e) {
// release locks when something fails
if (fLock != null) {
try {
release(fLock.getAuthorization());
} catch (WFSException e1) {
// log it
LOGGER.log(Level.SEVERE, "Error occured releasing locks", e1);
}
}
throw e;
}
}
/**
* Release lock by authorization
*
* @param lockID
*/
public void release(String lockId) throws WFSException {
try {
boolean refresh = false;
Set dataStores = catalog.getDataStores();
for (Iterator i = dataStores.iterator(); i.hasNext();) {
DataStoreInfo meta = (DataStoreInfo) i.next();
if (!meta.isEnabled()) {
continue; // disabled
}
DataStore dataStore;
try {
dataStore = meta.getDataStore();
} catch (IllegalStateException notAvailable) {
continue; // not available
}
LockingManager lockingManager = dataStore.getLockingManager();
if (lockingManager == null) {
continue; // locks not supported
}
org.geotools.data.Transaction t = new DefaultTransaction("Refresh "
+ meta.getNamesSpacePrefix());
try {
t.addAuthorization(lockId);
if (lockingManager.release(lockId, t)) {
refresh = true;
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
} finally {
try {
t.close();
} catch (IOException closeException) {
LOGGER.log(Level.FINEST, closeException.getMessage(), closeException);
}
}
}
if (!refresh) {
// throw exception? or ignore...
}
} catch (Exception e) {
throw new WFSException(e);
}
}
/**
* Release all feature locks currently held.
*
* <p>
* This is the implementation for the Admin "free lock" action, transaction
* locks are not released.
* </p>
*
* @return Number of locks released
*/
public void releaseAll() throws WFSException {
try {
Set dataStores = catalog.getDataStores();
for (Iterator i = dataStores.iterator(); i.hasNext();) {
DataStoreInfo meta = (DataStoreInfo) i.next();
if (!meta.isEnabled()) {
continue; // disabled
}
DataStore dataStore;
try {
dataStore = meta.getDataStore();
} catch (IllegalStateException notAvailable) {
continue; // not available
} catch (Throwable huh) {
continue; // not even working
}
LockingManager lockingManager = dataStore.getLockingManager();
if (lockingManager == null) {
continue; // locks not supported
}
// TODO: implement LockingManger.releaseAll()
// count += lockingManager.releaseAll();
}
} catch (Exception e) {
throw new WFSException(e);
}
}
public boolean exists(String lockId) throws WFSException {
try {
Set dataStores = catalog.getDataStores();
for (Iterator i = dataStores.iterator(); i.hasNext();) {
DataStoreInfo meta = (DataStoreInfo) i.next();
if (!meta.isEnabled()) {
continue; // disabled
}
DataStore dataStore;
try {
dataStore = meta.getDataStore();
} catch (IllegalStateException notAvailable) {
continue; // not available
}
LockingManager lockingManager = dataStore.getLockingManager();
if (lockingManager == null) {
continue; // locks not supported
}
if (lockingManager.exists(lockId)) {
return true;
}
}
return false;
} catch (Exception e) {
throw new WFSException(e);
}
}
public void refresh(String lockId) throws WFSException {
try {
boolean refresh = false;
Set dataStores = catalog.getDataStores();
for (Iterator i = dataStores.iterator(); i.hasNext();) {
DataStoreInfo meta = (DataStoreInfo) i.next();
if (!meta.isEnabled()) {
continue; // disabled
}
DataStore dataStore;
try {
dataStore = meta.getDataStore();
} catch (IllegalStateException notAvailable) {
continue; // not available
}
LockingManager lockingManager = dataStore.getLockingManager();
if (lockingManager == null) {
continue; // locks not supported
}
org.geotools.data.Transaction t = new DefaultTransaction("Refresh "
+ meta.getNamesSpacePrefix());
try {
t.addAuthorization(lockId);
if (lockingManager.refresh(lockId, t)) {
refresh = true;
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
} finally {
try {
t.close();
} catch (IOException closeException) {
LOGGER.log(Level.FINEST, closeException.getMessage(), closeException);
}
}
}
if (!refresh) {
// throw exception? or ignore...
}
} catch (Exception e) {
throw new WFSException(e);
}
}
private FeatureId fid(String fid) {
return filterFactory.featureId(fid);
}
private Id fidFilter(FeatureId fid) {
HashSet ids = new HashSet();
ids.add(fid);
return filterFactory.id(ids);
}
protected FeatureLock newFeatureLock(LockFeatureType request) {
if ((request.getHandle() == null) || request.getHandle().equals("")) {
request.setHandle("GeoServer");
}
if (request.getExpiry() == null) {
request.setExpiry(BigInteger.valueOf(0));
}
int lockExpiry = request.getExpiry().intValue();
if (lockExpiry < 0) {
// negative time used to query if lock is available!
return FeatureLockFactory.generate(request.getHandle(), lockExpiry);
}
if (lockExpiry == 0) {
// perma lock with no expiry!
return FeatureLockFactory.generate(request.getHandle(), 0);
}
// FeatureLock is specified in minutes
return FeatureLockFactory.generate(request.getHandle(), lockExpiry * 60 * 1000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -