View Javadoc
1 /* 2 $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/lcm/quota/QuotaServiceImpl.java,v 1.2 2002/11/09 22:37:53 peteburg Exp $ 3 */ 4 package com.sun.ebxml.registry.lcm.quota; 5 6 import java.io.*; 7 import java.util.*; 8 9 import com.sun.ebxml.registry.*; 10 import com.sun.ebxml.registry.util.*; 11 import com.sun.ebxml.registry.persistence.rdb.*; 12 import com.sun.ebxml.registry.repository.*; 13 14 import org.oasis.ebxml.registry.bindings.query.*; 15 import org.oasis.ebxml.registry.bindings.query.types.*; 16 import org.oasis.ebxml.registry.bindings.rim.ObjectRef; 17 18 public class QuotaServiceImpl { 19 20 private static QuotaServiceImpl instance = null; 21 private static long quotaLimit; // in MB 22 private static long quotaLimitInBytes; 23 24 public static QuotaServiceImpl getInstance() { 25 if (instance == null) { 26 synchronized(QuotaServiceImpl.class) { 27 if (instance == null) { 28 instance = new QuotaServiceImpl(); 29 quotaLimit = Integer.parseInt(RegistryProperties.getInstance() 30 .getProperty("ebxmlrr.repository.quota")); 31 quotaLimitInBytes = quotaLimit * 1024 * 1024; 32 } 33 } 34 } 35 return instance; 36 } 37 38 /*** 39 @throws QuotaExceededException if the size of already submitted items exceeds 40 the quota specified in ebxmlrr.properties. It simply counts the number of bytes 41 of previously submitted items and throws the exception on *next* request. So 42 a single request can submit an item whose size is bigger than the quota limit. 43 @throws RegistryException if there is a IOException when getting the items sizes. 44 */ 45 public void checkQuota(String userId) throws QuotaExceededException, 46 RegistryException { 47 // Get the id of items already submitted by this user 48 String sql = "SELECT id FROM ExtrinsicObject WHERE id IN " + 49 "(SELECT ae.registryObject FROM AuditableEvent ae WHERE ae.eventType='Created' AND " 50 + "ae.user_='" + userId + "')"; 51 //System.err.println(sql); 52 ResponseOption responseOption = new ResponseOption(); 53 responseOption.setReturnType(ReturnTypeType.OBJECTREF); 54 ArrayList results = SQLPersistenceManagerImpl.getInstance().executeSQLQuery(sql, responseOption 55 , "ExtrinsicObject", new ArrayList()); 56 57 // Get the total size of the repository items already submitted 58 Iterator resultsIter = results.iterator(); 59 ArrayList itemsIds = new ArrayList(); 60 while(resultsIter.hasNext()) { 61 ObjectRef objectRef = (ObjectRef)resultsIter.next(); 62 itemsIds.add(objectRef.getId()); 63 //System.err.println(objectRef.getId()); 64 } 65 RepositoryManager repManager = 66 RepositoryManagerFactory.getInstance().getRepositoryManager(); 67 long totalSizeOfSubmittedItems = repManager.getItemsSize(itemsIds); 68 69 //System.err.println("Size: " + totalSizeOfSubmittedItems); 70 71 if (totalSizeOfSubmittedItems > quotaLimitInBytes) { 72 throw new QuotaExceededException(userId, quotaLimit); 73 } 74 } 75 } 76

This page was automatically generated by Maven