All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tentackle.persist.wurblet.PdoCache Maven / Gradle / Ivy

// wurblet generated by Wurbelizer 21.6.0.0, see https://wurbelizer.org

package org.tentackle.persist.wurblet;

import org.tentackle.wurblet.*;
import org.tentackle.buildsupport.*;
import java.util.*;
import java.io.*;
import org.tentackle.common.*;
import org.wurbelizer.wurbel.*;
import org.tentackle.sql.*;
import org.tentackle.model.*;
import org.wurbelizer.wurblet.*;

/**
 * ({@code @wurblet}) Generate code for setting up a PdoCache for an entity.
 * 

* usage:
* @wurblet <tag> PdoCache * [--secure] [--preload] [--mutable] [--udk] * [--strategy=LRU|LFU|FORGET] [--maxsize=<n>] [--keepquota=<p>] [--configure=<method>] * [index1] [index2] ... *

* arguments: *

    *
  • --secure: if cache must check read permission for each access (default is no check).
  • *
  • --preload: the first access will load all entities at once.
  • *
  • --mutable: generates a non-shared cache, i.e. mutable PDOs (by default a shared readonly cache is generated).
  • *
  • --udk: add index for the unique domain key.
  • *
  • --strategy=LRU|LFU|FORGET: the caching strategy (default is FORGET).
  • *
  • --maxsize=<n>: the cache size (if not preloaded).
  • *
  • --keepquota=<p>: percentage of entries to keep when applying caching strategy. Default is 50.
  • *
  • --configure=<method>: an optional method to further configure the cache.
  • *
  • --index<n>: additional unique indexes. By default, only the ID-index will be created.
  • *
* For more options, see {@link DbModelWurblet}. */ public class PdoCache extends DbModelWurblet { @Override public void run() throws WurbelException { super.run(); try { wurbel(); } catch (Throwable t) { if (t instanceof WurbelException) { throw (WurbelException) t; } throw new WurbelException("wurblet " + this + " failed", t); } } // ----------------- begin wurblet code ----------------- private void wurbel() throws ModelException, WurbelException { // main class String pdoName = getPdoClassName(); boolean isAbstract = getEntity().isAbstract(); String pdoType = isAbstract ? "T" : pdoName; boolean secure = false; boolean preload = false; boolean mutable = false; boolean delayed = true; boolean genudk = false; String strategy = null; Integer maxSize = null; Integer keepQuota = null; String configure = null; for (String arg: getOptionArgs()) { if (arg.equals("preload")) { preload = true; } else if (arg.equals("secure")) { secure = true; } else if (arg.equals("mutable")) { mutable = true; } else if (arg.equals("immediate")) { delayed = false; } else if (arg.equals("udk")) { genudk = true; } else if (arg.startsWith("strategy=")) { strategy = arg.substring(9).toUpperCase(Locale.ROOT); } else if (arg.startsWith("maxsize=")) { maxSize = Integer.valueOf(arg.substring(8)); } else if (arg.startsWith("keepquota=")) { keepQuota = Integer.valueOf(arg.substring(10)); } else if (arg.startsWith("configure=")) { configure = arg.substring(10); } } if (secure && !getEntity().isRootEntity()) { throw new WurbelException(getEntity() + " is not a root-entity"); } if (getEntity().getInheritanceType() == InheritanceType.PLAIN) { throw new WurbelException("only concrete (leaf) entity types can be cached within a PLAIN inheritance hierarchy"); } List udk = null; String udkType = null; String udkName = null; String udkSuffix = null; if (genudk) { udk = getEntity().getUniqueDomainKey(); if (!udk.isEmpty()) { if (udk.size() == 1) { udkType = getNonPrimitiveJavaType(udk.get(0)); udkName = udk.get(0).getName(); udkSuffix = udk.get(0).getMethodNameSuffix(); } else { udkType = getEntity().getName() + "UDK"; udkName = "udk"; udkSuffix = "UniqueDomainKey"; udkType = getEntity().getName() + "." + udkType; } } else { udk = null; genudk = false; } } StringBuilder listenNames = new StringBuilder(); if (getEntity().getInheritanceType() == InheritanceType.MULTI) { for (Entity leaf : getEntity().getLeafEntities()) { if (!listenNames.isEmpty()) { listenNames.append(", "); } listenNames.append(leaf.getName()).append(".class"); } } else { listenNames.append(pdoName).append(".class"); } out.print(source[0]); // 119:2 = " /** Holder of the PDO cache singleton...." if (isAbstract) { out.print(source[1]); // 124:2 = " private static final PdoCache> CACHE = createCache();" for (WurbletArgument key: getExpressionArguments()) { String name = key.getMethodArgumentName(); String type = getNonPrimitiveJavaType(key.getAttribute()); out.print(source[3]); // 130:2 = " private static final PdoCacheIndex, " out.print(type); out.print(source[5]); // 131:73 = "> " out.print(name.toUpperCase(Locale.ROOT) + "_INDEX"); out.print(source[6]); // 131:119 = " = create" out.print(StringHelper.firstToUpper(name)); out.print(source[7]); // 131:163 = "Index();" } if (genudk) { out.print(source[8]); // 136:2 = " private static final PdoCacheIndex, " out.print(udkType); out.print(source[10]); // 137:76 = "> UDK_INDEX = createUdkIndex();" } out.print(source[11]); // 140:2 = " @SuppressWarnings("unchecked") ..." out.print(pdoName); out.print(source[12]); // 143:41 = "> PdoCache createCache() { P..." out.print(pdoName); out.print(source[13]); // 144:70 = ".class, " out.print(preload ? "true" : "false"); out.print(source[14]); // 144:108 = ", " out.print(mutable ? "false" : "true"); out.print(source[15]); // 144:140 = ", " out.print(secure ? "true" : "false"); out.print(source[16]); // 144:171 = "); Pdo.listen(cache::expire, " out.print(listenNames); out.print(source[17]); // 145:47 = ");" if (strategy != null) { out.print(source[18]); // 148:2 = " cache.setStrategy(PdoCacheStrategy..." out.print(strategy); out.print(source[19]); // 149:53 = ");" } if (maxSize != null) { out.print(source[20]); // 153:2 = " cache.setMaxSize(" out.print(maxSize); out.print(source[21]); // 154:34 = ");" } if (keepQuota != null) { out.print(source[22]); // 158:2 = " cache.setKeepQuota(" out.print(keepQuota); out.print(source[23]); // 159:38 = ");" } if (configure != null) { out.print(source[24]); // 163:2 = " " out.print(configure); out.print(source[25]); // 164:19 = "(cache);" } out.print(source[26]); // 167:2 = " return cache; }" for (WurbletArgument key: getExpressionArguments()) { String name = key.getMethodArgumentName(); String type = getNonPrimitiveJavaType(key.getAttribute()); String suffix = Character.toUpperCase(name.charAt(0)) + name.substring(1); if (isRemote()) { RemoteIncludes genInc = new RemoteIncludes(this); PrintStream implOut = genInc.getImplStream(); PrintStream remoteOut = genInc.getRemoteStream(); remoteOut.print(source[27]); // 180:16 = " T selectBy" remoteOut.print(suffix); remoteOut.print(source[28]); // 181:22 = "ForCache(DomainContext context, " remoteOut.print(type); remoteOut.print(source[29]); // 181:62 = " " remoteOut.print(name); remoteOut.print(source[30]); // 181:71 = ") throws RemoteException;" implOut.print(source[31]); // 182:14 = " @Override public T selectBy" implOut.print(suffix); implOut.print(source[32]); // 185:29 = "ForCache(DomainContext context, " implOut.print(type); implOut.print(source[33]); // 185:69 = " " implOut.print(name); implOut.print(source[34]); // 185:78 = ") throws RemoteException { try { ..." implOut.print(suffix); implOut.print(source[35]); // 187:58 = "(" implOut.print(name); implOut.print(source[36]); // 187:67 = "); } catch (RuntimeException e) ..." out.print(source[37]); // 193:6 = " private static ) ") : ""; String indexName = "CacheHolder." + name.toUpperCase(Locale.ROOT) + "_INDEX"; String indexMethod = "getCacheIndex" + StringHelper.firstToUpper(name); out.print(source[198]); // 539:2 = " /** * Gets the index for " out.print(name); out.print(source[199]); // 542:32 = ". * * @return the index for " out.print(type); out.print(source[200]); // 544:36 = " " out.print(name); out.print(source[201]); // 544:45 = " */" if (isAbstract) { out.print(source[202]); // 548:2 = " @SuppressWarnings("unchecked")" } out.print(source[203]); // 552:2 = " protected PdoCacheIndex<" out.print(pdoType); out.print(source[204]); // 553:37 = ", " out.print(type); out.print(source[205]); // 553:47 = "> " out.print(indexMethod); out.print(source[206]); // 553:64 = "() { return " out.print(indexCast); out.print(indexName); out.print(source[207]); // 554:37 = "; } /** * Selects from cache by ..." out.print(name); out.print(source[208]); // 558:35 = " but does not load from db if not in cac..." out.print(name); out.print(source[209]); // 560:21 = " the unique key * @return the pdo, nu..." out.print(pdoType); out.print(source[210]); // 564:20 = " selectCachedOnlyBy" out.print(suffix); out.print(source[211]); // 564:49 = "(" out.print(type); out.print(source[212]); // 564:58 = " " out.print(name); out.print(source[213]); // 564:67 = ") { return " out.print(filterBegin); out.print(source[214]); // 565:26 = "getCache().select(" out.print(indexMethod); out.print(source[215]); // 565:59 = "(), getDomainContext(), " out.print(name); out.print(source[216]); // 565:91 = ", false)" out.print(filterEnd); out.print(source[217]); // 565:112 = "; } /** * Selects via cache by " out.print(name); out.print(source[218]); // 569:34 = ". * * @param " out.print(name); out.print(source[219]); // 571:21 = " the unique key * @return the pdo, nu..." out.print(pdoType); out.print(source[220]); // 575:20 = " selectCachedBy" out.print(suffix); out.print(source[221]); // 575:45 = "(" out.print(type); out.print(source[222]); // 575:54 = " " out.print(name); out.print(source[223]); // 575:63 = ") { return " out.print(filterBegin); out.print(source[224]); // 576:26 = "getCache().select(" out.print(indexMethod); out.print(source[225]); // 576:59 = "(), getDomainContext(), " out.print(name); out.print(source[226]); // 576:91 = ")" out.print(filterEnd); out.print(source[227]); // 576:105 = "; } /** * Selects via remote cac..." out.print(name); out.print(source[228]); // 580:41 = ", if session is remote. * * @param..." out.print(name); out.print(source[229]); // 582:21 = " the unique key * @return the pdo, nu..." out.print(pdoType); out.print(source[230]); // 586:20 = " selectBy" out.print(suffix); out.print(source[231]); // 586:39 = "ForCache(" out.print(type); out.print(source[232]); // 586:56 = " " out.print(name); out.print(source[233]); // 586:65 = ") { " out.print(pdoType); out.print(source[234]); // 587:15 = " obj; if (getSession().isRemote()) {..." out.print(suffix); out.print(source[235]); // 591:52 = "ForCache(context, " out.print(name); out.print(source[236]); // 591:78 = "); configureRemoteObject(context..." out.print(suffix); out.print(source[237]); // 599:33 = "(" out.print(name); out.print(source[238]); // 599:42 = "); } return " out.print(filterBegin); out.print(source[239]); // 601:26 = "obj" out.print(filterEnd); out.print(source[240]); // 601:42 = "; }" } if (genudk) { String indexCast = isAbstract ? ("(PdoCacheIndex) ") : ""; String indexMethod = "getCacheIndexUdk"; out.print(source[241]); // 609:2 = " /** * Gets the index for the uniqu..." out.print(udkType); out.print(source[242]); // 614:39 = " " out.print(udkName); out.print(source[243]); // 614:51 = " */" if (isAbstract) { out.print(source[244]); // 618:2 = " @SuppressWarnings("unchecked")" } out.print(source[245]); // 622:2 = " protected PdoCacheIndex<" out.print(pdoType); out.print(source[246]); // 623:37 = ", " out.print(udkType); out.print(source[247]); // 623:50 = "> " out.print(indexMethod); out.print(source[248]); // 623:67 = "() { return " out.print(indexCast); out.print(source[249]); // 624:24 = "CacheHolder.UDK_INDEX; } /** * S..." out.print(udkName); out.print(source[250]); // 630:24 = " the unique domain key * @return the ..." out.print(pdoType); out.print(source[251]); // 634:20 = " selectCachedOnlyByUniqueDomainKey(" out.print(udkType); out.print(source[252]); // 634:66 = " " out.print(udkName); out.print(source[253]); // 634:78 = ") { return " out.print(filterBegin); out.print(source[254]); // 635:26 = "getCache().select(" out.print(indexMethod); out.print(source[255]); // 635:59 = "(), getDomainContext(), " out.print(udkName); out.print(source[256]); // 635:94 = ", false)" out.print(filterEnd); out.print(source[257]); // 635:115 = "; } /** * Selects via cache by u..." out.print(udkName); out.print(source[258]); // 641:24 = " the unique key * @return the pdo, nu..." out.print(pdoType); out.print(source[259]); // 645:20 = " selectCachedByUniqueDomainKey(" out.print(udkType); out.print(source[260]); // 645:62 = " " out.print(udkName); out.print(source[261]); // 645:74 = ") { return " out.print(filterBegin); out.print(source[262]); // 646:26 = "getCache().select(" out.print(indexMethod); out.print(source[263]); // 646:59 = "(), getDomainContext(), " out.print(udkName); out.print(source[264]); // 646:94 = ")" out.print(filterEnd); out.print(source[265]); // 646:108 = "; } /** * Selects via remote cac..." out.print(udkName); out.print(source[266]); // 652:24 = " the unique key * @return the pdo, nu..." out.print(pdoType); out.print(source[267]); // 656:20 = " selectByUniqueDomainKeyForCache(" out.print(udkType); out.print(source[268]); // 656:64 = " " out.print(udkName); out.print(source[269]); // 656:76 = ") { " out.print(pdoType); out.print(source[270]); // 657:15 = " obj; if (getSession().isRemote()) {..." out.print(udkName); out.print(source[271]); // 661:86 = "); configureRemoteObject(context..." out.print(udkName); out.print(source[272]); // 669:50 = "); } return " out.print(filterBegin); out.print(source[273]); // 671:26 = "obj" out.print(filterEnd); out.print(source[274]); // 671:42 = "; }" } out.print(source[275]); // 676:2 = " @Override public List<" out.print(pdoType); out.print(source[276]); // 679:25 = "> selectAllCached() { return " out.print(filterBegin); out.print(source[277]); // 680:26 = "getCache().selectAll(getDomainContext())..." out.print(filterEnd); out.print(source[278]); // 680:79 = "; }" } // ----------------- end wurblet code ----------------- }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy