List of usage examples for org.hibernate LockMode READ
LockMode READ
To view the source code for org.hibernate LockMode READ.
Click Source Link
From source file:hacks.VirtuosoSybaseDialect.java
License:Open Source License
public String appendLockHint(LockMode mode, String tableName) { if (mode.greaterThan(LockMode.READ)) { return tableName + " holdlock"; } else {//from www .j a v a2 s . c om return tableName; } }
From source file:hacks.VirtuosoSybaseDialect.java
License:Open Source License
@Override public String applyLocksToSql(String sql, Map aliasedLockModes, Map keyColumnNames) { Iterator itr = aliasedLockModes.entrySet().iterator(); StringBuffer buffer = new StringBuffer(sql); int correction = 0; while (itr.hasNext()) { final Map.Entry entry = (Map.Entry) itr.next(); final LockMode lockMode = (LockMode) entry.getValue(); if (lockMode.greaterThan(LockMode.READ)) { final String alias = (String) entry.getKey(); int start = -1, end = -1; if (sql.endsWith(" " + alias)) { start = (sql.length() - alias.length()) + correction; end = start + alias.length(); } else { int position = sql.indexOf(" " + alias + " "); if (position <= -1) { position = sql.indexOf(" " + alias + ","); }//from w w w . ja va2 s. c o m if (position > -1) { start = position + correction + 1; end = start + alias.length(); } } if (start > -1) { final String lockHint = appendLockHint(lockMode, alias); buffer.replace(start, end, lockHint); correction += (lockHint.length() - alias.length()); } } } return buffer.toString(); }
From source file:net.chrisrichardson.foodToGo.acknowledgeOrderService.hibernate.HibernateObjectAttacher.java
License:Apache License
public Object attach(Object object) { template.update(object); template.lock(object, LockMode.READ); return object; }
From source file:net.kamhon.ieagle.dao.HibernateDao.java
License:Apache License
public T getReadonly(Class<T> clazz, Serializable serializablekey) { try {/*from ww w . ja va 2 s .c o m*/ return (T) getHibernateTemplate().get(clazz, serializablekey, LockMode.READ); } catch (Exception e) { throw new DataException(e); } }
From source file:org.archiviststoolkit.dialog.AccessionLookup.java
License:Open Source License
private void initLookup() { try {/* ww w . j a v a 2 s .c o m*/ EventList eventList = new BasicEventList(); eventList.addAll(new DomainAccessObjectImpl(Accessions.class).findAll(LockMode.READ)); SortedList sortedItems = new SortedList(eventList); textFilteredIssues = new FilterList(sortedItems, new TextComponentMatcherEditor(filterField, new DomainFilterator())); lookupTableModel = new EventTableModel(textFilteredIssues, new DomainTableFormat(Accessions.class)); lookupTable.setModel(lookupTableModel); TableComparatorChooser tableSorter = new TableComparatorChooser(lookupTable, sortedItems, true); filterField.requestFocusInWindow(); } catch (LookupException e) { new ErrorDialog("", StringHelper.getStackTrace(e)).showDialog(); } }
From source file:org.archiviststoolkit.dialog.DigitalObjectLookup.java
License:Open Source License
private void initLookup() { try {/*from www. j a v a 2s. c om*/ eventList = new BasicEventList(); if (parentEditorType.equals(PARENT_EDITOR_TYPE_ASSESSMENTS)) { eventList.addAll(new DigitalObjectDAO().findAll(LockMode.READ)); } else if (parentEditorType.equals(PARENT_EDITOR_TYPE_RESOURCES)) { eventList.addAll(new DigitalObjectDAO().findAllUnlinked(LockMode.READ)); } SortedList sortedItems = new SortedList(eventList); textFilteredIssues = new FilterList(sortedItems, new TextComponentMatcherEditor(filterField, new DomainFilterator())); lookupTableModel = new EventTableModel(textFilteredIssues, new DomainTableFormat(DigitalObjects.class)); lookupTable.setModel(lookupTableModel); TableComparatorChooser tableSorter = new TableComparatorChooser(lookupTable, sortedItems, true); filterField.requestFocusInWindow(); } catch (LookupException e) { new ErrorDialog("", StringHelper.getStackTrace(e)).showDialog(); } }
From source file:org.archiviststoolkit.maintenance.upgrades.UpgradeTo_1_1_24.java
License:Open Source License
protected boolean runPostDBInitializationCode() { try {/*from ww w . j a va 2 s . com*/ DomainAccessObject access = new DomainAccessObjectImpl(DefaultValues.class); DefaultValues defaultValue; DatabaseFields fieldInfo; for (Object o : access.findAll(LockMode.READ)) { defaultValue = (DefaultValues) o; fieldInfo = defaultValue.getAtField(); if (fieldInfo.getDataType().equals(String.class.getName()) && (fieldInfo.getStringLengthLimit() == null || fieldInfo.getStringLengthLimit() == 0)) { defaultValue.setTextValue(defaultValue.getStringValue()); defaultValue.setStringValue(null); access.update(defaultValue); } } } catch (PersistenceException e) { setErrorString(e.getMessage()); return false; } catch (LookupException e) { setErrorString(e.getMessage()); return false; } return true; }
From source file:org.archiviststoolkit.maintenance.upgrades.UpgradeTo_1_7_0.java
License:Open Source License
/** * Run any sql and hibernate code that needs to be ran after the database has been * initialized by hibernate.//from www . jav a 2s . c o m * * @param conn The connection to the database * @return true if all the code executed fine */ protected boolean runPostDBInitializationSQLCode(Connection conn) { // first we need to set a repository id for all digital objects otherwise // the dont show up in hibernates list all String sqlString = ""; Statement stmt; try { stmt = conn.createStatement(); sqlString = "UPDATE DigitalObjects SET repositoryId = 1"; stmt.execute(sqlString); conn.commit(); } catch (SQLException e) { setErrorString(e.getMessage()); return false; } // now use hibernate to upgrade digital objects with correct repository and identifier information try { // this access is used for finding the repository of the DO, and findind only parent DO DigitalObjectDAO access = new DigitalObjectDAO(); access.getLongSession(); DigitalObjects digitalObject; // set the repository for digital objects and clear out the mets ID if they // are duplicates // HashMap<String,String> metsIDs = new HashMap<String,String>(); String metsID; Collection digitalObjects = access.findAll(LockMode.READ); totalCount = digitalObjects.size(); // if total count is greater than 1000 then run in // parallel code to help dramatically speed the process up if (totalCount > 1000) { System.out.println("Updating digital object using parallel code ..."); return updateDigitalObjectsInParallel(digitalObjects, access); } // open digital objects in long session digitalObjects = access.findAllLongSession(LockMode.READ); // update the collection for (Object o : digitalObjects) { digitalObject = (DigitalObjects) o; // for debug purposes print out the digital object being processed String progressMessage = "Updating Digital Object : " + count + " of " + totalCount + " ( ID = " + digitalObject.getIdentifier() + " )"; progress.setProgress("Updating Digital Object (ID:" + digitalObject.getIdentifier() + ")", count, totalCount); count++; // get the parent resource this digital object belongs to ArchDescriptionDigitalInstances digitalInstance = digitalObject.getDigitalInstance(); if (digitalInstance != null) { try { Resources parentResource = access.findResourceByDigitalObject(digitalInstance); // now update the repository if (parentResource != null) { setRepository(digitalObject, parentResource.getRepository()); // now set the parent resoure in the digital object instance to allow searching // by resource for digital objects digitalInstance.setParentResource(parentResource); } } catch (Exception e) { // lets handel any errors due to orphaned digital objects digitalObject.setDigitalInstance(null); System.out.println( "Error processing Digital Object ID = " + digitalObject.getIdentifier() + "\n"); e.printStackTrace(); } } // modify the metId if is not unique metsID = digitalObject.getMetsIdentifier(); if (metsID.length() != 0) { if (!metsIDs.containsKey(metsID)) { metsIDs.put(metsID, metsID); } else { // key already exist so clear it out digitalObject.setMetsIdentifier(""); } } access.updateLongSession(digitalObject, false); } access.closeLongSession(); } catch (PersistenceException e) { setErrorString(e.getMessage()); return false; } catch (LookupException e) { setErrorString(e.getMessage()); return false; } catch (SQLException e) { setErrorString(e.getMessage()); e.printStackTrace(); return false; } catch (Exception e) { setErrorString(e.getMessage()); e.printStackTrace(); return false; } return true; }
From source file:org.archiviststoolkit.model.Constants.java
License:Open Source License
public static void loadDefaultDateFormat() throws PersistenceException, LookupException, WrongNumberOfConstantsRecordsException { DomainAccessObject access = DomainAccessObjectFactory.getInstance().getDomainAccessObject(Constants.class); Collection constants = access.findAll(LockMode.READ); if (constants.size() == 1) { Constants constantRecord = (Constants) constants.iterator().next(); ApplicationFrame.applicationDateFormat = new SimpleDateFormat(constantRecord.getDefaultDateFormat()); ApplicationFrame.applicationDateFormat.setLenient(false); } else {/*from w ww.j ava 2 s .co m*/ throw new WrongNumberOfConstantsRecordsException(constants.size() + " records"); } }
From source file:org.archiviststoolkit.model.Repositories.java
License:Open Source License
public static boolean loadRepositories() { repositoryList = new ArrayList<Repositories>(); DomainAccessObject access = new DomainAccessObjectImpl(Repositories.class); try {//from w w w .j av a 2 s . com for (Object o : access.findAll(LockMode.READ, "repositoryName")) { Repositories.addRepositoryToList((Repositories) o); } } catch (LookupException e) { ErrorDialog dialog = new ErrorDialog("There is a problem loading repositories.", StringHelper.getStackTrace(e)); dialog.showDialog(); e.printStackTrace(); return false; } return true; }